forked from pquiring/javaforce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJFProfiler.java
More file actions
43 lines (37 loc) · 843 Bytes
/
Copy pathJFProfiler.java
File metadata and controls
43 lines (37 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package javaforce;
/** JFProfiler
*
* @author pquiring
*/
public class JFProfiler {
private long[] ms;
private String[] names;
private int step;
private String name;
private StringBuilder sb = new StringBuilder();
public JFProfiler(String name, int steps) {
steps++;
this.name = name;
ms = new long[steps];
names = new String[steps];
}
public void start() {
ms[0] = System.currentTimeMillis();
step = 1;
}
public void step(String name) {
ms[step] = System.currentTimeMillis();
names[step] = name;
step++;
}
public void stop() {
sb.setLength(0);
sb.append(name);
sb.append(":");
for(int i=1;i<step;i++) {
long delta = ms[i] - ms[i - 1];
sb.append(String.format("%02dms=(%s) ", delta, names[i]));
}
System.out.println(sb.toString());
}
}