ruby-prof 0.18.0-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES +500 -0
- data/LICENSE +25 -0
- data/README.rdoc +487 -0
- data/Rakefile +113 -0
- data/bin/ruby-prof +345 -0
- data/bin/ruby-prof-check-trace +45 -0
- data/examples/flat.txt +50 -0
- data/examples/graph.dot +84 -0
- data/examples/graph.html +823 -0
- data/examples/graph.txt +139 -0
- data/examples/multi.flat.txt +23 -0
- data/examples/multi.graph.html +760 -0
- data/examples/multi.grind.dat +114 -0
- data/examples/multi.stack.html +547 -0
- data/examples/stack.html +547 -0
- data/ext/ruby_prof/extconf.rb +68 -0
- data/ext/ruby_prof/rp_call_info.c +425 -0
- data/ext/ruby_prof/rp_call_info.h +53 -0
- data/ext/ruby_prof/rp_measure.c +40 -0
- data/ext/ruby_prof/rp_measure.h +45 -0
- data/ext/ruby_prof/rp_measure_allocations.c +76 -0
- data/ext/ruby_prof/rp_measure_cpu_time.c +136 -0
- data/ext/ruby_prof/rp_measure_gc_runs.c +73 -0
- data/ext/ruby_prof/rp_measure_gc_time.c +60 -0
- data/ext/ruby_prof/rp_measure_memory.c +77 -0
- data/ext/ruby_prof/rp_measure_process_time.c +71 -0
- data/ext/ruby_prof/rp_measure_wall_time.c +45 -0
- data/ext/ruby_prof/rp_method.c +630 -0
- data/ext/ruby_prof/rp_method.h +75 -0
- data/ext/ruby_prof/rp_stack.c +173 -0
- data/ext/ruby_prof/rp_stack.h +63 -0
- data/ext/ruby_prof/rp_thread.c +277 -0
- data/ext/ruby_prof/rp_thread.h +27 -0
- data/ext/ruby_prof/ruby_prof.c +794 -0
- data/ext/ruby_prof/ruby_prof.h +60 -0
- data/ext/ruby_prof/vc/ruby_prof.sln +31 -0
- data/ext/ruby_prof/vc/ruby_prof.vcxproj +141 -0
- data/lib/2.6.3/ruby_prof.so +0 -0
- data/lib/ruby-prof.rb +68 -0
- data/lib/ruby-prof/aggregate_call_info.rb +76 -0
- data/lib/ruby-prof/assets/call_stack_printer.css.html +117 -0
- data/lib/ruby-prof/assets/call_stack_printer.js.html +385 -0
- data/lib/ruby-prof/assets/call_stack_printer.png +0 -0
- data/lib/ruby-prof/call_info.rb +115 -0
- data/lib/ruby-prof/call_info_visitor.rb +40 -0
- data/lib/ruby-prof/compatibility.rb +179 -0
- data/lib/ruby-prof/method_info.rb +121 -0
- data/lib/ruby-prof/printers/abstract_printer.rb +104 -0
- data/lib/ruby-prof/printers/call_info_printer.rb +41 -0
- data/lib/ruby-prof/printers/call_stack_printer.rb +265 -0
- data/lib/ruby-prof/printers/call_tree_printer.rb +143 -0
- data/lib/ruby-prof/printers/dot_printer.rb +132 -0
- data/lib/ruby-prof/printers/flat_printer.rb +70 -0
- data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +83 -0
- data/lib/ruby-prof/printers/graph_html_printer.rb +249 -0
- data/lib/ruby-prof/printers/graph_printer.rb +116 -0
- data/lib/ruby-prof/printers/multi_printer.rb +84 -0
- data/lib/ruby-prof/profile.rb +26 -0
- data/lib/ruby-prof/profile/exclude_common_methods.rb +207 -0
- data/lib/ruby-prof/profile/legacy_method_elimination.rb +50 -0
- data/lib/ruby-prof/rack.rb +174 -0
- data/lib/ruby-prof/task.rb +147 -0
- data/lib/ruby-prof/thread.rb +35 -0
- data/lib/ruby-prof/version.rb +3 -0
- data/lib/unprof.rb +10 -0
- data/ruby-prof.gemspec +58 -0
- data/test/abstract_printer_test.rb +53 -0
- data/test/aggregate_test.rb +136 -0
- data/test/basic_test.rb +128 -0
- data/test/block_test.rb +74 -0
- data/test/call_info_test.rb +78 -0
- data/test/call_info_visitor_test.rb +31 -0
- data/test/duplicate_names_test.rb +32 -0
- data/test/dynamic_method_test.rb +55 -0
- data/test/enumerable_test.rb +21 -0
- data/test/exceptions_test.rb +24 -0
- data/test/exclude_methods_test.rb +146 -0
- data/test/exclude_threads_test.rb +53 -0
- data/test/fiber_test.rb +79 -0
- data/test/issue137_test.rb +63 -0
- data/test/line_number_test.rb +80 -0
- data/test/measure_allocations_test.rb +26 -0
- data/test/measure_cpu_time_test.rb +212 -0
- data/test/measure_gc_runs_test.rb +32 -0
- data/test/measure_gc_time_test.rb +36 -0
- data/test/measure_memory_test.rb +33 -0
- data/test/measure_process_time_test.rb +61 -0
- data/test/measure_wall_time_test.rb +255 -0
- data/test/method_elimination_test.rb +84 -0
- data/test/module_test.rb +45 -0
- data/test/multi_printer_test.rb +104 -0
- data/test/no_method_class_test.rb +15 -0
- data/test/pause_resume_test.rb +166 -0
- data/test/prime.rb +54 -0
- data/test/printers_test.rb +275 -0
- data/test/printing_recursive_graph_test.rb +127 -0
- data/test/rack_test.rb +157 -0
- data/test/recursive_test.rb +215 -0
- data/test/singleton_test.rb +38 -0
- data/test/stack_printer_test.rb +77 -0
- data/test/stack_test.rb +138 -0
- data/test/start_stop_test.rb +112 -0
- data/test/test_helper.rb +267 -0
- data/test/thread_test.rb +187 -0
- data/test/unique_call_path_test.rb +202 -0
- data/test/yarv_test.rb +55 -0
- metadata +199 -0
data/LICENSE
ADDED
@@ -0,0 +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
|
25
|
+
SUCH DAMAGE.
|
data/README.rdoc
ADDED
@@ -0,0 +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:
|
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.
|