ruby-prof 0.15.8 → 0.15.9
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.
- checksums.yaml +4 -4
- data/CHANGES +5 -0
- data/README.rdoc +187 -185
- data/doc/LICENSE.html +114 -0
- data/doc/README_rdoc.html +544 -0
- data/doc/Rack.html +95 -0
- data/doc/Rack/RubyProf.html +223 -0
- data/doc/RubyProf.html +961 -0
- data/doc/RubyProf/AbstractPrinter.html +546 -0
- data/doc/RubyProf/AggregateCallInfo.html +551 -0
- data/doc/RubyProf/CallInfo.html +639 -0
- data/doc/RubyProf/CallInfoPrinter.html +120 -0
- data/doc/RubyProf/CallInfoVisitor.html +198 -0
- data/doc/RubyProf/CallStackPrinter.html +1121 -0
- data/doc/RubyProf/CallTreePrinter.html +359 -0
- data/doc/RubyProf/Cmd.html +631 -0
- data/doc/RubyProf/DotPrinter.html +257 -0
- data/doc/RubyProf/FlatPrinter.html +163 -0
- data/doc/RubyProf/FlatPrinterWithLineNumbers.html +208 -0
- data/doc/RubyProf/GraphHtmlPrinter.html +552 -0
- data/doc/RubyProf/GraphPrinter.html +139 -0
- data/doc/RubyProf/MethodInfo.html +745 -0
- data/doc/RubyProf/MultiPrinter.html +358 -0
- data/doc/RubyProf/Profile.html +713 -0
- data/doc/RubyProf/ProfileTask.html +490 -0
- data/doc/RubyProf/Thread.html +268 -0
- data/doc/created.rid +13 -13
- data/doc/examples/flat_txt.html +138 -0
- data/doc/examples/graph_html.html +909 -0
- data/doc/examples/graph_txt.html +247 -0
- data/doc/images/add.png +0 -0
- data/doc/images/arrow_up.png +0 -0
- data/doc/images/brick.png +0 -0
- data/doc/images/brick_link.png +0 -0
- data/doc/images/bug.png +0 -0
- data/doc/images/bullet_black.png +0 -0
- data/doc/images/bullet_toggle_minus.png +0 -0
- data/doc/images/bullet_toggle_plus.png +0 -0
- data/doc/images/date.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/find.png +0 -0
- data/doc/images/macFFBgHack.png +0 -0
- data/doc/images/package.png +0 -0
- data/doc/images/page_green.png +0 -0
- data/doc/images/page_white_text.png +0 -0
- data/doc/images/page_white_width.png +0 -0
- data/doc/images/plugin.png +0 -0
- data/doc/images/ruby.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/tag_green.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/images/wrench.png +0 -0
- data/doc/images/wrench_orange.png +0 -0
- data/doc/images/zoom.png +0 -0
- data/doc/index.html +571 -0
- data/doc/js/navigation.js.gz +0 -0
- data/doc/js/search_index.js +1 -1
- data/doc/js/search_index.js.gz +0 -0
- data/doc/js/searcher.js.gz +0 -0
- data/doc/table_of_contents.html +893 -0
- data/examples/flat.txt +50 -55
- data/examples/graph.html +823 -823
- data/examples/graph.txt +139 -170
- data/ext/ruby_prof/extconf.rb +6 -1
- data/lib/ruby-prof/aggregate_call_info.rb +17 -11
- data/lib/ruby-prof/call_info.rb +2 -17
- data/lib/ruby-prof/method_info.rb +6 -22
- data/lib/ruby-prof/printers/graph_html_printer.rb +0 -2
- data/lib/ruby-prof/printers/graph_printer.rb +4 -6
- data/lib/ruby-prof/rack.rb +7 -0
- data/lib/ruby-prof/thread.rb +0 -4
- data/lib/ruby-prof/version.rb +1 -1
- data/ruby-prof.gemspec +1 -1
- data/test/basic_test.rb +26 -26
- data/test/issue137_test.rb +63 -0
- data/test/measure_allocations_test.rb +4 -3
- data/test/measure_cpu_time_test.rb +6 -6
- data/test/measure_process_time_test.rb +8 -8
- data/test/pause_resume_test.rb +9 -9
- data/test/printers_test.rb +1 -1
- data/test/printing_recursive_graph_test.rb +127 -0
- data/test/rack_test.rb +49 -1
- data/test/recursive_test.rb +41 -37
- data/test/test_helper.rb +93 -0
- metadata +59 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22ff7386396e7f34166a995b4f7a095d172544ef
|
4
|
+
data.tar.gz: caef497365c65eb46e411f511c9f19e30d5d9502
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09c37e34272db2c85851224b6ed454919797b3f6d9e9a2059272df0cbe09d4cbb1720b95683228c02966ad97927cf940c1a0c98a64fd77c684315b511915e528
|
7
|
+
data.tar.gz: 6b2aede7156ff82f4929b6d58e67febc869f933a8ef76948fbc785510e5bb350f69a9c0dbc523c5a4778a15f8de647efaa3f836d86d15939e37b857ad8c52bee
|
data/CHANGES
CHANGED
data/README.rdoc
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
= ruby-prof
|
2
|
+
|
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]
|
3
4
|
|
4
5
|
== Overview
|
5
6
|
|
6
|
-
ruby-prof is a fast code profiler for Ruby. Its features include:
|
7
|
+
ruby-prof is a fast code profiler for MRI Ruby. Its features include:
|
7
8
|
|
8
9
|
* Speed - it is a C extension and therefore many times faster than the standard Ruby profiler.
|
9
10
|
* Modes - Ruby prof can measure a number of different parameters, including call times, memory usage and object allocations.
|
@@ -11,7 +12,7 @@ ruby-prof is a fast code profiler for Ruby. Its features include:
|
|
11
12
|
- Flat Profiles - similar to the reports generated by the standard Ruby profiler
|
12
13
|
- Graph profiles - similar to GProf, these show how long a method runs, which methods call it and which methods it calls.
|
13
14
|
- Call tree profiles - outputs results in the calltree format suitable for the KCacheGrind profiling tool.
|
14
|
-
- Many more -- see reports section of this README.
|
15
|
+
- Many more -- see reports section of this \README.
|
15
16
|
* Threads - supports profiling multiple threads simultaneously
|
16
17
|
|
17
18
|
== Requirements
|
@@ -20,25 +21,28 @@ ruby-prof requires Ruby 1.9.3 or higher. Please note some ruby
|
|
20
21
|
releases have known bugs which cause ruby-prof problems, like
|
21
22
|
incorrect measurements. We suggest to use the latest minor patch level
|
22
23
|
release if possible. In particular, on the 2.1 branch of ruby you
|
23
|
-
should use 2.1.
|
24
|
+
should use 2.1.7.
|
24
25
|
|
25
|
-
If you are running Linux or Unix you'll need a C compiler so the
|
26
|
-
can be compiled when it is installed.
|
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.
|
27
28
|
|
28
29
|
If you are running Windows, then you may need to install the
|
29
30
|
Windows specific RubyGem which includes an already built extension (see Install section).
|
30
31
|
|
31
32
|
== Install
|
32
33
|
|
33
|
-
The easiest way to install ruby-prof is by using Ruby Gems. To
|
34
|
+
The easiest way to install ruby-prof is by using Ruby Gems. To
|
35
|
+
install:
|
34
36
|
|
35
|
-
|
37
|
+
gem install ruby-prof
|
36
38
|
|
37
|
-
If you're on windows then please install the devkit first so that it
|
39
|
+
If you're on windows then please install the devkit first so that it
|
40
|
+
can compile.
|
38
41
|
|
39
42
|
== Usage
|
40
43
|
|
41
|
-
There are two ways of running ruby-prof, via the command line or via
|
44
|
+
There are two ways of running ruby-prof, via the command line or via
|
45
|
+
its API.
|
42
46
|
|
43
47
|
=== ruby-prof executable
|
44
48
|
|
@@ -49,62 +53,58 @@ ruby-prof command.
|
|
49
53
|
|
50
54
|
=== ruby-prof API
|
51
55
|
|
52
|
-
The second way is to use the ruby-prof API to profile
|
53
|
-
|
56
|
+
The second way is to use the ruby-prof API to profile particular
|
57
|
+
segments of code.
|
54
58
|
|
55
|
-
|
59
|
+
require 'ruby-prof'
|
56
60
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
...
|
62
|
-
result = RubyProf.stop
|
61
|
+
# profile the code
|
62
|
+
RubyProf.start
|
63
|
+
# ... code to profile ...
|
64
|
+
result = RubyProf.stop
|
63
65
|
|
64
|
-
|
65
|
-
|
66
|
-
|
66
|
+
# print a flat profile to text
|
67
|
+
printer = RubyProf::FlatPrinter.new(result)
|
68
|
+
printer.print(STDOUT)
|
67
69
|
|
68
|
-
Alternatively, you can use a block to tell ruby-prof what
|
69
|
-
to profile:
|
70
|
+
Alternatively, you can use a block to tell ruby-prof what to profile:
|
70
71
|
|
71
|
-
|
72
|
+
require 'ruby-prof'
|
72
73
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
...
|
78
|
-
end
|
74
|
+
# profile the code
|
75
|
+
result = RubyProf.profile do
|
76
|
+
# ... code to profile ...
|
77
|
+
end
|
79
78
|
|
80
|
-
|
81
|
-
|
82
|
-
|
79
|
+
# print a graph profile to text
|
80
|
+
printer = RubyProf::GraphPrinter.new(result)
|
81
|
+
printer.print(STDOUT, {})
|
83
82
|
|
84
83
|
ruby-prof also supports pausing and resuming profiling runs.
|
85
84
|
|
86
|
-
|
85
|
+
require 'ruby-prof'
|
86
|
+
|
87
|
+
# profile the code
|
88
|
+
RubyProf.start
|
89
|
+
# ... code to profile ...
|
90
|
+
|
91
|
+
RubyProf.pause
|
92
|
+
# ... other code ...
|
87
93
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
RubyProf.pause
|
92
|
-
[other code]
|
93
|
-
RubyProf.resume
|
94
|
-
[code to profile]
|
95
|
-
result = RubyProf.stop
|
94
|
+
RubyProf.resume
|
95
|
+
# ... code to profile ...
|
96
|
+
result = RubyProf.stop
|
96
97
|
|
97
98
|
Note that resume will automatically call start if a profiling run
|
98
99
|
has not yet started. In addition, resume can also take a block:
|
99
100
|
|
100
|
-
|
101
|
+
require 'ruby-prof'
|
101
102
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
end
|
103
|
+
RubyProf.resume do
|
104
|
+
# ... code to profile...
|
105
|
+
end
|
106
106
|
|
107
|
-
|
107
|
+
data = RubyProf.stop
|
108
108
|
|
109
109
|
With this usage, resume will automatically call pause at the
|
110
110
|
end of the block.
|
@@ -112,22 +112,26 @@ end of the block.
|
|
112
112
|
|
113
113
|
== Method and Thread Elimination
|
114
114
|
|
115
|
-
ruby-prof supports eliminating specific methods and threads from
|
116
|
-
results. This is useful for reducing connectivity in the
|
117
|
-
|
115
|
+
ruby-prof supports eliminating specific methods and threads from
|
116
|
+
profiling results. This is useful for reducing connectivity in the
|
117
|
+
call graph, making it easier to identify the source of performance
|
118
|
+
problems when using a graph printer.
|
118
119
|
|
119
|
-
For example, consider Integer#times
|
120
|
-
spent in the method itself. We're much more
|
121
|
-
|
120
|
+
For example, consider <tt>Integer#times</tt>: it's hardly ever useful
|
121
|
+
to know how much time is spent in the method itself. We're much more
|
122
|
+
interested in how much the passed in block contributes to the time
|
123
|
+
spent in the method which contains the <tt>Integer#times</tt> call.
|
122
124
|
|
123
|
-
Methods are eliminated from the collected data by calling
|
124
|
-
profiling result, before submitting
|
125
|
+
Methods are eliminated from the collected data by calling
|
126
|
+
<tt>eliminate_methods!</tt> on the profiling result, before submitting
|
127
|
+
it to a printer.
|
125
128
|
|
126
|
-
|
127
|
-
|
129
|
+
result = RubyProf.stop
|
130
|
+
result.eliminate_methods!([/Integer#times/])
|
128
131
|
|
129
|
-
The argument given to
|
130
|
-
the name of a file containing a list of
|
132
|
+
The argument given to <tt>eliminate_methods!</tt> is either an array
|
133
|
+
of regular expressions, or the name of a file containing a list of
|
134
|
+
regular expressions (line separated text).
|
131
135
|
|
132
136
|
After eliminating methods the resulting profile will appear exactly as if those methods
|
133
137
|
had been inlined at their call sites.
|
@@ -135,30 +139,11 @@ had been inlined at their call sites.
|
|
135
139
|
In a similar manner, threads can be excluded so they are not profiled at all. To do this,
|
136
140
|
pass an array of threads to exclude to ruby-prof:
|
137
141
|
|
138
|
-
|
139
|
-
|
142
|
+
RubyProf::exclude_threads = [ thread2 ]
|
143
|
+
RubyProf.start
|
140
144
|
|
141
145
|
Note that the excluded threads must be specified *before* profiling.
|
142
146
|
|
143
|
-
|
144
|
-
== Benchmarking full load time including rubygems startup cost
|
145
|
-
|
146
|
-
If you want to get a more accurate measurement of what takes all of a gem's bin/xxx
|
147
|
-
command to load, you may want to also measure rubygems' startup penalty.
|
148
|
-
You can do this by calling into bin/ruby-prof directly, ex:
|
149
|
-
|
150
|
-
$ gem which ruby-prof
|
151
|
-
g:/192/lib/ruby/gems/1.9.1/gems/ruby-prof-0.10.2/lib/ruby-prof.rb
|
152
|
-
|
153
|
-
now run it thus (substitute lib/ruby-prof.rb with bin/ruby-prof):
|
154
|
-
|
155
|
-
$ ruby g:/192/lib/ruby/gems/1.9.1/gems/ruby-prof-0.10.2/bin/ruby-prof g:\192\bin\some_installed_gem_command
|
156
|
-
|
157
|
-
or
|
158
|
-
|
159
|
-
$ ruby g:/192/lib/ruby/gems/1.9.1/gems/ruby-prof-0.10.2/bin/ruby-prof ./some_file_that_does_a_require_rubygems_at_the_beginning.rb
|
160
|
-
|
161
|
-
|
162
147
|
== Profiling Rails
|
163
148
|
|
164
149
|
To profile a Rails application it is vital to run it using production like
|
@@ -170,30 +155,32 @@ profile.rb.
|
|
170
155
|
|
171
156
|
So to profile Rails:
|
172
157
|
|
173
|
-
1.
|
174
|
-
|
175
|
-
|
176
|
-
|
158
|
+
1. Create a new profile.rb environment. Make sure to turn on
|
159
|
+
<tt>cache_classes</tt> and
|
160
|
+
<tt>cache_template_loading</tt>. Otherwise your profiling results
|
161
|
+
will be overwhelemed by the time Rails spends loading required
|
162
|
+
files. You should likely turn off caching.
|
177
163
|
|
178
|
-
2.
|
164
|
+
2. Add the ruby-prof to your gemfile:
|
179
165
|
|
180
|
-
|
181
|
-
|
182
|
-
|
166
|
+
group :profile do
|
167
|
+
gem 'ruby-prof'
|
168
|
+
end
|
183
169
|
|
184
|
-
3.
|
185
|
-
|
170
|
+
3. Add the ruby prof rack adapter to your middleware stack. One way to
|
171
|
+
do this is by adding the following code to <tt>config.ru</tt>:
|
186
172
|
|
187
|
-
|
188
|
-
|
189
|
-
|
173
|
+
if Rails.env.profile?
|
174
|
+
use Rack::RubyProf, :path => '/temp/profile'
|
175
|
+
end
|
190
176
|
|
191
|
-
|
192
|
-
|
177
|
+
The path is where you want profiling results to be stored. By default the
|
178
|
+
rack adapter will generate a html call graph report and flat text report.
|
193
179
|
|
194
|
-
4.
|
195
|
-
|
196
|
-
|
180
|
+
4. Now make a request to your running server. New profiling
|
181
|
+
information will be generated for each request. Note that each
|
182
|
+
request will overwrite the profiling reports created by the
|
183
|
+
previous request!
|
197
184
|
|
198
185
|
== Reports
|
199
186
|
|
@@ -211,7 +198,7 @@ are a good way of quickly identifying which methods take the most time.
|
|
211
198
|
An example of a flat profile and an explanation can be found in
|
212
199
|
{examples/flat.txt}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/flat.txt].
|
213
200
|
|
214
|
-
There are several varieties of these
|
201
|
+
There are several varieties of these - run <tt>ruby-prof --help</tt>
|
215
202
|
|
216
203
|
Graph profiles also show the overall time spent in each method. In
|
217
204
|
addition, they also show which methods call the current method and which
|
@@ -236,7 +223,7 @@ Call stack reports produce a HTML visualization of the time spent in
|
|
236
223
|
each execution path of the profiled code. An example can be found at
|
237
224
|
{examples/stack.html}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/stack.html].
|
238
225
|
|
239
|
-
Another good example:
|
226
|
+
Another good example: http://twitpic.com/28z94a
|
240
227
|
|
241
228
|
Finally, there's a so called MultiPrinter which can generate several
|
242
229
|
reports in one profiling run. See
|
@@ -248,106 +235,121 @@ There is also a graphviz .dot visualiser.
|
|
248
235
|
|
249
236
|
Reports are created by printers. Supported printers include:
|
250
237
|
|
251
|
-
|
252
|
-
|
253
|
-
* RubyProf::GraphPrinter - Creates a call graph report in text format
|
254
|
-
* RubyProf::GraphHtmlPrinter - Creates a call graph report in HTML (separate files per thread)
|
255
|
-
* RubyProf::DotPrinter - Creates a call graph report in GraphViz's DOT format which can be converted to an image
|
256
|
-
* RubyProf::CallTreePrinter - Creates a call tree report compatible with KCachegrind.
|
257
|
-
* RubyProf::CallStackPrinter - Creates a HTML visualization of the Ruby stack
|
258
|
-
* RubyProf::MultiPrinter - Uses the other printers to create several reports in one profiling run
|
259
|
-
* More!
|
260
|
-
|
261
|
-
To use a printer:
|
262
|
-
|
263
|
-
...
|
264
|
-
result = RubyProf.stop
|
265
|
-
printer = RubyProf::GraphPrinter.new(result)
|
266
|
-
printer.print(STDOUT, :min_percent => 2)
|
238
|
+
RubyProf::FlatPrinter::
|
239
|
+
Creates a flat report in text format
|
267
240
|
|
268
|
-
|
269
|
-
|
270
|
-
to be printed. Percentages should be specified as integers in the range 0 to 100.
|
271
|
-
For more information please see the documentation for the different printers.
|
241
|
+
RubyProf::FlatPrinterWithLineNumbers::
|
242
|
+
Same as above but more verbose
|
272
243
|
|
273
|
-
|
274
|
-
|
244
|
+
RubyProf::GraphPrinter::
|
245
|
+
Creates a call graph report in text format
|
275
246
|
|
276
|
-
|
277
|
-
|
247
|
+
RubyProf::GraphHtmlPrinter::
|
248
|
+
Creates a call graph report in HTML (separate files per thread)
|
278
249
|
|
279
|
-
|
280
|
-
|
250
|
+
RubyProf::DotPrinter::
|
251
|
+
Creates a call graph report in GraphViz's DOT format which can be converted to an image
|
281
252
|
|
253
|
+
RubyProf::CallTreePrinter::
|
254
|
+
Creates a call tree report compatible with KCachegrind
|
282
255
|
|
283
|
-
|
256
|
+
RubyProf::CallStackPrinter::
|
257
|
+
Creates a HTML visualization of the Ruby stack
|
284
258
|
|
285
|
-
|
286
|
-
|
259
|
+
RubyProf::MultiPrinter::
|
260
|
+
Uses the other printers to create several reports in one profiling run
|
287
261
|
|
288
|
-
|
289
|
-
* process time (RubyProf::PROCESS_TIME)
|
290
|
-
* cpu time (RubyProf::CPU_TIME)
|
291
|
-
* object allocations (RubyProf::ALLOCATIONS)
|
292
|
-
* memory usage (RubyProf::MEMORY)
|
293
|
-
* garbage collection time (RubyProf::GC_TIME)
|
294
|
-
* garbage collections runs (RubyProf::GC_RUNS)
|
262
|
+
To use a printer:
|
295
263
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
then the reported results will be larger than expected.
|
264
|
+
result = RubyProf.stop
|
265
|
+
printer = RubyProf::GraphPrinter.new(result)
|
266
|
+
printer.print(STDOUT, :min_percent => 2)
|
300
267
|
|
301
|
-
Process time measures the time used by a process between any two moments.
|
302
|
-
It is unaffected by other processes concurrently running
|
303
|
-
on the system. Note that Windows does not support measuring process
|
304
|
-
times.
|
305
268
|
|
306
|
-
|
307
|
-
|
308
|
-
|
269
|
+
The first parameter is any writable IO object such as <tt>STDOUT</tt>
|
270
|
+
or a file. The second parameter, specifies the minimum percentage a
|
271
|
+
method must take to be printed. Percentages should be specified as
|
272
|
+
integers in the range 0 to 100. For more information please see the
|
273
|
+
documentation for the different printers.
|
309
274
|
|
310
|
-
|
311
|
-
|
312
|
-
and requires a patched Ruby interpreter. See below.
|
275
|
+
The other option is <tt>:print_file => true</tt> (default false),
|
276
|
+
which adds the filename to the output (GraphPrinter only).
|
313
277
|
|
314
|
-
|
315
|
-
|
316
|
-
patched Ruby interpreter. See below.
|
278
|
+
<tt>MultiPrinter</tt> differs from the other printers in that it
|
279
|
+
requires a directory path and a basename for the files it produces.
|
317
280
|
|
318
|
-
|
319
|
-
|
320
|
-
by Jeremy Kemper and requires a patched Ruby interpreter. See below.
|
281
|
+
printer = RubyProf::MultiPrinter.new(result)
|
282
|
+
printer.print(:path => ".", :profile => "profile")
|
321
283
|
|
322
|
-
|
323
|
-
is invoked during a profiling session. This support was added by
|
324
|
-
Jeremy Kemper and requires a patched Ruby interpreter. See below.
|
284
|
+
== Measurements
|
325
285
|
|
326
|
-
|
327
|
-
|
286
|
+
Depending on the mode and platform, ruby-prof can measure various
|
287
|
+
aspects of a Ruby program. Supported measurements include:
|
288
|
+
|
289
|
+
RubyProf::WALL_TIME::
|
290
|
+
Wall time measures the real-world time
|
291
|
+
elapsed between any two moments. If there are other processes
|
292
|
+
concurrently running on the system that use significant CPU or disk
|
293
|
+
time during a profiling run then the reported results will be larger
|
294
|
+
than expected.
|
295
|
+
|
296
|
+
RubyProf::PROCESS_TIME::
|
297
|
+
Process time measures the time used by a process between any two moments.
|
298
|
+
It is unaffected by other processes concurrently running
|
299
|
+
on the system. Note that Windows does not support measuring process
|
300
|
+
times.
|
301
|
+
|
302
|
+
RubyProf::CPU_TIME::
|
303
|
+
CPU time uses the CPU clock counter to measure time. The returned
|
304
|
+
values are dependent on the correctly setting the CPU's frequency.
|
305
|
+
This mode is only supported on Pentium or PowerPC platforms (linux only).
|
306
|
+
|
307
|
+
RubyProf::ALLOCATIONS::
|
308
|
+
Object allocation reports show how many objects each method in
|
309
|
+
a program allocates. This support was added by Sylvain Joyeux
|
310
|
+
and requires a patched Ruby interpreter. See below.
|
311
|
+
|
312
|
+
|
313
|
+
RubyProf::MEMORY::
|
314
|
+
Memory usage reports show how much memory each method in a program
|
315
|
+
uses. This support was added by Alexander Dymo and requires a
|
316
|
+
patched Ruby interpreter. See below.
|
317
|
+
|
318
|
+
RubyProf::GC_TIME::
|
319
|
+
Garbage collection time reports how much time is spent in Ruby's
|
320
|
+
garbage collector during a profiling session. This support was added
|
321
|
+
by Jeremy Kemper and requires a patched Ruby interpreter. See below.
|
322
|
+
|
323
|
+
RubyProf::GC_RUNS::
|
324
|
+
Garbage collection runs report how many times Ruby's garbage collector
|
325
|
+
is invoked during a profiling session. This support was added by
|
326
|
+
Jeremy Kemper and requires a patched Ruby interpreter. See below.
|
327
|
+
|
328
|
+
All of the patches to Ruby are included in the railsexpress patchsets
|
329
|
+
for rvm, see https://github.com/skaes/rvm-patchsets
|
328
330
|
|
329
331
|
To set the measurement:
|
330
332
|
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
333
|
+
RubyProf.measure_mode = RubyProf::WALL_TIME
|
334
|
+
RubyProf.measure_mode = RubyProf::PROCESS_TIME
|
335
|
+
RubyProf.measure_mode = RubyProf::CPU_TIME
|
336
|
+
RubyProf.measure_mode = RubyProf::ALLOCATIONS
|
337
|
+
RubyProf.measure_mode = RubyProf::MEMORY
|
338
|
+
RubyProf.measure_mode = RubyProf::GC_TIME
|
339
|
+
RubyProf.measure_mode = RubyProf::GC_RUNS
|
338
340
|
|
339
|
-
The default value is RubyProf::WALL_TIME
|
341
|
+
The default value is <tt>RubyProf::WALL_TIME</tt>.
|
340
342
|
|
341
|
-
You may also specify the
|
342
|
-
environment variable:
|
343
|
+
You may also specify the measure mode by using the
|
344
|
+
<tt>RUBY_PROF_MEASURE_MODE</tt> environment variable:
|
343
345
|
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
346
|
+
export RUBY_PROF_MEASURE_MODE=wall
|
347
|
+
export RUBY_PROF_MEASURE_MODE=process
|
348
|
+
export RUBY_PROF_MEASURE_MODE=cpu
|
349
|
+
export RUBY_PROF_MEASURE_MODE=allocations
|
350
|
+
export RUBY_PROF_MEASURE_MODE=memory
|
351
|
+
export RUBY_PROF_MEASURE_MODE=gc_time
|
352
|
+
export RUBY_PROF_MEASURE_MODE=gc_runs
|
351
353
|
|
352
354
|
On Linux, process time is measured using the clock method provided
|
353
355
|
by the C runtime library. Note that the clock method does not
|
@@ -356,10 +358,10 @@ does not measure time spent in methods such as Kernel.sleep method.
|
|
356
358
|
If you need to measure these values, then use wall time. Wall time
|
357
359
|
is measured using the gettimeofday kernel method.
|
358
360
|
|
359
|
-
If you set the clock mode to PROCESS_TIME
|
360
|
-
the clock method provided by the C runtime library. Note
|
361
|
-
these values are wall times on Windows and not process times
|
362
|
-
Linux. Wall time is measured using the GetLocalTime API.
|
361
|
+
If you set the clock mode to <tt>PROCESS_TIME</tt>, then timings are
|
362
|
+
read using the clock method provided by the C runtime library. Note
|
363
|
+
though, these values are wall times on Windows and not process times
|
364
|
+
like on Linux. Wall time is measured using the GetLocalTime API.
|
363
365
|
|
364
366
|
If you use wall time, the results will be affected by other
|
365
367
|
processes running on your computer, network delays, disk access,
|
@@ -369,7 +371,7 @@ otherwise quiescent.
|
|
369
371
|
|
370
372
|
== Multi-threaded Applications
|
371
373
|
|
372
|
-
Unfortunately, Ruby does not provide an internal
|
374
|
+
Unfortunately, Ruby does not provide an internal API
|
373
375
|
for detecting thread context switches in 1.8. As a result, the
|
374
376
|
timings ruby-prof reports for each thread may be slightly
|
375
377
|
inaccurate. In particular, this will happen for newly
|
@@ -397,4 +399,4 @@ See LICENSE for license information.
|
|
397
399
|
|
398
400
|
Code is located at https://github.com/ruby-prof/ruby-prof
|
399
401
|
|
400
|
-
Google group/mailing list: http://groups.google.com/group/ruby-optimization or
|
402
|
+
Google group/mailing list: http://groups.google.com/group/ruby-optimization or open a github issue.
|