Profiler can be paused
This commit is contained in:
@@ -57,7 +57,9 @@ public class Profiler {
|
|||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final PrintStream out;
|
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 StackTraceElement[] stackTrace;
|
||||||
private boolean mute;
|
private boolean mute;
|
||||||
|
|
||||||
@@ -114,16 +116,24 @@ public class Profiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Profiler start() {
|
public Profiler start() {
|
||||||
start = System.nanoTime();
|
if (!paused) {
|
||||||
|
start = System.nanoTime();
|
||||||
|
paused = false;
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Profiler end() {
|
public Profiler end() {
|
||||||
long delta = System.nanoTime() - start;
|
long result = cumulative;
|
||||||
|
if (!paused) {
|
||||||
|
result += System.nanoTime() - start;
|
||||||
|
}
|
||||||
|
paused = true;
|
||||||
|
cumulative = 0;
|
||||||
|
|
||||||
OUT_LOCK.lock();
|
OUT_LOCK.lock();
|
||||||
try {
|
try {
|
||||||
println(name, " took ", format(delta));
|
println(name, " took ", format(result));
|
||||||
printStackTrace();
|
printStackTrace();
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -133,6 +143,14 @@ public class Profiler {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Profiler pause() {
|
||||||
|
if (!paused) {
|
||||||
|
cumulative += System.nanoTime() - start;
|
||||||
|
paused = true;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Profiler mute() {
|
public Profiler mute() {
|
||||||
mute = true;
|
mute = true;
|
||||||
return this;
|
return this;
|
||||||
|
|||||||
Reference in New Issue
Block a user