Skip to content
Browse files

The JSON profile printer now outputs the thread name

  • Loading branch information...
1 parent 645a103 commit b70062d86c8b4335cb1f2d180191785ae43e1f21 @iconara committed
View
9 spec/profiler/json_profile_printer_spec.rb
@@ -16,6 +16,11 @@
it 'contains the total duration' do
json_output['total_time'].should == 0.0
end
+
+ it 'outputs the name of the thread' do
+ puts json_output
+ json_output['thread_name'].should == 'main'
+ end
end
context 'when printing a profile' do
@@ -31,6 +36,10 @@
json_output['total_time'].should > 0.0
end
+ it 'outputs the name of the thread' do
+ json_output['thread_name'].should == 'main'
+ end
+
context 'outputs method data which' do
let :method_invocation do
json_output['methods'].find { |m| m['name'] == 'ProfilerTest#test_instance_method' }
View
5 src/org/jruby/runtime/profile/JsonProfilePrinter.java
@@ -45,8 +45,9 @@ public JsonProfilePrinter(ProfileData profileData) {
public void printProfile(PrintStream out) {
Invocation topInvocation = getTopInvocation();
IntHashMap<MethodData> methods = methodData(topInvocation);
+ String threadName = getProfileData().getThreadContext().getThread().getNativeThread().getName();
- out.printf("{\n\t\"total_time\":%d,\n\t\"methods\":[\n", topInvocation.getDuration());
+ out.printf("{\n\t\"total_time\":%d,\n\t\"thread_name\":\"%s\",\n\t\"methods\":[\n", topInvocation.getDuration(), threadName);
Iterator<MethodData> i = methods.values().iterator();
while (i.hasNext()) {
@@ -59,7 +60,7 @@ public void printProfile(PrintStream out) {
out.println();
}
- out.print("\n\t]\n}\n");
+ out.print("\t]\n}\n");
}
private String methodToJson(MethodData method) {

0 comments on commit b70062d

Please sign in to comment.
Something went wrong with that request. Please try again.