ruby-prof 0.18.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +23 -0
  3. data/LICENSE +2 -2
  4. data/README.rdoc +1 -483
  5. data/Rakefile +3 -6
  6. data/bin/ruby-prof +65 -30
  7. data/ext/ruby_prof/extconf.rb +6 -38
  8. data/ext/ruby_prof/rp_allocation.c +292 -0
  9. data/ext/ruby_prof/rp_allocation.h +31 -0
  10. data/ext/ruby_prof/rp_call_info.c +137 -279
  11. data/ext/ruby_prof/rp_call_info.h +16 -34
  12. data/ext/ruby_prof/rp_measure_allocations.c +25 -49
  13. data/ext/ruby_prof/rp_measure_memory.c +21 -56
  14. data/ext/ruby_prof/rp_measure_process_time.c +28 -36
  15. data/ext/ruby_prof/rp_measure_wall_time.c +36 -19
  16. data/ext/ruby_prof/rp_measurement.c +236 -0
  17. data/ext/ruby_prof/rp_measurement.h +49 -0
  18. data/ext/ruby_prof/rp_method.c +395 -383
  19. data/ext/ruby_prof/rp_method.h +34 -39
  20. data/ext/ruby_prof/rp_profile.c +881 -0
  21. data/ext/ruby_prof/rp_profile.h +36 -0
  22. data/ext/ruby_prof/rp_stack.c +103 -80
  23. data/ext/ruby_prof/rp_stack.h +5 -12
  24. data/ext/ruby_prof/rp_thread.c +149 -88
  25. data/ext/ruby_prof/rp_thread.h +15 -6
  26. data/ext/ruby_prof/ruby_prof.c +11 -757
  27. data/ext/ruby_prof/ruby_prof.h +4 -47
  28. data/ext/ruby_prof/vc/ruby_prof.vcxproj +10 -8
  29. data/lib/ruby-prof.rb +2 -17
  30. data/lib/ruby-prof/assets/graph_printer.html.erb +356 -0
  31. data/lib/ruby-prof/call_info.rb +35 -93
  32. data/lib/ruby-prof/call_info_visitor.rb +19 -21
  33. data/lib/ruby-prof/compatibility.rb +37 -107
  34. data/lib/ruby-prof/exclude_common_methods.rb +198 -0
  35. data/lib/ruby-prof/measurement.rb +14 -0
  36. data/lib/ruby-prof/method_info.rb +52 -83
  37. data/lib/ruby-prof/printers/abstract_printer.rb +66 -52
  38. data/lib/ruby-prof/printers/call_info_printer.rb +13 -3
  39. data/lib/ruby-prof/printers/call_stack_printer.rb +32 -28
  40. data/lib/ruby-prof/printers/call_tree_printer.rb +20 -12
  41. data/lib/ruby-prof/printers/dot_printer.rb +5 -5
  42. data/lib/ruby-prof/printers/flat_printer.rb +6 -24
  43. data/lib/ruby-prof/printers/graph_html_printer.rb +7 -192
  44. data/lib/ruby-prof/printers/graph_printer.rb +13 -15
  45. data/lib/ruby-prof/printers/multi_printer.rb +66 -23
  46. data/lib/ruby-prof/profile.rb +10 -3
  47. data/lib/ruby-prof/rack.rb +0 -3
  48. data/lib/ruby-prof/thread.rb +12 -12
  49. data/lib/ruby-prof/version.rb +1 -1
  50. data/ruby-prof.gemspec +2 -2
  51. data/test/abstract_printer_test.rb +0 -27
  52. data/test/alias_test.rb +129 -0
  53. data/test/basic_test.rb +41 -40
  54. data/test/call_info_visitor_test.rb +3 -3
  55. data/test/dynamic_method_test.rb +0 -2
  56. data/test/line_number_test.rb +120 -39
  57. data/test/marshal_test.rb +119 -0
  58. data/test/measure_allocations.rb +30 -0
  59. data/test/measure_allocations_test.rb +371 -12
  60. data/test/measure_allocations_trace_test.rb +385 -0
  61. data/test/measure_memory_trace_test.rb +756 -0
  62. data/test/measure_process_time_test.rb +821 -33
  63. data/test/measure_times.rb +54 -0
  64. data/test/measure_wall_time_test.rb +349 -145
  65. data/test/multi_printer_test.rb +1 -34
  66. data/test/parser_timings.rb +24 -0
  67. data/test/pause_resume_test.rb +5 -5
  68. data/test/prime.rb +2 -0
  69. data/test/printer_call_tree_test.rb +31 -0
  70. data/test/printer_flat_test.rb +68 -0
  71. data/test/printer_graph_html_test.rb +60 -0
  72. data/test/printer_graph_test.rb +41 -0
  73. data/test/printers_test.rb +32 -166
  74. data/test/printing_recursive_graph_test.rb +26 -72
  75. data/test/recursive_test.rb +72 -77
  76. data/test/stack_printer_test.rb +2 -15
  77. data/test/start_stop_test.rb +22 -25
  78. data/test/test_helper.rb +5 -248
  79. data/test/thread_test.rb +11 -54
  80. data/test/unique_call_path_test.rb +16 -28
  81. data/test/yarv_test.rb +1 -0
  82. metadata +24 -34
  83. data/examples/flat.txt +0 -50
  84. data/examples/graph.dot +0 -84
  85. data/examples/graph.html +0 -823
  86. data/examples/graph.txt +0 -139
  87. data/examples/multi.flat.txt +0 -23
  88. data/examples/multi.graph.html +0 -760
  89. data/examples/multi.grind.dat +0 -114
  90. data/examples/multi.stack.html +0 -547
  91. data/examples/stack.html +0 -547
  92. data/ext/ruby_prof/rp_measure.c +0 -40
  93. data/ext/ruby_prof/rp_measure.h +0 -45
  94. data/ext/ruby_prof/rp_measure_cpu_time.c +0 -136
  95. data/ext/ruby_prof/rp_measure_gc_runs.c +0 -73
  96. data/ext/ruby_prof/rp_measure_gc_time.c +0 -60
  97. data/lib/ruby-prof/aggregate_call_info.rb +0 -76
  98. data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -83
  99. data/lib/ruby-prof/profile/exclude_common_methods.rb +0 -207
  100. data/lib/ruby-prof/profile/legacy_method_elimination.rb +0 -50
  101. data/test/aggregate_test.rb +0 -136
  102. data/test/block_test.rb +0 -74
  103. data/test/call_info_test.rb +0 -78
  104. data/test/fiber_test.rb +0 -79
  105. data/test/issue137_test.rb +0 -63
  106. data/test/measure_cpu_time_test.rb +0 -212
  107. data/test/measure_gc_runs_test.rb +0 -32
  108. data/test/measure_gc_time_test.rb +0 -36
  109. data/test/measure_memory_test.rb +0 -33
  110. data/test/method_elimination_test.rb +0 -84
  111. data/test/module_test.rb +0 -45
  112. data/test/stack_test.rb +0 -138
@@ -0,0 +1,54 @@
1
+ # Some classes used in measurement tests
2
+ module RubyProf
3
+ class C1
4
+ def C1.sleep_wait
5
+ sleep(0.1)
6
+ end
7
+
8
+ def C1.busy_wait
9
+ starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
10
+ while (Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting) < 0.1
11
+ end
12
+ end
13
+
14
+ def sleep_wait
15
+ sleep(0.2)
16
+ end
17
+
18
+ def busy_wait
19
+ starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
20
+ while (Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting) < 0.2
21
+ end
22
+ end
23
+ end
24
+
25
+ module M1
26
+ def sleep_wait
27
+ sleep(0.3)
28
+ end
29
+
30
+ def busy_wait
31
+ starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
32
+ while (Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting) < 0.3
33
+ end
34
+ end
35
+ end
36
+
37
+ class C2
38
+ include M1
39
+ extend M1
40
+ end
41
+
42
+ class C3
43
+ include Singleton
44
+ def sleep_wait
45
+ sleep(0.3)
46
+ end
47
+
48
+ def busy_wait
49
+ starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
50
+ while (Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting) < 0.2
51
+ end
52
+ end
53
+ end
54
+ end
@@ -2,11 +2,13 @@
2
2
  # encoding: UTF-8
3
3
 
4
4
  require File.expand_path('../test_helper', __FILE__)
5
+ require_relative './measure_times'
5
6
 
6
7
  class MeasureWallTimeTest < TestCase
7
8
  def setup
8
9
  # Need to use wall time for this test due to the sleep calls
9
10
  RubyProf::measure_mode = RubyProf::WALL_TIME
11
+ GC.start
10
12
  end
11
13
 
12
14
  def test_mode
@@ -14,242 +16,444 @@ class MeasureWallTimeTest < TestCase
14
16
  assert_equal(RubyProf::WALL_TIME, RubyProf::measure_mode)
15
17
  end
16
18
 
17
- def test_wall_time_enabled_defined
18
- assert(defined?(RubyProf::WALL_TIME_ENABLED))
19
- end
20
-
21
19
  def test_class_methods
22
20
  result = RubyProf.profile do
23
- RubyProf::C1.hello
21
+ RubyProf::C1.sleep_wait
24
22
  end
25
23
 
26
24
  thread = result.threads.first
27
- assert_in_delta(0.1, thread.total_time, 0.01)
25
+ assert_in_delta(0.1, thread.total_time, 0.03)
28
26
 
29
- top_methods = thread.top_methods
30
- assert_equal(1, top_methods.count)
31
- assert_equal("MeasureWallTimeTest#test_class_methods", top_methods[0].full_name)
32
-
33
- # Length should be 3:
34
- # MeasureWallTimeTest#test_class_methods
35
- # <Class::RubyProf::C1>#hello
36
- # Kernel#sleep
27
+ root_methods = thread.root_methods
28
+ assert_equal(1, root_methods.count)
29
+ assert_equal("MeasureWallTimeTest#test_class_methods", root_methods[0].full_name)
37
30
 
38
31
  methods = result.threads.first.methods.sort.reverse
39
32
  assert_equal(3, methods.length)
40
33
 
41
34
  # Check the names
42
35
  assert_equal('MeasureWallTimeTest#test_class_methods', methods[0].full_name)
43
- assert_equal('<Class::RubyProf::C1>#hello', methods[1].full_name)
36
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', methods[1].full_name)
44
37
  assert_equal('Kernel#sleep', methods[2].full_name)
45
38
 
46
39
  # Check times
47
- assert_in_delta(0.1, methods[0].total_time, 0.01)
48
- assert_in_delta(0, methods[0].wait_time, 0.01)
49
- assert_in_delta(0, methods[0].self_time, 0.01)
40
+ assert_in_delta(0.1, methods[0].total_time, 0.03)
41
+ assert_in_delta(0, methods[0].wait_time, 0.03)
42
+ assert_in_delta(0, methods[0].self_time, 0.03)
50
43
 
51
- assert_in_delta(0.1, methods[1].total_time, 0.01)
52
- assert_in_delta(0, methods[1].wait_time, 0.01)
53
- assert_in_delta(0, methods[1].self_time, 0.01)
44
+ assert_in_delta(0.1, methods[1].total_time, 0.03)
45
+ assert_in_delta(0, methods[1].wait_time, 0.03)
46
+ assert_in_delta(0, methods[1].self_time, 0.03)
54
47
 
55
- assert_in_delta(0.1, methods[2].total_time, 0.01)
56
- assert_in_delta(0, methods[2].wait_time, 0.01)
57
- assert_in_delta(0.1, methods[2].self_time, 0.01)
48
+ assert_in_delta(0.1, methods[2].total_time, 0.03)
49
+ assert_in_delta(0, methods[2].wait_time, 0.03)
50
+ assert_in_delta(0.1, methods[2].self_time, 0.03)
58
51
  end
59
52
 
60
- def test_instance_methods
53
+ def test_class_methods_threaded
61
54
  result = RubyProf.profile do
62
- RubyProf::C1.new.hello
55
+ background_thread = Thread.new do
56
+ RubyProf::C1.sleep_wait
57
+ end
58
+ background_thread.join
63
59
  end
64
60
 
61
+ assert_equal(2, result.threads.count)
62
+
65
63
  thread = result.threads.first
66
- assert_in_delta(0.2, thread.total_time, 0.01)
64
+ assert_in_delta(0.1, thread.total_time, 0.03)
65
+
66
+ root_methods = thread.root_methods
67
+ assert_equal(1, root_methods.count)
68
+ assert_equal("MeasureWallTimeTest#test_class_methods_threaded", root_methods[0].full_name)
69
+
70
+ methods = result.threads.first.methods.sort.reverse
71
+ assert_equal(4, methods.length)
72
+
73
+ # Check times
74
+ assert_equal('MeasureWallTimeTest#test_class_methods_threaded', methods[0].full_name)
75
+ assert_in_delta(0.1, methods[0].total_time, 0.03)
76
+ assert_in_delta(0.0, methods[0].wait_time, 0.03)
77
+ assert_in_delta(0.0, methods[0].self_time, 0.03)
78
+ assert_in_delta(0.1, methods[0].children_time, 0.03)
79
+
80
+ assert_equal('Thread#join', methods[1].full_name)
81
+ assert_in_delta(0.1, methods[1].total_time, 0.03)
82
+ assert_in_delta(0.1, methods[1].wait_time, 0.03)
83
+ assert_in_delta(0.0, methods[1].self_time, 0.03)
84
+ assert_in_delta(0.0, methods[1].children_time, 0.03)
85
+
86
+ assert_equal('<Class::Thread>#new', methods[2].full_name)
87
+ assert_in_delta(0.0, methods[2].total_time, 0.03)
88
+ assert_in_delta(0.0, methods[2].wait_time, 0.03)
89
+ assert_in_delta(0.0, methods[2].self_time, 0.03)
90
+ assert_in_delta(0.0, methods[2].children_time, 0.03)
91
+
92
+ assert_equal('Thread#initialize', methods[3].full_name)
93
+ assert_in_delta(0.0, methods[3].total_time, 0.03)
94
+ assert_in_delta(0.0, methods[3].wait_time, 0.03)
95
+ assert_in_delta(0.0, methods[3].self_time, 0.03)
96
+ assert_in_delta(0.0, methods[3].children_time, 0.03)
97
+
98
+ thread = result.threads.last
99
+ assert_in_delta(0.1, thread.total_time, 0.03)
100
+
101
+ root_methods = thread.root_methods
102
+ assert_equal(1, root_methods.count)
103
+ assert_equal("MeasureWallTimeTest#test_class_methods_threaded", root_methods[0].full_name)
104
+
105
+ methods = result.threads.first.methods.sort.reverse
106
+ assert_equal(4, methods.length)
107
+
108
+ methods = result.threads.last.methods.sort.reverse
109
+ assert_equal(3, methods.length)
110
+
111
+ # Check times
112
+ assert_equal('MeasureWallTimeTest#test_class_methods_threaded', methods[0].full_name)
113
+ assert_in_delta(0.1, methods[0].total_time, 0.03)
114
+ assert_in_delta(0.0, methods[0].wait_time, 0.03)
115
+ assert_in_delta(0.0, methods[0].self_time, 0.03)
116
+ assert_in_delta(0.1, methods[0].children_time, 0.03)
117
+
118
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', methods[1].full_name)
119
+ assert_in_delta(0.1, methods[1].total_time, 0.03)
120
+ assert_in_delta(0.0, methods[1].wait_time, 0.03)
121
+ assert_in_delta(0.0, methods[1].self_time, 0.03)
122
+ assert_in_delta(0.1, methods[1].children_time, 0.03)
123
+
124
+ assert_equal('Kernel#sleep', methods[2].full_name)
125
+ assert_in_delta(0.1, methods[2].total_time, 0.03)
126
+ assert_in_delta(0.0, methods[2].wait_time, 0.03)
127
+ assert_in_delta(0.1, methods[2].self_time, 0.03)
128
+ assert_in_delta(0.0, methods[2].children_time, 0.03)
129
+ end
130
+
131
+ def test_instance_methods
132
+ result = RubyProf.profile do
133
+ RubyProf::C1.new.sleep_wait
134
+ end
67
135
 
68
- top_methods = thread.top_methods
69
- assert_equal(1, top_methods.count)
70
- assert_equal("MeasureWallTimeTest#test_instance_methods", top_methods[0].full_name)
136
+ thread = result.threads.first
137
+ assert_in_delta(0.2, thread.total_time, 0.03)
71
138
 
72
- # Methods called
73
- # MeasureWallTimeTest#test_instance_methods
74
- # Class.new
75
- # Class:Object#allocate
76
- # for Object#initialize
77
- # C1#hello
78
- # Kernel#sleep
139
+ root_methods = thread.root_methods
140
+ assert_equal(1, root_methods.count)
141
+ assert_equal("MeasureWallTimeTest#test_instance_methods", root_methods[0].full_name)
79
142
 
80
143
  methods = result.threads.first.methods.sort.reverse
81
- assert_equal(RubyProf.ruby_2? ? 5 : 6, methods.length)
144
+ assert_equal(5, methods.length)
82
145
  names = methods.map(&:full_name)
83
- assert_equal('MeasureWallTimeTest#test_instance_methods', names[0])
84
- assert_equal('RubyProf::C1#hello', names[1])
85
- assert_equal('Kernel#sleep', names[2])
86
- assert_equal('Class#new', names[3])
87
146
 
88
147
  # order can differ
89
- assert(names.include?("#{RubyProf.parent_object}#initialize"))
90
- unless RubyProf.ruby_2?
91
- assert(names.include?("<Class::#{RubyProf.parent_object}>#allocate"))
148
+ assert(names.include?("BasicObject#initialize"))
149
+
150
+ # Check times
151
+ method = methods[0]
152
+ assert_equal('MeasureWallTimeTest#test_instance_methods', method.full_name)
153
+ assert_in_delta(0.2, method.total_time, 0.03)
154
+ assert_in_delta(0, method.wait_time, 0.03)
155
+ assert_in_delta(0, method.self_time, 0.03)
156
+
157
+ method = methods[1]
158
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
159
+ assert_in_delta(0.2, method.total_time, 0.03)
160
+ assert_in_delta(0, method.wait_time, 0.03)
161
+ assert_in_delta(0, method.self_time, 0.03)
162
+
163
+ method = methods[2]
164
+ assert_equal('Kernel#sleep', method.full_name)
165
+ assert_in_delta(0.2, method.total_time, 0.03)
166
+ assert_in_delta(0, method.wait_time, 0.03)
167
+ assert_in_delta(0.2, method.self_time, 0.03)
168
+
169
+ method = methods[3]
170
+ assert_equal('Class#new', method.full_name)
171
+ assert_in_delta(0, method.total_time, 0.03)
172
+ assert_in_delta(0, method.wait_time, 0.03)
173
+ assert_in_delta(0, method.self_time, 0.03)
174
+
175
+ method = methods[4]
176
+ assert_equal('BasicObject#initialize', method.full_name)
177
+ assert_in_delta(0, method.total_time, 0.03)
178
+ assert_in_delta(0, method.wait_time, 0.03)
179
+ assert_in_delta(0, method.self_time, 0.03)
180
+ end
181
+
182
+ def test_instance_methods_block
183
+ result = RubyProf.profile do
184
+ 1.times { RubyProf::C1.new.sleep_wait }
92
185
  end
93
186
 
187
+ methods = result.threads.first.methods.sort.reverse
188
+ assert_equal(6, methods.length)
189
+
94
190
  # Check times
95
- assert_in_delta(0.2, methods[0].total_time, 0.02)
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.2, methods[1].total_time, 0.02)
100
- assert_in_delta(0, methods[1].wait_time, 0.02)
101
- assert_in_delta(0, methods[1].self_time, 0.02)
102
-
103
- assert_in_delta(0.2, methods[2].total_time, 0.02)
104
- assert_in_delta(0, methods[2].wait_time, 0.02)
105
- assert_in_delta(0.2, methods[2].self_time, 0.02)
106
-
107
- assert_in_delta(0, methods[3].total_time, 0.01)
108
- assert_in_delta(0, methods[3].wait_time, 0.01)
109
- assert_in_delta(0, methods[3].self_time, 0.01)
110
-
111
- assert_in_delta(0, methods[4].total_time, 0.01)
112
- assert_in_delta(0, methods[4].wait_time, 0.01)
113
- assert_in_delta(0, methods[4].self_time, 0.01)
114
-
115
- unless RubyProf.ruby_2?
116
- assert_in_delta(0, methods[5].total_time, 0.01)
117
- assert_in_delta(0, methods[5].wait_time, 0.01)
118
- assert_in_delta(0, methods[5].self_time, 0.01)
191
+ method = methods[0]
192
+ assert_equal("MeasureWallTimeTest#test_instance_methods_block", method.full_name)
193
+ assert_in_delta(0.2, method.total_time, 0.03)
194
+ assert_in_delta(0.0, method.wait_time, 0.03)
195
+ assert_in_delta(0.0, method.self_time, 0.03)
196
+ assert_in_delta(0.2, method.children_time, 0.03)
197
+
198
+ method = methods[1]
199
+ assert_equal("Integer#times", method.full_name)
200
+ assert_in_delta(0.2, method.total_time, 0.03)
201
+ assert_in_delta(0.0, method.wait_time, 0.03)
202
+ assert_in_delta(0.0, method.self_time, 0.03)
203
+ assert_in_delta(0.2, method.children_time, 0.03)
204
+
205
+ method = methods[2]
206
+ assert_equal("RubyProf::C1#sleep_wait", method.full_name)
207
+ assert_in_delta(0.2, method.total_time, 0.03)
208
+ assert_in_delta(0.0, method.wait_time, 0.03)
209
+ assert_in_delta(0.0, method.self_time, 0.03)
210
+ assert_in_delta(0.2, method.children_time, 0.03)
211
+
212
+ method = methods[3]
213
+ assert_equal("Kernel#sleep", method.full_name)
214
+ assert_in_delta(0.2, method.total_time, 0.03)
215
+ assert_in_delta(0.0, method.wait_time, 0.03)
216
+ assert_in_delta(0.2, method.self_time, 0.03)
217
+ assert_in_delta(0.0, method.children_time, 0.03)
218
+
219
+ method = methods[4]
220
+ assert_equal("Class#new", method.full_name)
221
+ assert_in_delta(0.0, method.total_time, 0.03)
222
+ assert_in_delta(0.0, method.wait_time, 0.03)
223
+ assert_in_delta(0.0, method.self_time, 0.03)
224
+ assert_in_delta(0.0, method.children_time, 0.03)
225
+
226
+ method = methods[5]
227
+ assert_equal("BasicObject#initialize", method.full_name)
228
+ assert_in_delta(0.0, method.total_time, 0.03)
229
+ assert_in_delta(0.0, method.wait_time, 0.03)
230
+ assert_in_delta(0.0, method.self_time, 0.03)
231
+ assert_in_delta(0.0, method.children_time, 0.03)
232
+ end
233
+
234
+ def test_instance_methods_threaded
235
+ result = RubyProf.profile do
236
+ background_thread = Thread.new do
237
+ RubyProf::C1.new.sleep_wait
238
+ end
239
+ background_thread.join
119
240
  end
241
+
242
+ assert_equal(2, result.threads.count)
243
+
244
+ thread = result.threads.first
245
+ assert_in_delta(0.2, thread.total_time, 0.03)
246
+
247
+ root_methods = thread.root_methods
248
+ assert_equal(1, root_methods.count)
249
+ assert_equal("MeasureWallTimeTest#test_instance_methods_threaded", root_methods[0].full_name)
250
+
251
+ methods = result.threads.first.methods.sort.reverse
252
+ assert_equal(4, methods.length)
253
+
254
+ # Check times
255
+ assert_equal('MeasureWallTimeTest#test_instance_methods_threaded', methods[0].full_name)
256
+ assert_in_delta(0.2, methods[0].total_time, 0.03)
257
+ assert_in_delta(0.0, methods[0].wait_time, 0.03)
258
+ assert_in_delta(0.0, methods[0].self_time, 0.03)
259
+ assert_in_delta(0.2, methods[0].children_time, 0.03)
260
+
261
+ assert_equal('Thread#join', methods[1].full_name)
262
+ assert_in_delta(0.2, methods[1].total_time, 0.03)
263
+ assert_in_delta(0.2, methods[1].wait_time, 0.03)
264
+ assert_in_delta(0.0, methods[1].self_time, 0.03)
265
+ assert_in_delta(0.0, methods[1].children_time, 0.03)
266
+
267
+ assert_equal('<Class::Thread>#new', methods[2].full_name)
268
+ assert_in_delta(0.0, methods[2].total_time, 0.03)
269
+ assert_in_delta(0.0, methods[2].wait_time, 0.03)
270
+ assert_in_delta(0.0, methods[2].self_time, 0.03)
271
+ assert_in_delta(0.0, methods[2].children_time, 0.03)
272
+
273
+ assert_equal('Thread#initialize', methods[3].full_name)
274
+ assert_in_delta(0.0, methods[3].total_time, 0.03)
275
+ assert_in_delta(0.0, methods[3].wait_time, 0.03)
276
+ assert_in_delta(0.0, methods[3].self_time, 0.03)
277
+ assert_in_delta(0.0, methods[3].children_time, 0.03)
278
+
279
+ thread = result.threads.last
280
+ assert_in_delta(0.2, thread.total_time, 0.03)
281
+
282
+ root_methods = thread.root_methods
283
+ assert_equal(1, root_methods.count)
284
+ assert_equal("MeasureWallTimeTest#test_instance_methods_threaded", root_methods[0].full_name)
285
+
286
+ methods = result.threads.first.methods.sort.reverse
287
+ assert_equal(4, methods.length)
288
+
289
+ methods = result.threads.last.methods.sort.reverse
290
+ assert_equal(5, methods.length)
291
+
292
+ # Check times
293
+ assert_equal('MeasureWallTimeTest#test_instance_methods_threaded', methods[0].full_name)
294
+ assert_in_delta(0.2, methods[0].total_time, 0.03)
295
+ assert_in_delta(0.0, methods[0].wait_time, 0.03)
296
+ assert_in_delta(0.0, methods[0].self_time, 0.03)
297
+ assert_in_delta(0.2, methods[0].children_time, 0.03)
298
+
299
+ assert_equal('RubyProf::C1#sleep_wait', methods[1].full_name)
300
+ assert_in_delta(0.2, methods[1].total_time, 0.03)
301
+ assert_in_delta(0.0, methods[1].wait_time, 0.03)
302
+ assert_in_delta(0.0, methods[1].self_time, 0.03)
303
+ assert_in_delta(0.2, methods[1].children_time, 0.03)
304
+
305
+ assert_equal('Kernel#sleep', methods[2].full_name)
306
+ assert_in_delta(0.2, methods[2].total_time, 0.03)
307
+ assert_in_delta(0.0, methods[2].wait_time, 0.03)
308
+ assert_in_delta(0.2, methods[2].self_time, 0.03)
309
+ assert_in_delta(0.0, methods[2].children_time, 0.03)
310
+
311
+ assert_equal('Class#new', methods[3].full_name)
312
+ assert_in_delta(0.0, methods[3].total_time, 0.03)
313
+ assert_in_delta(0.0, methods[3].wait_time, 0.03)
314
+ assert_in_delta(0.0, methods[3].self_time, 0.03)
315
+ assert_in_delta(0.0, methods[3].children_time, 0.03)
316
+
317
+ assert_equal('BasicObject#initialize', methods[4].full_name)
318
+ assert_in_delta(0.0, methods[4].total_time, 0.03)
319
+ assert_in_delta(0.0, methods[4].wait_time, 0.03)
320
+ assert_in_delta(0.0, methods[4].self_time, 0.03)
321
+ assert_in_delta(0.0, methods[4].children_time, 0.03)
120
322
  end
121
323
 
122
324
  def test_module_methods
123
325
  result = RubyProf.profile do
124
- RubyProf::C2.hello
326
+ RubyProf::C2.sleep_wait
125
327
  end
126
328
 
127
329
  thread = result.threads.first
128
- assert_in_delta(0.3, thread.total_time, 0.01)
129
-
130
- top_methods = thread.top_methods
131
- assert_equal(1, top_methods.count)
132
- assert_equal("MeasureWallTimeTest#test_module_methods", top_methods[0].full_name)
330
+ assert_in_delta(0.3, thread.total_time, 0.03)
133
331
 
134
- # Methods:
135
- # MeasureWallTimeTest#test_module_methods
136
- # M1#hello
137
- # Kernel#sleep
332
+ root_methods = thread.root_methods
333
+ assert_equal(1, root_methods.count)
334
+ assert_equal("MeasureWallTimeTest#test_module_methods", root_methods[0].full_name)
138
335
 
139
336
  methods = result.threads.first.methods.sort.reverse
140
337
  assert_equal(3, methods.length)
141
338
 
142
339
  assert_equal('MeasureWallTimeTest#test_module_methods', methods[0].full_name)
143
- assert_equal('RubyProf::M1#hello', methods[1].full_name)
340
+ assert_equal('RubyProf::M1#sleep_wait', methods[1].full_name)
144
341
  assert_equal('Kernel#sleep', methods[2].full_name)
145
342
 
146
343
  # Check times
147
344
  assert_in_delta(0.3, methods[0].total_time, 0.1)
148
- assert_in_delta(0, methods[0].wait_time, 0.02)
149
- assert_in_delta(0, methods[0].self_time, 0.02)
345
+ assert_in_delta(0, methods[0].wait_time, 0.03)
346
+ assert_in_delta(0, methods[0].self_time, 0.03)
150
347
 
151
348
  assert_in_delta(0.3, methods[1].total_time, 0.1)
152
- assert_in_delta(0, methods[1].wait_time, 0.02)
153
- assert_in_delta(0, methods[1].self_time, 0.02)
349
+ assert_in_delta(0, methods[1].wait_time, 0.03)
350
+ assert_in_delta(0, methods[1].self_time, 0.03)
154
351
 
155
352
  assert_in_delta(0.3, methods[2].total_time, 0.1)
156
- assert_in_delta(0, methods[2].wait_time, 0.02)
353
+ assert_in_delta(0, methods[2].wait_time, 0.03)
157
354
  assert_in_delta(0.3, methods[2].self_time, 0.1)
158
355
  end
159
356
 
160
357
  def test_module_instance_methods
161
358
  result = RubyProf.profile do
162
- RubyProf::C2.new.hello
359
+ RubyProf::C2.new.sleep_wait
163
360
  end
164
361
 
165
362
  thread = result.threads.first
166
- assert_in_delta(0.3, thread.total_time, 0.01)
363
+ assert_in_delta(0.3, thread.total_time, 0.03)
167
364
 
168
- top_methods = thread.top_methods
169
- assert_equal(1, top_methods.count)
170
- assert_equal("MeasureWallTimeTest#test_module_instance_methods", top_methods[0].full_name)
171
-
172
- # Methods:
173
- # MeasureWallTimeTest#test_module_instance_methods
174
- # Class#new
175
- # <Class::Object>#allocate
176
- # Object#initialize
177
- # M1#hello
178
- # Kernel#sleep
365
+ root_methods = thread.root_methods
366
+ assert_equal(1, root_methods.count)
367
+ assert_equal("MeasureWallTimeTest#test_module_instance_methods", root_methods[0].full_name)
179
368
 
180
369
  methods = result.threads.first.methods.sort.reverse
181
- assert_equal(RubyProf.ruby_2? ? 5 : 6, methods.length)
370
+ assert_equal(5, methods.length)
182
371
  names = methods.map(&:full_name)
183
372
  assert_equal('MeasureWallTimeTest#test_module_instance_methods', names[0])
184
- assert_equal('RubyProf::M1#hello', names[1])
373
+ assert_equal('RubyProf::M1#sleep_wait', names[1])
185
374
  assert_equal('Kernel#sleep', names[2])
186
375
  assert_equal('Class#new', names[3])
187
376
 
188
377
  # order can differ
189
- assert(names.include?("#{RubyProf.parent_object}#initialize"))
190
- unless RubyProf.ruby_2?
191
- assert(names.include?("<Class::#{RubyProf.parent_object}>#allocate"))
192
- end
378
+ assert(names.include?("BasicObject#initialize"))
193
379
 
194
380
  # Check times
195
381
  assert_in_delta(0.3, methods[0].total_time, 0.1)
196
382
  assert_in_delta(0, methods[0].wait_time, 0.1)
197
383
  assert_in_delta(0, methods[0].self_time, 0.1)
198
384
 
199
- assert_in_delta(0.3, methods[1].total_time, 0.02)
200
- assert_in_delta(0, methods[1].wait_time, 0.01)
201
- assert_in_delta(0, methods[1].self_time, 0.01)
385
+ assert_in_delta(0.3, methods[1].total_time, 0.03)
386
+ assert_in_delta(0, methods[1].wait_time, 0.03)
387
+ assert_in_delta(0, methods[1].self_time, 0.03)
202
388
 
203
- assert_in_delta(0.3, methods[2].total_time, 0.02)
204
- assert_in_delta(0, methods[2].wait_time, 0.01)
205
- assert_in_delta(0.3, methods[2].self_time, 0.02)
389
+ assert_in_delta(0.3, methods[2].total_time, 0.03)
390
+ assert_in_delta(0, methods[2].wait_time, 0.03)
391
+ assert_in_delta(0.3, methods[2].self_time, 0.03)
206
392
 
207
- assert_in_delta(0, methods[3].total_time, 0.01)
208
- assert_in_delta(0, methods[3].wait_time, 0.01)
209
- assert_in_delta(0, methods[3].self_time, 0.01)
393
+ assert_in_delta(0, methods[3].total_time, 0.03)
394
+ assert_in_delta(0, methods[3].wait_time, 0.03)
395
+ assert_in_delta(0, methods[3].self_time, 0.03)
210
396
 
211
- assert_in_delta(0, methods[4].total_time, 0.01)
212
- assert_in_delta(0, methods[4].wait_time, 0.01)
213
- assert_in_delta(0, methods[4].self_time, 0.01)
214
-
215
- unless RubyProf.ruby_2?
216
- assert_in_delta(0, methods[5].total_time, 0.01)
217
- assert_in_delta(0, methods[5].wait_time, 0.01)
218
- assert_in_delta(0, methods[5].self_time, 0.01)
219
- end
397
+ assert_in_delta(0, methods[4].total_time, 0.03)
398
+ assert_in_delta(0, methods[4].wait_time, 0.03)
399
+ assert_in_delta(0, methods[4].self_time, 0.03)
220
400
  end
221
401
 
222
- def test_singleton
223
- c3 = RubyProf::C3.new
224
-
225
- class << c3
226
- def hello
227
- end
228
- end
229
-
402
+ def test_singleton_methods
230
403
  result = RubyProf.profile do
231
- c3.hello
404
+ RubyProf::C3.instance.sleep_wait
232
405
  end
233
406
 
234
407
  thread = result.threads.first
235
- assert_in_delta(0.0, thread.total_time, 0.01)
408
+ assert_in_delta(0.3, thread.total_time, 0.03)
236
409
 
237
- top_methods = thread.top_methods
238
- assert_equal(1, top_methods.count)
239
- assert_equal("MeasureWallTimeTest#test_singleton", top_methods[0].full_name)
410
+ root_methods = thread.root_methods
411
+ assert_equal(1, root_methods.count)
412
+ assert_equal("MeasureWallTimeTest#test_singleton_methods", root_methods[0].full_name)
240
413
 
241
414
  methods = result.threads.first.methods.sort.reverse
242
- assert_equal(2, methods.length)
415
+ assert_equal(7, methods.length)
243
416
 
244
- assert_equal('MeasureWallTimeTest#test_singleton', methods[0].full_name)
245
- assert_equal('<Object::RubyProf::C3>#hello', methods[1].full_name)
417
+ assert_equal('MeasureWallTimeTest#test_singleton_methods', methods[0].full_name)
418
+ assert_in_delta(0.3, methods[0].total_time, 0.03)
419
+ assert_in_delta(0.0, methods[0].wait_time, 0.03)
420
+ assert_in_delta(0.0, methods[0].self_time, 0.03)
421
+ assert_in_delta(0.3, methods[0].children_time, 0.03)
246
422
 
247
- assert_in_delta(0, methods[0].total_time, 0.01)
248
- assert_in_delta(0, methods[0].wait_time, 0.01)
249
- assert_in_delta(0, methods[0].self_time, 0.01)
423
+ assert_equal('RubyProf::C3#sleep_wait', methods[1].full_name)
424
+ assert_in_delta(0.3, methods[1].total_time, 0.03)
425
+ assert_in_delta(0.0, methods[1].wait_time, 0.03)
426
+ assert_in_delta(0.0, methods[1].self_time, 0.03)
427
+ assert_in_delta(0.3, methods[1].children_time, 0.03)
250
428
 
251
- assert_in_delta(0, methods[1].total_time, 0.01)
252
- assert_in_delta(0, methods[1].wait_time, 0.01)
253
- assert_in_delta(0, methods[1].self_time, 0.01)
429
+ assert_equal('Kernel#sleep', methods[2].full_name)
430
+ assert_in_delta(0.3, methods[2].total_time, 0.03)
431
+ assert_in_delta(0.0, methods[2].wait_time, 0.03)
432
+ assert_in_delta(0.3, methods[2].self_time, 0.03)
433
+ assert_in_delta(0.0, methods[2].children_time, 0.03)
434
+
435
+ assert_equal('<Class::RubyProf::C3>#instance', methods[3].full_name)
436
+ assert_in_delta(0.0, methods[3].total_time, 0.03)
437
+ assert_in_delta(0.0, methods[3].wait_time, 0.03)
438
+ assert_in_delta(0.0, methods[3].self_time, 0.03)
439
+ assert_in_delta(0.0, methods[3].children_time, 0.03)
440
+
441
+ assert_equal('Thread::Mutex#synchronize', methods[4].full_name)
442
+ assert_in_delta(0.0, methods[4].total_time, 0.03)
443
+ assert_in_delta(0.0, methods[4].wait_time, 0.03)
444
+ assert_in_delta(0.0, methods[4].self_time, 0.03)
445
+ assert_in_delta(0.0, methods[4].children_time, 0.03)
446
+
447
+ assert_equal('Class#new', methods[5].full_name)
448
+ assert_in_delta(0.0, methods[5].total_time, 0.03)
449
+ assert_in_delta(0.0, methods[5].wait_time, 0.03)
450
+ assert_in_delta(0.0, methods[5].self_time, 0.03)
451
+ assert_in_delta(0.0, methods[5].children_time, 0.03)
452
+
453
+ assert_equal('BasicObject#initialize', methods[6].full_name)
454
+ assert_in_delta(0.0, methods[6].total_time, 0.03)
455
+ assert_in_delta(0.0, methods[6].wait_time, 0.03)
456
+ assert_in_delta(0.0, methods[6].self_time, 0.03)
457
+ assert_in_delta(0.0, methods[6].children_time, 0.03)
254
458
  end
255
- end
459
+ end