ruby-prof 0.13.1 → 1.4.2
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 +579 -371
- data/LICENSE +24 -23
- data/README.rdoc +5 -433
- data/Rakefile +98 -110
- data/bin/ruby-prof +328 -329
- data/bin/ruby-prof-check-trace +45 -0
- data/ext/ruby_prof/extconf.rb +16 -59
- data/ext/ruby_prof/rp_aggregate_call_tree.c +59 -0
- data/ext/ruby_prof/rp_aggregate_call_tree.h +13 -0
- data/ext/ruby_prof/rp_allocation.c +287 -0
- data/ext/ruby_prof/rp_allocation.h +31 -0
- data/ext/ruby_prof/rp_call_tree.c +369 -0
- data/ext/ruby_prof/rp_call_tree.h +43 -0
- data/ext/ruby_prof/rp_call_trees.c +288 -0
- data/ext/ruby_prof/rp_call_trees.h +28 -0
- data/ext/ruby_prof/rp_measure_allocations.c +50 -65
- data/ext/ruby_prof/rp_measure_memory.c +42 -73
- data/ext/ruby_prof/rp_measure_process_time.c +65 -71
- data/ext/ruby_prof/rp_measure_wall_time.c +64 -42
- data/ext/ruby_prof/rp_measurement.c +237 -0
- data/ext/ruby_prof/rp_measurement.h +50 -0
- data/ext/ruby_prof/rp_method.c +491 -420
- data/ext/ruby_prof/rp_method.h +62 -57
- data/ext/ruby_prof/rp_profile.c +908 -0
- data/ext/ruby_prof/rp_profile.h +35 -0
- data/ext/ruby_prof/rp_stack.c +212 -128
- data/ext/ruby_prof/rp_stack.h +53 -51
- data/ext/ruby_prof/rp_thread.c +362 -268
- data/ext/ruby_prof/rp_thread.h +39 -27
- data/ext/ruby_prof/ruby_prof.c +52 -695
- data/ext/ruby_prof/ruby_prof.h +26 -55
- data/ext/ruby_prof/vc/ruby_prof.sln +28 -21
- data/ext/ruby_prof/vc/{ruby_prof_20.vcxproj → ruby_prof.vcxproj} +56 -8
- data/lib/ruby-prof.rb +52 -67
- data/lib/ruby-prof/assets/call_stack_printer.html.erb +710 -0
- data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
- data/lib/ruby-prof/assets/graph_printer.html.erb +355 -0
- data/lib/ruby-prof/call_tree.rb +57 -0
- data/lib/ruby-prof/call_tree_visitor.rb +36 -0
- data/lib/ruby-prof/compatibility.rb +99 -169
- data/lib/ruby-prof/exclude_common_methods.rb +198 -0
- data/lib/ruby-prof/measurement.rb +17 -0
- data/lib/ruby-prof/method_info.rb +78 -131
- data/lib/ruby-prof/printers/abstract_printer.rb +137 -85
- data/lib/ruby-prof/printers/call_info_printer.rb +53 -41
- data/lib/ruby-prof/printers/call_stack_printer.rb +180 -773
- data/lib/ruby-prof/printers/call_tree_printer.rb +151 -92
- data/lib/ruby-prof/printers/dot_printer.rb +132 -132
- data/lib/ruby-prof/printers/flat_printer.rb +53 -69
- data/lib/ruby-prof/printers/graph_html_printer.rb +63 -255
- data/lib/ruby-prof/printers/graph_printer.rb +113 -116
- data/lib/ruby-prof/printers/multi_printer.rb +127 -56
- data/lib/ruby-prof/profile.rb +37 -77
- data/lib/ruby-prof/rack.rb +62 -15
- data/lib/ruby-prof/task.rb +147 -147
- data/lib/ruby-prof/thread.rb +10 -12
- data/lib/ruby-prof/version.rb +3 -0
- data/lib/unprof.rb +10 -10
- data/ruby-prof.gemspec +65 -61
- data/test/abstract_printer_test.rb +26 -0
- data/test/alias_test.rb +126 -0
- data/test/basic_test.rb +43 -128
- data/test/call_tree_visitor_test.rb +32 -0
- data/test/call_trees_test.rb +66 -0
- data/test/duplicate_names_test.rb +32 -32
- data/test/dynamic_method_test.rb +53 -74
- data/test/enumerable_test.rb +21 -16
- data/test/exceptions_test.rb +24 -16
- data/test/exclude_methods_test.rb +151 -0
- data/test/exclude_threads_test.rb +53 -54
- data/test/fiber_test.rb +129 -65
- data/test/gc_test.rb +90 -0
- data/test/inverse_call_tree_test.rb +175 -0
- data/test/line_number_test.rb +158 -71
- data/test/marshal_test.rb +113 -0
- data/test/measure_allocations.rb +30 -0
- data/test/measure_allocations_test.rb +375 -25
- data/test/measure_allocations_trace_test.rb +375 -0
- data/test/measure_memory_trace_test.rb +1101 -0
- data/test/measure_process_time_test.rb +785 -62
- data/test/measure_times.rb +56 -0
- data/test/measure_wall_time_test.rb +434 -254
- data/test/multi_printer_test.rb +71 -82
- data/test/no_method_class_test.rb +15 -15
- data/test/pause_resume_test.rb +175 -166
- data/test/prime.rb +54 -54
- data/test/prime_script.rb +6 -0
- data/test/printer_call_stack_test.rb +27 -0
- data/test/printer_call_tree_test.rb +30 -0
- data/test/printer_flat_test.rb +99 -0
- data/test/printer_graph_html_test.rb +59 -0
- data/test/printer_graph_test.rb +40 -0
- data/test/printers_test.rb +141 -257
- data/test/printing_recursive_graph_test.rb +81 -0
- data/test/profile_test.rb +16 -0
- data/test/rack_test.rb +93 -0
- data/test/recursive_test.rb +206 -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 +13 -115
- data/test/thread_test.rb +144 -178
- data/test/unique_call_path_test.rb +120 -224
- data/test/yarv_test.rb +56 -0
- metadata +77 -133
- data/doc/LICENSE.html +0 -155
- data/doc/README_rdoc.html +0 -648
- data/doc/Rack.html +0 -167
- data/doc/Rack/RubyProf.html +0 -319
- data/doc/RubyProf.html +0 -1000
- data/doc/RubyProf/AbstractPrinter.html +0 -580
- data/doc/RubyProf/AggregateCallInfo.html +0 -570
- data/doc/RubyProf/CallInfo.html +0 -512
- data/doc/RubyProf/CallInfoPrinter.html +0 -190
- data/doc/RubyProf/CallInfoVisitor.html +0 -332
- data/doc/RubyProf/CallStackPrinter.html +0 -1600
- data/doc/RubyProf/CallTreePrinter.html +0 -413
- data/doc/RubyProf/Cmd.html +0 -669
- data/doc/RubyProf/DotPrinter.html +0 -312
- data/doc/RubyProf/FlatPrinter.html +0 -229
- data/doc/RubyProf/FlatPrinterWithLineNumbers.html +0 -267
- data/doc/RubyProf/GraphHtmlPrinter.html +0 -630
- data/doc/RubyProf/GraphPrinter.html +0 -209
- data/doc/RubyProf/MethodInfo.html +0 -713
- data/doc/RubyProf/MultiPrinter.html +0 -407
- data/doc/RubyProf/Profile.html +0 -821
- data/doc/RubyProf/ProfileTask.html +0 -532
- data/doc/RubyProf/Test.html +0 -578
- data/doc/RubyProf/Thread.html +0 -262
- data/doc/created.rid +0 -32
- data/doc/examples/flat_txt.html +0 -191
- data/doc/examples/graph_txt.html +0 -305
- data/doc/images/add.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 -647
- data/doc/js/darkfish.js +0 -155
- data/doc/js/jquery.js +0 -18
- data/doc/js/navigation.js +0 -142
- data/doc/js/search.js +0 -94
- data/doc/js/search_index.js +0 -1
- data/doc/js/searcher.js +0 -228
- data/doc/rdoc.css +0 -543
- data/doc/table_of_contents.html +0 -462
- data/examples/empty.png +0 -0
- data/examples/flat.txt +0 -55
- data/examples/graph.dot +0 -106
- data/examples/graph.html +0 -823
- data/examples/graph.png +0 -0
- data/examples/graph.txt +0 -170
- data/examples/minus.png +0 -0
- data/examples/multi.flat.txt +0 -23
- data/examples/multi.graph.html +0 -906
- data/examples/multi.grind.dat +0 -194
- data/examples/multi.stack.html +0 -573
- data/examples/plus.png +0 -0
- data/examples/stack.html +0 -573
- data/ext/ruby_prof/rp_call_info.c +0 -407
- data/ext/ruby_prof/rp_call_info.h +0 -48
- data/ext/ruby_prof/rp_measure.c +0 -48
- data/ext/ruby_prof/rp_measure.h +0 -45
- data/ext/ruby_prof/rp_measure_cpu_time.c +0 -112
- data/ext/ruby_prof/rp_measure_gc_runs.c +0 -65
- data/ext/ruby_prof/rp_measure_gc_time.c +0 -57
- data/ext/ruby_prof/vc/ruby_prof_18.vcxproj +0 -108
- data/ext/ruby_prof/vc/ruby_prof_19.vcxproj +0 -110
- data/ext/ruby_prof/version.h +0 -7
- data/lib/ruby-prof/aggregate_call_info.rb +0 -72
- data/lib/ruby-prof/call_info.rb +0 -89
- data/lib/ruby-prof/call_info_visitor.rb +0 -44
- data/lib/ruby-prof/images/empty.png +0 -0
- data/lib/ruby-prof/images/minus.png +0 -0
- data/lib/ruby-prof/images/plus.png +0 -0
- data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -57
- data/lib/ruby-prof/test.rb +0 -150
- data/test/aggregate_test.rb +0 -136
- data/test/call_info_test.rb +0 -78
- data/test/call_info_visitor_test.rb +0 -31
- data/test/exec_test.rb +0 -14
- data/test/measure_cpu_time_test.rb +0 -220
- 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 -31
- data/test/method_elimination_test.rb +0 -84
- data/test/module_test.rb +0 -45
- data/test/stack_test.rb +0 -138
- data/test/test_suite.rb +0 -37
data/test/thread_test.rb
CHANGED
@@ -1,178 +1,144 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
require File.expand_path('../test_helper', __FILE__)
|
5
|
-
require 'timeout'
|
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
|
-
assert(thread_ids.include?(threads[
|
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
|
-
assert_equal(
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
assert_equal(
|
82
|
-
|
83
|
-
assert_in_delta(1
|
84
|
-
assert_in_delta(0, method.
|
85
|
-
assert_in_delta(0, method.
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
assert_equal(
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
method
|
99
|
-
|
100
|
-
# the
|
101
|
-
#
|
102
|
-
|
103
|
-
|
104
|
-
assert_in_delta(
|
105
|
-
assert_in_delta(0, method.
|
106
|
-
assert_in_delta(
|
107
|
-
|
108
|
-
|
109
|
-
assert_equal(
|
110
|
-
|
111
|
-
|
112
|
-
assert_equal(
|
113
|
-
|
114
|
-
method
|
115
|
-
|
116
|
-
|
117
|
-
assert_in_delta(
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
assert_equal(
|
125
|
-
|
126
|
-
|
127
|
-
method
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
assert_equal(1, method.
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
assert_equal(
|
142
|
-
assert_equal(
|
143
|
-
|
144
|
-
|
145
|
-
assert_in_delta(0, method.wait_time, 0.05)
|
146
|
-
assert_in_delta(0, method.children_time, 0.05)
|
147
|
-
|
148
|
-
assert_equal(1, method.call_infos.length)
|
149
|
-
call_info = method.call_infos[0]
|
150
|
-
assert_equal('ThreadTest#test_thread_timings-><Class::Thread>#new->Thread#initialize', call_info.call_sequence)
|
151
|
-
assert_equal(0, call_info.children.length)
|
152
|
-
end
|
153
|
-
|
154
|
-
# useless test
|
155
|
-
def test_thread_back_and_forth
|
156
|
-
result = RubyProf.profile do
|
157
|
-
a = Thread.new { 100_000.times { sleep 0 }}
|
158
|
-
b = Thread.new { 100_000.times { sleep 0 }}
|
159
|
-
a.join
|
160
|
-
b.join
|
161
|
-
end
|
162
|
-
methods = result.threads.map {|thread| thread.methods}
|
163
|
-
assert(methods.flatten.sort[-1].total_time < 10) # 10s. Amazingly, this can fail in OS X at times. Amazing.
|
164
|
-
end
|
165
|
-
|
166
|
-
def test_thread
|
167
|
-
RubyProf.profile do
|
168
|
-
begin
|
169
|
-
Timeout::timeout(2) do
|
170
|
-
while true
|
171
|
-
next
|
172
|
-
end
|
173
|
-
end
|
174
|
-
rescue Timeout::Error
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
require File.expand_path('../test_helper', __FILE__)
|
5
|
+
require 'timeout'
|
6
|
+
require 'benchmark'
|
7
|
+
|
8
|
+
# -- Tests ----
|
9
|
+
class ThreadTest < TestCase
|
10
|
+
def setup
|
11
|
+
# Need to use wall time for this test due to the sleep calls
|
12
|
+
RubyProf::measure_mode = RubyProf::WALL_TIME
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_thread_count
|
16
|
+
RubyProf.start
|
17
|
+
|
18
|
+
thread = Thread.new do
|
19
|
+
sleep(1)
|
20
|
+
end
|
21
|
+
|
22
|
+
thread.join
|
23
|
+
result = RubyProf.stop
|
24
|
+
assert_equal(2, result.threads.length)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_thread_identity
|
28
|
+
RubyProf.start
|
29
|
+
sleep_thread = Thread.new do
|
30
|
+
sleep(1)
|
31
|
+
end
|
32
|
+
sleep_thread.join
|
33
|
+
result = RubyProf.stop
|
34
|
+
|
35
|
+
thread_ids = result.threads.map {|thread| thread.id}.sort
|
36
|
+
threads = [Thread.current, sleep_thread]
|
37
|
+
assert_equal(2, result.threads.length)
|
38
|
+
|
39
|
+
assert(thread_ids.include?(threads[0].object_id))
|
40
|
+
assert(thread_ids.include?(threads[1].object_id))
|
41
|
+
|
42
|
+
assert_instance_of(Thread, ObjectSpace._id2ref(thread_ids[0]))
|
43
|
+
assert(threads.include?(ObjectSpace._id2ref(thread_ids[0])))
|
44
|
+
|
45
|
+
assert_instance_of(Thread, ObjectSpace._id2ref(thread_ids[1]))
|
46
|
+
assert(threads.include?(ObjectSpace._id2ref(thread_ids[1])))
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_thread_timings
|
50
|
+
RubyProf.start
|
51
|
+
thread = Thread.new do
|
52
|
+
sleep 0
|
53
|
+
# force it to hit thread.join, below, first
|
54
|
+
# thus forcing sleep(1), below, to be counted as (wall) self_time
|
55
|
+
# since we currently count time "in some other thread" as self.wait_time
|
56
|
+
# for whatever reason
|
57
|
+
sleep(1)
|
58
|
+
end
|
59
|
+
thread.join
|
60
|
+
result = RubyProf.stop
|
61
|
+
|
62
|
+
# Check background thread
|
63
|
+
assert_equal(2, result.threads.length)
|
64
|
+
|
65
|
+
rp_thread = result.threads.detect {|t| t.id == thread.object_id}
|
66
|
+
methods = rp_thread.methods.sort.reverse
|
67
|
+
# fails on travis. why?
|
68
|
+
# expected_methods = ["ThreadTest#test_thread_timings", "Kernel#sleep"]
|
69
|
+
# assert_equal(expected_methods, methods.map(&:full_name))
|
70
|
+
|
71
|
+
method = methods[0]
|
72
|
+
assert_equal('ThreadTest#test_thread_timings', method.full_name)
|
73
|
+
assert_equal(1, method.called)
|
74
|
+
assert_in_delta(1, method.total_time, 0.05)
|
75
|
+
assert_in_delta(0, method.self_time, 0.05)
|
76
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
77
|
+
assert_in_delta(1, method.children_time, 0.05)
|
78
|
+
assert_equal(0, method.call_trees.callers.length)
|
79
|
+
|
80
|
+
method = methods[1]
|
81
|
+
assert_equal('Kernel#sleep', method.full_name)
|
82
|
+
assert_equal(2, method.called)
|
83
|
+
assert_in_delta(1, method.total_time, 0.05)
|
84
|
+
assert_in_delta(1.0, method.self_time, 0.05)
|
85
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
86
|
+
assert_in_delta(0, method.children_time, 0.05)
|
87
|
+
|
88
|
+
assert_equal(1, method.call_trees.callers.length)
|
89
|
+
assert_equal(0, method.call_trees.callees.length)
|
90
|
+
|
91
|
+
# Check foreground thread
|
92
|
+
rp_thread = result.threads.detect {|athread| athread.id == Thread.current.object_id}
|
93
|
+
methods = rp_thread.methods.sort.reverse
|
94
|
+
assert_equal(4, methods.length)
|
95
|
+
methods = methods.sort.reverse
|
96
|
+
|
97
|
+
method = methods[0]
|
98
|
+
assert_equal('ThreadTest#test_thread_timings', method.full_name)
|
99
|
+
# the sub calls to Object#new, when popped,
|
100
|
+
# cause the parent frame to be created for method #test_thread_timings, which means a +1 when it's popped in the end
|
101
|
+
# xxxx a test that shows it the other way, too (never creates parent frame--if that's even possible)
|
102
|
+
assert_equal(1, method.called)
|
103
|
+
assert_in_delta(1, method.total_time, 0.05)
|
104
|
+
assert_in_delta(0, method.self_time, 0.05)
|
105
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
106
|
+
assert_in_delta(1, method.children_time, 0.05)
|
107
|
+
|
108
|
+
assert_equal(0, method.call_trees.callers.length)
|
109
|
+
assert_equal(2, method.call_trees.callees.length)
|
110
|
+
|
111
|
+
method = methods[1]
|
112
|
+
assert_equal('Thread#join', method.full_name)
|
113
|
+
assert_equal(1, method.called)
|
114
|
+
assert_in_delta(1, method.total_time, 0.05)
|
115
|
+
assert_in_delta(0, method.self_time, 0.05)
|
116
|
+
assert_in_delta(1.0, method.wait_time, 0.05)
|
117
|
+
assert_in_delta(0, method.children_time, 0.05)
|
118
|
+
|
119
|
+
assert_equal(1, method.call_trees.callers.length)
|
120
|
+
assert_equal(0, method.call_trees.callees.length)
|
121
|
+
|
122
|
+
method = methods[2]
|
123
|
+
assert_equal('<Class::Thread>#new', method.full_name)
|
124
|
+
assert_equal(1, method.called)
|
125
|
+
assert_in_delta(0, method.total_time, 0.05)
|
126
|
+
assert_in_delta(0, method.self_time, 0.05)
|
127
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
128
|
+
assert_in_delta(0, method.children_time, 0.05)
|
129
|
+
|
130
|
+
assert_equal(1, method.call_trees.callers.length)
|
131
|
+
assert_equal(1, method.call_trees.callees.length)
|
132
|
+
|
133
|
+
method = methods[3]
|
134
|
+
assert_equal('Thread#initialize', method.full_name)
|
135
|
+
assert_equal(1, method.called)
|
136
|
+
assert_in_delta(0, method.total_time, 0.05)
|
137
|
+
assert_in_delta(0, method.self_time, 0.05)
|
138
|
+
assert_in_delta(0, method.wait_time, 0.05)
|
139
|
+
assert_in_delta(0, method.children_time, 0.05)
|
140
|
+
|
141
|
+
assert_equal(1, method.call_trees.callers.length)
|
142
|
+
assert_equal(0, method.call_trees.callees.length)
|
143
|
+
end
|
144
|
+
end
|
@@ -1,224 +1,120 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: UTF-8
|
3
|
-
|
4
|
-
require File.expand_path('../test_helper', __FILE__)
|
5
|
-
|
6
|
-
class UniqueCallPath
|
7
|
-
def method_a(i)
|
8
|
-
if i==1
|
9
|
-
method_b
|
10
|
-
else
|
11
|
-
method_c
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def method_b
|
16
|
-
method_c
|
17
|
-
end
|
18
|
-
|
19
|
-
def method_c
|
20
|
-
end
|
21
|
-
|
22
|
-
def method_k(i)
|
23
|
-
method_a(i)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
# -- Tests ----
|
29
|
-
class UniqueCallPathTest <
|
30
|
-
def
|
31
|
-
unique_call_path = UniqueCallPath.new
|
32
|
-
|
33
|
-
result = RubyProf.profile do
|
34
|
-
unique_call_path.method_a(1)
|
35
|
-
end
|
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
|
-
end
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
assert_equal(
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
unique_call_path.
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
result.threads.
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
children_of_a
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
if RUBY_VERSION < '1.9'
|
125
|
-
assert_equal(4, call_info_a.target.children.length)
|
126
|
-
else
|
127
|
-
assert_equal(2, call_info_a.target.children.length)
|
128
|
-
end
|
129
|
-
|
130
|
-
children_of_a = children_of_a.sort do |c1, c2|
|
131
|
-
c1.target.full_name <=> c2.target.full_name
|
132
|
-
end
|
133
|
-
if RUBY_VERSION < '1.9'
|
134
|
-
assert_equal(2, children_of_a.length)
|
135
|
-
assert_equal("Fixnum#==", children_of_a[0].target.full_name)
|
136
|
-
assert_equal("UniqueCallPath#method_b", children_of_a[1].target.full_name)
|
137
|
-
else
|
138
|
-
assert_equal(1, children_of_a.length)
|
139
|
-
assert_equal("UniqueCallPath#method_b", children_of_a[0].target.full_name)
|
140
|
-
end
|
141
|
-
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_id2ref
|
145
|
-
unique_call_path = UniqueCallPath.new
|
146
|
-
|
147
|
-
result = RubyProf.profile do
|
148
|
-
unique_call_path.method_a(1)
|
149
|
-
end
|
150
|
-
|
151
|
-
root_methods = Array.new
|
152
|
-
result.threads.each do |thread|
|
153
|
-
thread.methods.each do | m |
|
154
|
-
if m.root?
|
155
|
-
root_methods.push(m)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
child = root_methods[0].children[0]
|
161
|
-
|
162
|
-
assert_not_equal(0, child.object_id)
|
163
|
-
#assert_equal(RubyProf::CallInfo.id2ref(child.id).target.full_name, child.target.full_name)
|
164
|
-
end
|
165
|
-
|
166
|
-
def test_unique_path
|
167
|
-
unique_call_path = UniqueCallPath.new
|
168
|
-
|
169
|
-
result = RubyProf.profile do
|
170
|
-
unique_call_path.method_a(1)
|
171
|
-
unique_call_path.method_k(1)
|
172
|
-
end
|
173
|
-
|
174
|
-
root_methods = Array.new
|
175
|
-
result.threads.each do |thread|
|
176
|
-
thread.methods.each do | m |
|
177
|
-
if m.root?
|
178
|
-
root_methods.push(m)
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
assert_equal(1, root_methods.length)
|
184
|
-
|
185
|
-
call_info_a = nil
|
186
|
-
root_methods[0].children.each do | c |
|
187
|
-
if c.target.full_name == "UniqueCallPath#method_a"
|
188
|
-
call_info_a = c
|
189
|
-
break
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
assert !call_info_a.nil?
|
194
|
-
|
195
|
-
children_of_a = Array.new
|
196
|
-
call_info_a.children.each do |c|
|
197
|
-
if c.parent.eql?(call_info_a)
|
198
|
-
children_of_a.push(c)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
if RUBY_VERSION < '1.9'
|
203
|
-
assert_equal(4, call_info_a.target.children.length)
|
204
|
-
else
|
205
|
-
assert_equal(2, call_info_a.target.children.length)
|
206
|
-
end
|
207
|
-
|
208
|
-
children_of_a = children_of_a.sort do |c1, c2|
|
209
|
-
c1.target.full_name <=> c2.target.full_name
|
210
|
-
end
|
211
|
-
|
212
|
-
if RUBY_VERSION < '1.9'
|
213
|
-
assert_equal(2, children_of_a.length)
|
214
|
-
assert_equal(1, children_of_a[0].called)
|
215
|
-
assert_equal("Fixnum#==", children_of_a[0].target.full_name)
|
216
|
-
assert_equal(1, children_of_a[1].called)
|
217
|
-
assert_equal("UniqueCallPath#method_b", children_of_a[1].target.full_name)
|
218
|
-
else
|
219
|
-
assert_equal(1, children_of_a.length)
|
220
|
-
assert_equal(1, children_of_a[0].called)
|
221
|
-
assert_equal("UniqueCallPath#method_b", children_of_a[0].target.full_name)
|
222
|
-
end
|
223
|
-
end
|
224
|
-
end
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
require File.expand_path('../test_helper', __FILE__)
|
5
|
+
|
6
|
+
class UniqueCallPath
|
7
|
+
def method_a(i)
|
8
|
+
if i==1
|
9
|
+
method_b
|
10
|
+
else
|
11
|
+
method_c
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_b
|
16
|
+
method_c
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_c
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_k(i)
|
23
|
+
method_a(i)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
# -- Tests ----
|
29
|
+
class UniqueCallPathTest < TestCase
|
30
|
+
def test_root
|
31
|
+
unique_call_path = UniqueCallPath.new
|
32
|
+
|
33
|
+
result = RubyProf.profile do
|
34
|
+
unique_call_path.method_a(1)
|
35
|
+
end
|
36
|
+
|
37
|
+
root_call_info = result.threads.first.call_tree
|
38
|
+
assert_equal("UniqueCallPathTest#test_root", root_call_info.target.full_name)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_root_children
|
42
|
+
unique_call_path = UniqueCallPath.new
|
43
|
+
|
44
|
+
result = RubyProf.profile do
|
45
|
+
unique_call_path.method_a(1)
|
46
|
+
unique_call_path.method_k(2)
|
47
|
+
end
|
48
|
+
|
49
|
+
root_call_info = result.threads.first.call_tree
|
50
|
+
children = root_call_info.children.sort do |c1, c2|
|
51
|
+
c1.target.full_name <=> c2.target.full_name
|
52
|
+
end
|
53
|
+
|
54
|
+
assert_equal(2, children.length)
|
55
|
+
assert_equal("UniqueCallPath#method_a", children[0].target.full_name)
|
56
|
+
assert_equal("UniqueCallPath#method_k", children[1].target.full_name)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_children_of
|
60
|
+
unique_call_path = UniqueCallPath.new
|
61
|
+
|
62
|
+
result = RubyProf.profile do
|
63
|
+
unique_call_path.method_a(1)
|
64
|
+
unique_call_path.method_k(2)
|
65
|
+
end
|
66
|
+
|
67
|
+
root_call_info = result.threads.first.call_tree
|
68
|
+
assert_equal("UniqueCallPathTest#test_children_of", root_call_info.target.full_name)
|
69
|
+
|
70
|
+
call_info_a = root_call_info.children.detect do |call_tree|
|
71
|
+
call_tree.target.full_name == "UniqueCallPath#method_a"
|
72
|
+
end
|
73
|
+
refute_nil(call_info_a)
|
74
|
+
|
75
|
+
_children_of_a = call_info_a.children.inject(Array.new) do |array, c|
|
76
|
+
if c.parent.eql?(call_info_a)
|
77
|
+
array << c
|
78
|
+
end
|
79
|
+
array
|
80
|
+
end
|
81
|
+
|
82
|
+
assert_equal(1, call_info_a.children.length)
|
83
|
+
assert_equal("UniqueCallPath#method_b", call_info_a.children.first.target.full_name)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_unique_path
|
87
|
+
unique_call_path = UniqueCallPath.new
|
88
|
+
|
89
|
+
result = RubyProf.profile do
|
90
|
+
unique_call_path.method_a(1)
|
91
|
+
unique_call_path.method_k(1)
|
92
|
+
end
|
93
|
+
|
94
|
+
root_call_info = result.threads.first.call_tree
|
95
|
+
assert_equal("UniqueCallPathTest#test_unique_path", root_call_info.target.full_name)
|
96
|
+
|
97
|
+
call_info_a = root_call_info.children.detect do |call_tree|
|
98
|
+
call_tree.target.full_name == "UniqueCallPath#method_a"
|
99
|
+
end
|
100
|
+
refute_nil(call_info_a)
|
101
|
+
|
102
|
+
children_of_a = call_info_a.children.reduce(Array.new) do |array, c|
|
103
|
+
if c.parent.eql?(call_info_a)
|
104
|
+
array << c
|
105
|
+
end
|
106
|
+
array
|
107
|
+
end
|
108
|
+
|
109
|
+
assert_equal(1, call_info_a.children.length)
|
110
|
+
assert_equal(1, children_of_a.length)
|
111
|
+
|
112
|
+
children_of_a = children_of_a.sort do |c1, c2|
|
113
|
+
c1.target.full_name <=> c2.target.full_name
|
114
|
+
end
|
115
|
+
|
116
|
+
assert_equal(1, children_of_a.length)
|
117
|
+
assert_equal(1, children_of_a[0].called)
|
118
|
+
assert_equal("UniqueCallPath#method_b", children_of_a[0].target.full_name)
|
119
|
+
end
|
120
|
+
end
|