ruby-prof 0.17.0 → 0.18.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 (185) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGES +500 -482
  3. data/LICENSE +24 -24
  4. data/README.rdoc +487 -485
  5. data/Rakefile +113 -113
  6. data/bin/ruby-prof +345 -345
  7. data/bin/ruby-prof-check-trace +45 -45
  8. data/examples/flat.txt +50 -50
  9. data/examples/graph.dot +84 -84
  10. data/examples/graph.html +823 -823
  11. data/examples/graph.txt +139 -139
  12. data/examples/multi.flat.txt +23 -23
  13. data/examples/multi.graph.html +760 -760
  14. data/examples/multi.grind.dat +114 -114
  15. data/examples/multi.stack.html +547 -547
  16. data/examples/stack.html +547 -547
  17. data/ext/ruby_prof/extconf.rb +68 -68
  18. data/ext/ruby_prof/rp_call_info.c +425 -425
  19. data/ext/ruby_prof/rp_call_info.h +53 -53
  20. data/ext/ruby_prof/rp_measure.c +40 -40
  21. data/ext/ruby_prof/rp_measure.h +45 -45
  22. data/ext/ruby_prof/rp_measure_allocations.c +76 -76
  23. data/ext/ruby_prof/rp_measure_cpu_time.c +136 -136
  24. data/ext/ruby_prof/rp_measure_gc_runs.c +73 -73
  25. data/ext/ruby_prof/rp_measure_gc_time.c +60 -60
  26. data/ext/ruby_prof/rp_measure_memory.c +77 -77
  27. data/ext/ruby_prof/rp_measure_process_time.c +71 -71
  28. data/ext/ruby_prof/rp_measure_wall_time.c +45 -45
  29. data/ext/ruby_prof/rp_method.c +630 -636
  30. data/ext/ruby_prof/rp_method.h +75 -75
  31. data/ext/ruby_prof/rp_stack.c +173 -173
  32. data/ext/ruby_prof/rp_stack.h +63 -63
  33. data/ext/ruby_prof/rp_thread.c +277 -276
  34. data/ext/ruby_prof/rp_thread.h +27 -27
  35. data/ext/ruby_prof/ruby_prof.c +794 -774
  36. data/ext/ruby_prof/ruby_prof.h +60 -59
  37. data/ext/ruby_prof/vc/ruby_prof.sln +20 -21
  38. data/ext/ruby_prof/vc/{ruby_prof_20.vcxproj → ruby_prof.vcxproj} +31 -0
  39. data/lib/ruby-prof.rb +68 -68
  40. data/lib/ruby-prof/aggregate_call_info.rb +76 -76
  41. data/lib/ruby-prof/assets/call_stack_printer.css.html +116 -116
  42. data/lib/ruby-prof/assets/call_stack_printer.js.html +384 -384
  43. data/lib/ruby-prof/call_info.rb +115 -115
  44. data/lib/ruby-prof/call_info_visitor.rb +40 -40
  45. data/lib/ruby-prof/compatibility.rb +179 -178
  46. data/lib/ruby-prof/method_info.rb +121 -121
  47. data/lib/ruby-prof/printers/abstract_printer.rb +104 -103
  48. data/lib/ruby-prof/printers/call_info_printer.rb +41 -41
  49. data/lib/ruby-prof/printers/call_stack_printer.rb +265 -265
  50. data/lib/ruby-prof/printers/call_tree_printer.rb +143 -143
  51. data/lib/ruby-prof/printers/dot_printer.rb +132 -132
  52. data/lib/ruby-prof/printers/flat_printer.rb +70 -70
  53. data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +83 -83
  54. data/lib/ruby-prof/printers/graph_html_printer.rb +249 -249
  55. data/lib/ruby-prof/printers/graph_printer.rb +116 -116
  56. data/lib/ruby-prof/printers/multi_printer.rb +84 -84
  57. data/lib/ruby-prof/profile.rb +26 -26
  58. data/lib/ruby-prof/profile/exclude_common_methods.rb +207 -201
  59. data/lib/ruby-prof/profile/legacy_method_elimination.rb +50 -49
  60. data/lib/ruby-prof/rack.rb +174 -174
  61. data/lib/ruby-prof/task.rb +147 -147
  62. data/lib/ruby-prof/thread.rb +35 -35
  63. data/lib/ruby-prof/version.rb +3 -3
  64. data/lib/unprof.rb +10 -10
  65. data/ruby-prof.gemspec +58 -58
  66. data/test/abstract_printer_test.rb +53 -0
  67. data/test/aggregate_test.rb +136 -136
  68. data/test/basic_test.rb +128 -128
  69. data/test/block_test.rb +74 -74
  70. data/test/call_info_test.rb +78 -78
  71. data/test/call_info_visitor_test.rb +31 -31
  72. data/test/duplicate_names_test.rb +32 -32
  73. data/test/dynamic_method_test.rb +55 -55
  74. data/test/enumerable_test.rb +21 -21
  75. data/test/exceptions_test.rb +24 -16
  76. data/test/exclude_methods_test.rb +146 -146
  77. data/test/exclude_threads_test.rb +53 -53
  78. data/test/fiber_test.rb +79 -79
  79. data/test/issue137_test.rb +63 -63
  80. data/test/line_number_test.rb +80 -80
  81. data/test/measure_allocations_test.rb +26 -26
  82. data/test/measure_cpu_time_test.rb +212 -213
  83. data/test/measure_gc_runs_test.rb +32 -32
  84. data/test/measure_gc_time_test.rb +36 -36
  85. data/test/measure_memory_test.rb +33 -33
  86. data/test/measure_process_time_test.rb +61 -63
  87. data/test/measure_wall_time_test.rb +255 -255
  88. data/test/method_elimination_test.rb +84 -84
  89. data/test/module_test.rb +45 -45
  90. data/test/multi_printer_test.rb +104 -104
  91. data/test/no_method_class_test.rb +15 -15
  92. data/test/pause_resume_test.rb +166 -166
  93. data/test/prime.rb +54 -54
  94. data/test/printers_test.rb +275 -275
  95. data/test/printing_recursive_graph_test.rb +127 -127
  96. data/test/rack_test.rb +157 -157
  97. data/test/recursive_test.rb +215 -215
  98. data/test/singleton_test.rb +38 -38
  99. data/test/stack_printer_test.rb +77 -78
  100. data/test/stack_test.rb +138 -138
  101. data/test/start_stop_test.rb +112 -112
  102. data/test/test_helper.rb +267 -275
  103. data/test/thread_test.rb +187 -187
  104. data/test/unique_call_path_test.rb +202 -202
  105. data/test/yarv_test.rb +55 -55
  106. metadata +17 -96
  107. data/doc/LICENSE.html +0 -115
  108. data/doc/README_rdoc.html +0 -637
  109. data/doc/Rack.html +0 -96
  110. data/doc/Rack/RubyProf.html +0 -233
  111. data/doc/Rack/RubyProf/RackProfiler.html +0 -343
  112. data/doc/RubyProf.html +0 -974
  113. data/doc/RubyProf/AbstractPrinter.html +0 -625
  114. data/doc/RubyProf/AggregateCallInfo.html +0 -552
  115. data/doc/RubyProf/CallInfo.html +0 -579
  116. data/doc/RubyProf/CallInfoPrinter.html +0 -121
  117. data/doc/RubyProf/CallInfoVisitor.html +0 -199
  118. data/doc/RubyProf/CallStackPrinter.html +0 -1127
  119. data/doc/RubyProf/CallTreePrinter.html +0 -725
  120. data/doc/RubyProf/Cmd.html +0 -637
  121. data/doc/RubyProf/DeprecationWarnings.html +0 -148
  122. data/doc/RubyProf/DotPrinter.html +0 -258
  123. data/doc/RubyProf/FlatPrinter.html +0 -164
  124. data/doc/RubyProf/FlatPrinterWithLineNumbers.html +0 -210
  125. data/doc/RubyProf/GraphHtmlPrinter.html +0 -558
  126. data/doc/RubyProf/GraphPrinter.html +0 -140
  127. data/doc/RubyProf/MethodInfo.html +0 -676
  128. data/doc/RubyProf/MultiPrinter.html +0 -574
  129. data/doc/RubyProf/Profile.html +0 -908
  130. data/doc/RubyProf/Profile/ExcludeCommonMethods.html +0 -411
  131. data/doc/RubyProf/Profile/LegacyMethodElimination.html +0 -158
  132. data/doc/RubyProf/ProfileTask.html +0 -491
  133. data/doc/RubyProf/Thread.html +0 -275
  134. data/doc/created.rid +0 -33
  135. data/doc/css/fonts.css +0 -167
  136. data/doc/css/rdoc.css +0 -590
  137. data/doc/examples/flat_txt.html +0 -139
  138. data/doc/examples/graph_html.html +0 -910
  139. data/doc/examples/graph_txt.html +0 -248
  140. data/doc/fonts/Lato-Light.ttf +0 -0
  141. data/doc/fonts/Lato-LightItalic.ttf +0 -0
  142. data/doc/fonts/Lato-Regular.ttf +0 -0
  143. data/doc/fonts/Lato-RegularItalic.ttf +0 -0
  144. data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
  145. data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
  146. data/doc/images/add.png +0 -0
  147. data/doc/images/arrow_up.png +0 -0
  148. data/doc/images/brick.png +0 -0
  149. data/doc/images/brick_link.png +0 -0
  150. data/doc/images/bug.png +0 -0
  151. data/doc/images/bullet_black.png +0 -0
  152. data/doc/images/bullet_toggle_minus.png +0 -0
  153. data/doc/images/bullet_toggle_plus.png +0 -0
  154. data/doc/images/date.png +0 -0
  155. data/doc/images/delete.png +0 -0
  156. data/doc/images/find.png +0 -0
  157. data/doc/images/loadingAnimation.gif +0 -0
  158. data/doc/images/macFFBgHack.png +0 -0
  159. data/doc/images/package.png +0 -0
  160. data/doc/images/page_green.png +0 -0
  161. data/doc/images/page_white_text.png +0 -0
  162. data/doc/images/page_white_width.png +0 -0
  163. data/doc/images/plugin.png +0 -0
  164. data/doc/images/ruby.png +0 -0
  165. data/doc/images/tag_blue.png +0 -0
  166. data/doc/images/tag_green.png +0 -0
  167. data/doc/images/transparent.png +0 -0
  168. data/doc/images/wrench.png +0 -0
  169. data/doc/images/wrench_orange.png +0 -0
  170. data/doc/images/zoom.png +0 -0
  171. data/doc/index.html +0 -666
  172. data/doc/js/darkfish.js +0 -161
  173. data/doc/js/jquery.js +0 -4
  174. data/doc/js/navigation.js +0 -142
  175. data/doc/js/navigation.js.gz +0 -0
  176. data/doc/js/search.js +0 -109
  177. data/doc/js/search_index.js +0 -1
  178. data/doc/js/search_index.js.gz +0 -0
  179. data/doc/js/searcher.js +0 -229
  180. data/doc/js/searcher.js.gz +0 -0
  181. data/doc/table_of_contents.html +0 -1052
  182. data/examples/cachegrind.out.1 +0 -114
  183. data/examples/cachegrind.out.1.32313213 +0 -114
  184. data/ext/ruby_prof/vc/ruby_prof_18.vcxproj +0 -108
  185. data/ext/ruby_prof/vc/ruby_prof_19.vcxproj +0 -110
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 - 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
25
25
  SUCH DAMAGE.
@@ -1,485 +1,487 @@
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: `$ ruby-prof -h.`
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 (Deprecated)
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
- == Method Exclusion
184
-
185
- ruby-prof supports exluding methods from profiling. The effect on
186
- collected metrics are identical to eliminating methods from the
187
- profiling result in a prost process step. The interface is slightly
188
- different though:
189
-
190
- profile = RubyProf.new(...)
191
- profile.exclude_methods!(Integer, :times, ...)
192
- profile.start
193
-
194
- A convenience method is provided to exclude a large number of methods
195
- which usually clutter up profiles:
196
-
197
- profile.exclude_common_methods!
198
-
199
- However, this is a somewhat opinionated method collection. It's
200
- usually better to view it as an inspiration instead of using it
201
- directly (see https://github.com/ruby-prof/ruby-prof/blob/e087b7d7ca11eecf1717d95a5c5fea1e36ea3136/lib/ruby-prof/profile/exclude_common_methods.rb).
202
-
203
-
204
- == Profiling Rails
205
-
206
- To profile a Rails application it is vital to run it using production like
207
- settings (cache classes, cache view lookups, etc.). Otherwise, Rail's
208
- dependency loading code will overwhelm any time spent in the application
209
- itself (our tests show that Rails dependency loading causes a roughly 6x
210
- slowdown). The best way to do this is create a new Rails environment,
211
- profile.rb.
212
-
213
- So to profile Rails:
214
-
215
- 1. Create a new profile.rb environment. Make sure to turn on
216
- <tt>cache_classes</tt> and
217
- <tt>cache_template_loading</tt>. Otherwise your profiling results
218
- will be overwhelmed by the time Rails spends loading required
219
- files. You should likely turn off caching.
220
-
221
- 2. Add the ruby-prof to your gemfile:
222
-
223
- group :profile do
224
- gem 'ruby-prof'
225
- end
226
-
227
- 3. Add the ruby prof rack adapter to your middleware stack. One way to
228
- do this is by adding the following code to <tt>config.ru</tt>:
229
-
230
- if Rails.env.profile?
231
- use Rack::RubyProf, :path => '/temp/profile'
232
- end
233
-
234
- The path is where you want profiling results to be stored. By default the
235
- rack adapter will generate a html call graph report and flat text report.
236
-
237
- 4. Now make a request to your running server. New profiling
238
- information will be generated for each request. Note that each
239
- request will overwrite the profiling reports created by the
240
- previous request!
241
-
242
- == Reports
243
-
244
- ruby-prof can generate a number of different reports:
245
-
246
- * Flat Reports
247
- * Graph Reports
248
- * HTML Graph Reports
249
- * Call graphs
250
- * Call stack reports
251
- * More!
252
-
253
- Flat profiles show the overall time spent in each method. They
254
- are a good way of quickly identifying which methods take the most time.
255
- An example of a flat profile and an explanation can be found in
256
- {examples/flat.txt}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/flat.txt].
257
-
258
- There are several varieties of these - run <tt>ruby-prof --help</tt>
259
-
260
- Graph profiles also show the overall time spent in each method. In
261
- addition, they also show which methods call the current method and which
262
- methods its calls. Thus they are good for understanding how methods
263
- gets called and provide insight into the flow of your program. An
264
- example text graph profile is located at
265
- {examples/graph.txt}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/graph.txt].
266
-
267
- HTML Graph profiles are the same as graph profiles, except output is
268
- generated in hyper-linked HTML. Since graph profiles can be quite large,
269
- the embedded links make it much easier to navigate the results. An
270
- example html graph profile is located at
271
- {examples/graph.html}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/graph.html].
272
-
273
- Call graphs output results in the calltree profile format which is used
274
- by KCachegrind. Call graph support was generously donated by Carl
275
- Shimer. More information about the format can be found at the
276
- {KCachegrind}[http://kcachegrind.sourceforge.net/cgi-bin/show.cgi/KcacheGrindCalltreeFormat]
277
- site.
278
-
279
- Call stack reports produce a HTML visualization of the time spent in
280
- each execution path of the profiled code. An example can be found at
281
- {examples/stack.html}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/stack.html].
282
-
283
- Another good example: http://twitpic.com/28z94a
284
-
285
- Finally, there's a so called MultiPrinter which can generate several
286
- reports in one profiling run. See
287
- {examples/multi.stack.html}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/multi.stack.html].
288
-
289
- There is also a graphviz .dot visualiser.
290
-
291
- == Printers
292
-
293
- Reports are created by printers. Supported printers include:
294
-
295
- RubyProf::FlatPrinter::
296
- Creates a flat report in text format
297
-
298
- RubyProf::FlatPrinterWithLineNumbers::
299
- Same as above but more verbose
300
-
301
- RubyProf::GraphPrinter::
302
- Creates a call graph report in text format
303
-
304
- RubyProf::GraphHtmlPrinter::
305
- Creates a call graph report in HTML (separate files per thread)
306
-
307
- RubyProf::DotPrinter::
308
- Creates a call graph report in GraphViz's DOT format which can be converted to an image
309
-
310
- RubyProf::CallTreePrinter::
311
- Creates a call tree report compatible with KCachegrind
312
-
313
- RubyProf::CallStackPrinter::
314
- Creates a HTML visualization of the Ruby stack
315
-
316
- RubyProf::MultiPrinter::
317
- Uses the other printers to create several reports in one profiling run
318
-
319
- Most printers are used in the following way:
320
-
321
- result = RubyProf.stop
322
- printer = RubyProf::GraphPrinter.new(result)
323
- printer.print(STDOUT, :min_percent => 2)
324
-
325
-
326
- The first parameter is any writable IO object such as <tt>STDOUT</tt>
327
- or a file. The second parameter, specifies the minimum percentage a
328
- method must take to be printed. Percentages should be specified as
329
- integers in the range 0 to 100. For more information please see the
330
- documentation for the different printers.
331
-
332
- The other option is <tt>:print_file => true</tt> (default false),
333
- which adds the filename to the output (GraphPrinter only).
334
-
335
- <tt>MultiPrinter</tt> and <tt>CallTreePrinter</tt>differ from the
336
- other printers in that they require a directory path and a profile
337
- basename for the files they produce:
338
-
339
- printer = RubyProf::MultiPrinter.new(result)
340
- printer.print(:path => ".", :profile => "profile")
341
-
342
- The values given in the example above are the defaults.
343
-
344
- == Measurements
345
-
346
- Depending on the mode and platform, ruby-prof can measure various
347
- aspects of a Ruby program. Supported measurements include:
348
-
349
- RubyProf::WALL_TIME::
350
- Wall time measures the real-world time
351
- elapsed between any two moments. If there are other processes
352
- concurrently running on the system that use significant CPU or disk
353
- time during a profiling run then the reported results will be larger
354
- than expected.
355
-
356
- RubyProf::PROCESS_TIME::
357
- Process time measures the time used by a process between any two moments.
358
- It is unaffected by other processes concurrently running
359
- on the system. Note that Windows does not support measuring process
360
- times.
361
-
362
- RubyProf::CPU_TIME::
363
- CPU time uses the CPU clock counter to measure time. The returned
364
- values are dependent on the correctly setting the CPU's frequency.
365
- This mode is only supported on Pentium or PowerPC platforms (linux only).
366
-
367
- RubyProf::ALLOCATIONS::
368
- Object allocation reports show how many objects each method in
369
- a program allocates. This support was added by Sylvain Joyeux
370
- and requires a patched Ruby interpreter. See below.
371
-
372
-
373
- RubyProf::MEMORY::
374
- Memory usage reports show how much memory each method in a program
375
- uses. This support was added by Alexander Dymo and requires a
376
- patched Ruby interpreter. See below.
377
-
378
- RubyProf::GC_TIME::
379
- Garbage collection time reports how much time is spent in Ruby's
380
- garbage collector during a profiling session. This support was added
381
- by Jeremy Kemper and requires a patched Ruby interpreter. See below.
382
-
383
- RubyProf::GC_RUNS::
384
- Garbage collection runs report how many times Ruby's garbage collector
385
- is invoked during a profiling session. This support was added by
386
- Jeremy Kemper and requires a patched Ruby interpreter. See below.
387
-
388
- == Patching ruby
389
-
390
- All of the patches to Ruby are included in the railsexpress patchsets
391
- for rvm, see https://github.com/skaes/rvm-patchsets. You can also use
392
- these patches manually with other ruby managers (ruby-install,
393
- ruby-build, etc.).
394
-
395
- Note if you rebuild your ruby with patches you must uninstall and
396
- reinstall the ruby-prof gem to take advantage of the new capabilities.
397
-
398
- == Measure modes
399
-
400
- To set the measurement:
401
-
402
- RubyProf.measure_mode = RubyProf::WALL_TIME
403
- RubyProf.measure_mode = RubyProf::PROCESS_TIME
404
- RubyProf.measure_mode = RubyProf::CPU_TIME
405
- RubyProf.measure_mode = RubyProf::ALLOCATIONS
406
- RubyProf.measure_mode = RubyProf::MEMORY
407
- RubyProf.measure_mode = RubyProf::GC_TIME
408
- RubyProf.measure_mode = RubyProf::GC_RUNS
409
-
410
- The default value is <tt>RubyProf::WALL_TIME</tt>.
411
-
412
- You may also specify the measure mode by using the
413
- <tt>RUBY_PROF_MEASURE_MODE</tt> environment variable:
414
-
415
- export RUBY_PROF_MEASURE_MODE=wall
416
- export RUBY_PROF_MEASURE_MODE=process
417
- export RUBY_PROF_MEASURE_MODE=cpu
418
- export RUBY_PROF_MEASURE_MODE=allocations
419
- export RUBY_PROF_MEASURE_MODE=memory
420
- export RUBY_PROF_MEASURE_MODE=gc_time
421
- export RUBY_PROF_MEASURE_MODE=gc_runs
422
-
423
- On Linux, process time is measured using the clock method provided
424
- by the C runtime library. Note that the clock method does not
425
- report time spent in the kernel or child processes and therefore
426
- does not measure time spent in methods such as Kernel.sleep method.
427
- If you need to measure these values, then use wall time. Wall time
428
- is measured using the gettimeofday kernel method.
429
-
430
- If you set the clock mode to <tt>PROCESS_TIME</tt>, then timings are
431
- read using the clock method provided by the C runtime library. Note
432
- though, these values are wall times on Windows and not process times
433
- like on Linux. Wall time is measured using the GetLocalTime API.
434
-
435
- If you use wall time, the results will be affected by other
436
- processes running on your computer, network delays, disk access,
437
- etc. As result, for the best results, try to make sure your
438
- computer is only performing your profiling run and is
439
- otherwise quiescent.
440
-
441
- == Multi-threaded Applications
442
-
443
- Unfortunately, Ruby does not provide an internal API for detecting
444
- thread context switches. As a result, the timings ruby-prof reports
445
- for each thread may be slightly inaccurate. In particular, this will
446
- happen for newly spawned threads that go to sleep immediately (their
447
- first call). For instance, if you use Ruby's timeout library to wait
448
- for 2 seconds, the 2 seconds will be assigned to the foreground thread
449
- and not the newly created background thread. These errors can largely
450
- be avoided if the background thread performs any operation before
451
- going to sleep.
452
-
453
- == Performance
454
-
455
- Significant effort has been put into reducing ruby-prof's overhead
456
- as much as possible. Our tests show that the overhead associated
457
- with profiling code varies considerably with the code being
458
- profiled. Most programs will run approximately twice as slow
459
- while highly recursive programs (like the fibonacci series test)
460
- will run three times slower.
461
-
462
- == Editing links
463
-
464
- Use <tt>RUBY_PROF_EDITOR_URI</tt> environment variable to open source
465
- code files in your favorite text editor. For example,
466
- <tt>RUBY_PROF_EDITOR_URI=atm</tt> will produce links for Atom text
467
- editor.
468
-
469
- == License
470
-
471
- See LICENSE for license information.
472
-
473
- == API Documentation
474
-
475
- The ruby-prof API documentation for the latest released gem version
476
- can be found here: http://www.rubydoc.info/gems/ruby-prof/
477
-
478
- The ruby-prof API documentation for the master branch is available
479
- here: http://www.rubydoc.info/github/ruby-prof/ruby-prof/
480
-
481
- == Development
482
-
483
- Code is located at https://github.com/ruby-prof/ruby-prof
484
-
485
- 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
+ == 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
+ $ ruby-prof -h
54
+
55
+
56
+ === ruby-prof Convenience API
57
+
58
+ The second way is to use the ruby-prof convenience API to profile
59
+ particular segments of code.
60
+
61
+ require 'ruby-prof'
62
+
63
+ # profile the code
64
+ RubyProf.start
65
+ # ... code to profile ...
66
+ result = RubyProf.stop
67
+
68
+ # print a flat profile to text
69
+ printer = RubyProf::FlatPrinter.new(result)
70
+ printer.print(STDOUT)
71
+
72
+ Alternatively, you can use a block to tell ruby-prof what to profile:
73
+
74
+ require 'ruby-prof'
75
+
76
+ # profile the code
77
+ result = RubyProf.profile do
78
+ # ... code to profile ...
79
+ end
80
+
81
+ # print a graph profile to text
82
+ printer = RubyProf::GraphPrinter.new(result)
83
+ printer.print(STDOUT, {})
84
+
85
+ ruby-prof also supports pausing and resuming profiling runs.
86
+
87
+ require 'ruby-prof'
88
+
89
+ # profile the code
90
+ RubyProf.start
91
+ # ... code to profile ...
92
+
93
+ RubyProf.pause
94
+ # ... other code ...
95
+
96
+ RubyProf.resume
97
+ # ... code to profile ...
98
+ result = RubyProf.stop
99
+
100
+ Note that resume will only work if start has been called previously.
101
+ In addition, resume can also take a block:
102
+
103
+ require 'ruby-prof'
104
+
105
+ RubyProf.resume do
106
+ # ... code to profile...
107
+ end
108
+
109
+ result = RubyProf.stop
110
+
111
+ With this usage, resume will automatically call pause at the
112
+ end of the block.
113
+
114
+ === Profiling Selected Threads (Core API)
115
+
116
+ The convenience API does not support running multiple profiles in
117
+ separate threads concurrently, but the RubyProf::Profile API does. In
118
+ fact, the convenience layer uses the Profile API internally. It all
119
+ revolves around Profile objects:
120
+
121
+ RubyProf::Profile.new::
122
+ Create a profile object given an options hash (see below)
123
+
124
+ The following options are available when creating Profile instances:
125
+
126
+ measure_mode::
127
+ One of the defined measure modes
128
+
129
+ exclude_threads::
130
+ Array of threads which should not be profiled.
131
+
132
+ include_threads::
133
+ Array of threads which should be profiled. All other threads will
134
+ be ignored.
135
+
136
+ merge_fibers::
137
+ Whether profiling data for a given thread's fibers should all be
138
+ subsumed under a single entry. Basically only useful to produce
139
+ callgrind profiles.
140
+
141
+ RubyProf::Profile#start::
142
+ Start profiling
143
+
144
+ RubyProf::Profile#pause::
145
+ Pause profiling
146
+
147
+ RubyProf::Profile#resume::
148
+ Resume profiling
149
+
150
+ RubyProf::Profile#stop::
151
+ Stop profiling and return self
152
+
153
+ RubyProf::Profile#profile::
154
+ Perform a profile run and return result. Accepts the same arguments
155
+ as RubyProf::Profile.new.
156
+
157
+
158
+ == Method Elimination (Deprecated)
159
+
160
+ ruby-prof supports eliminating specific methods and threads from
161
+ profiling results. This is useful for reducing connectivity in the
162
+ call graph, making it easier to identify the source of performance
163
+ problems when using a graph printer.
164
+
165
+ For example, consider <tt>Integer#times</tt>: it's hardly ever useful
166
+ to know how much time is spent in the method itself. We're much more
167
+ interested in how much the passed in block contributes to the time
168
+ spent in the method which contains the <tt>Integer#times</tt> call.
169
+
170
+ Methods are eliminated from the collected data by calling
171
+ <tt>eliminate_methods!</tt> on the profiling result, before submitting
172
+ it to a printer.
173
+
174
+ result = RubyProf.stop
175
+ result.eliminate_methods!([/Integer#times/])
176
+
177
+ The argument given to <tt>eliminate_methods!</tt> is either an array
178
+ of regular expressions, or the name of a file containing a list of
179
+ regular expressions (line separated text).
180
+
181
+ After eliminating methods the resulting profile will appear exactly as if those methods
182
+ had been inlined at their call sites.
183
+
184
+
185
+ == Method Exclusion
186
+
187
+ ruby-prof supports excluding methods from profiling. The effect on
188
+ collected metrics are identical to eliminating methods from the
189
+ profiling result in a prost process step. The interface is slightly
190
+ different though:
191
+
192
+ profile = RubyProf::Profile.new(...)
193
+ profile.exclude_methods!(Integer, :times, ...)
194
+ profile.start
195
+
196
+ A convenience method is provided to exclude a large number of methods
197
+ which usually clutter up profiles:
198
+
199
+ profile.exclude_common_methods!
200
+
201
+ However, this is a somewhat opinionated method collection. It's
202
+ usually better to view it as an inspiration instead of using it
203
+ directly (see https://github.com/ruby-prof/ruby-prof/blob/e087b7d7ca11eecf1717d95a5c5fea1e36ea3136/lib/ruby-prof/profile/exclude_common_methods.rb).
204
+
205
+
206
+ == Profiling Rails
207
+
208
+ To profile a Rails application it is vital to run it using production like
209
+ settings (cache classes, cache view lookups, etc.). Otherwise, Rail's
210
+ dependency loading code will overwhelm any time spent in the application
211
+ itself (our tests show that Rails dependency loading causes a roughly 6x
212
+ slowdown). The best way to do this is create a new Rails environment,
213
+ profile.rb.
214
+
215
+ So to profile Rails:
216
+
217
+ 1. Create a new profile.rb environment. Make sure to turn on
218
+ <tt>cache_classes</tt> and
219
+ <tt>cache_template_loading</tt>. Otherwise your profiling results
220
+ will be overwhelmed by the time Rails spends loading required
221
+ files. You should likely turn off caching.
222
+
223
+ 2. Add the ruby-prof to your gemfile:
224
+
225
+ group :profile do
226
+ gem 'ruby-prof'
227
+ end
228
+
229
+ 3. Add the ruby prof rack adapter to your middleware stack. One way to
230
+ do this is by adding the following code to <tt>config.ru</tt>:
231
+
232
+ if Rails.env.profile?
233
+ use Rack::RubyProf, :path => './tmp/profile'
234
+ end
235
+
236
+ The path is where you want profiling results to be stored. By default the
237
+ rack adapter will generate a html call graph report and flat text report.
238
+
239
+ 4. Now make a request to your running server. New profiling
240
+ information will be generated for each request. Note that each
241
+ request will overwrite the profiling reports created by the
242
+ previous request!
243
+
244
+ == Reports
245
+
246
+ ruby-prof can generate a number of different reports:
247
+
248
+ * Flat Reports
249
+ * Graph Reports
250
+ * HTML Graph Reports
251
+ * Call graphs
252
+ * Call stack reports
253
+ * More!
254
+
255
+ Flat profiles show the overall time spent in each method. They
256
+ are a good way of quickly identifying which methods take the most time.
257
+ An example of a flat profile and an explanation can be found in
258
+ {examples/flat.txt}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/flat.txt].
259
+
260
+ There are several varieties of these - run <tt>ruby-prof --help</tt>
261
+
262
+ Graph profiles also show the overall time spent in each method. In
263
+ addition, they also show which methods call the current method and which
264
+ methods its calls. Thus they are good for understanding how methods
265
+ gets called and provide insight into the flow of your program. An
266
+ example text graph profile is located at
267
+ {examples/graph.txt}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/graph.txt].
268
+
269
+ HTML Graph profiles are the same as graph profiles, except output is
270
+ generated in hyper-linked HTML. Since graph profiles can be quite large,
271
+ the embedded links make it much easier to navigate the results. An
272
+ example html graph profile is located at
273
+ {examples/graph.html}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/graph.html].
274
+
275
+ Call graphs output results in the calltree profile format which is used
276
+ by KCachegrind. Call graph support was generously donated by Carl
277
+ Shimer. More information about the format can be found at the
278
+ {KCachegrind}[http://kcachegrind.sourceforge.net/cgi-bin/show.cgi/KcacheGrindCalltreeFormat]
279
+ site.
280
+
281
+ Call stack reports produce a HTML visualization of the time spent in
282
+ each execution path of the profiled code. An example can be found at
283
+ {examples/stack.html}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/stack.html].
284
+
285
+ Another good example: http://twitpic.com/28z94a
286
+
287
+ Finally, there's a so called MultiPrinter which can generate several
288
+ reports in one profiling run. See
289
+ {examples/multi.stack.html}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/multi.stack.html].
290
+
291
+ There is also a graphviz .dot visualiser.
292
+
293
+ == Printers
294
+
295
+ Reports are created by printers. Supported printers include:
296
+
297
+ RubyProf::FlatPrinter::
298
+ Creates a flat report in text format
299
+
300
+ RubyProf::FlatPrinterWithLineNumbers::
301
+ Same as above but more verbose
302
+
303
+ RubyProf::GraphPrinter::
304
+ Creates a call graph report in text format
305
+
306
+ RubyProf::GraphHtmlPrinter::
307
+ Creates a call graph report in HTML (separate files per thread)
308
+
309
+ RubyProf::DotPrinter::
310
+ Creates a call graph report in GraphViz's DOT format which can be converted to an image
311
+
312
+ RubyProf::CallTreePrinter::
313
+ Creates a call tree report compatible with KCachegrind
314
+
315
+ RubyProf::CallStackPrinter::
316
+ Creates a HTML visualization of the Ruby stack
317
+
318
+ RubyProf::MultiPrinter::
319
+ Uses the other printers to create several reports in one profiling run
320
+
321
+ Most printers are used in the following way:
322
+
323
+ result = RubyProf.stop
324
+ printer = RubyProf::GraphPrinter.new(result)
325
+ printer.print(STDOUT, :min_percent => 2)
326
+
327
+
328
+ The first parameter is any writable IO object such as <tt>STDOUT</tt>
329
+ or a file. The second parameter, specifies the minimum percentage a
330
+ method must take to be printed. Percentages should be specified as
331
+ integers in the range 0 to 100. For more information please see the
332
+ documentation for the different printers.
333
+
334
+ The other option is <tt>:print_file => true</tt> (default false),
335
+ which adds the filename to the output (GraphPrinter only).
336
+
337
+ <tt>MultiPrinter</tt> and <tt>CallTreePrinter</tt>differ from the
338
+ other printers in that they require a directory path and a profile
339
+ basename for the files they produce:
340
+
341
+ printer = RubyProf::MultiPrinter.new(result)
342
+ printer.print(:path => ".", :profile => "profile")
343
+
344
+ The values given in the example above are the defaults.
345
+
346
+ == Measurements
347
+
348
+ Depending on the mode and platform, ruby-prof can measure various
349
+ aspects of a Ruby program. Supported measurements include:
350
+
351
+ RubyProf::WALL_TIME::
352
+ Wall time measures the real-world time
353
+ elapsed between any two moments. If there are other processes
354
+ concurrently running on the system that use significant CPU or disk
355
+ time during a profiling run then the reported results will be larger
356
+ than expected.
357
+
358
+ RubyProf::PROCESS_TIME::
359
+ Process time measures the time used by a process between any two moments.
360
+ It is unaffected by other processes concurrently running
361
+ on the system. Note that Windows does not support measuring process
362
+ times.
363
+
364
+ RubyProf::CPU_TIME::
365
+ CPU time uses the CPU clock counter to measure time. The returned
366
+ values are dependent on the correctly setting the CPU's frequency.
367
+ This mode is only supported on Pentium or PowerPC platforms (linux only).
368
+
369
+ RubyProf::ALLOCATIONS::
370
+ Object allocation reports show how many objects each method in
371
+ a program allocates. This support was added by Sylvain Joyeux
372
+ and requires a patched Ruby interpreter. See below.
373
+
374
+
375
+ RubyProf::MEMORY::
376
+ Memory usage reports show how much memory each method in a program
377
+ uses. This support was added by Alexander Dymo and requires a
378
+ patched Ruby interpreter. See below.
379
+
380
+ RubyProf::GC_TIME::
381
+ Garbage collection time reports how much time is spent in Ruby's
382
+ garbage collector during a profiling session. This support was added
383
+ by Jeremy Kemper and requires a patched Ruby interpreter. See below.
384
+
385
+ RubyProf::GC_RUNS::
386
+ Garbage collection runs report how many times Ruby's garbage collector
387
+ is invoked during a profiling session. This support was added by
388
+ Jeremy Kemper and requires a patched Ruby interpreter. See below.
389
+
390
+ == Patching ruby
391
+
392
+ All of the patches to Ruby are included in the railsexpress patchsets
393
+ for rvm, see https://github.com/skaes/rvm-patchsets. You can also use
394
+ these patches manually with other ruby managers (ruby-install,
395
+ ruby-build, etc.).
396
+
397
+ Note if you rebuild your ruby with patches you must uninstall and
398
+ reinstall the ruby-prof gem to take advantage of the new capabilities.
399
+
400
+ == Measure modes
401
+
402
+ To set the measurement:
403
+
404
+ RubyProf.measure_mode = RubyProf::WALL_TIME
405
+ RubyProf.measure_mode = RubyProf::PROCESS_TIME
406
+ RubyProf.measure_mode = RubyProf::CPU_TIME
407
+ RubyProf.measure_mode = RubyProf::ALLOCATIONS
408
+ RubyProf.measure_mode = RubyProf::MEMORY
409
+ RubyProf.measure_mode = RubyProf::GC_TIME
410
+ RubyProf.measure_mode = RubyProf::GC_RUNS
411
+
412
+ The default value is <tt>RubyProf::WALL_TIME</tt>.
413
+
414
+ You may also specify the measure mode by using the
415
+ <tt>RUBY_PROF_MEASURE_MODE</tt> environment variable:
416
+
417
+ export RUBY_PROF_MEASURE_MODE=wall
418
+ export RUBY_PROF_MEASURE_MODE=process
419
+ export RUBY_PROF_MEASURE_MODE=cpu
420
+ export RUBY_PROF_MEASURE_MODE=allocations
421
+ export RUBY_PROF_MEASURE_MODE=memory
422
+ export RUBY_PROF_MEASURE_MODE=gc_time
423
+ export RUBY_PROF_MEASURE_MODE=gc_runs
424
+
425
+ On Linux, process time is measured using the clock method provided
426
+ by the C runtime library. Note that the clock method does not
427
+ report time spent in the kernel or child processes and therefore
428
+ does not measure time spent in methods such as Kernel.sleep method.
429
+ If you need to measure these values, then use wall time. Wall time
430
+ is measured using the gettimeofday kernel method.
431
+
432
+ If you set the clock mode to <tt>PROCESS_TIME</tt>, then timings are
433
+ read using the clock method provided by the C runtime library. Note
434
+ though, these values are wall times on Windows and not process times
435
+ like on Linux. Wall time is measured using the GetLocalTime API.
436
+
437
+ If you use wall time, the results will be affected by other
438
+ processes running on your computer, network delays, disk access,
439
+ etc. As result, for the best results, try to make sure your
440
+ computer is only performing your profiling run and is
441
+ otherwise quiescent.
442
+
443
+ == Multi-threaded Applications
444
+
445
+ Unfortunately, Ruby does not provide an internal API for detecting
446
+ thread context switches. As a result, the timings ruby-prof reports
447
+ for each thread may be slightly inaccurate. In particular, this will
448
+ happen for newly spawned threads that go to sleep immediately (their
449
+ first call). For instance, if you use Ruby's timeout library to wait
450
+ for 2 seconds, the 2 seconds will be assigned to the foreground thread
451
+ and not the newly created background thread. These errors can largely
452
+ be avoided if the background thread performs any operation before
453
+ going to sleep.
454
+
455
+ == Performance
456
+
457
+ Significant effort has been put into reducing ruby-prof's overhead
458
+ as much as possible. Our tests show that the overhead associated
459
+ with profiling code varies considerably with the code being
460
+ profiled. Most programs will run approximately twice as slow
461
+ while highly recursive programs (like the fibonacci series test)
462
+ will run three times slower.
463
+
464
+ == Editing links
465
+
466
+ Use <tt>RUBY_PROF_EDITOR_URI</tt> environment variable to open source
467
+ code files in your favorite text editor. For example,
468
+ <tt>RUBY_PROF_EDITOR_URI=atm</tt> will produce links for Atom text
469
+ editor.
470
+
471
+ == License
472
+
473
+ See LICENSE for license information.
474
+
475
+ == API Documentation
476
+
477
+ The ruby-prof API documentation for the latest released gem version
478
+ can be found here: http://www.rubydoc.info/gems/ruby-prof/
479
+
480
+ The ruby-prof API documentation for the master branch is available
481
+ here: http://www.rubydoc.info/github/ruby-prof/ruby-prof/
482
+
483
+ == Development
484
+
485
+ Code is located at https://github.com/ruby-prof/ruby-prof
486
+
487
+ Google group/mailing list: http://groups.google.com/group/ruby-optimization or open a github issue.