1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.jour.rt.agent;
22
23 import net.sf.jour.timer.NativeTimer;
24 import net.sf.jour.util.TimeUtil;
25
26 /***
27 * TODO Add docs
28 *
29 * Created on 02.12.2004
30 *
31 * Contributing Author(s):
32 *
33 * Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
34 * Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
35 *
36 * @author michaellif
37 * @version $Revision: 1.12 $ ($Author: vlads $) $Date: 2004/12/15 08:00:37 $
38 */
39 public class ProfilerEvent
40
41 /***
42 * Stable <code>serialVersionUID</code>.
43 */
44 private static final long serialVersionUID = 29132123L;
45
46 transient private boolean isConstructed;
47
48 public static int counter = 0;
49
50 public static final int START = 0;
51 public static final int END = 1;
52
53 private double timeStamp;
54 private long id;
55
56 private int type;
57
58 private Throwable throwable;
59
60 private EventIdentifier eventIdentifier;
61
62
63 transient private String threadName;
64
65
66 private ProfilerEvent() {
67
68 }
69
70 public ProfilerEvent(int type, Throwable t, EventIdentifier eventIdentifier) {
71 synchronized (this) {
72 this.timeStamp = NativeTimer.getTimeSafe();
73 this.id = counter++;
74 }
75 this.type = type;
76 this.throwable = t;
77 if (eventIdentifier == null) {
78
79 } else {
80
81 }
82 this.eventIdentifier = eventIdentifier;
83 this.threadName = Thread.currentThread().getName();
84 }
85
86
87
88
89
90
91
92
93
94
95 public boolean onMethodStart() {
96 return (this.type == START);
97 }
98
99 public boolean onMethodEnd() {
100 return (this.type == END);
101 }
102
103 public Throwable getThrowable() {
104 return this.throwable;
105 }
106
107
108 public String getThreadName() {
109 return this.threadName;
110 }
111
112 public Object getThreadID() {
113 return this.threadName;
114 }
115
116 public void setThreadName(String threadName) {
117 this.threadName = threadName;
118 }
119
120 public boolean onConstruction() {
121 if (this.eventIdentifier != null) {
122 return this.eventIdentifier.isConstruction();
123 } else {
124 return this.getMethodName().trim().equalsIgnoreCase("<init>") && (type == END);
125 }
126 }
127
128 public boolean onDeletion() {
129 if (this.eventIdentifier != null) {
130 return this.eventIdentifier.isDeletion();
131 } else {
132 return this.getMethodName().trim().equalsIgnoreCase("finalize") && (type == END);
133 }
134 }
135
136 public String getClassName() {
137 if (this.eventIdentifier != null) {
138 return this.eventIdentifier.getClassName();
139 } else {
140 return "j1.3";
141 }
142 }
143
144 public String getMethodName() {
145 if (this.eventIdentifier != null) {
146 return this.eventIdentifier.getMethodName();
147 } else {
148 return "j1.3";
149 }
150 }
151
152 public String getMethodSignature() {
153 if (this.eventIdentifier != null) {
154 return this.eventIdentifier.getMethodSignature();
155 } else {
156 return "?";
157 }
158 }
159
160 public Object getMethodID() {
161 if (this.eventIdentifier != null) {
162 return this.eventIdentifier.getKey();
163 } else {
164 return new String("?");
165 }
166 }
167
168 public double getTimestamp() {
169 return this.timeStamp;
170 }
171
172 public long getTimestampLong() {
173 return new Double(this.timeStamp).longValue();
174 }
175
176 public String getType() {
177 return ((type == START)?"START":"END");
178 }
179
180
181
182
183
184 public String toString() {
185 return "ProfilerEvent [className=" + getClassName() + "," +
186 "methodName=" + getMethodName() + "," +
187 "threadName=" + getThreadID() + "," +
188 getType() +
189 "timeStamp=" + TimeUtil.timeStamp2string(this.timeStamp) + "]";
190 }
191 }
192