ruby-prof 0.16.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
data/LICENSE CHANGED
@@ -1,25 +1,25 @@
1
- Copyright (C) 2005 - 2014 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
2
- Copyright (C) 2010 - 2014 Stefan Kaes <skaes@railsepxress.de>
3
- All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions
7
- are met:
8
-
9
- 1. Redistributions of source code must retain the above copyright
10
- notice, this list of conditions and the following disclaimer.
11
- 2. Redistributions in binary form must reproduce the above copyright
12
- notice, this list of conditions and the following disclaimer in the
13
- documentation and/or other materials provided with the distribution.
14
-
15
- THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
16
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
- ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
19
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1
+ Copyright (C) 2005 - 2019 Shugo Maeda <shugo@ruby-lang.org>, Charlie Savage <cfis@savagexi.com> and
2
+ Stefan Kaes <skaes@railsepxress.de>
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions
7
+ are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright
10
+ notice, this list of conditions and the following disclaimer.
11
+ 2. Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the distribution.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
19
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
25
  SUCH DAMAGE.
@@ -1,454 +1,5 @@
1
- = ruby-prof
2
-
3
- {<img src="https://travis-ci.org/ruby-prof/ruby-prof.png?branch=master" alt="Build Status" />}[https://travis-ci.org/ruby-prof/ruby-prof]
4
-
5
- == Overview
6
-
7
- ruby-prof is a fast code profiler for MRI Ruby. Its features include:
8
-
9
- * Speed - it is a C extension and therefore many times faster than the standard Ruby profiler.
10
- * Modes - Ruby prof can measure a number of different parameters, including call times, memory usage and object allocations.
11
- * Reports - can generate text and cross-referenced html reports
12
- - Flat Profiles - similar to the reports generated by the standard Ruby profiler
13
- - Graph profiles - similar to GProf, these show how long a method runs, which methods call it and which methods it calls.
14
- - Call tree profiles - outputs results in the calltree format suitable for the KCacheGrind profiling tool.
15
- - Many more -- see reports section of this \README.
16
- * Threads - supports profiling multiple threads simultaneously
17
-
18
- == Requirements
19
-
20
- ruby-prof requires Ruby 1.9.3 or higher. Please note some ruby
21
- releases have known bugs which cause ruby-prof problems, like
22
- incorrect measurements. We suggest to use the latest minor patch level
23
- release if possible. In particular, on the 2.1 branch of ruby you
24
- should use at least 2.1.7.
25
-
26
- If you are running Linux or Unix you'll need a C compiler so the
27
- extension can be compiled when it is installed.
28
-
29
- If you are running Windows, then you may need to install the
30
- Windows specific RubyGem which includes an already built extension (see Install section).
31
-
32
- == Install
33
-
34
- The easiest way to install ruby-prof is by using Ruby Gems. To
35
- install:
36
-
37
- gem install ruby-prof
38
-
39
- If you're on windows then please install the devkit first so that it
40
- can compile.
41
-
42
- == Usage
43
-
44
- There are three major options for running ruby-prof: via the command
45
- line, via its convenience API or via its core API.
46
-
47
- === ruby-prof Executable
48
-
49
- The first is to use ruby-prof to run the Ruby program you want to
50
- profile. For more information refer to the documentation of the
51
- ruby-prof command.
52
-
53
-
54
- === ruby-prof Convenience API
55
-
56
- The second way is to use the ruby-prof convenience API to profile
57
- particular segments of code.
58
-
59
- require 'ruby-prof'
60
-
61
- # profile the code
62
- RubyProf.start
63
- # ... code to profile ...
64
- result = RubyProf.stop
65
-
66
- # print a flat profile to text
67
- printer = RubyProf::FlatPrinter.new(result)
68
- printer.print(STDOUT)
69
-
70
- Alternatively, you can use a block to tell ruby-prof what to profile:
71
-
72
- require 'ruby-prof'
73
-
74
- # profile the code
75
- result = RubyProf.profile do
76
- # ... code to profile ...
77
- end
78
-
79
- # print a graph profile to text
80
- printer = RubyProf::GraphPrinter.new(result)
81
- printer.print(STDOUT, {})
82
-
83
- ruby-prof also supports pausing and resuming profiling runs.
84
-
85
- require 'ruby-prof'
86
-
87
- # profile the code
88
- RubyProf.start
89
- # ... code to profile ...
90
-
91
- RubyProf.pause
92
- # ... other code ...
93
-
94
- RubyProf.resume
95
- # ... code to profile ...
96
- result = RubyProf.stop
97
-
98
- Note that resume will only work if start has been called previously.
99
- In addition, resume can also take a block:
100
-
101
- require 'ruby-prof'
102
-
103
- RubyProf.resume do
104
- # ... code to profile...
105
- end
106
-
107
- result = RubyProf.stop
108
-
109
- With this usage, resume will automatically call pause at the
110
- end of the block.
111
-
112
- === Profiling Selected Threads (Core API)
113
-
114
- The convenience API does not support running multiple profiles in
115
- separate threads concurrently, but the RubyProf::Profile API does. In
116
- fact, the convenience layer uses the Profile API internally. It all
117
- revolves around Profile objects:
118
-
119
- RubyProf::Profile.new::
120
- Create a profile object given an options hash (see below)
121
-
122
- The following options are available when creating Profile instances:
123
-
124
- measure_mode::
125
- One of the defined measure modes
126
-
127
- exclude_threads::
128
- Array of threads which should not be profiled.
129
-
130
- include_threads::
131
- Array of threads which should be profiled. All other threads will
132
- be ignored.
133
-
134
- merge_fibers::
135
- Whether profiling data for a given thread's fibers should all be
136
- subsumed under a single entry. Basically only useful to produce
137
- callgrind profiles.
138
-
139
- RubyProf::Profile#start::
140
- Start profiling
141
-
142
- RubyProf::Profile#pause::
143
- Pause profiling
144
-
145
- RubyProf::Profile#resume::
146
- Resume profiling
147
-
148
- RubyProf::Profile#stop::
149
- Stop profiling and return self
150
-
151
- RubyProf::Profile#profile::
152
- Perform a profile run and return result. Accepts the same arguments
153
- as RubyProf::Profile.new.
154
-
155
-
156
- == Method Elimination
157
-
158
- ruby-prof supports eliminating specific methods and threads from
159
- profiling results. This is useful for reducing connectivity in the
160
- call graph, making it easier to identify the source of performance
161
- problems when using a graph printer.
162
-
163
- For example, consider <tt>Integer#times</tt>: it's hardly ever useful
164
- to know how much time is spent in the method itself. We're much more
165
- interested in how much the passed in block contributes to the time
166
- spent in the method which contains the <tt>Integer#times</tt> call.
167
-
168
- Methods are eliminated from the collected data by calling
169
- <tt>eliminate_methods!</tt> on the profiling result, before submitting
170
- it to a printer.
171
-
172
- result = RubyProf.stop
173
- result.eliminate_methods!([/Integer#times/])
174
-
175
- The argument given to <tt>eliminate_methods!</tt> is either an array
176
- of regular expressions, or the name of a file containing a list of
177
- regular expressions (line separated text).
178
-
179
- After eliminating methods the resulting profile will appear exactly as if those methods
180
- had been inlined at their call sites.
181
-
182
-
183
- == Profiling Rails
184
-
185
- To profile a Rails application it is vital to run it using production like
186
- settings (cache classes, cache view lookups, etc.). Otherwise, Rail's
187
- dependency loading code will overwhelm any time spent in the application
188
- itself (our tests show that Rails dependency loading causes a roughly 6x
189
- slowdown). The best way to do this is create a new Rails environment,
190
- profile.rb.
191
-
192
- So to profile Rails:
193
-
194
- 1. Create a new profile.rb environment. Make sure to turn on
195
- <tt>cache_classes</tt> and
196
- <tt>cache_template_loading</tt>. Otherwise your profiling results
197
- will be overwhelmed by the time Rails spends loading required
198
- files. You should likely turn off caching.
199
-
200
- 2. Add the ruby-prof to your gemfile:
201
-
202
- group :profile do
203
- gem 'ruby-prof'
204
- end
205
-
206
- 3. Add the ruby prof rack adapter to your middleware stack. One way to
207
- do this is by adding the following code to <tt>config.ru</tt>:
208
-
209
- if Rails.env.profile?
210
- use Rack::RubyProf, :path => '/temp/profile'
211
- end
212
-
213
- The path is where you want profiling results to be stored. By default the
214
- rack adapter will generate a html call graph report and flat text report.
215
-
216
- 4. Now make a request to your running server. New profiling
217
- information will be generated for each request. Note that each
218
- request will overwrite the profiling reports created by the
219
- previous request!
220
-
221
- == Reports
222
-
223
- ruby-prof can generate a number of different reports:
224
-
225
- * Flat Reports
226
- * Graph Reports
227
- * HTML Graph Reports
228
- * Call graphs
229
- * Call stack reports
230
- * More!
231
-
232
- Flat profiles show the overall time spent in each method. They
233
- are a good way of quickly identifying which methods take the most time.
234
- An example of a flat profile and an explanation can be found in
235
- {examples/flat.txt}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/flat.txt].
236
-
237
- There are several varieties of these - run <tt>ruby-prof --help</tt>
238
-
239
- Graph profiles also show the overall time spent in each method. In
240
- addition, they also show which methods call the current method and which
241
- methods its calls. Thus they are good for understanding how methods
242
- gets called and provide insight into the flow of your program. An
243
- example text graph profile is located at
244
- {examples/graph.txt}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/graph.txt].
245
-
246
- HTML Graph profiles are the same as graph profiles, except output is
247
- generated in hyper-linked HTML. Since graph profiles can be quite large,
248
- the embedded links make it much easier to navigate the results. An
249
- example html graph profile is located at
250
- {examples/graph.html}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/graph.html].
251
-
252
- Call graphs output results in the calltree profile format which is used
253
- by KCachegrind. Call graph support was generously donated by Carl
254
- Shimer. More information about the format can be found at the
255
- {KCachegrind}[http://kcachegrind.sourceforge.net/cgi-bin/show.cgi/KcacheGrindCalltreeFormat]
256
- site.
257
-
258
- Call stack reports produce a HTML visualization of the time spent in
259
- each execution path of the profiled code. An example can be found at
260
- {examples/stack.html}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/stack.html].
261
-
262
- Another good example: http://twitpic.com/28z94a
263
-
264
- Finally, there's a so called MultiPrinter which can generate several
265
- reports in one profiling run. See
266
- {examples/multi.stack.html}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/multi.stack.html].
267
-
268
- There is also a graphviz .dot visualiser.
269
-
270
- == Printers
271
-
272
- Reports are created by printers. Supported printers include:
273
-
274
- RubyProf::FlatPrinter::
275
- Creates a flat report in text format
276
-
277
- RubyProf::FlatPrinterWithLineNumbers::
278
- Same as above but more verbose
279
-
280
- RubyProf::GraphPrinter::
281
- Creates a call graph report in text format
282
-
283
- RubyProf::GraphHtmlPrinter::
284
- Creates a call graph report in HTML (separate files per thread)
285
-
286
- RubyProf::DotPrinter::
287
- Creates a call graph report in GraphViz's DOT format which can be converted to an image
288
-
289
- RubyProf::CallTreePrinter::
290
- Creates a call tree report compatible with KCachegrind
291
-
292
- RubyProf::CallStackPrinter::
293
- Creates a HTML visualization of the Ruby stack
294
-
295
- RubyProf::MultiPrinter::
296
- Uses the other printers to create several reports in one profiling run
297
-
298
- To use a printer:
299
-
300
- result = RubyProf.stop
301
- printer = RubyProf::GraphPrinter.new(result)
302
- printer.print(STDOUT, :min_percent => 2)
303
-
304
-
305
- The first parameter is any writable IO object such as <tt>STDOUT</tt>
306
- or a file. The second parameter, specifies the minimum percentage a
307
- method must take to be printed. Percentages should be specified as
308
- integers in the range 0 to 100. For more information please see the
309
- documentation for the different printers.
310
-
311
- The other option is <tt>:print_file => true</tt> (default false),
312
- which adds the filename to the output (GraphPrinter only).
313
-
314
- <tt>MultiPrinter</tt> differs from the other printers in that it
315
- requires a directory path and a basename for the files it produces.
316
-
317
- printer = RubyProf::MultiPrinter.new(result)
318
- printer.print(:path => ".", :profile => "profile")
319
-
320
- == Measurements
321
-
322
- Depending on the mode and platform, ruby-prof can measure various
323
- aspects of a Ruby program. Supported measurements include:
324
-
325
- RubyProf::WALL_TIME::
326
- Wall time measures the real-world time
327
- elapsed between any two moments. If there are other processes
328
- concurrently running on the system that use significant CPU or disk
329
- time during a profiling run then the reported results will be larger
330
- than expected.
331
-
332
- RubyProf::PROCESS_TIME::
333
- Process time measures the time used by a process between any two moments.
334
- It is unaffected by other processes concurrently running
335
- on the system. Note that Windows does not support measuring process
336
- times.
337
-
338
- RubyProf::CPU_TIME::
339
- CPU time uses the CPU clock counter to measure time. The returned
340
- values are dependent on the correctly setting the CPU's frequency.
341
- This mode is only supported on Pentium or PowerPC platforms (linux only).
342
-
343
- RubyProf::ALLOCATIONS::
344
- Object allocation reports show how many objects each method in
345
- a program allocates. This support was added by Sylvain Joyeux
346
- and requires a patched Ruby interpreter. See below.
347
-
348
-
349
- RubyProf::MEMORY::
350
- Memory usage reports show how much memory each method in a program
351
- uses. This support was added by Alexander Dymo and requires a
352
- patched Ruby interpreter. See below.
353
-
354
- RubyProf::GC_TIME::
355
- Garbage collection time reports how much time is spent in Ruby's
356
- garbage collector during a profiling session. This support was added
357
- by Jeremy Kemper and requires a patched Ruby interpreter. See below.
358
-
359
- RubyProf::GC_RUNS::
360
- Garbage collection runs report how many times Ruby's garbage collector
361
- is invoked during a profiling session. This support was added by
362
- Jeremy Kemper and requires a patched Ruby interpreter. See below.
363
-
364
- == Patching ruby
365
-
366
- All of the patches to Ruby are included in the railsexpress patchsets
367
- for rvm, see https://github.com/skaes/rvm-patchsets. You can also use
368
- these patches manually with other ruby managers (ruby-install,
369
- ruby-build, etc.).
370
-
371
- Note if you rebuild your ruby with patches you must uninstall and
372
- reinstall the ruby-prof gem to take advantage of the new capabilities.
373
-
374
- == Measure modes
375
-
376
- To set the measurement:
377
-
378
- RubyProf.measure_mode = RubyProf::WALL_TIME
379
- RubyProf.measure_mode = RubyProf::PROCESS_TIME
380
- RubyProf.measure_mode = RubyProf::CPU_TIME
381
- RubyProf.measure_mode = RubyProf::ALLOCATIONS
382
- RubyProf.measure_mode = RubyProf::MEMORY
383
- RubyProf.measure_mode = RubyProf::GC_TIME
384
- RubyProf.measure_mode = RubyProf::GC_RUNS
385
-
386
- The default value is <tt>RubyProf::WALL_TIME</tt>.
387
-
388
- You may also specify the measure mode by using the
389
- <tt>RUBY_PROF_MEASURE_MODE</tt> environment variable:
390
-
391
- export RUBY_PROF_MEASURE_MODE=wall
392
- export RUBY_PROF_MEASURE_MODE=process
393
- export RUBY_PROF_MEASURE_MODE=cpu
394
- export RUBY_PROF_MEASURE_MODE=allocations
395
- export RUBY_PROF_MEASURE_MODE=memory
396
- export RUBY_PROF_MEASURE_MODE=gc_time
397
- export RUBY_PROF_MEASURE_MODE=gc_runs
398
-
399
- On Linux, process time is measured using the clock method provided
400
- by the C runtime library. Note that the clock method does not
401
- report time spent in the kernel or child processes and therefore
402
- does not measure time spent in methods such as Kernel.sleep method.
403
- If you need to measure these values, then use wall time. Wall time
404
- is measured using the gettimeofday kernel method.
405
-
406
- If you set the clock mode to <tt>PROCESS_TIME</tt>, then timings are
407
- read using the clock method provided by the C runtime library. Note
408
- though, these values are wall times on Windows and not process times
409
- like on Linux. Wall time is measured using the GetLocalTime API.
410
-
411
- If you use wall time, the results will be affected by other
412
- processes running on your computer, network delays, disk access,
413
- etc. As result, for the best results, try to make sure your
414
- computer is only performing your profiling run and is
415
- otherwise quiescent.
416
-
417
- == Multi-threaded Applications
418
-
419
- Unfortunately, Ruby does not provide an internal API for detecting
420
- thread context switches. As a result, the timings ruby-prof reports
421
- for each thread may be slightly inaccurate. In particular, this will
422
- happen for newly spawned threads that go to sleep immediately (their
423
- first call). For instance, if you use Ruby's timeout library to wait
424
- for 2 seconds, the 2 seconds will be assigned to the foreground thread
425
- and not the newly created background thread. These errors can largely
426
- be avoided if the background thread performs any operation before
427
- going to sleep.
428
-
429
- == Performance
430
-
431
- Significant effort has been put into reducing ruby-prof's overhead
432
- as much as possible. Our tests show that the overhead associated
433
- with profiling code varies considerably with the code being
434
- profiled. Most programs will run approximately twice as slow
435
- while highly recursive programs (like the fibonacci series test)
436
- will run three times slower.
437
-
438
- == License
439
-
440
- See LICENSE for license information.
441
-
442
- == API Documentation
443
-
444
- The ruby-prof API documentation for the latest released gem version
445
- can be found here: http://www.rubydoc.info/gems/ruby-prof/
446
-
447
- The ruby-prof API documentation for the master branch is available
448
- here: http://www.rubydoc.info/github/ruby-prof/ruby-prof/
449
-
450
- == Development
451
-
452
- Code is located at https://github.com/ruby-prof/ruby-prof
453
-
454
- Google group/mailing list: http://groups.google.com/group/ruby-optimization or open a github issue.
1
+ = ruby-prof
2
+
3
+ {<img src="https://travis-ci.org/ruby-prof/ruby-prof.png?branch=master" alt="Build Status" />}[https://travis-ci.org/ruby-prof/ruby-prof]
4
+
5
+ For an overview of ruby-prof please see https://ruby-prof.github.io