Improved profiler logs

This commit is contained in:
LemADEC 2015-09-01 23:02:01 +02:00
parent 29fcc5539d
commit 9759f468fe

View file

@ -8,9 +8,9 @@ public class LocalProfiler {
public long internal;
public String name;
}
private static Stack<StackElement> stack = new Stack<StackElement>();
public static void start(String name) {
StackElement stackElement = new StackElement();
stackElement.start = System.nanoTime();
@ -18,12 +18,12 @@ public class LocalProfiler {
stackElement.name = name;
stack.push(stackElement);
}
public static void stop() {
if (stack.isEmpty()) {
return;
}
StackElement stackElement = stack.pop();
long end = System.nanoTime();
long dt = end - stackElement.start;
@ -32,9 +32,10 @@ public class LocalProfiler {
StackElement nextStackElement = stack.peek();
nextStackElement.internal += dt;
}
long self = (dt - stackElement.internal) / 1000; // in microseconds
// convert to microseconds
long self = (dt - stackElement.internal) / 1000;
long total = dt / 1000;
WarpDrive.logger.info("Profiling '" + stackElement.name + "': " + (self / 1000.0F) + " ms, total: " + (total / 1000.0F) + " ms");
WarpDrive.logger.info("Profiling " + stackElement.name + ": " + (self / 1000.0F) + " ms" + ((total == self) ? "" : (", total: " + (total / 1000.0F) + " ms")));
}
}