Allow to configure print accuracy and fetch temprory results from profiler

This commit is contained in:
Nikolay Krasko
2016-01-12 14:51:38 +03:00
committed by Nikolay Krasko
parent 61bd0e7265
commit 5431c6937f
@@ -68,10 +68,12 @@ public class Profiler {
private boolean paused = true; private boolean paused = true;
private StackTraceElement[] stackTrace; private StackTraceElement[] stackTrace;
private boolean mute; private boolean mute;
private String formatString;
private Profiler(@NotNull String name, @NotNull Logger log) { private Profiler(@NotNull String name, @NotNull Logger log) {
this.name = name; this.name = name;
this.log = log; this.log = log;
setPrintAccuracy(3);
} }
public Profiler recordStackTrace(int depth) { public Profiler recordStackTrace(int depth) {
@@ -164,6 +166,10 @@ public class Profiler {
return this; return this;
} }
public long getCumulative() {
return cumulative;
}
public Profiler mute() { public Profiler mute() {
mute = true; mute = true;
return this; return this;
@@ -227,7 +233,12 @@ public class Profiler {
return this; return this;
} }
private static String format(long delta) { public Profiler setPrintAccuracy(int accuracy) {
return String.format("%.3fs", delta / 1e9); formatString = "%." + accuracy + "fs";
return this;
}
private String format(long delta) {
return String.format(formatString, delta / 1e9);
} }
} }