Profiler can be paused

This commit is contained in:
Andrey Breslav
2013-05-09 12:01:17 +03:00
parent e351dfca12
commit ba4c012000
@@ -57,7 +57,9 @@ public class Profiler {
private final String name;
private final PrintStream out;
private long start;
private long start = Long.MAX_VALUE;
private long cumulative = 0;
private boolean paused = true;
private StackTraceElement[] stackTrace;
private boolean mute;
@@ -114,16 +116,24 @@ public class Profiler {
}
public Profiler start() {
start = System.nanoTime();
if (!paused) {
start = System.nanoTime();
paused = false;
}
return this;
}
public Profiler end() {
long delta = System.nanoTime() - start;
long result = cumulative;
if (!paused) {
result += System.nanoTime() - start;
}
paused = true;
cumulative = 0;
OUT_LOCK.lock();
try {
println(name, " took ", format(delta));
println(name, " took ", format(result));
printStackTrace();
}
finally {
@@ -133,6 +143,14 @@ public class Profiler {
return this;
}
public Profiler pause() {
if (!paused) {
cumulative += System.nanoTime() - start;
paused = true;
}
return this;
}
public Profiler mute() {
mute = true;
return this;