1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
require 'spec/profiler/profiler_spec_helpers'
describe JRuby::Profiler, "::JsonProfilePrinter" do
include JRuby::Profiler::SpecHelpers
context 'when printing an empty profile' do
before do
@profile_data = JRuby::Profiler.profile {}
end
it 'contains only the top invocation' do
json_output['methods'].length.should equal(1)
json_output['methods'].first['name'].should == '(top)'
end
it 'contains the total duration' do
json_output['total_time'].should == 0.0
end
it 'outputs the name of the thread' do
json_output['thread_name'].should == 'main'
end
end
context 'when printing a profile' do
before do
obj = ProfilerTest.new
@profile_data = JRuby::Profiler.profile do
obj.wait(0.01)
obj.test_instance_method
end
end
it 'outputs the total duration' do
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' }
end
let :top_invocation do
json_output['methods'].find { |m| m['name'] == '(top)' }
end
it 'contains the number of calls, total, self and child time' do
method_invocation.should include('total_calls' => 1, 'total_time' => anything, 'self_time' => anything, 'child_time' => anything)
end
it 'contains data on the calls from parents, including calls, total, self and child time' do
method_invocation['parents'].length.should equal(1)
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'].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
end
|