ruby-prof 0.18.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +44 -1
  3. data/LICENSE +2 -2
  4. data/README.rdoc +1 -483
  5. data/Rakefile +3 -6
  6. data/bin/ruby-prof +111 -128
  7. data/ext/ruby_prof/extconf.rb +6 -38
  8. data/ext/ruby_prof/rp_aggregate_call_tree.c +41 -0
  9. data/ext/ruby_prof/rp_aggregate_call_tree.h +13 -0
  10. data/ext/ruby_prof/rp_allocation.c +259 -0
  11. data/ext/ruby_prof/rp_allocation.h +31 -0
  12. data/ext/ruby_prof/rp_call_tree.c +353 -0
  13. data/ext/ruby_prof/rp_call_tree.h +43 -0
  14. data/ext/ruby_prof/rp_call_trees.c +266 -0
  15. data/ext/ruby_prof/rp_call_trees.h +29 -0
  16. data/ext/ruby_prof/rp_measure_allocations.c +25 -51
  17. data/ext/ruby_prof/rp_measure_memory.c +21 -56
  18. data/ext/ruby_prof/rp_measure_process_time.c +37 -43
  19. data/ext/ruby_prof/rp_measure_wall_time.c +40 -21
  20. data/ext/ruby_prof/rp_measurement.c +221 -0
  21. data/ext/ruby_prof/rp_measurement.h +50 -0
  22. data/ext/ruby_prof/rp_method.c +279 -439
  23. data/ext/ruby_prof/rp_method.h +33 -45
  24. data/ext/ruby_prof/rp_profile.c +902 -0
  25. data/ext/ruby_prof/rp_profile.h +36 -0
  26. data/ext/ruby_prof/rp_stack.c +163 -132
  27. data/ext/ruby_prof/rp_stack.h +18 -28
  28. data/ext/ruby_prof/rp_thread.c +192 -124
  29. data/ext/ruby_prof/rp_thread.h +18 -8
  30. data/ext/ruby_prof/ruby_prof.c +36 -778
  31. data/ext/ruby_prof/ruby_prof.h +11 -45
  32. data/ext/ruby_prof/vc/ruby_prof.vcxproj +18 -12
  33. data/lib/ruby-prof.rb +4 -21
  34. data/lib/ruby-prof/assets/call_stack_printer.html.erb +710 -0
  35. data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
  36. data/lib/ruby-prof/assets/graph_printer.html.erb +355 -0
  37. data/lib/ruby-prof/call_tree.rb +57 -0
  38. data/lib/ruby-prof/call_tree_visitor.rb +36 -0
  39. data/lib/ruby-prof/compatibility.rb +37 -107
  40. data/lib/ruby-prof/exclude_common_methods.rb +198 -0
  41. data/lib/ruby-prof/measurement.rb +17 -0
  42. data/lib/ruby-prof/method_info.rb +47 -90
  43. data/lib/ruby-prof/printers/abstract_printer.rb +73 -50
  44. data/lib/ruby-prof/printers/call_info_printer.rb +24 -12
  45. data/lib/ruby-prof/printers/call_stack_printer.rb +66 -152
  46. data/lib/ruby-prof/printers/call_tree_printer.rb +20 -12
  47. data/lib/ruby-prof/printers/dot_printer.rb +5 -5
  48. data/lib/ruby-prof/printers/flat_printer.rb +6 -24
  49. data/lib/ruby-prof/printers/graph_html_printer.rb +6 -192
  50. data/lib/ruby-prof/printers/graph_printer.rb +11 -14
  51. data/lib/ruby-prof/printers/multi_printer.rb +66 -23
  52. data/lib/ruby-prof/profile.rb +10 -3
  53. data/lib/ruby-prof/thread.rb +5 -20
  54. data/lib/ruby-prof/version.rb +1 -1
  55. data/ruby-prof.gemspec +9 -2
  56. data/test/abstract_printer_test.rb +0 -27
  57. data/test/alias_test.rb +126 -0
  58. data/test/basic_test.rb +1 -86
  59. data/test/call_tree_visitor_test.rb +32 -0
  60. data/test/call_trees_test.rb +66 -0
  61. data/test/dynamic_method_test.rb +0 -2
  62. data/test/exclude_methods_test.rb +17 -12
  63. data/test/fiber_test.rb +214 -23
  64. data/test/gc_test.rb +105 -0
  65. data/test/inverse_call_tree_test.rb +175 -0
  66. data/test/line_number_test.rb +118 -40
  67. data/test/marshal_test.rb +115 -0
  68. data/test/measure_allocations.rb +30 -0
  69. data/test/measure_allocations_test.rb +361 -12
  70. data/test/measure_allocations_trace_test.rb +375 -0
  71. data/test/measure_memory_trace_test.rb +1101 -0
  72. data/test/measure_process_time_test.rb +757 -33
  73. data/test/measure_times.rb +56 -0
  74. data/test/measure_wall_time_test.rb +329 -149
  75. data/test/multi_printer_test.rb +1 -34
  76. data/test/pause_resume_test.rb +24 -15
  77. data/test/prime.rb +1 -1
  78. data/test/prime_script.rb +6 -0
  79. data/test/printer_call_stack_test.rb +28 -0
  80. data/test/printer_call_tree_test.rb +31 -0
  81. data/test/printer_flat_test.rb +68 -0
  82. data/test/printer_graph_html_test.rb +60 -0
  83. data/test/printer_graph_test.rb +41 -0
  84. data/test/printers_test.rb +32 -166
  85. data/test/printing_recursive_graph_test.rb +26 -72
  86. data/test/recursive_test.rb +68 -77
  87. data/test/stack_printer_test.rb +2 -15
  88. data/test/start_stop_test.rb +22 -25
  89. data/test/test_helper.rb +6 -261
  90. data/test/thread_test.rb +11 -54
  91. data/test/unique_call_path_test.rb +25 -107
  92. data/test/yarv_test.rb +1 -0
  93. metadata +43 -41
  94. data/examples/flat.txt +0 -50
  95. data/examples/graph.dot +0 -84
  96. data/examples/graph.html +0 -823
  97. data/examples/graph.txt +0 -139
  98. data/examples/multi.flat.txt +0 -23
  99. data/examples/multi.graph.html +0 -760
  100. data/examples/multi.grind.dat +0 -114
  101. data/examples/multi.stack.html +0 -547
  102. data/examples/stack.html +0 -547
  103. data/ext/ruby_prof/rp_call_info.c +0 -425
  104. data/ext/ruby_prof/rp_call_info.h +0 -53
  105. data/ext/ruby_prof/rp_measure.c +0 -40
  106. data/ext/ruby_prof/rp_measure.h +0 -45
  107. data/ext/ruby_prof/rp_measure_cpu_time.c +0 -136
  108. data/ext/ruby_prof/rp_measure_gc_runs.c +0 -73
  109. data/ext/ruby_prof/rp_measure_gc_time.c +0 -60
  110. data/lib/ruby-prof/aggregate_call_info.rb +0 -76
  111. data/lib/ruby-prof/assets/call_stack_printer.css.html +0 -117
  112. data/lib/ruby-prof/assets/call_stack_printer.js.html +0 -385
  113. data/lib/ruby-prof/call_info.rb +0 -115
  114. data/lib/ruby-prof/call_info_visitor.rb +0 -40
  115. data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -83
  116. data/lib/ruby-prof/profile/exclude_common_methods.rb +0 -207
  117. data/lib/ruby-prof/profile/legacy_method_elimination.rb +0 -50
  118. data/test/aggregate_test.rb +0 -136
  119. data/test/block_test.rb +0 -74
  120. data/test/call_info_test.rb +0 -78
  121. data/test/call_info_visitor_test.rb +0 -31
  122. data/test/issue137_test.rb +0 -63
  123. data/test/measure_cpu_time_test.rb +0 -212
  124. data/test/measure_gc_runs_test.rb +0 -32
  125. data/test/measure_gc_time_test.rb +0 -36
  126. data/test/measure_memory_test.rb +0 -33
  127. data/test/method_elimination_test.rb +0 -84
  128. data/test/module_test.rb +0 -45
  129. data/test/stack_test.rb +0 -138
@@ -2,60 +2,784 @@
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 MeasureProcessTimeTest < TestCase
7
8
  def setup
8
9
  # Need to fix this for linux (windows works since PROCESS_TIME is WALL_TIME anyway)
9
10
  RubyProf::measure_mode = RubyProf::PROCESS_TIME
11
+ GC.start
10
12
  end
11
13
 
12
14
  def test_mode
13
15
  assert_equal(RubyProf::PROCESS_TIME, RubyProf::measure_mode)
14
16
  end
15
17
 
16
- def test_process_time_enabled_defined
17
- assert(defined?(RubyProf::PROCESS_TIME_ENABLED))
18
+ def test_class_methods_sleep
19
+ result = RubyProf.profile do
20
+ RubyProf::C1.sleep_wait
21
+ end
22
+
23
+ thread = result.threads.first
24
+ assert_in_delta(0.0, thread.total_time, 0.05)
25
+
26
+ methods = result.threads.first.methods.sort.reverse
27
+ assert_equal(3, methods.length)
28
+
29
+ # Check times
30
+ method = methods[0]
31
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep', method.full_name)
32
+ assert_in_delta(0.0, method.total_time, 0.05)
33
+ assert_in_delta(0.0, method.wait_time, 0.05)
34
+ assert_in_delta(0.0, method.self_time, 0.05)
35
+ assert_in_delta(0.0, method.children_time, 0.05)
36
+
37
+ method = methods[1]
38
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
39
+ assert_in_delta(0.0, method.total_time, 0.05)
40
+ assert_in_delta(0.0, method.wait_time, 0.05)
41
+ assert_in_delta(0.0, method.self_time, 0.05)
42
+ assert_in_delta(0.0, method.children_time, 0.05)
43
+
44
+ method = methods[2]
45
+ assert_equal('Kernel#sleep', method.full_name)
46
+ assert_in_delta(0.0, method.total_time, 0.05)
47
+ assert_in_delta(0.0, method.wait_time, 0.05)
48
+ assert_in_delta(0.0, method.self_time, 0.05)
49
+ assert_in_delta(0.0, method.children_time, 0.05)
18
50
  end
19
51
 
20
- def test_primes
21
- start = Process.times
52
+ def test_class_methods_sleep_threaded
22
53
  result = RubyProf.profile do
23
- run_primes(10000)
54
+ background_thread = Thread.new do
55
+ RubyProf::C1.sleep_wait
56
+ end
57
+ background_thread.join
24
58
  end
25
- finish = Process.times
26
59
 
27
- total_time = (finish.utime - start.utime) + (finish.stime - start.stime)
60
+ assert_equal(2, result.threads.count)
61
+
62
+ thread = result.threads.first
63
+ assert_in_delta(0.0, thread.total_time, 0.05)
64
+
65
+ methods = result.threads.first.methods.sort.reverse
66
+ assert_equal(4, methods.length)
67
+
68
+ # Check times
69
+ method = methods[0]
70
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
71
+ assert_in_delta(0.0, method.total_time, 0.05)
72
+ assert_in_delta(0.0, method.wait_time, 0.05)
73
+ assert_in_delta(0.0, method.self_time, 0.05)
74
+ assert_in_delta(0.0, method.children_time, 0.05)
75
+
76
+ method = methods[1]
77
+ assert_equal('Thread#join', method.full_name)
78
+ assert_in_delta(0.0, method.total_time, 0.05)
79
+ assert_in_delta(0.0, method.wait_time, 0.05)
80
+ assert_in_delta(0.0, method.self_time, 0.05)
81
+ assert_in_delta(0.0, method.children_time, 0.05)
82
+
83
+ method = methods[2]
84
+ assert_equal('<Class::Thread>#new', method.full_name)
85
+ assert_in_delta(0.0, method.total_time, 0.05)
86
+ assert_in_delta(0.0, method.wait_time, 0.05)
87
+ assert_in_delta(0.0, method.self_time, 0.05)
88
+ assert_in_delta(0.0, method.children_time, 0.05)
89
+
90
+ method = methods[3]
91
+ assert_equal('Thread#initialize', method.full_name)
92
+ assert_in_delta(0.0, method.total_time, 0.05)
93
+ assert_in_delta(0.0, method.wait_time, 0.05)
94
+ assert_in_delta(0.0, method.self_time, 0.05)
95
+ assert_in_delta(0.0, method.children_time, 0.05)
96
+
97
+ thread = result.threads.last
98
+ assert_in_delta(0.0, thread.total_time, 0.05)
99
+
100
+ methods = result.threads.first.methods.sort.reverse
101
+ assert_equal(4, methods.length)
102
+
103
+ methods = result.threads.last.methods.sort.reverse
104
+ assert_equal(3, methods.length)
105
+
106
+ # Check times
107
+ method = methods[0]
108
+ assert_equal('MeasureProcessTimeTest#test_class_methods_sleep_threaded', method.full_name)
109
+ assert_in_delta(0.0, method.total_time, 0.05)
110
+ assert_in_delta(0.0, method.wait_time, 0.05)
111
+ assert_in_delta(0.0, method.self_time, 0.05)
112
+ assert_in_delta(0.0, method.children_time, 0.05)
113
+
114
+ method = methods[1]
115
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', method.full_name)
116
+ assert_in_delta(0.0, method.total_time, 0.05)
117
+ assert_in_delta(0.0, method.wait_time, 0.05)
118
+ assert_in_delta(0.0, method.self_time, 0.05)
119
+ assert_in_delta(0.0, method.children_time, 0.05)
120
+
121
+ method = methods[2]
122
+ assert_equal('Kernel#sleep', method.full_name)
123
+ assert_in_delta(0.0, method.total_time, 0.05)
124
+ assert_in_delta(0.0, method.wait_time, 0.05)
125
+ assert_in_delta(0.0, method.self_time, 0.05)
126
+ assert_in_delta(0.0, method.children_time, 0.05)
127
+ end
128
+
129
+ def test_class_methods_busy
130
+ result = RubyProf.profile do
131
+ RubyProf::C1.busy_wait
132
+ end
28
133
 
29
134
  thread = result.threads.first
30
- assert_in_delta(total_time, thread.total_time, 0.03)
135
+ assert_in_delta(0.08, thread.total_time, 0.05)
31
136
 
32
137
  methods = result.threads.first.methods.sort.reverse
138
+ assert_equal(3, methods.length)
139
+
140
+ # Check times
141
+ method = methods[0]
142
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy', method.full_name)
143
+ assert_in_delta(0.1, method.total_time, 0.05)
144
+ assert_in_delta(0.0, method.wait_time, 0.05)
145
+ assert_in_delta(0.0, method.self_time, 0.05)
146
+ assert_in_delta(0.1, method.children_time, 0.05)
33
147
 
34
- expected_number_of_methods =
35
- case RUBY_VERSION
36
- when /^2\.(1|2)/ then 14
37
- else 13
148
+ method = methods[1]
149
+ assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
150
+ assert_in_delta(0.1, method.total_time, 0.05)
151
+ assert_in_delta(0.0, method.wait_time, 0.05)
152
+ assert_in_delta(0.06, method.self_time, 0.05)
153
+ assert_in_delta(0.07, method.children_time, 0.05)
154
+
155
+ method = methods[2]
156
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
157
+ assert_in_delta(0.05, method.total_time, 0.05)
158
+ assert_in_delta(0.0, method.wait_time, 0.05)
159
+ assert_in_delta(0.05, method.self_time, 0.05)
160
+ assert_in_delta(0.0, method.children_time, 0.05)
161
+ end
162
+
163
+ def test_class_methods_busy_threaded
164
+ result = RubyProf.profile do
165
+ background_thread = Thread.new do
166
+ RubyProf::C1.busy_wait
38
167
  end
39
- # puts methods.map(&:full_name).inspect
40
- assert_equal expected_number_of_methods, methods.length
41
-
42
- # Check times
43
- assert_equal("MeasureProcessTimeTest#test_primes", methods[0].full_name)
44
- assert_in_delta(total_time, methods[0].total_time, 0.02)
45
- assert_in_delta(0.0, methods[0].wait_time, 0.01)
46
- assert_in_delta(0.0, methods[0].self_time, 0.01)
47
-
48
- assert_equal("Object#run_primes", methods[1].full_name)
49
- assert_in_delta(total_time, methods[1].total_time, 0.02)
50
- assert_in_delta(0.0, methods[1].wait_time, 0.01)
51
- assert_in_delta(0.0, methods[1].self_time, 0.01)
52
-
53
- assert_equal("Object#find_primes", methods[2].full_name)
54
- assert_equal("Array#select", methods[3].full_name)
55
- assert_equal("Object#is_prime", methods[4].full_name)
56
- assert_equal("Integer#upto", methods[5].full_name)
57
- assert_equal("Object#make_random_array", methods[6].full_name)
58
- assert_equal("Array#each_index", methods[7].full_name)
59
- assert_equal("Kernel#rand", methods[8].full_name)
168
+ background_thread.join
169
+ end
170
+
171
+ assert_equal(2, result.threads.count)
172
+
173
+ thread = result.threads.first
174
+ assert_in_delta(0.1, thread.total_time, 0.05)
175
+
176
+ methods = result.threads.first.methods.sort.reverse
177
+ assert_equal(4, methods.length)
178
+
179
+ # Check times
180
+ method = methods[0]
181
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
182
+ assert_in_delta(0.1, method.total_time, 0.05)
183
+ assert_in_delta(0.0, method.wait_time, 0.05)
184
+ assert_in_delta(0.0, method.self_time, 0.05)
185
+ assert_in_delta(0.1, method.children_time, 0.05)
186
+
187
+ method = methods[1]
188
+ assert_equal('Thread#join', method.full_name)
189
+ assert_in_delta(0.1, method.total_time, 0.05)
190
+ assert_in_delta(0.1, method.wait_time, 0.05)
191
+ assert_in_delta(0.0, method.self_time, 0.05)
192
+ assert_in_delta(0.0, method.children_time, 0.05)
193
+
194
+ method = methods[2]
195
+ assert_equal('<Class::Thread>#new', method.full_name)
196
+ assert_in_delta(0.0, method.total_time, 0.05)
197
+ assert_in_delta(0.0, method.wait_time, 0.05)
198
+ assert_in_delta(0.0, method.self_time, 0.05)
199
+ assert_in_delta(0.0, method.children_time, 0.05)
200
+
201
+ method = methods[3]
202
+ assert_equal('Thread#initialize', method.full_name)
203
+ assert_in_delta(0.0, method.total_time, 0.05)
204
+ assert_in_delta(0.0, method.wait_time, 0.05)
205
+ assert_in_delta(0.0, method.self_time, 0.05)
206
+ assert_in_delta(0.0, method.children_time, 0.05)
207
+
208
+ thread = result.threads.last
209
+ assert_in_delta(0.1, thread.total_time, 0.05)
210
+
211
+ methods = result.threads.first.methods.sort.reverse
212
+ assert_equal(4, methods.length)
213
+
214
+ methods = result.threads.last.methods.sort.reverse
215
+ assert_equal(3, methods.length)
216
+
217
+ # Check times
218
+ method = methods[0]
219
+ assert_equal('MeasureProcessTimeTest#test_class_methods_busy_threaded', method.full_name)
220
+ assert_in_delta(0.1, method.total_time, 0.05)
221
+ assert_in_delta(0.0, method.wait_time, 0.05)
222
+ assert_in_delta(0.0, method.self_time, 0.05)
223
+ assert_in_delta(0.1, method.children_time, 0.05)
224
+
225
+ method = methods[1]
226
+ assert_equal('<Class::RubyProf::C1>#busy_wait', method.full_name)
227
+ assert_in_delta(0.1, method.total_time, 0.05)
228
+ assert_in_delta(0.0, method.wait_time, 0.05)
229
+ assert_in_delta(0.05, method.self_time, 0.05)
230
+ assert_in_delta(0.05, method.children_time, 0.05)
231
+
232
+ method = methods[2]
233
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
234
+ assert_in_delta(0.05, method.total_time, 0.05)
235
+ assert_in_delta(0.0, method.wait_time, 0.05)
236
+ assert_in_delta(0.05, method.self_time, 0.05)
237
+ assert_in_delta(0.0, method.children_time, 0.05)
238
+ end
239
+
240
+ def test_instance_methods_sleep
241
+ result = RubyProf.profile do
242
+ RubyProf::C1.new.sleep_wait
243
+ end
244
+
245
+ thread = result.threads.first
246
+ assert_in_delta(0.0, thread.total_time, 0.05)
247
+
248
+ methods = result.threads.first.methods.sort.reverse
249
+ assert_equal(5, methods.length)
250
+
251
+ # Check times
252
+ method = methods[0]
253
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep', method.full_name)
254
+ assert_in_delta(0.0, method.total_time, 0.05)
255
+ assert_in_delta(0.0, method.wait_time, 0.05)
256
+ assert_in_delta(0.0, method.self_time, 0.05)
257
+ assert_in_delta(0.0, method.children_time, 0.05)
258
+
259
+ method = methods[1]
260
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
261
+ assert_in_delta(0.0, method.total_time, 0.05)
262
+ assert_in_delta(0.0, method.wait_time, 0.05)
263
+ assert_in_delta(0.0, method.self_time, 0.05)
264
+ assert_in_delta(0.0, method.children_time, 0.05)
265
+
266
+ method = methods[2]
267
+ assert_equal('Kernel#sleep', method.full_name)
268
+ assert_in_delta(0.0, method.total_time, 0.05)
269
+ assert_in_delta(0.0, method.wait_time, 0.05)
270
+ assert_in_delta(0.0, method.self_time, 0.05)
271
+ assert_in_delta(0.0, method.children_time, 0.05)
272
+
273
+ method = methods[3]
274
+ assert_equal('Class#new', method.full_name)
275
+ assert_in_delta(0.0, method.total_time, 0.05)
276
+ assert_in_delta(0.0, method.wait_time, 0.05)
277
+ assert_in_delta(0.0, method.self_time, 0.05)
278
+ assert_in_delta(0.0, method.children_time, 0.05)
279
+
280
+ method = methods[4]
281
+ assert_equal('BasicObject#initialize', method.full_name)
282
+ assert_in_delta(0.0, method.total_time, 0.05)
283
+ assert_in_delta(0.0, method.wait_time, 0.05)
284
+ assert_in_delta(0.0, method.self_time, 0.05)
285
+ assert_in_delta(0.0, method.children_time, 0.05)
286
+ end
287
+
288
+ def test_instance_methods_sleep_block
289
+ result = RubyProf.profile do
290
+ 1.times { RubyProf::C1.new.sleep_wait }
291
+ end
292
+
293
+ methods = result.threads.first.methods.sort.reverse
294
+ assert_equal(6, methods.length)
295
+
296
+ # Check times
297
+ method = methods[0]
298
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_sleep_block", method.full_name)
299
+ assert_in_delta(0.0, method.total_time, 0.05)
300
+ assert_in_delta(0.0, method.wait_time, 0.05)
301
+ assert_in_delta(0.0, method.self_time, 0.05)
302
+ assert_in_delta(0.0, method.children_time, 0.05)
303
+
304
+ method = methods[1]
305
+ assert_equal('Integer#times', method.full_name)
306
+ assert_in_delta(0.0, method.total_time, 0.05)
307
+ assert_in_delta(0.0, method.wait_time, 0.05)
308
+ assert_in_delta(0.0, method.self_time, 0.05)
309
+ assert_in_delta(0.0, method.children_time, 0.05)
310
+
311
+ method = methods[2]
312
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
313
+ assert_in_delta(0.0, method.total_time, 0.05)
314
+ assert_in_delta(0.0, method.wait_time, 0.05)
315
+ assert_in_delta(0.0, method.self_time, 0.05)
316
+ assert_in_delta(0.0, method.children_time, 0.05)
317
+
318
+ method = methods[3]
319
+ assert_equal('Kernel#sleep', method.full_name)
320
+ assert_in_delta(0.0, method.total_time, 0.05)
321
+ assert_in_delta(0.0, method.wait_time, 0.05)
322
+ assert_in_delta(0.0, method.self_time, 0.05)
323
+ assert_in_delta(0.0, method.children_time, 0.05)
324
+
325
+ method = methods[4]
326
+ assert_equal('Class#new', method.full_name)
327
+ assert_in_delta(0.0, method.total_time, 0.05)
328
+ assert_in_delta(0.0, method.wait_time, 0.05)
329
+ assert_in_delta(0.0, method.self_time, 0.05)
330
+ assert_in_delta(0.0, method.children_time, 0.05)
331
+
332
+ method = methods[5]
333
+ assert_equal('BasicObject#initialize', method.full_name)
334
+ assert_in_delta(0.0, method.total_time, 0.05)
335
+ assert_in_delta(0.0, method.wait_time, 0.05)
336
+ assert_in_delta(0.0, method.self_time, 0.05)
337
+ assert_in_delta(0.0, method.children_time, 0.05)
338
+ end
339
+
340
+ def test_instance_methods_sleep_threaded
341
+ result = RubyProf.profile do
342
+ background_thread = Thread.new do
343
+ RubyProf::C1.new.sleep_wait
344
+ end
345
+ background_thread.join
346
+ end
347
+
348
+ assert_equal(2, result.threads.count)
349
+
350
+ thread = result.threads.first
351
+ assert_in_delta(0.0, thread.total_time, 0.05)
352
+
353
+ methods = result.threads.first.methods.sort.reverse
354
+ assert_equal(4, methods.length)
355
+
356
+ # Check times
357
+ method = methods[0]
358
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
359
+ assert_in_delta(0.0, method.total_time, 0.05)
360
+ assert_in_delta(0.0, method.wait_time, 0.05)
361
+ assert_in_delta(0.0, method.self_time, 0.05)
362
+ assert_in_delta(0.0, method.children_time, 0.05)
363
+
364
+ method = methods[1]
365
+ assert_equal('Thread#join', method.full_name)
366
+ assert_in_delta(0.0, method.total_time, 0.05)
367
+ assert_in_delta(0.0, method.wait_time, 0.05)
368
+ assert_in_delta(0.0, method.self_time, 0.05)
369
+ assert_in_delta(0.0, method.children_time, 0.05)
370
+
371
+ method = methods[2]
372
+ assert_equal('<Class::Thread>#new', method.full_name)
373
+ assert_in_delta(0.0, method.total_time, 0.05)
374
+ assert_in_delta(0.0, method.wait_time, 0.05)
375
+ assert_in_delta(0.0, method.self_time, 0.05)
376
+ assert_in_delta(0.0, method.children_time, 0.05)
377
+
378
+ method = methods[3]
379
+ assert_equal('Thread#initialize', method.full_name)
380
+ assert_in_delta(0.0, method.total_time, 0.05)
381
+ assert_in_delta(0.0, method.wait_time, 0.05)
382
+ assert_in_delta(0.0, method.self_time, 0.05)
383
+ assert_in_delta(0.0, method.children_time, 0.05)
384
+
385
+ thread = result.threads.last
386
+ assert_in_delta(0.0, thread.total_time, 0.05)
387
+
388
+ methods = result.threads.first.methods.sort.reverse
389
+ assert_equal(4, methods.length)
390
+
391
+ methods = result.threads.last.methods.sort.reverse
392
+ assert_equal(5, methods.length)
393
+
394
+ # Check times
395
+ method = methods[0]
396
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_sleep_threaded', method.full_name)
397
+ assert_in_delta(0.0, method.total_time, 0.05)
398
+ assert_in_delta(0.0, method.wait_time, 0.05)
399
+ assert_in_delta(0.0, method.self_time, 0.05)
400
+ assert_in_delta(0.0, method.children_time, 0.05)
401
+
402
+ method = methods[1]
403
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
404
+ assert_in_delta(0.0, method.total_time, 0.05)
405
+ assert_in_delta(0.0, method.wait_time, 0.05)
406
+ assert_in_delta(0.0, method.self_time, 0.05)
407
+ assert_in_delta(0.0, method.children_time, 0.05)
408
+
409
+ method = methods[2]
410
+ assert_equal('Kernel#sleep', method.full_name)
411
+ assert_in_delta(0.0, method.total_time, 0.05)
412
+ assert_in_delta(0.0, method.wait_time, 0.05)
413
+ assert_in_delta(0.0, method.self_time, 0.05)
414
+ assert_in_delta(0.0, method.children_time, 0.05)
415
+
416
+ method = methods[3]
417
+ assert_equal('Class#new', method.full_name)
418
+ assert_in_delta(0.0, method.total_time, 0.05)
419
+ assert_in_delta(0.0, method.wait_time, 0.05)
420
+ assert_in_delta(0.0, method.self_time, 0.05)
421
+ assert_in_delta(0.0, method.children_time, 0.05)
422
+
423
+ method = methods[4]
424
+ assert_equal('BasicObject#initialize', method.full_name)
425
+ assert_in_delta(0.0, method.total_time, 0.05)
426
+ assert_in_delta(0.0, method.wait_time, 0.05)
427
+ assert_in_delta(0.0, method.self_time, 0.05)
428
+ assert_in_delta(0.0, method.children_time, 0.05)
429
+ end
430
+
431
+ def test_instance_methods_busy
432
+ result = RubyProf.profile do
433
+ RubyProf::C1.new.busy_wait
434
+ end
435
+
436
+ thread = result.threads.first
437
+ assert_in_delta(0.2, thread.total_time, 0.05)
438
+
439
+ methods = result.threads.first.methods.sort.reverse
440
+ assert_equal(5, methods.length)
441
+
442
+ # Check times
443
+ method = methods[0]
444
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy', method.full_name)
445
+ assert_in_delta(0.2, method.total_time, 0.05)
446
+ assert_in_delta(0.0, method.wait_time, 0.05)
447
+ assert_in_delta(0.0, method.self_time, 0.05)
448
+ assert_in_delta(0.2, method.children_time, 0.05)
449
+
450
+ method = methods[1]
451
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
452
+ assert_in_delta(0.2, method.total_time, 0.05)
453
+ assert_in_delta(0.0, method.wait_time, 0.05)
454
+ assert_in_delta(0.09, method.self_time, 0.05)
455
+ assert_in_delta(0.11, method.children_time, 0.05)
456
+
457
+ method = methods[2]
458
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
459
+ assert_in_delta(0.11, method.total_time, 0.05)
460
+ assert_in_delta(0.0, method.wait_time, 0.05)
461
+ assert_in_delta(0.11, method.self_time, 0.05)
462
+ assert_in_delta(0.0, method.children_time, 0.05)
463
+
464
+ method = methods[3]
465
+ assert_equal('Class#new', method.full_name)
466
+ assert_in_delta(0.0, method.total_time, 0.05)
467
+ assert_in_delta(0.0, method.wait_time, 0.05)
468
+ assert_in_delta(0.0, method.self_time, 0.05)
469
+ assert_in_delta(0.0, method.children_time, 0.05)
470
+
471
+ method = methods[4]
472
+ assert_equal('BasicObject#initialize', method.full_name)
473
+ assert_in_delta(0.0, method.total_time, 0.05)
474
+ assert_in_delta(0.0, method.wait_time, 0.05)
475
+ assert_in_delta(0.0, method.self_time, 0.05)
476
+ assert_in_delta(0.0, method.children_time, 0.05)
477
+ end
478
+
479
+ def test_instance_methods_busy_block
480
+ result = RubyProf.profile do
481
+ 1.times { RubyProf::C1.new.busy_wait }
482
+ end
483
+
484
+ methods = result.threads.first.methods.sort.reverse
485
+ assert_equal(6, methods.length)
486
+
487
+ # Check times
488
+ method = methods[0]
489
+ assert_equal("MeasureProcessTimeTest#test_instance_methods_busy_block", method.full_name)
490
+ assert_in_delta(0.2, method.total_time, 0.05)
491
+ assert_in_delta(0.0, method.wait_time, 0.05)
492
+ assert_in_delta(0.0, method.self_time, 0.05)
493
+ assert_in_delta(0.2, method.children_time, 0.05)
494
+
495
+ method = methods[1]
496
+ assert_equal('Integer#times', method.full_name)
497
+ assert_in_delta(0.2, method.total_time, 0.05)
498
+ assert_in_delta(0.0, method.wait_time, 0.05)
499
+ assert_in_delta(0.0, method.self_time, 0.05)
500
+ assert_in_delta(0.2, method.children_time, 0.05)
501
+
502
+ method = methods[2]
503
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
504
+ assert_in_delta(0.2, method.total_time, 0.05)
505
+ assert_in_delta(0.0, method.wait_time, 0.05)
506
+ assert_in_delta(0.09, method.self_time, 0.05)
507
+ assert_in_delta(0.11, method.children_time, 0.05)
508
+
509
+ method = methods[3]
510
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
511
+ assert_in_delta(0.11, method.total_time, 0.05)
512
+ assert_in_delta(0.0, method.wait_time, 0.05)
513
+ assert_in_delta(0.11, method.self_time, 0.05)
514
+ assert_in_delta(0.0, method.children_time, 0.05)
515
+
516
+ method = methods[4]
517
+ assert_equal('Class#new', method.full_name)
518
+ assert_in_delta(0.0, method.total_time, 0.05)
519
+ assert_in_delta(0.0, method.wait_time, 0.05)
520
+ assert_in_delta(0.0, method.self_time, 0.05)
521
+ assert_in_delta(0.0, method.children_time, 0.05)
522
+
523
+ method = methods[5]
524
+ assert_equal('BasicObject#initialize', method.full_name)
525
+ assert_in_delta(0.0, method.total_time, 0.05)
526
+ assert_in_delta(0.0, method.wait_time, 0.05)
527
+ assert_in_delta(0.0, method.self_time, 0.05)
528
+ assert_in_delta(0.0, method.children_time, 0.05)
529
+ end
530
+
531
+ def test_instance_methods_busy_threaded
532
+ result = RubyProf.profile do
533
+ background_thread = Thread.new do
534
+ RubyProf::C1.new.busy_wait
535
+ end
536
+ background_thread.join
537
+ end
538
+
539
+ assert_equal(2, result.threads.count)
540
+
541
+ thread = result.threads.first
542
+ assert_in_delta(0.2, thread.total_time, 0.05)
543
+
544
+ methods = result.threads.first.methods.sort.reverse
545
+ assert_equal(4, methods.length)
546
+
547
+ # Check times
548
+ method = methods[0]
549
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
550
+ assert_in_delta(0.2, method.total_time, 0.05)
551
+ assert_in_delta(0.0, method.wait_time, 0.05)
552
+ assert_in_delta(0.0, method.self_time, 0.05)
553
+ assert_in_delta(0.2, method.children_time, 0.05)
554
+
555
+ method = methods[1]
556
+ assert_equal('Thread#join', method.full_name)
557
+ assert_in_delta(0.2, method.total_time, 0.05)
558
+ assert_in_delta(0.2, method.wait_time, 0.05)
559
+ assert_in_delta(0.0, method.self_time, 0.05)
560
+ assert_in_delta(0.0, method.children_time, 0.05)
561
+
562
+ method = methods[2]
563
+ assert_equal('<Class::Thread>#new', method.full_name)
564
+ assert_in_delta(0.0, method.total_time, 0.05)
565
+ assert_in_delta(0.0, method.wait_time, 0.05)
566
+ assert_in_delta(0.0, method.self_time, 0.05)
567
+ assert_in_delta(0.0, method.children_time, 0.05)
568
+
569
+ method = methods[3]
570
+ assert_equal('Thread#initialize', method.full_name)
571
+ assert_in_delta(0.0, method.total_time, 0.05)
572
+ assert_in_delta(0.0, method.wait_time, 0.05)
573
+ assert_in_delta(0.0, method.self_time, 0.05)
574
+ assert_in_delta(0.0, method.children_time, 0.05)
575
+
576
+ thread = result.threads.last
577
+ assert_in_delta(0.2, thread.total_time, 0.05)
578
+
579
+ methods = result.threads.first.methods.sort.reverse
580
+ assert_equal(4, methods.length)
581
+
582
+ methods = result.threads.last.methods.sort.reverse
583
+ assert_equal(5, methods.length)
584
+
585
+ # Check times
586
+ method = methods[0]
587
+ assert_equal('MeasureProcessTimeTest#test_instance_methods_busy_threaded', method.full_name)
588
+ assert_in_delta(0.2, method.total_time, 0.05)
589
+ assert_in_delta(0.0, method.wait_time, 0.05)
590
+ assert_in_delta(0.0, method.self_time, 0.05)
591
+ assert_in_delta(0.2, method.children_time, 0.05)
592
+
593
+ method = methods[1]
594
+ assert_equal('RubyProf::C1#busy_wait', method.full_name)
595
+ assert_in_delta(0.2, method.total_time, 0.05)
596
+ assert_in_delta(0.0, method.wait_time, 0.05)
597
+ assert_in_delta(0.1, method.self_time, 0.05)
598
+ assert_in_delta(0.1, method.children_time, 0.05)
599
+
600
+ method = methods[2]
601
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
602
+ assert_in_delta(0.1, method.total_time, 0.05)
603
+ assert_in_delta(0.0, method.wait_time, 0.05)
604
+ assert_in_delta(0.1, method.self_time, 0.05)
605
+ assert_in_delta(0.0, method.children_time, 0.05)
606
+
607
+ method = methods[3]
608
+ assert_equal('Class#new', method.full_name)
609
+ assert_in_delta(0.0, method.total_time, 0.05)
610
+ assert_in_delta(0.0, method.wait_time, 0.05)
611
+ assert_in_delta(0.0, method.self_time, 0.05)
612
+ assert_in_delta(0.0, method.children_time, 0.05)
613
+
614
+ method = methods[4]
615
+ assert_equal('BasicObject#initialize', method.full_name)
616
+ assert_in_delta(0.0, method.total_time, 0.05)
617
+ assert_in_delta(0.0, method.wait_time, 0.05)
618
+ assert_in_delta(0.0, method.self_time, 0.05)
619
+ assert_in_delta(0.0, method.children_time, 0.05)
620
+ end
621
+
622
+ def test_module_methods_sleep
623
+ result = RubyProf.profile do
624
+ RubyProf::C2.sleep_wait
625
+ end
626
+
627
+ thread = result.threads.first
628
+ assert_in_delta(0.0, thread.total_time, 0.05)
629
+
630
+ methods = result.threads.first.methods.sort.reverse
631
+ assert_equal(3, methods.length)
632
+
633
+ # Check times
634
+ method = methods[0]
635
+ assert_equal('MeasureProcessTimeTest#test_module_methods_sleep', method.full_name)
636
+ assert_in_delta(0.0, method.total_time, 0.05)
637
+ assert_in_delta(0.0, method.wait_time, 0.05)
638
+ assert_in_delta(0.0, method.self_time, 0.05)
639
+ assert_in_delta(0.0, method.children_time, 0.05)
640
+
641
+ method = methods[1]
642
+ assert_equal('RubyProf::M1#sleep_wait', method.full_name)
643
+ assert_in_delta(0.0, method.total_time, 0.05)
644
+ assert_in_delta(0.0, method.wait_time, 0.05)
645
+ assert_in_delta(0.0, method.self_time, 0.05)
646
+ assert_in_delta(0.0, method.children_time, 0.05)
647
+
648
+ method = methods[2]
649
+ assert_equal('Kernel#sleep', method.full_name)
650
+ assert_in_delta(0.0, method.total_time, 0.05)
651
+ assert_in_delta(0.0, method.wait_time, 0.05)
652
+ assert_in_delta(0.0, method.self_time, 0.05)
653
+ assert_in_delta(0.0, method.children_time, 0.05)
654
+ end
655
+
656
+ def test_module_methods_busy
657
+ result = RubyProf.profile do
658
+ RubyProf::C2.busy_wait
659
+ end
660
+
661
+ thread = result.threads.first
662
+ assert_in_delta(0.3, thread.total_time, 0.05)
663
+
664
+ methods = result.threads.first.methods.sort.reverse
665
+ assert_equal(3, methods.length)
666
+
667
+ # Check times
668
+ method = methods[0]
669
+ assert_equal('MeasureProcessTimeTest#test_module_methods_busy', method.full_name)
670
+ assert_in_delta(0.3, method.total_time, 0.05)
671
+ assert_in_delta(0.0, method.wait_time, 0.05)
672
+ assert_in_delta(0.0, method.self_time, 0.05)
673
+ assert_in_delta(0.3, method.children_time, 0.05)
674
+
675
+ method = methods[1]
676
+ assert_equal('RubyProf::M1#busy_wait', method.full_name)
677
+ assert_in_delta(0.3, method.total_time, 0.05)
678
+ assert_in_delta(0.0, method.wait_time, 0.05)
679
+ assert_in_delta(0.15, method.self_time, 0.05)
680
+ assert_in_delta(0.15, method.children_time, 0.05)
681
+
682
+ method = methods[2]
683
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
684
+ assert_in_delta(0.15, method.total_time, 0.05)
685
+ assert_in_delta(0.0, method.wait_time, 0.05)
686
+ assert_in_delta(0.15, method.self_time, 0.05)
687
+ assert_in_delta(0.0, method.children_time, 0.05)
688
+ end
689
+
690
+ def test_module_instance_methods_sleep
691
+ result = RubyProf.profile do
692
+ RubyProf::C2.new.sleep_wait
693
+ end
694
+
695
+ thread = result.threads.first
696
+ assert_in_delta(0.0, thread.total_time, 0.05)
697
+
698
+ methods = result.threads.first.methods.sort.reverse
699
+ assert_equal(5, methods.length)
700
+
701
+ # Check times
702
+ method = methods[0]
703
+ assert_equal('MeasureProcessTimeTest#test_module_instance_methods_sleep', method.full_name)
704
+ assert_in_delta(0.0, method.total_time, 0.05)
705
+ assert_in_delta(0.0, method.wait_time, 0.05)
706
+ assert_in_delta(0.0, method.self_time, 0.05)
707
+ assert_in_delta(0.0, method.children_time, 0.05)
708
+
709
+ method = methods[1]
710
+ assert_equal('RubyProf::M1#sleep_wait', method.full_name)
711
+ assert_in_delta(0.0, method.total_time, 0.05)
712
+ assert_in_delta(0.0, method.wait_time, 0.05)
713
+ assert_in_delta(0.0, method.self_time, 0.05)
714
+ assert_in_delta(0.0, method.children_time, 0.05)
715
+
716
+ method = methods[2]
717
+ assert_equal('Kernel#sleep', method.full_name)
718
+ assert_in_delta(0.0, method.total_time, 0.05)
719
+ assert_in_delta(0.0, method.wait_time, 0.05)
720
+ assert_in_delta(0.0, method.self_time, 0.05)
721
+ assert_in_delta(0.0, method.children_time, 0.05)
722
+
723
+ method = methods[3]
724
+ assert_equal('Class#new', method.full_name)
725
+ assert_in_delta(0.0, method.total_time, 0.05)
726
+ assert_in_delta(0.0, method.wait_time, 0.05)
727
+ assert_in_delta(0.0, method.self_time, 0.05)
728
+ assert_in_delta(0.0, method.children_time, 0.05)
729
+
730
+ method = methods[4]
731
+ assert_equal('BasicObject#initialize', method.full_name)
732
+ assert_in_delta(0.0, method.total_time, 0.05)
733
+ assert_in_delta(0.0, method.wait_time, 0.05)
734
+ assert_in_delta(0.0, method.self_time, 0.05)
735
+ assert_in_delta(0.0, method.children_time, 0.05)
736
+ end
737
+
738
+ def test_module_instance_methods_busy
739
+ result = RubyProf.profile do
740
+ RubyProf::C2.new.busy_wait
741
+ end
742
+
743
+ thread = result.threads.first
744
+ assert_in_delta(0.3, thread.total_time, 0.05)
745
+
746
+ methods = result.threads.first.methods.sort.reverse
747
+ assert_equal(5, methods.length)
748
+
749
+ # Check times
750
+ method = methods[0]
751
+ assert_equal('MeasureProcessTimeTest#test_module_instance_methods_busy', method.full_name)
752
+ assert_in_delta(0.3, method.total_time, 0.05)
753
+ assert_in_delta(0.0, method.wait_time, 0.05)
754
+ assert_in_delta(0.0, method.self_time, 0.05)
755
+ assert_in_delta(0.3, method.children_time, 0.05)
756
+
757
+ method = methods[1]
758
+ assert_equal('RubyProf::M1#busy_wait', method.full_name)
759
+ assert_in_delta(0.3, method.total_time, 0.05)
760
+ assert_in_delta(0.0, method.wait_time, 0.05)
761
+ assert_in_delta(0.15, method.self_time, 0.05)
762
+ assert_in_delta(0.15, method.children_time, 0.05)
763
+
764
+ method = methods[2]
765
+ assert_equal('<Module::Process>#clock_gettime', method.full_name)
766
+ assert_in_delta(0.15, method.total_time, 0.05)
767
+ assert_in_delta(0.0, method.wait_time, 0.05)
768
+ assert_in_delta(0.15, method.self_time, 0.05)
769
+ assert_in_delta(0.0, method.children_time, 0.05)
770
+
771
+ method = methods[3]
772
+ assert_equal('Class#new', method.full_name)
773
+ assert_in_delta(0.0, method.total_time, 0.05)
774
+ assert_in_delta(0.0, method.wait_time, 0.05)
775
+ assert_in_delta(0.0, method.self_time, 0.05)
776
+ assert_in_delta(0.0, method.children_time, 0.05)
777
+
778
+ method = methods[4]
779
+ assert_equal('BasicObject#initialize', method.full_name)
780
+ assert_in_delta(0.0, method.total_time, 0.05)
781
+ assert_in_delta(0.0, method.wait_time, 0.05)
782
+ assert_in_delta(0.0, method.self_time, 0.05)
783
+ assert_in_delta(0.0, method.children_time, 0.05)
60
784
  end
61
785
  end