ruby-prof 0.16.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +532 -467
  3. data/LICENSE +24 -24
  4. data/README.rdoc +5 -454
  5. data/Rakefile +110 -113
  6. data/bin/ruby-prof +380 -340
  7. data/bin/ruby-prof-check-trace +45 -45
  8. data/ext/ruby_prof/extconf.rb +36 -64
  9. data/ext/ruby_prof/rp_allocation.c +279 -0
  10. data/ext/ruby_prof/rp_allocation.h +31 -0
  11. data/ext/ruby_prof/rp_call_info.c +271 -407
  12. data/ext/ruby_prof/rp_call_info.h +35 -48
  13. data/ext/ruby_prof/rp_measure_allocations.c +52 -76
  14. data/ext/ruby_prof/rp_measure_memory.c +42 -77
  15. data/ext/ruby_prof/rp_measure_process_time.c +67 -71
  16. data/ext/ruby_prof/rp_measure_wall_time.c +62 -45
  17. data/ext/ruby_prof/rp_measurement.c +230 -0
  18. data/ext/ruby_prof/rp_measurement.h +50 -0
  19. data/ext/ruby_prof/rp_method.c +630 -411
  20. data/ext/ruby_prof/rp_method.h +70 -52
  21. data/ext/ruby_prof/rp_profile.c +895 -0
  22. data/ext/ruby_prof/rp_profile.h +37 -0
  23. data/ext/ruby_prof/rp_stack.c +196 -128
  24. data/ext/ruby_prof/rp_stack.h +56 -51
  25. data/ext/ruby_prof/rp_thread.c +337 -273
  26. data/ext/ruby_prof/rp_thread.h +36 -27
  27. data/ext/ruby_prof/ruby_prof.c +48 -671
  28. data/ext/ruby_prof/ruby_prof.h +17 -56
  29. data/ext/ruby_prof/vc/ruby_prof.sln +20 -21
  30. data/ext/ruby_prof/vc/{ruby_prof_20.vcxproj → ruby_prof.vcxproj} +38 -5
  31. data/lib/ruby-prof.rb +52 -58
  32. data/lib/ruby-prof/assets/call_stack_printer.html.erb +713 -0
  33. data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
  34. data/lib/ruby-prof/assets/graph_printer.html.erb +356 -0
  35. data/lib/ruby-prof/call_info.rb +57 -126
  36. data/lib/ruby-prof/call_info_visitor.rb +38 -40
  37. data/lib/ruby-prof/compatibility.rb +109 -178
  38. data/lib/ruby-prof/exclude_common_methods.rb +198 -0
  39. data/lib/ruby-prof/measurement.rb +14 -0
  40. data/lib/ruby-prof/method_info.rb +90 -129
  41. data/lib/ruby-prof/printers/abstract_printer.rb +127 -85
  42. data/lib/ruby-prof/printers/call_info_printer.rb +51 -41
  43. data/lib/ruby-prof/printers/call_stack_printer.rb +182 -260
  44. data/lib/ruby-prof/printers/call_tree_printer.rb +151 -130
  45. data/lib/ruby-prof/printers/dot_printer.rb +132 -132
  46. data/lib/ruby-prof/printers/flat_printer.rb +52 -70
  47. data/lib/ruby-prof/printers/graph_html_printer.rb +63 -244
  48. data/lib/ruby-prof/printers/graph_printer.rb +114 -116
  49. data/lib/ruby-prof/printers/multi_printer.rb +127 -58
  50. data/lib/ruby-prof/profile.rb +33 -55
  51. data/lib/ruby-prof/rack.rb +171 -95
  52. data/lib/ruby-prof/task.rb +147 -147
  53. data/lib/ruby-prof/thread.rb +35 -41
  54. data/lib/ruby-prof/version.rb +3 -3
  55. data/lib/unprof.rb +10 -10
  56. data/ruby-prof.gemspec +58 -57
  57. data/test/abstract_printer_test.rb +26 -0
  58. data/test/alias_test.rb +129 -0
  59. data/test/basic_test.rb +129 -128
  60. data/test/call_info_visitor_test.rb +31 -31
  61. data/test/duplicate_names_test.rb +32 -32
  62. data/test/dynamic_method_test.rb +53 -55
  63. data/test/enumerable_test.rb +21 -21
  64. data/test/exceptions_test.rb +24 -16
  65. data/test/exclude_methods_test.rb +146 -0
  66. data/test/exclude_threads_test.rb +53 -53
  67. data/test/fiber_test.rb +73 -79
  68. data/test/gc_test.rb +96 -0
  69. data/test/line_number_test.rb +161 -71
  70. data/test/marshal_test.rb +119 -0
  71. data/test/measure_allocations.rb +30 -0
  72. data/test/measure_allocations_test.rb +385 -26
  73. data/test/measure_allocations_trace_test.rb +385 -0
  74. data/test/measure_memory_trace_test.rb +756 -0
  75. data/test/measure_process_time_test.rb +849 -63
  76. data/test/measure_times.rb +54 -0
  77. data/test/measure_wall_time_test.rb +459 -255
  78. data/test/multi_printer_test.rb +71 -83
  79. data/test/no_method_class_test.rb +15 -15
  80. data/test/parser_timings.rb +24 -0
  81. data/test/pause_resume_test.rb +166 -166
  82. data/test/prime.rb +56 -54
  83. data/test/printer_call_stack_test.rb +28 -0
  84. data/test/printer_call_tree_test.rb +31 -0
  85. data/test/printer_flat_test.rb +68 -0
  86. data/test/printer_graph_html_test.rb +60 -0
  87. data/test/printer_graph_test.rb +41 -0
  88. data/test/printers_test.rb +141 -255
  89. data/test/printing_recursive_graph_test.rb +81 -127
  90. data/test/rack_test.rb +157 -93
  91. data/test/recursive_test.rb +210 -215
  92. data/test/singleton_test.rb +38 -38
  93. data/test/stack_printer_test.rb +64 -78
  94. data/test/start_stop_test.rb +109 -112
  95. data/test/test_helper.rb +24 -264
  96. data/test/thread_test.rb +144 -187
  97. data/test/unique_call_path_test.rb +190 -202
  98. data/test/yarv_test.rb +56 -55
  99. metadata +34 -114
  100. data/doc/LICENSE.html +0 -114
  101. data/doc/README_rdoc.html +0 -603
  102. data/doc/Rack.html +0 -95
  103. data/doc/Rack/RubyProf.html +0 -226
  104. data/doc/RubyProf.html +0 -962
  105. data/doc/RubyProf/AbstractPrinter.html +0 -546
  106. data/doc/RubyProf/AggregateCallInfo.html +0 -551
  107. data/doc/RubyProf/CallInfo.html +0 -639
  108. data/doc/RubyProf/CallInfoPrinter.html +0 -120
  109. data/doc/RubyProf/CallInfoVisitor.html +0 -198
  110. data/doc/RubyProf/CallStackPrinter.html +0 -1121
  111. data/doc/RubyProf/CallTreePrinter.html +0 -641
  112. data/doc/RubyProf/Cmd.html +0 -631
  113. data/doc/RubyProf/DotPrinter.html +0 -257
  114. data/doc/RubyProf/FlatPrinter.html +0 -163
  115. data/doc/RubyProf/FlatPrinterWithLineNumbers.html +0 -208
  116. data/doc/RubyProf/GraphHtmlPrinter.html +0 -552
  117. data/doc/RubyProf/GraphPrinter.html +0 -139
  118. data/doc/RubyProf/MethodInfo.html +0 -745
  119. data/doc/RubyProf/MultiPrinter.html +0 -360
  120. data/doc/RubyProf/Profile.html +0 -763
  121. data/doc/RubyProf/ProfileTask.html +0 -490
  122. data/doc/RubyProf/Thread.html +0 -310
  123. data/doc/created.rid +0 -31
  124. data/doc/css/fonts.css +0 -167
  125. data/doc/css/rdoc.css +0 -590
  126. data/doc/examples/flat_txt.html +0 -138
  127. data/doc/examples/graph_html.html +0 -909
  128. data/doc/examples/graph_txt.html +0 -247
  129. data/doc/fonts/Lato-Light.ttf +0 -0
  130. data/doc/fonts/Lato-LightItalic.ttf +0 -0
  131. data/doc/fonts/Lato-Regular.ttf +0 -0
  132. data/doc/fonts/Lato-RegularItalic.ttf +0 -0
  133. data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
  134. data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
  135. data/doc/images/add.png +0 -0
  136. data/doc/images/arrow_up.png +0 -0
  137. data/doc/images/brick.png +0 -0
  138. data/doc/images/brick_link.png +0 -0
  139. data/doc/images/bug.png +0 -0
  140. data/doc/images/bullet_black.png +0 -0
  141. data/doc/images/bullet_toggle_minus.png +0 -0
  142. data/doc/images/bullet_toggle_plus.png +0 -0
  143. data/doc/images/date.png +0 -0
  144. data/doc/images/delete.png +0 -0
  145. data/doc/images/find.png +0 -0
  146. data/doc/images/loadingAnimation.gif +0 -0
  147. data/doc/images/macFFBgHack.png +0 -0
  148. data/doc/images/package.png +0 -0
  149. data/doc/images/page_green.png +0 -0
  150. data/doc/images/page_white_text.png +0 -0
  151. data/doc/images/page_white_width.png +0 -0
  152. data/doc/images/plugin.png +0 -0
  153. data/doc/images/ruby.png +0 -0
  154. data/doc/images/tag_blue.png +0 -0
  155. data/doc/images/tag_green.png +0 -0
  156. data/doc/images/transparent.png +0 -0
  157. data/doc/images/wrench.png +0 -0
  158. data/doc/images/wrench_orange.png +0 -0
  159. data/doc/images/zoom.png +0 -0
  160. data/doc/index.html +0 -626
  161. data/doc/js/darkfish.js +0 -161
  162. data/doc/js/jquery.js +0 -4
  163. data/doc/js/navigation.js +0 -142
  164. data/doc/js/navigation.js.gz +0 -0
  165. data/doc/js/search.js +0 -109
  166. data/doc/js/search_index.js +0 -1
  167. data/doc/js/search_index.js.gz +0 -0
  168. data/doc/js/searcher.js +0 -228
  169. data/doc/js/searcher.js.gz +0 -0
  170. data/doc/table_of_contents.html +0 -942
  171. data/examples/cachegrind.out.1 +0 -114
  172. data/examples/cachegrind.out.1.32313213 +0 -114
  173. data/examples/flat.txt +0 -50
  174. data/examples/graph.dot +0 -84
  175. data/examples/graph.html +0 -823
  176. data/examples/graph.txt +0 -139
  177. data/examples/multi.flat.txt +0 -23
  178. data/examples/multi.graph.html +0 -760
  179. data/examples/multi.grind.dat +0 -114
  180. data/examples/multi.stack.html +0 -547
  181. data/examples/stack.html +0 -547
  182. data/ext/ruby_prof/rp_measure.c +0 -40
  183. data/ext/ruby_prof/rp_measure.h +0 -45
  184. data/ext/ruby_prof/rp_measure_cpu_time.c +0 -136
  185. data/ext/ruby_prof/rp_measure_gc_runs.c +0 -73
  186. data/ext/ruby_prof/rp_measure_gc_time.c +0 -60
  187. data/ext/ruby_prof/vc/ruby_prof_18.vcxproj +0 -108
  188. data/ext/ruby_prof/vc/ruby_prof_19.vcxproj +0 -110
  189. data/lib/ruby-prof/aggregate_call_info.rb +0 -76
  190. data/lib/ruby-prof/assets/call_stack_printer.css.html +0 -117
  191. data/lib/ruby-prof/assets/call_stack_printer.js.html +0 -385
  192. data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -64
  193. data/test/aggregate_test.rb +0 -136
  194. data/test/block_test.rb +0 -74
  195. data/test/call_info_test.rb +0 -78
  196. data/test/issue137_test.rb +0 -63
  197. data/test/measure_cpu_time_test.rb +0 -213
  198. data/test/measure_gc_runs_test.rb +0 -32
  199. data/test/measure_gc_time_test.rb +0 -36
  200. data/test/measure_memory_test.rb +0 -33
  201. data/test/method_elimination_test.rb +0 -84
  202. data/test/module_test.rb +0 -45
  203. 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
@@ -1,255 +1,459 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- require File.expand_path('../test_helper', __FILE__)
5
-
6
- class MeasureWallTimeTest < TestCase
7
- def setup
8
- # Need to use wall time for this test due to the sleep calls
9
- RubyProf::measure_mode = RubyProf::WALL_TIME
10
- end
11
-
12
- def test_mode
13
- RubyProf::measure_mode = RubyProf::WALL_TIME
14
- assert_equal(RubyProf::WALL_TIME, RubyProf::measure_mode)
15
- end
16
-
17
- def test_wall_time_enabled_defined
18
- assert(defined?(RubyProf::WALL_TIME_ENABLED))
19
- end
20
-
21
- def test_class_methods
22
- result = RubyProf.profile do
23
- RubyProf::C1.hello
24
- end
25
-
26
- thread = result.threads.first
27
- assert_in_delta(0.1, thread.total_time, 0.01)
28
-
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
37
-
38
- methods = result.threads.first.methods.sort.reverse
39
- assert_equal(3, methods.length)
40
-
41
- # Check the names
42
- assert_equal('MeasureWallTimeTest#test_class_methods', methods[0].full_name)
43
- assert_equal('<Class::RubyProf::C1>#hello', methods[1].full_name)
44
- assert_equal('Kernel#sleep', methods[2].full_name)
45
-
46
- # 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)
50
-
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)
54
-
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)
58
- end
59
-
60
- def test_instance_methods
61
- result = RubyProf.profile do
62
- RubyProf::C1.new.hello
63
- end
64
-
65
- thread = result.threads.first
66
- assert_in_delta(0.2, thread.total_time, 0.01)
67
-
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)
71
-
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
79
-
80
- methods = result.threads.first.methods.sort.reverse
81
- assert_equal(RubyProf.ruby_2? ? 5 : 6, methods.length)
82
- 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
-
88
- # 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"))
92
- end
93
-
94
- # 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)
119
- end
120
- end
121
-
122
- def test_module_methods
123
- result = RubyProf.profile do
124
- RubyProf::C2.hello
125
- end
126
-
127
- 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)
133
-
134
- # Methods:
135
- # MeasureWallTimeTest#test_module_methods
136
- # M1#hello
137
- # Kernel#sleep
138
-
139
- methods = result.threads.first.methods.sort.reverse
140
- assert_equal(3, methods.length)
141
-
142
- assert_equal('MeasureWallTimeTest#test_module_methods', methods[0].full_name)
143
- assert_equal('RubyProf::M1#hello', methods[1].full_name)
144
- assert_equal('Kernel#sleep', methods[2].full_name)
145
-
146
- # Check times
147
- 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)
150
-
151
- 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)
154
-
155
- assert_in_delta(0.3, methods[2].total_time, 0.1)
156
- assert_in_delta(0, methods[2].wait_time, 0.02)
157
- assert_in_delta(0.3, methods[2].self_time, 0.1)
158
- end
159
-
160
- def test_module_instance_methods
161
- result = RubyProf.profile do
162
- RubyProf::C2.new.hello
163
- end
164
-
165
- thread = result.threads.first
166
- assert_in_delta(0.3, thread.total_time, 0.01)
167
-
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
179
-
180
- methods = result.threads.first.methods.sort.reverse
181
- assert_equal(RubyProf.ruby_2? ? 5 : 6, methods.length)
182
- names = methods.map(&:full_name)
183
- assert_equal('MeasureWallTimeTest#test_module_instance_methods', names[0])
184
- assert_equal('RubyProf::M1#hello', names[1])
185
- assert_equal('Kernel#sleep', names[2])
186
- assert_equal('Class#new', names[3])
187
-
188
- # 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
193
-
194
- # Check times
195
- assert_in_delta(0.3, methods[0].total_time, 0.1)
196
- assert_in_delta(0, methods[0].wait_time, 0.1)
197
- assert_in_delta(0, methods[0].self_time, 0.1)
198
-
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)
202
-
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)
206
-
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)
210
-
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
220
- end
221
-
222
- def test_singleton
223
- c3 = RubyProf::C3.new
224
-
225
- class << c3
226
- def hello
227
- end
228
- end
229
-
230
- result = RubyProf.profile do
231
- c3.hello
232
- end
233
-
234
- thread = result.threads.first
235
- assert_in_delta(0.0, thread.total_time, 0.01)
236
-
237
- top_methods = thread.top_methods
238
- assert_equal(1, top_methods.count)
239
- assert_equal("MeasureWallTimeTest#test_singleton", top_methods[0].full_name)
240
-
241
- methods = result.threads.first.methods.sort.reverse
242
- assert_equal(2, methods.length)
243
-
244
- assert_equal('MeasureWallTimeTest#test_singleton', methods[0].full_name)
245
- assert_equal('<Object::RubyProf::C3>#hello', methods[1].full_name)
246
-
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)
250
-
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)
254
- end
255
- end
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+
4
+ require File.expand_path('../test_helper', __FILE__)
5
+ require_relative './measure_times'
6
+
7
+ class MeasureWallTimeTest < TestCase
8
+ def setup
9
+ # Need to use wall time for this test due to the sleep calls
10
+ RubyProf::measure_mode = RubyProf::WALL_TIME
11
+ GC.start
12
+ end
13
+
14
+ def test_mode
15
+ RubyProf::measure_mode = RubyProf::WALL_TIME
16
+ assert_equal(RubyProf::WALL_TIME, RubyProf::measure_mode)
17
+ end
18
+
19
+ def test_class_methods
20
+ result = RubyProf.profile do
21
+ RubyProf::C1.sleep_wait
22
+ end
23
+
24
+ thread = result.threads.first
25
+ assert_in_delta(0.1, thread.total_time, 0.03)
26
+
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)
30
+
31
+ methods = result.threads.first.methods.sort.reverse
32
+ assert_equal(3, methods.length)
33
+
34
+ # Check the names
35
+ assert_equal('MeasureWallTimeTest#test_class_methods', methods[0].full_name)
36
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', methods[1].full_name)
37
+ assert_equal('Kernel#sleep', methods[2].full_name)
38
+
39
+ # Check times
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)
43
+
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)
47
+
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)
51
+ end
52
+
53
+ def test_class_methods_threaded
54
+ result = RubyProf.profile do
55
+ background_thread = Thread.new do
56
+ RubyProf::C1.sleep_wait
57
+ end
58
+ background_thread.join
59
+ end
60
+
61
+ assert_equal(2, result.threads.count)
62
+
63
+ thread = result.threads.first
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
135
+
136
+ thread = result.threads.first
137
+ assert_in_delta(0.2, thread.total_time, 0.03)
138
+
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)
142
+
143
+ methods = result.threads.first.methods.sort.reverse
144
+ assert_equal(5, methods.length)
145
+ names = methods.map(&:full_name)
146
+
147
+ # order can differ
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 }
185
+ end
186
+
187
+ methods = result.threads.first.methods.sort.reverse
188
+ assert_equal(6, methods.length)
189
+
190
+ # Check times
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
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)
322
+ end
323
+
324
+ def test_module_methods
325
+ result = RubyProf.profile do
326
+ RubyProf::C2.sleep_wait
327
+ end
328
+
329
+ thread = result.threads.first
330
+ assert_in_delta(0.3, thread.total_time, 0.03)
331
+
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)
335
+
336
+ methods = result.threads.first.methods.sort.reverse
337
+ assert_equal(3, methods.length)
338
+
339
+ assert_equal('MeasureWallTimeTest#test_module_methods', methods[0].full_name)
340
+ assert_equal('RubyProf::M1#sleep_wait', methods[1].full_name)
341
+ assert_equal('Kernel#sleep', methods[2].full_name)
342
+
343
+ # Check times
344
+ assert_in_delta(0.3, methods[0].total_time, 0.1)
345
+ assert_in_delta(0, methods[0].wait_time, 0.03)
346
+ assert_in_delta(0, methods[0].self_time, 0.03)
347
+
348
+ assert_in_delta(0.3, methods[1].total_time, 0.1)
349
+ assert_in_delta(0, methods[1].wait_time, 0.03)
350
+ assert_in_delta(0, methods[1].self_time, 0.03)
351
+
352
+ assert_in_delta(0.3, methods[2].total_time, 0.1)
353
+ assert_in_delta(0, methods[2].wait_time, 0.03)
354
+ assert_in_delta(0.3, methods[2].self_time, 0.1)
355
+ end
356
+
357
+ def test_module_instance_methods
358
+ result = RubyProf.profile do
359
+ RubyProf::C2.new.sleep_wait
360
+ end
361
+
362
+ thread = result.threads.first
363
+ assert_in_delta(0.3, thread.total_time, 0.03)
364
+
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)
368
+
369
+ methods = result.threads.first.methods.sort.reverse
370
+ assert_equal(5, methods.length)
371
+ names = methods.map(&:full_name)
372
+ assert_equal('MeasureWallTimeTest#test_module_instance_methods', names[0])
373
+ assert_equal('RubyProf::M1#sleep_wait', names[1])
374
+ assert_equal('Kernel#sleep', names[2])
375
+ assert_equal('Class#new', names[3])
376
+
377
+ # order can differ
378
+ assert(names.include?("BasicObject#initialize"))
379
+
380
+ # Check times
381
+ assert_in_delta(0.3, methods[0].total_time, 0.1)
382
+ assert_in_delta(0, methods[0].wait_time, 0.1)
383
+ assert_in_delta(0, methods[0].self_time, 0.1)
384
+
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)
388
+
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)
392
+
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)
396
+
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)
400
+ end
401
+
402
+ def test_singleton_methods
403
+ result = RubyProf.profile do
404
+ RubyProf::C3.instance.sleep_wait
405
+ end
406
+
407
+ thread = result.threads.first
408
+ assert_in_delta(0.3, thread.total_time, 0.03)
409
+
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)
413
+
414
+ methods = result.threads.first.methods.sort.reverse
415
+ assert_equal(7, methods.length)
416
+
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)
422
+
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)
428
+
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)
458
+ end
459
+ end