Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

JSON profile format change in child and parent calls

  • Loading branch information...
commit c5ec25fcc5da0f294436a720579272251ba5c0e7 1 parent b70062d
@iconara authored
View
13 spec/profiler/json_profile_printer_spec.rb
@@ -18,7 +18,6 @@
end
it 'outputs the name of the thread' do
- puts json_output
json_output['thread_name'].should == 'main'
end
end
@@ -55,17 +54,17 @@
it 'contains data on the calls from parents, including calls, total, self and child time' do
method_invocation['parents'].should have(1).item
- call_data = method_invocation['parents'][top_invocation['id']]
- call_data.should include('calls' => 1, 'total_time' => anything, 'self_time' => anything, 'child_time' => anything)
+ call_data = method_invocation['parents'].find { |c| c['id'] == top_invocation['id'] }
+ call_data.should include('total_calls' => 1, 'total_time' => anything, 'self_time' => anything, 'child_time' => anything)
end
it 'contains data on the calls to children' do
method1_invocation = json_output['methods'].find { |m| m['name'] == 'ProfilerTest#wait' }
method2_invocation = json_output['methods'].find { |m| m['name'] == 'ProfilerTest#test_instance_method' }
- call1_data = top_invocation['children'][method1_invocation['id']]
- call1_data.should include('calls' => 1, 'total_time' => anything, 'self_time' => anything, 'child_time' => anything)
- call2_data = top_invocation['children'][method2_invocation['id']]
- call2_data.should include('calls' => 1, 'total_time' => anything, 'self_time' => anything, 'child_time' => anything)
+ call1_data = top_invocation['children'].find { |c| c['id'] == method1_invocation['id'] }
+ call1_data.should include('total_calls' => 1, 'total_time' => anything, 'self_time' => anything, 'child_time' => anything)
+ call2_data = top_invocation['children'].find { |c| c['id'] == method2_invocation['id'] }
+ call2_data.should include('total_calls' => 1, 'total_time' => anything, 'self_time' => anything, 'child_time' => anything)
end
end
end
View
27 src/org/jruby/runtime/profile/JsonProfilePrinter.java
@@ -78,37 +78,38 @@ private String methodToJson(MethodData method) {
private String parentCallsToJson(MethodData method) {
if (method.serialNumber == 0) {
- return toJsonObject(new String[] { });
+ return toJsonArray(new String[] { });
} else {
int[] parentSerials = method.parents();
- String[] parentCalls = new String[parentSerials.length * 2];
+ String[] parentCalls = new String[parentSerials.length];
for (int i = 0; i < parentSerials.length; i++) {
- parentCalls[i * 2] = String.valueOf(parentSerials[i]);
- parentCalls[i * 2 + 1] = callToJson(
+ parentCalls[i] = callToJson(
+ parentSerials[i],
method.invocationsFromParent(parentSerials[i]).totalCalls(),
method.rootInvocationsFromParent(parentSerials[i])
);
}
- return toJsonObject(parentCalls);
+ return toJsonArray(parentCalls);
}
}
private String childCallsToJson(MethodData method) {
int[] childSerials = method.children();
- String[] childCalls = new String[childSerials.length * 2];
+ String[] childCalls = new String[childSerials.length];
for (int i = 0; i < childSerials.length; i++) {
- childCalls[i * 2] = String.valueOf(childSerials[i]);
- childCalls[i * 2 + 1] = callToJson(
+ childCalls[i] = callToJson(
+ childSerials[i],
method.invocationsOfChild(childSerials[i]).totalCalls(),
method.rootInvocationsOfChild(childSerials[i])
);
}
- return toJsonObject(childCalls);
+ return toJsonArray(childCalls);
}
- private String callToJson(int calls, InvocationSet invocations) {
+ private String callToJson(int serial, int calls, InvocationSet invocations) {
return toJsonObject(
- "calls", String.valueOf(calls),
+ "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())
@@ -119,6 +120,10 @@ private String quote(String str) {
return String.format("\"%s\"", str);
}
+ private String quote(int num) {
+ return String.format("\"%d\"", num);
+ }
+
private String quote(long num) {
return String.format("\"%d\"", num);
}
Please sign in to comment.
Something went wrong with that request. Please try again.