Skip to content

Commit

Permalink
JSON profile format change in child and parent calls
Browse files Browse the repository at this point in the history
  • Loading branch information
iconara committed Aug 23, 2012
1 parent b70062d commit c5ec25f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
13 changes: 6 additions & 7 deletions spec/profiler/json_profile_printer_spec.rb
Expand Up @@ -18,7 +18,6 @@
end

it 'outputs the name of the thread' do
puts json_output
json_output['thread_name'].should == 'main'
end
end
Expand Down Expand Up @@ -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
Expand Down
27 changes: 16 additions & 11 deletions src/org/jruby/runtime/profile/JsonProfilePrinter.java
Expand Up @@ -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())
Expand All @@ -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);
}
Expand Down

0 comments on commit c5ec25f

Please sign in to comment.