Permalink
Browse files

JSON profile printer outputs durations in seconds, instead of nanos

  • Loading branch information...
iconara committed Aug 23, 2012
1 parent c5ec25f commit 3a720edeac4e6e042bfc460d5f736057adb288ef
Showing with 12 additions and 6 deletions.
  1. +12 −6 src/org/jruby/runtime/profile/JsonProfilePrinter.java
@@ -28,11 +28,13 @@
import java.io.PrintStream;
import java.util.Iterator;
+import java.util.Locale;
import org.jruby.util.collections.IntHashMap;
public class JsonProfilePrinter extends ProfilePrinter {
+ private static Locale JSON_LOCALE = Locale.ROOT;
public JsonProfilePrinter(ProfileData profileData) {
super(profileData);
@@ -68,9 +70,9 @@ private String methodToJson(MethodData method) {
"id", quote(method.serialNumber),
"name", quote(methodName(method.serialNumber)),
"total_calls", String.valueOf(method.totalCalls()),
- "total_time", String.valueOf(method.totalTime()),
- "self_time", String.valueOf(method.selfTime()),
- "child_time", String.valueOf(method.childTime()),
+ "total_time", nanosToSecondsString(method.totalTime()),
+ "self_time", nanosToSecondsString(method.selfTime()),
+ "child_time", nanosToSecondsString(method.childTime()),
"parents", parentCallsToJson(method),
"children", childCallsToJson(method)
);
@@ -110,12 +112,16 @@ private String callToJson(int serial, int calls, InvocationSet invocations) {
return toJsonObject(
"id", quote(serial),
"total_calls", String.valueOf(calls),
- "total_time", String.valueOf(invocations.totalTime()),
- "self_time", String.valueOf(invocations.selfTime()),
- "child_time", String.valueOf(invocations.childTime())
+ "total_time", nanosToSecondsString(invocations.totalTime()),
+ "self_time", nanosToSecondsString(invocations.selfTime()),
+ "child_time", nanosToSecondsString(invocations.childTime())
);
}
+ private String nanosToSecondsString(long nanos) {
+ return String.format(JSON_LOCALE, "%f", nanos/1.0e9);
+ }
+
private String quote(String str) {
return String.format("\"%s\"", str);
}

0 comments on commit 3a720ed

Please sign in to comment.