Logger update and code cleanup in profiler
This commit is contained in:
parent
c424f68a3d
commit
da0186a592
1 changed files with 29 additions and 35 deletions
|
@ -2,45 +2,39 @@ package cr0s.warpdrive;
|
|||
|
||||
import java.util.Stack;
|
||||
|
||||
public class LocalProfiler
|
||||
{
|
||||
private static class StackElement
|
||||
{
|
||||
public long start;
|
||||
public long internal;
|
||||
public String name;
|
||||
}
|
||||
public class LocalProfiler {
|
||||
private static class StackElement {
|
||||
public long start;
|
||||
public long internal;
|
||||
public String name;
|
||||
}
|
||||
|
||||
private static Stack<StackElement> stack = new Stack<StackElement>();
|
||||
private static Stack<StackElement> stack = new Stack<StackElement>();
|
||||
|
||||
public static void start(String name)
|
||||
{
|
||||
StackElement e = new StackElement();
|
||||
e.start = System.nanoTime();
|
||||
e.internal = 0;
|
||||
e.name = name;
|
||||
stack.push(e);
|
||||
}
|
||||
public static void start(String name) {
|
||||
StackElement stackElement = new StackElement();
|
||||
stackElement.start = System.nanoTime();
|
||||
stackElement.internal = 0;
|
||||
stackElement.name = name;
|
||||
stack.push(stackElement);
|
||||
}
|
||||
|
||||
public static void stop()
|
||||
{
|
||||
if (stack.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
public static void stop() {
|
||||
if (stack.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
StackElement e = stack.pop();
|
||||
long end = System.nanoTime();
|
||||
long dt = end - e.start;
|
||||
StackElement stackElement = stack.pop();
|
||||
long end = System.nanoTime();
|
||||
long dt = end - stackElement.start;
|
||||
|
||||
if (!stack.isEmpty())
|
||||
{
|
||||
StackElement e2 = stack.peek();
|
||||
e2.internal += dt;
|
||||
}
|
||||
if (!stack.isEmpty()) {
|
||||
StackElement nextStackElement = stack.peek();
|
||||
nextStackElement.internal += dt;
|
||||
}
|
||||
|
||||
long self = (dt - e.internal) / 1000; // in microseconds
|
||||
long total = dt / 1000;
|
||||
WarpDrive.print("[PROF] {" + e.name + "} self: " + (self / 1000F) + "ms, total: " + (total / 1000F) + "ms");
|
||||
}
|
||||
long self = (dt - stackElement.internal) / 1000; // in microseconds
|
||||
long total = dt / 1000;
|
||||
WarpDrive.logger.fine("Profiling '" + stackElement.name + "': " + (self / 1000.0F) + " ms, total: " + (total / 1000.0F) + " ms");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue