ruby-prof 0.16.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/CHANGES +532 -467
- data/LICENSE +24 -24
- data/README.rdoc +5 -454
- data/Rakefile +110 -113
- data/bin/ruby-prof +380 -340
- data/bin/ruby-prof-check-trace +45 -45
- data/ext/ruby_prof/extconf.rb +36 -64
- data/ext/ruby_prof/rp_allocation.c +279 -0
- data/ext/ruby_prof/rp_allocation.h +31 -0
- data/ext/ruby_prof/rp_call_info.c +271 -407
- data/ext/ruby_prof/rp_call_info.h +35 -48
- data/ext/ruby_prof/rp_measure_allocations.c +52 -76
- data/ext/ruby_prof/rp_measure_memory.c +42 -77
- data/ext/ruby_prof/rp_measure_process_time.c +67 -71
- data/ext/ruby_prof/rp_measure_wall_time.c +62 -45
- data/ext/ruby_prof/rp_measurement.c +230 -0
- data/ext/ruby_prof/rp_measurement.h +50 -0
- data/ext/ruby_prof/rp_method.c +630 -411
- data/ext/ruby_prof/rp_method.h +70 -52
- data/ext/ruby_prof/rp_profile.c +895 -0
- data/ext/ruby_prof/rp_profile.h +37 -0
- data/ext/ruby_prof/rp_stack.c +196 -128
- data/ext/ruby_prof/rp_stack.h +56 -51
- data/ext/ruby_prof/rp_thread.c +337 -273
- data/ext/ruby_prof/rp_thread.h +36 -27
- data/ext/ruby_prof/ruby_prof.c +48 -671
- data/ext/ruby_prof/ruby_prof.h +17 -56
- data/ext/ruby_prof/vc/ruby_prof.sln +20 -21
- data/ext/ruby_prof/vc/{ruby_prof_20.vcxproj → ruby_prof.vcxproj} +38 -5
- data/lib/ruby-prof.rb +52 -58
- data/lib/ruby-prof/assets/call_stack_printer.html.erb +713 -0
- data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
- data/lib/ruby-prof/assets/graph_printer.html.erb +356 -0
- data/lib/ruby-prof/call_info.rb +57 -126
- data/lib/ruby-prof/call_info_visitor.rb +38 -40
- data/lib/ruby-prof/compatibility.rb +109 -178
- data/lib/ruby-prof/exclude_common_methods.rb +198 -0
- data/lib/ruby-prof/measurement.rb +14 -0
- data/lib/ruby-prof/method_info.rb +90 -129
- data/lib/ruby-prof/printers/abstract_printer.rb +127 -85
- data/lib/ruby-prof/printers/call_info_printer.rb +51 -41
- data/lib/ruby-prof/printers/call_stack_printer.rb +182 -260
- data/lib/ruby-prof/printers/call_tree_printer.rb +151 -130
- data/lib/ruby-prof/printers/dot_printer.rb +132 -132
- data/lib/ruby-prof/printers/flat_printer.rb +52 -70
- data/lib/ruby-prof/printers/graph_html_printer.rb +63 -244
- data/lib/ruby-prof/printers/graph_printer.rb +114 -116
- data/lib/ruby-prof/printers/multi_printer.rb +127 -58
- data/lib/ruby-prof/profile.rb +33 -55
- data/lib/ruby-prof/rack.rb +171 -95
- data/lib/ruby-prof/task.rb +147 -147
- data/lib/ruby-prof/thread.rb +35 -41
- data/lib/ruby-prof/version.rb +3 -3
- data/lib/unprof.rb +10 -10
- data/ruby-prof.gemspec +58 -57
- data/test/abstract_printer_test.rb +26 -0
- data/test/alias_test.rb +129 -0
- data/test/basic_test.rb +129 -128
- data/test/call_info_visitor_test.rb +31 -31
- data/test/duplicate_names_test.rb +32 -32
- data/test/dynamic_method_test.rb +53 -55
- data/test/enumerable_test.rb +21 -21
- data/test/exceptions_test.rb +24 -16
- data/test/exclude_methods_test.rb +146 -0
- data/test/exclude_threads_test.rb +53 -53
- data/test/fiber_test.rb +73 -79
- data/test/gc_test.rb +96 -0
- data/test/line_number_test.rb +161 -71
- data/test/marshal_test.rb +119 -0
- data/test/measure_allocations.rb +30 -0
- data/test/measure_allocations_test.rb +385 -26
- data/test/measure_allocations_trace_test.rb +385 -0
- data/test/measure_memory_trace_test.rb +756 -0
- data/test/measure_process_time_test.rb +849 -63
- data/test/measure_times.rb +54 -0
- data/test/measure_wall_time_test.rb +459 -255
- data/test/multi_printer_test.rb +71 -83
- data/test/no_method_class_test.rb +15 -15
- data/test/parser_timings.rb +24 -0
- data/test/pause_resume_test.rb +166 -166
- data/test/prime.rb +56 -54
- data/test/printer_call_stack_test.rb +28 -0
- data/test/printer_call_tree_test.rb +31 -0
- data/test/printer_flat_test.rb +68 -0
- data/test/printer_graph_html_test.rb +60 -0
- data/test/printer_graph_test.rb +41 -0
- data/test/printers_test.rb +141 -255
- data/test/printing_recursive_graph_test.rb +81 -127
- data/test/rack_test.rb +157 -93
- data/test/recursive_test.rb +210 -215
- data/test/singleton_test.rb +38 -38
- data/test/stack_printer_test.rb +64 -78
- data/test/start_stop_test.rb +109 -112
- data/test/test_helper.rb +24 -264
- data/test/thread_test.rb +144 -187
- data/test/unique_call_path_test.rb +190 -202
- data/test/yarv_test.rb +56 -55
- metadata +34 -114
- data/doc/LICENSE.html +0 -114
- data/doc/README_rdoc.html +0 -603
- data/doc/Rack.html +0 -95
- data/doc/Rack/RubyProf.html +0 -226
- data/doc/RubyProf.html +0 -962
- data/doc/RubyProf/AbstractPrinter.html +0 -546
- data/doc/RubyProf/AggregateCallInfo.html +0 -551
- data/doc/RubyProf/CallInfo.html +0 -639
- data/doc/RubyProf/CallInfoPrinter.html +0 -120
- data/doc/RubyProf/CallInfoVisitor.html +0 -198
- data/doc/RubyProf/CallStackPrinter.html +0 -1121
- data/doc/RubyProf/CallTreePrinter.html +0 -641
- data/doc/RubyProf/Cmd.html +0 -631
- data/doc/RubyProf/DotPrinter.html +0 -257
- data/doc/RubyProf/FlatPrinter.html +0 -163
- data/doc/RubyProf/FlatPrinterWithLineNumbers.html +0 -208
- data/doc/RubyProf/GraphHtmlPrinter.html +0 -552
- data/doc/RubyProf/GraphPrinter.html +0 -139
- data/doc/RubyProf/MethodInfo.html +0 -745
- data/doc/RubyProf/MultiPrinter.html +0 -360
- data/doc/RubyProf/Profile.html +0 -763
- data/doc/RubyProf/ProfileTask.html +0 -490
- data/doc/RubyProf/Thread.html +0 -310
- data/doc/created.rid +0 -31
- data/doc/css/fonts.css +0 -167
- data/doc/css/rdoc.css +0 -590
- data/doc/examples/flat_txt.html +0 -138
- data/doc/examples/graph_html.html +0 -909
- data/doc/examples/graph_txt.html +0 -247
- data/doc/fonts/Lato-Light.ttf +0 -0
- data/doc/fonts/Lato-LightItalic.ttf +0 -0
- data/doc/fonts/Lato-Regular.ttf +0 -0
- data/doc/fonts/Lato-RegularItalic.ttf +0 -0
- data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
- data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
- data/doc/images/add.png +0 -0
- data/doc/images/arrow_up.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/loadingAnimation.gif +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +0 -626
- data/doc/js/darkfish.js +0 -161
- data/doc/js/jquery.js +0 -4
- data/doc/js/navigation.js +0 -142
- data/doc/js/navigation.js.gz +0 -0
- data/doc/js/search.js +0 -109
- data/doc/js/search_index.js +0 -1
- data/doc/js/search_index.js.gz +0 -0
- data/doc/js/searcher.js +0 -228
- data/doc/js/searcher.js.gz +0 -0
- data/doc/table_of_contents.html +0 -942
- data/examples/cachegrind.out.1 +0 -114
- data/examples/cachegrind.out.1.32313213 +0 -114
- data/examples/flat.txt +0 -50
- data/examples/graph.dot +0 -84
- data/examples/graph.html +0 -823
- data/examples/graph.txt +0 -139
- data/examples/multi.flat.txt +0 -23
- data/examples/multi.graph.html +0 -760
- data/examples/multi.grind.dat +0 -114
- data/examples/multi.stack.html +0 -547
- data/examples/stack.html +0 -547
- data/ext/ruby_prof/rp_measure.c +0 -40
- data/ext/ruby_prof/rp_measure.h +0 -45
- data/ext/ruby_prof/rp_measure_cpu_time.c +0 -136
- data/ext/ruby_prof/rp_measure_gc_runs.c +0 -73
- data/ext/ruby_prof/rp_measure_gc_time.c +0 -60
- data/ext/ruby_prof/vc/ruby_prof_18.vcxproj +0 -108
- data/ext/ruby_prof/vc/ruby_prof_19.vcxproj +0 -110
- data/lib/ruby-prof/aggregate_call_info.rb +0 -76
- data/lib/ruby-prof/assets/call_stack_printer.css.html +0 -117
- data/lib/ruby-prof/assets/call_stack_printer.js.html +0 -385
- data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -64
- data/test/aggregate_test.rb +0 -136
- data/test/block_test.rb +0 -74
- data/test/call_info_test.rb +0 -78
- data/test/issue137_test.rb +0 -63
- data/test/measure_cpu_time_test.rb +0 -213
- data/test/measure_gc_runs_test.rb +0 -32
- data/test/measure_gc_time_test.rb +0 -36
- data/test/measure_memory_test.rb +0 -33
- data/test/method_elimination_test.rb +0 -84
- data/test/module_test.rb +0 -45
- data/test/stack_test.rb +0 -138
@@ -1,64 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module RubyProf
|
4
|
-
# Generates flat[link:files/examples/flat_txt.html] profile reports as text.
|
5
|
-
# To use the flat printer with line numbers:
|
6
|
-
#
|
7
|
-
# result = RubyProf.profile do
|
8
|
-
# [code to profile]
|
9
|
-
# end
|
10
|
-
#
|
11
|
-
# printer = RubyProf::FlatPrinterWithLineNumbers.new(result)
|
12
|
-
# printer.print(STDOUT, {})
|
13
|
-
#
|
14
|
-
class FlatPrinterWithLineNumbers < FlatPrinter
|
15
|
-
def print_methods(thread)
|
16
|
-
total_time = thread.total_time
|
17
|
-
|
18
|
-
methods = thread.methods.sort_by(&sort_method).reverse
|
19
|
-
sum = 0
|
20
|
-
methods.each do |method|
|
21
|
-
self_percent = (method.self_time / total_time) * 100
|
22
|
-
next if self_percent < min_percent
|
23
|
-
|
24
|
-
sum += method.self_time
|
25
|
-
#self_time_called = method.called > 0 ? method.self_time/method.called : 0
|
26
|
-
#total_time_called = method.called > 0? method.total_time/method.called : 0
|
27
|
-
|
28
|
-
@output << "%6.2f %9.3f %9.3f %9.3f %9.3f %8d %s%s" % [
|
29
|
-
method.self_time / total_time * 100, # %self
|
30
|
-
method.total_time, # total
|
31
|
-
method.self_time, # self
|
32
|
-
method.wait_time, # wait
|
33
|
-
method.children_time, # children
|
34
|
-
method.called, # calls
|
35
|
-
method.recursive? ? "*" : " ", # cycle
|
36
|
-
method_name(method) # name
|
37
|
-
]
|
38
|
-
if method.source_file == 'ruby_runtime'
|
39
|
-
@output << "\n"
|
40
|
-
else
|
41
|
-
@output << "\n defined at:\n"
|
42
|
-
@output << " %s:%s\n" % [File.expand_path(method.source_file), method.line]
|
43
|
-
end
|
44
|
-
|
45
|
-
callers = []
|
46
|
-
method.call_infos.each do |ci|
|
47
|
-
if ci.parent && ci.parent.target.source_file != 'ruby_runtime'
|
48
|
-
callers << [method_name(ci.parent.target), File.expand_path(ci.parent.target.source_file), ci.parent.target.line]
|
49
|
-
end
|
50
|
-
end
|
51
|
-
# make sure callers are unique
|
52
|
-
callers.uniq!
|
53
|
-
|
54
|
-
unless callers.empty?
|
55
|
-
@output << " called from:\n"
|
56
|
-
callers.each do |args|
|
57
|
-
@output << " %s (%s:%s)\n" % args
|
58
|
-
end
|
59
|
-
end
|
60
|
-
@output << "\n"
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
data/test/aggregate_test.rb
DELETED
@@ -1,136 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
require File.expand_path('../test_helper', __FILE__)
|
5
|
-
|
6
|
-
# Test data
|
7
|
-
# A B C
|
8
|
-
# | | |
|
9
|
-
# Z A A
|
10
|
-
# | |
|
11
|
-
# Z Z
|
12
|
-
|
13
|
-
class AggClass
|
14
|
-
def z
|
15
|
-
sleep 1
|
16
|
-
end
|
17
|
-
|
18
|
-
def a
|
19
|
-
z
|
20
|
-
end
|
21
|
-
|
22
|
-
def b
|
23
|
-
a
|
24
|
-
end
|
25
|
-
|
26
|
-
def c
|
27
|
-
a
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class AggregateTest < TestCase
|
32
|
-
def setup
|
33
|
-
# Need to use wall time for this test due to the sleep calls
|
34
|
-
RubyProf::measure_mode = RubyProf::WALL_TIME
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_all_call_infos_are_not_recursive
|
38
|
-
c1 = AggClass.new
|
39
|
-
result = RubyProf.profile do
|
40
|
-
c1.a
|
41
|
-
c1.b
|
42
|
-
c1.c
|
43
|
-
end
|
44
|
-
methods = result.threads.first.methods.sort.reverse
|
45
|
-
methods.each do |m|
|
46
|
-
m.call_infos.each do |ci|
|
47
|
-
assert(!ci.recursive)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_call_infos
|
53
|
-
c1 = AggClass.new
|
54
|
-
result = RubyProf.profile do
|
55
|
-
c1.a
|
56
|
-
c1.b
|
57
|
-
c1.c
|
58
|
-
end
|
59
|
-
|
60
|
-
methods = result.threads.first.methods.sort.reverse
|
61
|
-
method = methods.find {|meth| meth.full_name == 'AggClass#z'}
|
62
|
-
|
63
|
-
# Check AggClass#z
|
64
|
-
assert_equal('AggClass#z', method.full_name)
|
65
|
-
assert_equal(3, method.called)
|
66
|
-
assert_in_delta(3, method.total_time, 0.05)
|
67
|
-
assert_in_delta(0, method.wait_time, 0.05)
|
68
|
-
assert_in_delta(0, method.self_time, 0.05)
|
69
|
-
assert_in_delta(3, method.children_time, 0.05)
|
70
|
-
assert_equal(3, method.call_infos.length)
|
71
|
-
|
72
|
-
call_info = method.call_infos[0]
|
73
|
-
assert_equal('AggregateTest#test_call_infos->AggClass#a->AggClass#z', call_info.call_sequence)
|
74
|
-
assert_equal(1, call_info.children.length)
|
75
|
-
|
76
|
-
call_info = method.call_infos[1]
|
77
|
-
assert_equal('AggregateTest#test_call_infos->AggClass#b->AggClass#a->AggClass#z', call_info.call_sequence)
|
78
|
-
assert_equal(1, call_info.children.length)
|
79
|
-
|
80
|
-
call_info = method.call_infos[2]
|
81
|
-
assert_equal('AggregateTest#test_call_infos->AggClass#c->AggClass#a->AggClass#z', call_info.call_sequence)
|
82
|
-
assert_equal(1, call_info.children.length)
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_aggregates_parents
|
86
|
-
c1 = AggClass.new
|
87
|
-
result = RubyProf.profile do
|
88
|
-
c1.a
|
89
|
-
c1.b
|
90
|
-
c1.c
|
91
|
-
end
|
92
|
-
|
93
|
-
methods = result.threads.first.methods.sort.reverse
|
94
|
-
method = methods.find {|meth| meth.full_name == 'AggClass#z'}
|
95
|
-
|
96
|
-
# Check AggClass#z
|
97
|
-
assert_equal('AggClass#z', method.full_name)
|
98
|
-
|
99
|
-
call_infos = method.aggregate_parents
|
100
|
-
assert_equal(1, call_infos.length)
|
101
|
-
|
102
|
-
call_info = call_infos.first
|
103
|
-
assert_equal('AggClass#a', call_info.parent.target.full_name)
|
104
|
-
assert_in_delta(3, call_info.total_time, 0.05)
|
105
|
-
assert_in_delta(0, call_info.wait_time, 0.05)
|
106
|
-
assert_in_delta(0, call_info.self_time, 0.05)
|
107
|
-
assert_in_delta(3, call_info.children_time, 0.05)
|
108
|
-
assert_equal(3, call_info.called)
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_aggregates_children
|
112
|
-
c1 = AggClass.new
|
113
|
-
result = RubyProf.profile do
|
114
|
-
c1.a
|
115
|
-
c1.b
|
116
|
-
c1.c
|
117
|
-
end
|
118
|
-
|
119
|
-
methods = result.threads.first.methods.sort.reverse
|
120
|
-
method = methods.find {|meth| meth.full_name == 'AggClass#a'}
|
121
|
-
|
122
|
-
# Check AggClass#a
|
123
|
-
assert_equal('AggClass#a', method.full_name)
|
124
|
-
|
125
|
-
call_infos = method.aggregate_children
|
126
|
-
assert_equal(1, call_infos.length)
|
127
|
-
|
128
|
-
call_info = call_infos.first
|
129
|
-
assert_equal('AggClass#z', call_info.target.full_name)
|
130
|
-
assert_in_delta(3, call_info.total_time, 0.05)
|
131
|
-
assert_in_delta(0, call_info.wait_time, 0.05)
|
132
|
-
assert_in_delta(0, call_info.self_time, 0.05)
|
133
|
-
assert_in_delta(3, call_info.children_time, 0.05)
|
134
|
-
assert_equal(3, call_info.called)
|
135
|
-
end
|
136
|
-
end
|
data/test/block_test.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
require File.expand_path("../test_helper", __FILE__)
|
5
|
-
|
6
|
-
class BlockMethodTest < TestCase
|
7
|
-
def setup
|
8
|
-
# Need to use wall time for this test due to the sleep calls
|
9
|
-
RubyProf::measure_mode = RubyProf::WALL_TIME
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_block
|
13
|
-
result = RubyProf.profile do
|
14
|
-
1.times { RubyProf::C1.new.hello }
|
15
|
-
end
|
16
|
-
|
17
|
-
# Methods called
|
18
|
-
# Kernel#sleep
|
19
|
-
# <Class::BasicObject>#allocate
|
20
|
-
# #{RubyProf.parent_object}#inizialize
|
21
|
-
# RubyProf::C1#hello
|
22
|
-
# Class#new
|
23
|
-
# Integer#times
|
24
|
-
# BlockMethodTest#test_block
|
25
|
-
|
26
|
-
methods = result.threads.first.methods.sort.reverse
|
27
|
-
assert_equal(RubyProf.ruby_2? ? 6 : 7, methods.length)
|
28
|
-
|
29
|
-
# Check times
|
30
|
-
assert_equal("BlockMethodTest#test_block", methods[0].full_name)
|
31
|
-
assert_in_delta(0.2, methods[0].total_time, 0.02)
|
32
|
-
assert_in_delta(0.0, methods[0].wait_time, 0.02)
|
33
|
-
assert_in_delta(0.0, methods[0].self_time, 0.02)
|
34
|
-
|
35
|
-
assert_equal("Integer#times", methods[1].full_name)
|
36
|
-
assert_in_delta(0.2, methods[1].total_time, 0.02)
|
37
|
-
assert_in_delta(0.0, methods[1].wait_time, 0.02)
|
38
|
-
assert_in_delta(0.0, methods[1].self_time, 0.02)
|
39
|
-
|
40
|
-
assert_equal("RubyProf::C1#hello", methods[2].full_name)
|
41
|
-
assert_in_delta(0.2, methods[2].total_time, 0.02)
|
42
|
-
assert_in_delta(0.0, methods[2].wait_time, 0.02)
|
43
|
-
assert_in_delta(0.0, methods[2].self_time, 0.02)
|
44
|
-
|
45
|
-
assert_equal("Kernel#sleep", methods[3].full_name)
|
46
|
-
assert_in_delta(0.2, methods[3].total_time, 0.01)
|
47
|
-
assert_in_delta(0.0, methods[3].wait_time, 0.01)
|
48
|
-
assert_in_delta(0.2, methods[3].self_time, 0.01)
|
49
|
-
|
50
|
-
assert_equal("Class#new", methods[4].full_name)
|
51
|
-
assert_in_delta(0.0, methods[4].total_time, 0.01)
|
52
|
-
assert_in_delta(0.0, methods[4].wait_time, 0.01)
|
53
|
-
assert_in_delta(0.0, methods[4].self_time, 0.01)
|
54
|
-
|
55
|
-
# the timing difference between #initialize and #allocate is so small
|
56
|
-
# that we cannot rely on #initialize appearing first.
|
57
|
-
# so switch them, if necessary
|
58
|
-
if methods[5].full_name =~ /#allocate/
|
59
|
-
methods[5], methods[6] = methods[6], methods[5]
|
60
|
-
end
|
61
|
-
|
62
|
-
assert_equal("#{RubyProf.parent_object}#initialize", methods[5].full_name)
|
63
|
-
assert_in_delta(0.0, methods[5].total_time, 0.01)
|
64
|
-
assert_in_delta(0.0, methods[5].wait_time, 0.01)
|
65
|
-
assert_in_delta(0.0, methods[5].self_time, 0.01)
|
66
|
-
|
67
|
-
unless RubyProf.ruby_2?
|
68
|
-
assert_equal("<Class::#{RubyProf.parent_object}>#allocate", methods[6].full_name)
|
69
|
-
assert_in_delta(0.0, methods[6].total_time, 0.01)
|
70
|
-
assert_in_delta(0.0, methods[6].wait_time, 0.01)
|
71
|
-
assert_in_delta(0.0, methods[6].self_time, 0.01)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
data/test/call_info_test.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
require File.expand_path('../test_helper', __FILE__)
|
5
|
-
|
6
|
-
class CallInfoTest < TestCase
|
7
|
-
def setup
|
8
|
-
# Need to use wall time for this test due to the sleep calls
|
9
|
-
RubyProf::measure_mode = RubyProf::WALL_TIME
|
10
|
-
end
|
11
|
-
|
12
|
-
# def test_clone
|
13
|
-
# result = RubyProf.profile do
|
14
|
-
# RubyProf::C1.hello
|
15
|
-
# end
|
16
|
-
#
|
17
|
-
# method = result.threads.first.top_methods.first
|
18
|
-
# call_info = method.call_infos.first
|
19
|
-
# call_info_clone = call_info.clone
|
20
|
-
#
|
21
|
-
## assert_equal(call_info.target, call_info_clone.target)
|
22
|
-
# assert_equal(call_info.total_time, call_info_clone.total_time)
|
23
|
-
# end
|
24
|
-
|
25
|
-
def test_merge
|
26
|
-
result1 = RubyProf.profile do
|
27
|
-
RubyProf::C1.hello
|
28
|
-
end
|
29
|
-
|
30
|
-
methods = result1.threads.first.methods.sort.reverse
|
31
|
-
assert_equal(3, methods.length)
|
32
|
-
|
33
|
-
assert_equal('CallInfoTest#test_merge', methods[0].full_name)
|
34
|
-
assert_in_delta(0.1, methods[0].total_time, 0.01)
|
35
|
-
assert_in_delta(0, methods[0].wait_time, 0.01)
|
36
|
-
assert_in_delta(0, methods[0].self_time, 0.01)
|
37
|
-
assert_equal(1, methods[0].called)
|
38
|
-
|
39
|
-
assert_equal('<Class::RubyProf::C1>#hello', methods[1].full_name)
|
40
|
-
assert_in_delta(0.1, methods[1].total_time, 0.01)
|
41
|
-
assert_in_delta(0, methods[1].wait_time, 0.01)
|
42
|
-
assert_in_delta(0, methods[1].self_time, 0.01)
|
43
|
-
assert_equal(1, methods[1].called)
|
44
|
-
|
45
|
-
assert_equal('Kernel#sleep', methods[2].full_name)
|
46
|
-
assert_in_delta(0.1, methods[2].total_time, 0.01)
|
47
|
-
assert_in_delta(0, methods[2].wait_time, 0.01)
|
48
|
-
assert_in_delta(0.1, methods[2].self_time, 0.01)
|
49
|
-
assert_equal(1, methods[2].called)
|
50
|
-
|
51
|
-
RubyProf.profile do
|
52
|
-
RubyProf::C1.hello
|
53
|
-
end
|
54
|
-
|
55
|
-
# Merge the trees
|
56
|
-
methods = result1.threads.first.methods.sort.reverse
|
57
|
-
assert_equal(3, methods.length)
|
58
|
-
|
59
|
-
assert_equal('CallInfoTest#test_merge', methods[0].full_name)
|
60
|
-
assert_in_delta(0.1, methods[0].total_time, 0.01)
|
61
|
-
assert_in_delta(0, methods[0].wait_time, 0.01)
|
62
|
-
assert_in_delta(0, methods[0].self_time, 0.01)
|
63
|
-
assert_equal(1, methods[0].called)
|
64
|
-
|
65
|
-
assert_equal('<Class::RubyProf::C1>#hello', methods[1].full_name)
|
66
|
-
assert_in_delta(0.1, methods[1].total_time, 0.01)
|
67
|
-
assert_in_delta(0, methods[1].wait_time, 0.01)
|
68
|
-
assert_in_delta(0, methods[1].self_time, 0.01)
|
69
|
-
assert_equal(1, methods[1].called)
|
70
|
-
|
71
|
-
assert_equal('Kernel#sleep', methods[2].full_name)
|
72
|
-
assert_in_delta(0.1, methods[2].total_time, 0.01)
|
73
|
-
assert_in_delta(0, methods[2].wait_time, 0.01)
|
74
|
-
assert_in_delta(0.1, methods[2].self_time, 0.01)
|
75
|
-
assert_equal(1, methods[2].called)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
data/test/issue137_test.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
require File.expand_path('../test_helper', __FILE__)
|
5
|
-
|
6
|
-
# issue 137 is about correctly attributing time of recursive children
|
7
|
-
|
8
|
-
class RecursiveChildrenTest < TestCase
|
9
|
-
class SlowClass
|
10
|
-
def time_sink
|
11
|
-
1234567890 ** 100 == 0
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class SlowSearcher
|
16
|
-
def do_find(slow_objects)
|
17
|
-
slow_objects.find(&:time_sink)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
class MainClass
|
22
|
-
def self.main_method
|
23
|
-
slow_objects = [SlowClass.new] * 100_000
|
24
|
-
slow_searcher = SlowSearcher.new
|
25
|
-
slow_searcher.do_find(slow_objects)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
include PrinterTestHelper
|
30
|
-
|
31
|
-
def setup
|
32
|
-
# Need to use wall time for this test due to the sleep calls
|
33
|
-
RubyProf::measure_mode = RubyProf::WALL_TIME
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_simple
|
37
|
-
result = RubyProf.profile do
|
38
|
-
# make array each recursive
|
39
|
-
[1].each do
|
40
|
-
MainClass.main_method
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# methods = result.threads.first.methods.sort.reverse
|
45
|
-
|
46
|
-
printer = RubyProf::GraphPrinter.new(result)
|
47
|
-
|
48
|
-
buffer = ''
|
49
|
-
printer.print(StringIO.new(buffer))
|
50
|
-
|
51
|
-
puts buffer if ENV['SHOW_RUBY_PROF_PRINTER_OUTPUT'] == "1"
|
52
|
-
|
53
|
-
parsed_output = MetricsArray.parse(buffer)
|
54
|
-
|
55
|
-
assert( enum_find = parsed_output.metrics_for("Enumerable#find") )
|
56
|
-
assert( array_each = enum_find.child("Array#each") )
|
57
|
-
|
58
|
-
assert_operator enum_find.metrics.total, :>=, array_each.total
|
59
|
-
assert_operator enum_find.metrics.total, :>, 0
|
60
|
-
assert_in_delta enum_find.metrics.total, array_each.total, 0.02
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
@@ -1,213 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
require File.expand_path('../test_helper', __FILE__)
|
5
|
-
|
6
|
-
class MeasureCpuTimeTest < TestCase
|
7
|
-
def setup
|
8
|
-
RubyProf::measure_mode = RubyProf::CPU_TIME
|
9
|
-
end
|
10
|
-
|
11
|
-
def teardown
|
12
|
-
RubyProf::measure_mode = RubyProf::WALL_TIME
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_mode
|
16
|
-
assert_equal(RubyProf::CPU_TIME, RubyProf::measure_mode)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_cpu_time_enabled_defined
|
20
|
-
assert(defined?(RubyProf::CPU_TIME_ENABLED))
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_class_methods
|
24
|
-
result = RubyProf.profile do
|
25
|
-
RubyProf::C7.busy_wait
|
26
|
-
end
|
27
|
-
|
28
|
-
# Length should be greater 2:
|
29
|
-
# MeasureCpuTimeTest#test_class_methods
|
30
|
-
# <Class::RubyProf::C1>#busy_wait
|
31
|
-
# ....
|
32
|
-
|
33
|
-
methods = result.threads.first.methods.sort.reverse[0..1]
|
34
|
-
assert_equal(2, methods.length)
|
35
|
-
|
36
|
-
# Check the names
|
37
|
-
assert_equal('MeasureCpuTimeTest#test_class_methods', methods[0].full_name)
|
38
|
-
assert_equal('<Class::RubyProf::C7>#busy_wait', methods[1].full_name)
|
39
|
-
|
40
|
-
# Check times
|
41
|
-
assert_in_delta(0.1, methods[0].total_time, 0.05)
|
42
|
-
assert_in_delta(0, methods[0].wait_time, 0.05)
|
43
|
-
assert_in_delta(0, methods[0].self_time, 0.05)
|
44
|
-
|
45
|
-
assert_in_delta(0.1, methods[1].total_time, 0.05)
|
46
|
-
assert_in_delta(0, methods[1].wait_time, 0.05)
|
47
|
-
assert_in_delta(0, methods[1].self_time, 0.05)
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_instance_methods
|
51
|
-
result = RubyProf.profile do
|
52
|
-
RubyProf::C7.new.busy_wait
|
53
|
-
end
|
54
|
-
|
55
|
-
methods = result.threads.first.methods.sort.reverse[0..1]
|
56
|
-
assert_equal(2, methods.length)
|
57
|
-
|
58
|
-
# Methods at this point:
|
59
|
-
# MeasureCpuTimeTest#test_instance_methods
|
60
|
-
# C7#busy_wait
|
61
|
-
# ...
|
62
|
-
|
63
|
-
names = methods.map(&:full_name)
|
64
|
-
assert_equal('MeasureCpuTimeTest#test_instance_methods', names[0])
|
65
|
-
assert_equal('RubyProf::C7#busy_wait', names[1])
|
66
|
-
|
67
|
-
|
68
|
-
# Check times
|
69
|
-
assert_in_delta(0.2, methods[0].total_time, 0.03)
|
70
|
-
assert_in_delta(0, methods[0].wait_time, 0.03)
|
71
|
-
assert_in_delta(0, methods[0].self_time, 0.03)
|
72
|
-
|
73
|
-
assert_in_delta(0.2, methods[1].total_time, 0.03)
|
74
|
-
assert_in_delta(0, methods[1].wait_time, 0.03)
|
75
|
-
assert_in_delta(0, methods[1].self_time, 0.2)
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_module_methods
|
79
|
-
result = RubyProf.profile do
|
80
|
-
RubyProf::C8.busy_wait
|
81
|
-
end
|
82
|
-
|
83
|
-
# Methods:
|
84
|
-
# MeasureCpuTimeTest#test_module_methods
|
85
|
-
# M1#busy_wait
|
86
|
-
# ...
|
87
|
-
|
88
|
-
methods = result.threads.first.methods.sort.reverse[0..1]
|
89
|
-
assert_equal(2, methods.length)
|
90
|
-
|
91
|
-
assert_equal('MeasureCpuTimeTest#test_module_methods', methods[0].full_name)
|
92
|
-
assert_equal('RubyProf::M7#busy_wait', methods[1].full_name)
|
93
|
-
|
94
|
-
# Check times
|
95
|
-
assert_in_delta(0.3, methods[0].total_time, 0.1)
|
96
|
-
assert_in_delta(0, methods[0].wait_time, 0.02)
|
97
|
-
assert_in_delta(0, methods[0].self_time, 0.02)
|
98
|
-
|
99
|
-
assert_in_delta(0.3, methods[1].total_time, 0.1)
|
100
|
-
assert_in_delta(0, methods[1].wait_time, 0.02)
|
101
|
-
assert_in_delta(0, methods[1].self_time, 0.1)
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_module_instance_methods
|
105
|
-
result = RubyProf.profile do
|
106
|
-
RubyProf::C8.new.busy_wait
|
107
|
-
end
|
108
|
-
|
109
|
-
# Methods:
|
110
|
-
# MeasureCpuTimeTest#test_module_instance_methods
|
111
|
-
# M7#busy_wait
|
112
|
-
# ...
|
113
|
-
|
114
|
-
methods = result.threads.first.methods.sort.reverse[0..1]
|
115
|
-
assert_equal(2, methods.length)
|
116
|
-
names = methods.map(&:full_name)
|
117
|
-
assert_equal('MeasureCpuTimeTest#test_module_instance_methods', names[0])
|
118
|
-
assert_equal('RubyProf::M7#busy_wait', names[1])
|
119
|
-
|
120
|
-
# Check times
|
121
|
-
assert_in_delta(0.3, methods[0].total_time, 0.1)
|
122
|
-
assert_in_delta(0, methods[0].wait_time, 0.1)
|
123
|
-
assert_in_delta(0, methods[0].self_time, 0.1)
|
124
|
-
|
125
|
-
assert_in_delta(0.3, methods[1].total_time, 0.1)
|
126
|
-
assert_in_delta(0, methods[1].wait_time, 0.01)
|
127
|
-
assert_in_delta(0, methods[1].self_time, 0.1)
|
128
|
-
end
|
129
|
-
|
130
|
-
def test_singleton
|
131
|
-
c3 = RubyProf::C3.new
|
132
|
-
|
133
|
-
class << c3
|
134
|
-
def busy_wait
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
result = RubyProf.profile do
|
139
|
-
c3.busy_wait
|
140
|
-
end
|
141
|
-
|
142
|
-
methods = result.threads.first.methods.sort.reverse
|
143
|
-
assert_equal(2, methods.length)
|
144
|
-
|
145
|
-
assert_equal('MeasureCpuTimeTest#test_singleton', methods[0].full_name)
|
146
|
-
assert_equal('<Object::RubyProf::C3>#busy_wait', methods[1].full_name)
|
147
|
-
|
148
|
-
assert_in_delta(0, methods[0].total_time, 0.01)
|
149
|
-
assert_in_delta(0, methods[0].wait_time, 0.01)
|
150
|
-
assert_in_delta(0, methods[0].self_time, 0.01)
|
151
|
-
|
152
|
-
assert_in_delta(0, methods[1].total_time, 0.01)
|
153
|
-
assert_in_delta(0, methods[1].wait_time, 0.01)
|
154
|
-
assert_in_delta(0, methods[1].self_time, 0.01)
|
155
|
-
end
|
156
|
-
|
157
|
-
|
158
|
-
def test_sleeping_does_accumulate_wall_time
|
159
|
-
RubyProf::measure_mode = RubyProf::WALL_TIME
|
160
|
-
result = RubyProf.profile do
|
161
|
-
sleep 0.1
|
162
|
-
end
|
163
|
-
methods = result.threads.first.methods.sort.reverse
|
164
|
-
assert_equal(["MeasureCpuTimeTest#test_sleeping_does_accumulate_wall_time", "Kernel#sleep"], methods.map(&:full_name))
|
165
|
-
assert_in_delta(0.1, methods[1].total_time, 0.01)
|
166
|
-
assert_equal(0, methods[1].wait_time)
|
167
|
-
assert_in_delta(0.1, methods[1].self_time, 0.01)
|
168
|
-
end
|
169
|
-
|
170
|
-
def test_sleeping_does_not_accumulate_significant_cpu_time
|
171
|
-
result = RubyProf.profile do
|
172
|
-
sleep 0.1
|
173
|
-
end
|
174
|
-
methods = result.threads.first.methods.sort.reverse
|
175
|
-
assert_equal(["MeasureCpuTimeTest#test_sleeping_does_not_accumulate_significant_cpu_time", "Kernel#sleep"], methods.map(&:full_name))
|
176
|
-
assert_in_delta(0, methods[1].total_time, 0.01)
|
177
|
-
assert_equal(0, methods[1].wait_time)
|
178
|
-
assert_in_delta(0, methods[1].self_time, 0.01)
|
179
|
-
end
|
180
|
-
|
181
|
-
def test_waiting_for_threads_does_not_accumulate_cpu_time
|
182
|
-
background_thread = nil
|
183
|
-
result = RubyProf.profile do
|
184
|
-
background_thread = Thread.new{ sleep 0.1 }
|
185
|
-
background_thread.join
|
186
|
-
end
|
187
|
-
# check number of threads
|
188
|
-
assert_equal(2, result.threads.length)
|
189
|
-
fg, bg = result.threads
|
190
|
-
assert(fg.methods.map(&:full_name).include?("Thread#join"))
|
191
|
-
assert(bg.methods.map(&:full_name).include?("Kernel#sleep"))
|
192
|
-
assert_in_delta(0, fg.total_time, 0.01)
|
193
|
-
assert_in_delta(0, bg.total_time, 0.01)
|
194
|
-
end
|
195
|
-
|
196
|
-
def test_waiting_for_threads_does_accumulate_wall_time
|
197
|
-
RubyProf::measure_mode = RubyProf::WALL_TIME
|
198
|
-
background_thread = nil
|
199
|
-
result = RubyProf.profile do
|
200
|
-
background_thread = Thread.new{ sleep 0.1 }
|
201
|
-
background_thread.join
|
202
|
-
end
|
203
|
-
# check number of threads
|
204
|
-
assert_equal(2, result.threads.length)
|
205
|
-
fg, bg = result.threads
|
206
|
-
assert(fg.methods.map(&:full_name).include?("Thread#join"))
|
207
|
-
assert(bg.methods.map(&:full_name).include?("Kernel#sleep"))
|
208
|
-
assert_in_delta(0.1, fg.total_time, 0.01)
|
209
|
-
assert_in_delta(0.1, fg.wait_time, 0.01)
|
210
|
-
assert_in_delta(0.1, bg.total_time, 0.01)
|
211
|
-
end
|
212
|
-
|
213
|
-
end
|