ruby-prof 0.13.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +579 -371
  3. data/LICENSE +24 -23
  4. data/README.rdoc +5 -433
  5. data/Rakefile +98 -110
  6. data/bin/ruby-prof +328 -329
  7. data/bin/ruby-prof-check-trace +45 -0
  8. data/ext/ruby_prof/extconf.rb +16 -59
  9. data/ext/ruby_prof/rp_aggregate_call_tree.c +59 -0
  10. data/ext/ruby_prof/rp_aggregate_call_tree.h +13 -0
  11. data/ext/ruby_prof/rp_allocation.c +287 -0
  12. data/ext/ruby_prof/rp_allocation.h +31 -0
  13. data/ext/ruby_prof/rp_call_tree.c +369 -0
  14. data/ext/ruby_prof/rp_call_tree.h +43 -0
  15. data/ext/ruby_prof/rp_call_trees.c +288 -0
  16. data/ext/ruby_prof/rp_call_trees.h +28 -0
  17. data/ext/ruby_prof/rp_measure_allocations.c +50 -65
  18. data/ext/ruby_prof/rp_measure_memory.c +42 -73
  19. data/ext/ruby_prof/rp_measure_process_time.c +65 -71
  20. data/ext/ruby_prof/rp_measure_wall_time.c +64 -42
  21. data/ext/ruby_prof/rp_measurement.c +237 -0
  22. data/ext/ruby_prof/rp_measurement.h +50 -0
  23. data/ext/ruby_prof/rp_method.c +491 -420
  24. data/ext/ruby_prof/rp_method.h +62 -57
  25. data/ext/ruby_prof/rp_profile.c +908 -0
  26. data/ext/ruby_prof/rp_profile.h +35 -0
  27. data/ext/ruby_prof/rp_stack.c +212 -128
  28. data/ext/ruby_prof/rp_stack.h +53 -51
  29. data/ext/ruby_prof/rp_thread.c +362 -268
  30. data/ext/ruby_prof/rp_thread.h +39 -27
  31. data/ext/ruby_prof/ruby_prof.c +52 -695
  32. data/ext/ruby_prof/ruby_prof.h +26 -55
  33. data/ext/ruby_prof/vc/ruby_prof.sln +28 -21
  34. data/ext/ruby_prof/vc/{ruby_prof_20.vcxproj → ruby_prof.vcxproj} +56 -8
  35. data/lib/ruby-prof.rb +52 -67
  36. data/lib/ruby-prof/assets/call_stack_printer.html.erb +710 -0
  37. data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
  38. data/lib/ruby-prof/assets/graph_printer.html.erb +355 -0
  39. data/lib/ruby-prof/call_tree.rb +57 -0
  40. data/lib/ruby-prof/call_tree_visitor.rb +36 -0
  41. data/lib/ruby-prof/compatibility.rb +99 -169
  42. data/lib/ruby-prof/exclude_common_methods.rb +198 -0
  43. data/lib/ruby-prof/measurement.rb +17 -0
  44. data/lib/ruby-prof/method_info.rb +78 -131
  45. data/lib/ruby-prof/printers/abstract_printer.rb +137 -85
  46. data/lib/ruby-prof/printers/call_info_printer.rb +53 -41
  47. data/lib/ruby-prof/printers/call_stack_printer.rb +180 -773
  48. data/lib/ruby-prof/printers/call_tree_printer.rb +151 -92
  49. data/lib/ruby-prof/printers/dot_printer.rb +132 -132
  50. data/lib/ruby-prof/printers/flat_printer.rb +53 -69
  51. data/lib/ruby-prof/printers/graph_html_printer.rb +63 -255
  52. data/lib/ruby-prof/printers/graph_printer.rb +113 -116
  53. data/lib/ruby-prof/printers/multi_printer.rb +127 -56
  54. data/lib/ruby-prof/profile.rb +37 -77
  55. data/lib/ruby-prof/rack.rb +62 -15
  56. data/lib/ruby-prof/task.rb +147 -147
  57. data/lib/ruby-prof/thread.rb +10 -12
  58. data/lib/ruby-prof/version.rb +3 -0
  59. data/lib/unprof.rb +10 -10
  60. data/ruby-prof.gemspec +65 -61
  61. data/test/abstract_printer_test.rb +26 -0
  62. data/test/alias_test.rb +126 -0
  63. data/test/basic_test.rb +43 -128
  64. data/test/call_tree_visitor_test.rb +32 -0
  65. data/test/call_trees_test.rb +66 -0
  66. data/test/duplicate_names_test.rb +32 -32
  67. data/test/dynamic_method_test.rb +53 -74
  68. data/test/enumerable_test.rb +21 -16
  69. data/test/exceptions_test.rb +24 -16
  70. data/test/exclude_methods_test.rb +151 -0
  71. data/test/exclude_threads_test.rb +53 -54
  72. data/test/fiber_test.rb +129 -65
  73. data/test/gc_test.rb +90 -0
  74. data/test/inverse_call_tree_test.rb +175 -0
  75. data/test/line_number_test.rb +158 -71
  76. data/test/marshal_test.rb +113 -0
  77. data/test/measure_allocations.rb +30 -0
  78. data/test/measure_allocations_test.rb +375 -25
  79. data/test/measure_allocations_trace_test.rb +375 -0
  80. data/test/measure_memory_trace_test.rb +1101 -0
  81. data/test/measure_process_time_test.rb +785 -62
  82. data/test/measure_times.rb +56 -0
  83. data/test/measure_wall_time_test.rb +434 -254
  84. data/test/multi_printer_test.rb +71 -82
  85. data/test/no_method_class_test.rb +15 -15
  86. data/test/pause_resume_test.rb +175 -166
  87. data/test/prime.rb +54 -54
  88. data/test/prime_script.rb +6 -0
  89. data/test/printer_call_stack_test.rb +27 -0
  90. data/test/printer_call_tree_test.rb +30 -0
  91. data/test/printer_flat_test.rb +99 -0
  92. data/test/printer_graph_html_test.rb +59 -0
  93. data/test/printer_graph_test.rb +40 -0
  94. data/test/printers_test.rb +141 -257
  95. data/test/printing_recursive_graph_test.rb +81 -0
  96. data/test/profile_test.rb +16 -0
  97. data/test/rack_test.rb +93 -0
  98. data/test/recursive_test.rb +206 -215
  99. data/test/singleton_test.rb +38 -38
  100. data/test/stack_printer_test.rb +64 -78
  101. data/test/start_stop_test.rb +109 -112
  102. data/test/test_helper.rb +13 -115
  103. data/test/thread_test.rb +144 -178
  104. data/test/unique_call_path_test.rb +120 -224
  105. data/test/yarv_test.rb +56 -0
  106. metadata +77 -133
  107. data/doc/LICENSE.html +0 -155
  108. data/doc/README_rdoc.html +0 -648
  109. data/doc/Rack.html +0 -167
  110. data/doc/Rack/RubyProf.html +0 -319
  111. data/doc/RubyProf.html +0 -1000
  112. data/doc/RubyProf/AbstractPrinter.html +0 -580
  113. data/doc/RubyProf/AggregateCallInfo.html +0 -570
  114. data/doc/RubyProf/CallInfo.html +0 -512
  115. data/doc/RubyProf/CallInfoPrinter.html +0 -190
  116. data/doc/RubyProf/CallInfoVisitor.html +0 -332
  117. data/doc/RubyProf/CallStackPrinter.html +0 -1600
  118. data/doc/RubyProf/CallTreePrinter.html +0 -413
  119. data/doc/RubyProf/Cmd.html +0 -669
  120. data/doc/RubyProf/DotPrinter.html +0 -312
  121. data/doc/RubyProf/FlatPrinter.html +0 -229
  122. data/doc/RubyProf/FlatPrinterWithLineNumbers.html +0 -267
  123. data/doc/RubyProf/GraphHtmlPrinter.html +0 -630
  124. data/doc/RubyProf/GraphPrinter.html +0 -209
  125. data/doc/RubyProf/MethodInfo.html +0 -713
  126. data/doc/RubyProf/MultiPrinter.html +0 -407
  127. data/doc/RubyProf/Profile.html +0 -821
  128. data/doc/RubyProf/ProfileTask.html +0 -532
  129. data/doc/RubyProf/Test.html +0 -578
  130. data/doc/RubyProf/Thread.html +0 -262
  131. data/doc/created.rid +0 -32
  132. data/doc/examples/flat_txt.html +0 -191
  133. data/doc/examples/graph_txt.html +0 -305
  134. data/doc/images/add.png +0 -0
  135. data/doc/images/brick.png +0 -0
  136. data/doc/images/brick_link.png +0 -0
  137. data/doc/images/bug.png +0 -0
  138. data/doc/images/bullet_black.png +0 -0
  139. data/doc/images/bullet_toggle_minus.png +0 -0
  140. data/doc/images/bullet_toggle_plus.png +0 -0
  141. data/doc/images/date.png +0 -0
  142. data/doc/images/delete.png +0 -0
  143. data/doc/images/find.png +0 -0
  144. data/doc/images/loadingAnimation.gif +0 -0
  145. data/doc/images/macFFBgHack.png +0 -0
  146. data/doc/images/package.png +0 -0
  147. data/doc/images/page_green.png +0 -0
  148. data/doc/images/page_white_text.png +0 -0
  149. data/doc/images/page_white_width.png +0 -0
  150. data/doc/images/plugin.png +0 -0
  151. data/doc/images/ruby.png +0 -0
  152. data/doc/images/tag_blue.png +0 -0
  153. data/doc/images/tag_green.png +0 -0
  154. data/doc/images/transparent.png +0 -0
  155. data/doc/images/wrench.png +0 -0
  156. data/doc/images/wrench_orange.png +0 -0
  157. data/doc/images/zoom.png +0 -0
  158. data/doc/index.html +0 -647
  159. data/doc/js/darkfish.js +0 -155
  160. data/doc/js/jquery.js +0 -18
  161. data/doc/js/navigation.js +0 -142
  162. data/doc/js/search.js +0 -94
  163. data/doc/js/search_index.js +0 -1
  164. data/doc/js/searcher.js +0 -228
  165. data/doc/rdoc.css +0 -543
  166. data/doc/table_of_contents.html +0 -462
  167. data/examples/empty.png +0 -0
  168. data/examples/flat.txt +0 -55
  169. data/examples/graph.dot +0 -106
  170. data/examples/graph.html +0 -823
  171. data/examples/graph.png +0 -0
  172. data/examples/graph.txt +0 -170
  173. data/examples/minus.png +0 -0
  174. data/examples/multi.flat.txt +0 -23
  175. data/examples/multi.graph.html +0 -906
  176. data/examples/multi.grind.dat +0 -194
  177. data/examples/multi.stack.html +0 -573
  178. data/examples/plus.png +0 -0
  179. data/examples/stack.html +0 -573
  180. data/ext/ruby_prof/rp_call_info.c +0 -407
  181. data/ext/ruby_prof/rp_call_info.h +0 -48
  182. data/ext/ruby_prof/rp_measure.c +0 -48
  183. data/ext/ruby_prof/rp_measure.h +0 -45
  184. data/ext/ruby_prof/rp_measure_cpu_time.c +0 -112
  185. data/ext/ruby_prof/rp_measure_gc_runs.c +0 -65
  186. data/ext/ruby_prof/rp_measure_gc_time.c +0 -57
  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/ext/ruby_prof/version.h +0 -7
  190. data/lib/ruby-prof/aggregate_call_info.rb +0 -72
  191. data/lib/ruby-prof/call_info.rb +0 -89
  192. data/lib/ruby-prof/call_info_visitor.rb +0 -44
  193. data/lib/ruby-prof/images/empty.png +0 -0
  194. data/lib/ruby-prof/images/minus.png +0 -0
  195. data/lib/ruby-prof/images/plus.png +0 -0
  196. data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +0 -57
  197. data/lib/ruby-prof/test.rb +0 -150
  198. data/test/aggregate_test.rb +0 -136
  199. data/test/call_info_test.rb +0 -78
  200. data/test/call_info_visitor_test.rb +0 -31
  201. data/test/exec_test.rb +0 -14
  202. data/test/measure_cpu_time_test.rb +0 -220
  203. data/test/measure_gc_runs_test.rb +0 -32
  204. data/test/measure_gc_time_test.rb +0 -36
  205. data/test/measure_memory_test.rb +0 -31
  206. data/test/method_elimination_test.rb +0 -84
  207. data/test/module_test.rb +0 -45
  208. data/test/stack_test.rb +0 -138
  209. data/test/test_suite.rb +0 -37
@@ -0,0 +1,56 @@
1
+ # Some classes used in measurement tests
2
+ require 'singleton'
3
+
4
+ module RubyProf
5
+ class C1
6
+ def C1.sleep_wait
7
+ sleep(0.1)
8
+ end
9
+
10
+ def C1.busy_wait
11
+ starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
12
+ while (Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting) < 0.1
13
+ end
14
+ end
15
+
16
+ def sleep_wait
17
+ sleep(0.2)
18
+ end
19
+
20
+ def busy_wait
21
+ starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
22
+ while (Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting) < 0.2
23
+ end
24
+ end
25
+ end
26
+
27
+ module M1
28
+ def sleep_wait
29
+ sleep(0.3)
30
+ end
31
+
32
+ def busy_wait
33
+ starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
34
+ while (Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting) < 0.3
35
+ end
36
+ end
37
+ end
38
+
39
+ class C2
40
+ include M1
41
+ extend M1
42
+ end
43
+
44
+ class C3
45
+ include Singleton
46
+ def sleep_wait
47
+ sleep(0.3)
48
+ end
49
+
50
+ def busy_wait
51
+ starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
52
+ while (Process.clock_gettime(Process::CLOCK_MONOTONIC) - starting) < 0.2
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,255 +1,435 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- require File.expand_path('../test_helper', __FILE__)
5
-
6
- class MeasureWallTimeTest < Test::Unit::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
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
+ end
12
+
13
+ def test_mode
14
+ RubyProf::measure_mode = RubyProf::WALL_TIME
15
+ assert_equal(RubyProf::WALL_TIME, RubyProf::measure_mode)
16
+ end
17
+
18
+ def test_class_methods
19
+ result = RubyProf.profile do
20
+ RubyProf::C1.sleep_wait
21
+ end
22
+
23
+ thread = result.threads.first
24
+ assert_in_delta(0.1, thread.total_time, 0.03)
25
+
26
+ methods = result.threads.first.methods.sort.reverse
27
+ assert_equal(3, methods.length)
28
+
29
+ # Check the names
30
+ assert_equal('MeasureWallTimeTest#test_class_methods', methods[0].full_name)
31
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', methods[1].full_name)
32
+ assert_equal('Kernel#sleep', methods[2].full_name)
33
+
34
+ # Check times
35
+ assert_in_delta(0.1, methods[0].total_time, 0.03)
36
+ assert_in_delta(0, methods[0].wait_time, 0.03)
37
+ assert_in_delta(0, methods[0].self_time, 0.03)
38
+
39
+ assert_in_delta(0.1, methods[1].total_time, 0.03)
40
+ assert_in_delta(0, methods[1].wait_time, 0.03)
41
+ assert_in_delta(0, methods[1].self_time, 0.03)
42
+
43
+ assert_in_delta(0.1, methods[2].total_time, 0.03)
44
+ assert_in_delta(0, methods[2].wait_time, 0.03)
45
+ assert_in_delta(0.1, methods[2].self_time, 0.03)
46
+ end
47
+
48
+ def test_class_methods_threaded
49
+ result = RubyProf.profile do
50
+ background_thread = Thread.new do
51
+ RubyProf::C1.sleep_wait
52
+ end
53
+ background_thread.join
54
+ end
55
+
56
+ assert_equal(2, result.threads.count)
57
+
58
+ thread = result.threads.first
59
+ assert_in_delta(0.1, thread.total_time, 0.03)
60
+
61
+ methods = result.threads.first.methods.sort.reverse
62
+ assert_equal(4, methods.length)
63
+
64
+ # Check times
65
+ assert_equal('MeasureWallTimeTest#test_class_methods_threaded', methods[0].full_name)
66
+ assert_in_delta(0.1, methods[0].total_time, 0.03)
67
+ assert_in_delta(0.0, methods[0].wait_time, 0.03)
68
+ assert_in_delta(0.0, methods[0].self_time, 0.03)
69
+ assert_in_delta(0.1, methods[0].children_time, 0.03)
70
+
71
+ assert_equal('Thread#join', methods[1].full_name)
72
+ assert_in_delta(0.1, methods[1].total_time, 0.03)
73
+ assert_in_delta(0.1, methods[1].wait_time, 0.03)
74
+ assert_in_delta(0.0, methods[1].self_time, 0.03)
75
+ assert_in_delta(0.0, methods[1].children_time, 0.03)
76
+
77
+ assert_equal('<Class::Thread>#new', methods[2].full_name)
78
+ assert_in_delta(0.0, methods[2].total_time, 0.03)
79
+ assert_in_delta(0.0, methods[2].wait_time, 0.03)
80
+ assert_in_delta(0.0, methods[2].self_time, 0.03)
81
+ assert_in_delta(0.0, methods[2].children_time, 0.03)
82
+
83
+ assert_equal('Thread#initialize', methods[3].full_name)
84
+ assert_in_delta(0.0, methods[3].total_time, 0.03)
85
+ assert_in_delta(0.0, methods[3].wait_time, 0.03)
86
+ assert_in_delta(0.0, methods[3].self_time, 0.03)
87
+ assert_in_delta(0.0, methods[3].children_time, 0.03)
88
+
89
+ thread = result.threads.last
90
+ assert_in_delta(0.1, thread.total_time, 0.03)
91
+
92
+ methods = result.threads.first.methods.sort.reverse
93
+ assert_equal(4, methods.length)
94
+
95
+ methods = result.threads.last.methods.sort.reverse
96
+ assert_equal(3, methods.length)
97
+
98
+ # Check times
99
+ assert_equal('MeasureWallTimeTest#test_class_methods_threaded', methods[0].full_name)
100
+ assert_in_delta(0.1, methods[0].total_time, 0.03)
101
+ assert_in_delta(0.0, methods[0].wait_time, 0.03)
102
+ assert_in_delta(0.0, methods[0].self_time, 0.03)
103
+ assert_in_delta(0.1, methods[0].children_time, 0.03)
104
+
105
+ assert_equal('<Class::RubyProf::C1>#sleep_wait', methods[1].full_name)
106
+ assert_in_delta(0.1, methods[1].total_time, 0.03)
107
+ assert_in_delta(0.0, methods[1].wait_time, 0.03)
108
+ assert_in_delta(0.0, methods[1].self_time, 0.03)
109
+ assert_in_delta(0.1, methods[1].children_time, 0.03)
110
+
111
+ assert_equal('Kernel#sleep', methods[2].full_name)
112
+ assert_in_delta(0.1, methods[2].total_time, 0.03)
113
+ assert_in_delta(0.0, methods[2].wait_time, 0.03)
114
+ assert_in_delta(0.1, methods[2].self_time, 0.03)
115
+ assert_in_delta(0.0, methods[2].children_time, 0.03)
116
+ end
117
+
118
+ def test_instance_methods
119
+ result = RubyProf.profile do
120
+ RubyProf::C1.new.sleep_wait
121
+ end
122
+
123
+ thread = result.threads.first
124
+ assert_in_delta(0.2, thread.total_time, 0.03)
125
+
126
+ methods = result.threads.first.methods.sort.reverse
127
+ assert_equal(5, methods.length)
128
+ names = methods.map(&:full_name)
129
+
130
+ # order can differ
131
+ assert(names.include?("BasicObject#initialize"))
132
+
133
+ # Check times
134
+ method = methods[0]
135
+ assert_equal('MeasureWallTimeTest#test_instance_methods', method.full_name)
136
+ assert_in_delta(0.2, method.total_time, 0.03)
137
+ assert_in_delta(0, method.wait_time, 0.03)
138
+ assert_in_delta(0, method.self_time, 0.03)
139
+
140
+ method = methods[1]
141
+ assert_equal('RubyProf::C1#sleep_wait', method.full_name)
142
+ assert_in_delta(0.2, method.total_time, 0.03)
143
+ assert_in_delta(0, method.wait_time, 0.03)
144
+ assert_in_delta(0, method.self_time, 0.03)
145
+
146
+ method = methods[2]
147
+ assert_equal('Kernel#sleep', method.full_name)
148
+ assert_in_delta(0.2, method.total_time, 0.03)
149
+ assert_in_delta(0, method.wait_time, 0.03)
150
+ assert_in_delta(0.2, method.self_time, 0.03)
151
+
152
+ method = methods[3]
153
+ assert_equal('Class#new', method.full_name)
154
+ assert_in_delta(0, method.total_time, 0.03)
155
+ assert_in_delta(0, method.wait_time, 0.03)
156
+ assert_in_delta(0, method.self_time, 0.03)
157
+
158
+ method = methods[4]
159
+ assert_equal('BasicObject#initialize', method.full_name)
160
+ assert_in_delta(0, method.total_time, 0.03)
161
+ assert_in_delta(0, method.wait_time, 0.03)
162
+ assert_in_delta(0, method.self_time, 0.03)
163
+ end
164
+
165
+ def test_instance_methods_block
166
+ result = RubyProf.profile do
167
+ 1.times { RubyProf::C1.new.sleep_wait }
168
+ end
169
+
170
+ methods = result.threads.first.methods.sort.reverse
171
+ assert_equal(6, methods.length)
172
+
173
+ # Check times
174
+ method = methods[0]
175
+ assert_equal("MeasureWallTimeTest#test_instance_methods_block", method.full_name)
176
+ assert_in_delta(0.2, method.total_time, 0.03)
177
+ assert_in_delta(0.0, method.wait_time, 0.03)
178
+ assert_in_delta(0.0, method.self_time, 0.03)
179
+ assert_in_delta(0.2, method.children_time, 0.03)
180
+
181
+ method = methods[1]
182
+ assert_equal("Integer#times", method.full_name)
183
+ assert_in_delta(0.2, method.total_time, 0.03)
184
+ assert_in_delta(0.0, method.wait_time, 0.03)
185
+ assert_in_delta(0.0, method.self_time, 0.03)
186
+ assert_in_delta(0.2, method.children_time, 0.03)
187
+
188
+ method = methods[2]
189
+ assert_equal("RubyProf::C1#sleep_wait", method.full_name)
190
+ assert_in_delta(0.2, method.total_time, 0.03)
191
+ assert_in_delta(0.0, method.wait_time, 0.03)
192
+ assert_in_delta(0.0, method.self_time, 0.03)
193
+ assert_in_delta(0.2, method.children_time, 0.03)
194
+
195
+ method = methods[3]
196
+ assert_equal("Kernel#sleep", method.full_name)
197
+ assert_in_delta(0.2, method.total_time, 0.03)
198
+ assert_in_delta(0.0, method.wait_time, 0.03)
199
+ assert_in_delta(0.2, method.self_time, 0.03)
200
+ assert_in_delta(0.0, method.children_time, 0.03)
201
+
202
+ method = methods[4]
203
+ assert_equal("Class#new", method.full_name)
204
+ assert_in_delta(0.0, method.total_time, 0.03)
205
+ assert_in_delta(0.0, method.wait_time, 0.03)
206
+ assert_in_delta(0.0, method.self_time, 0.03)
207
+ assert_in_delta(0.0, method.children_time, 0.03)
208
+
209
+ method = methods[5]
210
+ assert_equal("BasicObject#initialize", method.full_name)
211
+ assert_in_delta(0.0, method.total_time, 0.03)
212
+ assert_in_delta(0.0, method.wait_time, 0.03)
213
+ assert_in_delta(0.0, method.self_time, 0.03)
214
+ assert_in_delta(0.0, method.children_time, 0.03)
215
+ end
216
+
217
+ def test_instance_methods_threaded
218
+ result = RubyProf.profile do
219
+ background_thread = Thread.new do
220
+ RubyProf::C1.new.sleep_wait
221
+ end
222
+ background_thread.join
223
+ end
224
+
225
+ assert_equal(2, result.threads.count)
226
+
227
+ thread = result.threads.first
228
+ assert_in_delta(0.2, thread.total_time, 0.03)
229
+
230
+ methods = result.threads.first.methods.sort.reverse
231
+ assert_equal(4, methods.length)
232
+
233
+ # Check times
234
+ assert_equal('MeasureWallTimeTest#test_instance_methods_threaded', methods[0].full_name)
235
+ assert_in_delta(0.2, methods[0].total_time, 0.03)
236
+ assert_in_delta(0.0, methods[0].wait_time, 0.03)
237
+ assert_in_delta(0.0, methods[0].self_time, 0.03)
238
+ assert_in_delta(0.2, methods[0].children_time, 0.03)
239
+
240
+ assert_equal('Thread#join', methods[1].full_name)
241
+ assert_in_delta(0.2, methods[1].total_time, 0.03)
242
+ assert_in_delta(0.2, methods[1].wait_time, 0.03)
243
+ assert_in_delta(0.0, methods[1].self_time, 0.03)
244
+ assert_in_delta(0.0, methods[1].children_time, 0.03)
245
+
246
+ assert_equal('<Class::Thread>#new', methods[2].full_name)
247
+ assert_in_delta(0.0, methods[2].total_time, 0.03)
248
+ assert_in_delta(0.0, methods[2].wait_time, 0.03)
249
+ assert_in_delta(0.0, methods[2].self_time, 0.03)
250
+ assert_in_delta(0.0, methods[2].children_time, 0.03)
251
+
252
+ assert_equal('Thread#initialize', methods[3].full_name)
253
+ assert_in_delta(0.0, methods[3].total_time, 0.03)
254
+ assert_in_delta(0.0, methods[3].wait_time, 0.03)
255
+ assert_in_delta(0.0, methods[3].self_time, 0.03)
256
+ assert_in_delta(0.0, methods[3].children_time, 0.03)
257
+
258
+ thread = result.threads.last
259
+ assert_in_delta(0.2, thread.total_time, 0.03)
260
+
261
+ methods = result.threads.first.methods.sort.reverse
262
+ assert_equal(4, methods.length)
263
+
264
+ methods = result.threads.last.methods.sort.reverse
265
+ assert_equal(5, methods.length)
266
+
267
+ # Check times
268
+ assert_equal('MeasureWallTimeTest#test_instance_methods_threaded', methods[0].full_name)
269
+ assert_in_delta(0.2, methods[0].total_time, 0.03)
270
+ assert_in_delta(0.0, methods[0].wait_time, 0.03)
271
+ assert_in_delta(0.0, methods[0].self_time, 0.03)
272
+ assert_in_delta(0.2, methods[0].children_time, 0.03)
273
+
274
+ assert_equal('RubyProf::C1#sleep_wait', methods[1].full_name)
275
+ assert_in_delta(0.2, methods[1].total_time, 0.03)
276
+ assert_in_delta(0.0, methods[1].wait_time, 0.03)
277
+ assert_in_delta(0.0, methods[1].self_time, 0.03)
278
+ assert_in_delta(0.2, methods[1].children_time, 0.03)
279
+
280
+ assert_equal('Kernel#sleep', methods[2].full_name)
281
+ assert_in_delta(0.2, methods[2].total_time, 0.03)
282
+ assert_in_delta(0.0, methods[2].wait_time, 0.03)
283
+ assert_in_delta(0.2, methods[2].self_time, 0.03)
284
+ assert_in_delta(0.0, methods[2].children_time, 0.03)
285
+
286
+ assert_equal('Class#new', methods[3].full_name)
287
+ assert_in_delta(0.0, methods[3].total_time, 0.03)
288
+ assert_in_delta(0.0, methods[3].wait_time, 0.03)
289
+ assert_in_delta(0.0, methods[3].self_time, 0.03)
290
+ assert_in_delta(0.0, methods[3].children_time, 0.03)
291
+
292
+ assert_equal('BasicObject#initialize', methods[4].full_name)
293
+ assert_in_delta(0.0, methods[4].total_time, 0.03)
294
+ assert_in_delta(0.0, methods[4].wait_time, 0.03)
295
+ assert_in_delta(0.0, methods[4].self_time, 0.03)
296
+ assert_in_delta(0.0, methods[4].children_time, 0.03)
297
+ end
298
+
299
+ def test_module_methods
300
+ result = RubyProf.profile do
301
+ RubyProf::C2.sleep_wait
302
+ end
303
+
304
+ thread = result.threads.first
305
+ assert_in_delta(0.3, thread.total_time, 0.03)
306
+
307
+ methods = result.threads.first.methods.sort.reverse
308
+ assert_equal(3, methods.length)
309
+
310
+ assert_equal('MeasureWallTimeTest#test_module_methods', methods[0].full_name)
311
+ assert_equal('RubyProf::M1#sleep_wait', methods[1].full_name)
312
+ assert_equal('Kernel#sleep', methods[2].full_name)
313
+
314
+ # Check times
315
+ assert_in_delta(0.3, methods[0].total_time, 0.1)
316
+ assert_in_delta(0, methods[0].wait_time, 0.03)
317
+ assert_in_delta(0, methods[0].self_time, 0.03)
318
+
319
+ assert_in_delta(0.3, methods[1].total_time, 0.1)
320
+ assert_in_delta(0, methods[1].wait_time, 0.03)
321
+ assert_in_delta(0, methods[1].self_time, 0.03)
322
+
323
+ assert_in_delta(0.3, methods[2].total_time, 0.1)
324
+ assert_in_delta(0, methods[2].wait_time, 0.03)
325
+ assert_in_delta(0.3, methods[2].self_time, 0.1)
326
+ end
327
+
328
+ def test_module_instance_methods
329
+ result = RubyProf.profile do
330
+ RubyProf::C2.new.sleep_wait
331
+ end
332
+
333
+ thread = result.threads.first
334
+ assert_in_delta(0.3, thread.total_time, 0.03)
335
+
336
+ methods = result.threads.first.methods.sort.reverse
337
+ assert_equal(5, methods.length)
338
+ names = methods.map(&:full_name)
339
+ assert_equal('MeasureWallTimeTest#test_module_instance_methods', names[0])
340
+ assert_equal('RubyProf::M1#sleep_wait', names[1])
341
+ assert_equal('Kernel#sleep', names[2])
342
+ assert_equal('Class#new', names[3])
343
+
344
+ # order can differ
345
+ assert(names.include?("BasicObject#initialize"))
346
+
347
+ # Check times
348
+ assert_in_delta(0.3, methods[0].total_time, 0.1)
349
+ assert_in_delta(0, methods[0].wait_time, 0.1)
350
+ assert_in_delta(0, methods[0].self_time, 0.1)
351
+
352
+ assert_in_delta(0.3, methods[1].total_time, 0.03)
353
+ assert_in_delta(0, methods[1].wait_time, 0.03)
354
+ assert_in_delta(0, methods[1].self_time, 0.03)
355
+
356
+ assert_in_delta(0.3, methods[2].total_time, 0.03)
357
+ assert_in_delta(0, methods[2].wait_time, 0.03)
358
+ assert_in_delta(0.3, methods[2].self_time, 0.03)
359
+
360
+ assert_in_delta(0, methods[3].total_time, 0.03)
361
+ assert_in_delta(0, methods[3].wait_time, 0.03)
362
+ assert_in_delta(0, methods[3].self_time, 0.03)
363
+
364
+ assert_in_delta(0, methods[4].total_time, 0.03)
365
+ assert_in_delta(0, methods[4].wait_time, 0.03)
366
+ assert_in_delta(0, methods[4].self_time, 0.03)
367
+ end
368
+
369
+ def test_singleton_methods
370
+ result = RubyProf.profile do
371
+ RubyProf::C3.instance.sleep_wait
372
+ end
373
+
374
+ thread = result.threads.first
375
+ assert_in_delta(0.3, thread.total_time, 0.03)
376
+
377
+ methods = result.threads.first.methods.sort.reverse
378
+ assert_equal(7, methods.length)
379
+
380
+ assert_equal('MeasureWallTimeTest#test_singleton_methods', methods[0].full_name)
381
+ assert_in_delta(0.3, methods[0].total_time, 0.03)
382
+ assert_in_delta(0.0, methods[0].wait_time, 0.03)
383
+ assert_in_delta(0.0, methods[0].self_time, 0.03)
384
+ assert_in_delta(0.3, methods[0].children_time, 0.03)
385
+
386
+ assert_equal('RubyProf::C3#sleep_wait', methods[1].full_name)
387
+ assert_in_delta(0.3, methods[1].total_time, 0.03)
388
+ assert_in_delta(0.0, methods[1].wait_time, 0.03)
389
+ assert_in_delta(0.0, methods[1].self_time, 0.03)
390
+ assert_in_delta(0.3, methods[1].children_time, 0.03)
391
+
392
+ assert_equal('Kernel#sleep', methods[2].full_name)
393
+ assert_in_delta(0.3, methods[2].total_time, 0.03)
394
+ assert_in_delta(0.0, methods[2].wait_time, 0.03)
395
+ assert_in_delta(0.3, methods[2].self_time, 0.03)
396
+ assert_in_delta(0.0, methods[2].children_time, 0.03)
397
+
398
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7')
399
+ method = methods.detect {|a_method| a_method.full_name == '<Class::RubyProf::C3>#instance'}
400
+ assert_equal('<Class::RubyProf::C3>#instance', method.full_name)
401
+ assert_in_delta(0.0, method.total_time, 0.03)
402
+ assert_in_delta(0.0, method.wait_time, 0.03)
403
+ assert_in_delta(0.0, method.self_time, 0.03)
404
+ assert_in_delta(0.0, method.children_time, 0.03)
405
+ else
406
+ method = methods.detect {|a_method| a_method.full_name == 'Singleton::SingletonClassMethods#instance'}
407
+ assert_equal('Singleton::SingletonClassMethods#instance', method.full_name)
408
+ assert_in_delta(0.0, method.total_time, 0.03)
409
+ assert_in_delta(0.0, method.wait_time, 0.03)
410
+ assert_in_delta(0.0, method.self_time, 0.03)
411
+ assert_in_delta(0.0, method.children_time, 0.03)
412
+ end
413
+
414
+ method = methods.detect {|a_method| a_method.full_name == 'Thread::Mutex#synchronize'}
415
+ assert_equal('Thread::Mutex#synchronize', method.full_name)
416
+ assert_in_delta(0.0, method.total_time, 0.03)
417
+ assert_in_delta(0.0, method.wait_time, 0.03)
418
+ assert_in_delta(0.0, method.self_time, 0.03)
419
+ assert_in_delta(0.0, method.children_time, 0.03)
420
+
421
+ method = methods.detect {|a_method| a_method.full_name == 'Class#new'}
422
+ assert_equal('Class#new', method.full_name)
423
+ assert_in_delta(0.0, method.total_time, 0.03)
424
+ assert_in_delta(0.0, method.wait_time, 0.03)
425
+ assert_in_delta(0.0, method.self_time, 0.03)
426
+ assert_in_delta(0.0, method.children_time, 0.03)
427
+
428
+ method = methods.detect {|a_method| a_method.full_name == 'BasicObject#initialize'}
429
+ assert_equal('BasicObject#initialize', method.full_name)
430
+ assert_in_delta(0.0, method.total_time, 0.03)
431
+ assert_in_delta(0.0, method.wait_time, 0.03)
432
+ assert_in_delta(0.0, method.self_time, 0.03)
433
+ assert_in_delta(0.0, method.children_time, 0.03)
434
+ end
255
435
  end