ruby-prof 0.15.2 → 0.15.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/doc/LICENSE.html +11 -14
- data/doc/README_rdoc.html +106 -109
- data/doc/Rack.html +6 -9
- data/doc/Rack/RubyProf.html +12 -15
- data/doc/RubyProf.html +11 -13
- data/doc/RubyProf/AbstractPrinter.html +7 -10
- data/doc/RubyProf/AggregateCallInfo.html +6 -9
- data/doc/RubyProf/CallInfo.html +8 -11
- data/doc/RubyProf/CallInfoPrinter.html +7 -10
- data/doc/RubyProf/CallInfoVisitor.html +6 -9
- data/doc/RubyProf/CallStackPrinter.html +48 -51
- data/doc/RubyProf/CallTreePrinter.html +14 -17
- data/doc/RubyProf/Cmd.html +44 -47
- data/doc/RubyProf/DotPrinter.html +8 -11
- data/doc/RubyProf/FlatPrinter.html +6 -9
- data/doc/RubyProf/FlatPrinterWithLineNumbers.html +9 -12
- data/doc/RubyProf/GraphHtmlPrinter.html +14 -18
- data/doc/RubyProf/GraphPrinter.html +6 -9
- data/doc/RubyProf/MethodInfo.html +8 -11
- data/doc/RubyProf/MultiPrinter.html +6 -9
- data/doc/RubyProf/Profile.html +7 -10
- data/doc/RubyProf/ProfileTask.html +18 -20
- data/doc/RubyProf/Thread.html +6 -9
- data/doc/created.rid +4 -4
- data/doc/{fonts.css → css/fonts.css} +0 -0
- data/doc/{rdoc.css → css/rdoc.css} +11 -1
- data/doc/examples/flat_txt.html +8 -11
- data/doc/examples/graph_html.html +8 -10
- data/doc/examples/graph_txt.html +13 -16
- data/doc/index.html +108 -109
- data/doc/js/darkfish.js +32 -11
- data/doc/js/jquery.js +4 -18
- 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 +9 -9
- data/ext/ruby_prof/ruby_prof.c +2 -2
- data/lib/ruby-prof/version.rb +1 -1
- data/ruby-prof.gemspec +1 -1
- data/test/aggregate_test.rb +1 -1
- data/test/basic_test.rb +5 -5
- data/test/block_test.rb +74 -0
- data/test/call_info_test.rb +1 -1
- data/test/call_info_visitor_test.rb +1 -1
- data/test/duplicate_names_test.rb +1 -1
- data/test/dynamic_method_test.rb +37 -56
- data/test/enumerable_test.rb +7 -2
- data/test/exceptions_test.rb +2 -2
- data/test/exclude_threads_test.rb +1 -1
- data/test/fiber_test.rb +1 -1
- data/test/line_number_test.rb +1 -1
- data/test/measure_allocations_test.rb +1 -1
- data/test/measure_cpu_time_test.rb +1 -1
- data/test/measure_gc_runs_test.rb +1 -1
- data/test/measure_gc_time_test.rb +1 -1
- data/test/measure_memory_test.rb +2 -2
- data/test/measure_process_time_test.rb +1 -1
- data/test/measure_wall_time_test.rb +2 -2
- data/test/method_elimination_test.rb +1 -1
- data/test/module_test.rb +1 -1
- data/test/multi_printer_test.rb +1 -1
- data/test/pause_resume_test.rb +1 -1
- data/test/printers_test.rb +5 -5
- data/test/rack_test.rb +2 -2
- data/test/recursive_test.rb +1 -1
- data/test/singleton_test.rb +1 -1
- data/test/stack_printer_test.rb +1 -1
- data/test/stack_test.rb +1 -1
- data/test/start_stop_test.rb +4 -4
- data/test/test_helper.rb +8 -1
- data/test/thread_test.rb +1 -1
- data/test/unique_call_path_test.rb +2 -2
- data/test/yarv_test.rb +1 -1
- metadata +64 -71
data/doc/examples/graph_txt.html
CHANGED
@@ -6,20 +6,17 @@
|
|
6
6
|
|
7
7
|
<title>graph - ruby-prof</title>
|
8
8
|
|
9
|
-
<link href="../fonts.css" rel="stylesheet">
|
10
|
-
<link href="../rdoc.css" rel="stylesheet">
|
11
|
-
|
12
9
|
<script type="text/javascript">
|
13
10
|
var rdoc_rel_prefix = "../";
|
14
11
|
</script>
|
15
12
|
|
16
13
|
<script src="../js/jquery.js"></script>
|
17
|
-
<script src="../js/navigation.js"></script>
|
18
|
-
<script src="../js/search_index.js"></script>
|
19
|
-
<script src="../js/search.js"></script>
|
20
|
-
<script src="../js/searcher.js"></script>
|
21
14
|
<script src="../js/darkfish.js"></script>
|
22
15
|
|
16
|
+
<link href="../css/fonts.css" rel="stylesheet">
|
17
|
+
<link href="../css/rdoc.css" rel="stylesheet">
|
18
|
+
|
19
|
+
|
23
20
|
|
24
21
|
<body id="top" role="document" class="file">
|
25
22
|
<nav role="navigation">
|
@@ -90,7 +87,7 @@
|
|
90
87
|
|
91
88
|
<main role="main" aria-label="Page examples/graph.txt">
|
92
89
|
|
93
|
-
<h1 id="label-Graph+Profiles">Graph Profiles<span><a href="#label-Graph+Profiles">¶</a> <a href="#
|
90
|
+
<h1 id="label-Graph+Profiles">Graph Profiles<span><a href="#label-Graph+Profiles">¶</a> <a href="#top">↑</a></span></h1>
|
94
91
|
|
95
92
|
<p>Graph profiles show how long each method runs, which methods call it and
|
96
93
|
which methods it calls.</p>
|
@@ -191,7 +188,7 @@ which methods it calls.</p>
|
|
191
188
|
0.00% 0.00% 0.00 0.00 0.00 500 Kernel.rand
|
192
189
|
0.00 0.00 0.00 1/1 Integer#to_int</pre>
|
193
190
|
|
194
|
-
<h2 id="label-Overview">Overview<span><a href="#label-Overview">¶</a> <a href="#
|
191
|
+
<h2 id="label-Overview">Overview<span><a href="#label-Overview">¶</a> <a href="#top">↑</a></span></h2>
|
195
192
|
|
196
193
|
<p>Dashed lines divide the report into entries, with one entry per method.
|
197
194
|
Entries are sorted by total time which is the time spent in the method
|
@@ -208,7 +205,7 @@ below it are the methods it called (children).</p>
|
|
208
205
|
%self - The percentage of time spent in this method
|
209
206
|
total - The time spent in this method and its children.
|
210
207
|
self - The time spent in this method.
|
211
|
-
children - The time spent in this method
|
208
|
+
children - The time spent in this method's children.
|
212
209
|
calls - The number of times this method was called.
|
213
210
|
name - The name of the method.</pre>
|
214
211
|
|
@@ -226,7 +223,7 @@ method on a singleton class.</p>
|
|
226
223
|
its children. Of that time, 4.06 seconds was spent in Integer#upto itself
|
227
224
|
and 4.66 in its children. Overall, Integer#upto was called 501 times.</p>
|
228
225
|
|
229
|
-
<h2 id="label-Parents">Parents<span><a href="#label-Parents">¶</a> <a href="#
|
226
|
+
<h2 id="label-Parents">Parents<span><a href="#label-Parents">¶</a> <a href="#top">↑</a></span></h2>
|
230
227
|
|
231
228
|
<p>In each entry, the lines above the primary line are the methods that
|
232
229
|
called the current method. If the current method is a root method then no
|
@@ -236,7 +233,7 @@ parents are shown.</p>
|
|
236
233
|
|
237
234
|
<pre>total - The time spent in the current method and it children on behalf of the parent method.
|
238
235
|
self - The time spent in this method on behalf of the parent method.
|
239
|
-
children - The time spent in this method
|
236
|
+
children - The time spent in this method's children on behalf of the parent.
|
240
237
|
calls - The number of times the parent method called this child</pre>
|
241
238
|
|
242
239
|
<p>Looking at Integer#upto again, we see that it was called 500 times from
|
@@ -244,7 +241,7 @@ Object#is_prime and 1 time from find_largest. Of the 8.72 total seconds
|
|
244
241
|
spent in Integer#upto, 6.63 were done for Object#is_prime and 2.09 for
|
245
242
|
Object#find_largest.</p>
|
246
243
|
|
247
|
-
<h2 id="label-Children">Children<span><a href="#label-Children">¶</a> <a href="#
|
244
|
+
<h2 id="label-Children">Children<span><a href="#label-Children">¶</a> <a href="#top">↑</a></span></h2>
|
248
245
|
|
249
246
|
<p>In each entry, the lines below the primary line are the methods that the
|
250
247
|
current method called. If the current method is a leaf method then no
|
@@ -254,7 +251,7 @@ children are shown.</p>
|
|
254
251
|
|
255
252
|
<pre>total - The time spent in the child, and its children, on behalf of the current method
|
256
253
|
self - The time spent in the child on behalf of the current method.
|
257
|
-
children - The time spent in the child
|
254
|
+
children - The time spent in the child's children (ie, granchildren) in behalf of the current method
|
258
255
|
calls - The number of times the child method was called by the current method.</pre>
|
259
256
|
|
260
257
|
<p>Taking our example of Integer#upto, we see that it called five other
|
@@ -271,7 +268,7 @@ in the graph table.</p>
|
|
271
268
|
|
272
269
|
<footer id="validator-badges" role="contentinfo">
|
273
270
|
<p><a href="http://validator.w3.org/check/referer">Validate</a>
|
274
|
-
<p>Generated by <a href="http://
|
275
|
-
<p>Based on <a href="http://deveiate.org/projects/Darkfish-
|
271
|
+
<p>Generated by <a href="http://docs.seattlerb.org/rdoc/">RDoc</a> 4.2.0.
|
272
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
276
273
|
</footer>
|
277
274
|
|
data/doc/index.html
CHANGED
@@ -6,20 +6,17 @@
|
|
6
6
|
|
7
7
|
<title>ruby-prof</title>
|
8
8
|
|
9
|
-
<link href="./fonts.css" rel="stylesheet">
|
10
|
-
<link href="./rdoc.css" rel="stylesheet">
|
11
|
-
|
12
9
|
<script type="text/javascript">
|
13
10
|
var rdoc_rel_prefix = "./";
|
14
11
|
</script>
|
15
12
|
|
16
13
|
<script src="./js/jquery.js"></script>
|
17
|
-
<script src="./js/navigation.js"></script>
|
18
|
-
<script src="./js/search_index.js"></script>
|
19
|
-
<script src="./js/search.js"></script>
|
20
|
-
<script src="./js/searcher.js"></script>
|
21
14
|
<script src="./js/darkfish.js"></script>
|
22
15
|
|
16
|
+
<link href="./css/fonts.css" rel="stylesheet">
|
17
|
+
<link href="./css/rdoc.css" rel="stylesheet">
|
18
|
+
|
19
|
+
|
23
20
|
|
24
21
|
<body id="top" role="document" class="file">
|
25
22
|
<nav role="navigation">
|
@@ -78,6 +75,8 @@
|
|
78
75
|
|
79
76
|
<ul class="link-list">
|
80
77
|
|
78
|
+
<li><a href="./Rack.html">Rack</a>
|
79
|
+
|
81
80
|
<li><a href="./Rack/RubyProf.html">Rack::RubyProf</a>
|
82
81
|
|
83
82
|
<li><a href="./RubyProf.html">RubyProf</a>
|
@@ -127,13 +126,13 @@
|
|
127
126
|
<main role="main">
|
128
127
|
|
129
128
|
|
130
|
-
<h1 id="label-ruby-prof">ruby-prof<span><a href="#label-ruby-prof">¶</a> <a href="#
|
129
|
+
<h1 id="label-ruby-prof">ruby-prof<span><a href="#label-ruby-prof">¶</a> <a href="#top">↑</a></span></h1>
|
131
130
|
|
132
131
|
<p><a href="https://travis-ci.org/ruby-prof/ruby-prof"><img
|
133
132
|
src="https://travis-ci.org/ruby-prof/ruby-prof.png?branch=master"
|
134
133
|
alt="Build Status" /></a></p>
|
135
134
|
|
136
|
-
<h2 id="label-Overview">Overview<span><a href="#label-Overview">¶</a> <a href="#
|
135
|
+
<h2 id="label-Overview">Overview<span><a href="#label-Overview">¶</a> <a href="#top">↑</a></span></h2>
|
137
136
|
|
138
137
|
<p>ruby-prof is a fast code profiler for Ruby. Its features include:</p>
|
139
138
|
<ul><li>
|
@@ -161,119 +160,117 @@ href="README_rdoc.html">README</a>.</p>
|
|
161
160
|
<p>Threads - supports profiling multiple threads simultaneously</p>
|
162
161
|
</li></ul>
|
163
162
|
|
164
|
-
<h2 id="label-Requirements">Requirements<span><a href="#label-Requirements">¶</a> <a href="#
|
163
|
+
<h2 id="label-Requirements">Requirements<span><a href="#label-Requirements">¶</a> <a href="#top">↑</a></span></h2>
|
165
164
|
|
166
165
|
<p>ruby-prof requires Ruby 1.9.3 or higher.</p>
|
167
166
|
|
168
|
-
<p>If you are running Linux or Unix you
|
169
|
-
can be compiled when it is installed.</p>
|
167
|
+
<p>If you are running Linux or Unix you'll need a C compiler so the
|
168
|
+
extension can be compiled when it is installed.</p>
|
170
169
|
|
171
170
|
<p>If you are running Windows, then you may need to install the Windows
|
172
171
|
specific RubyGem which includes an already built extension (see Install
|
173
172
|
section).</p>
|
174
173
|
|
175
|
-
<h2 id="label-Install">Install<span><a href="#label-Install">¶</a> <a href="#
|
174
|
+
<h2 id="label-Install">Install<span><a href="#label-Install">¶</a> <a href="#top">↑</a></span></h2>
|
176
175
|
|
177
176
|
<p>The easiest way to install ruby-prof is by using Ruby Gems. To install:</p>
|
178
177
|
|
179
|
-
<pre>gem install ruby-prof</
|
178
|
+
<pre class="ruby"><span class="ruby-identifier">gem</span> <span class="ruby-identifier">install</span> <span class="ruby-identifier">ruby</span><span class="ruby-operator">-</span><span class="ruby-identifier">prof</span>
|
179
|
+
</pre>
|
180
180
|
|
181
|
-
<p>If you
|
182
|
-
compile.</p>
|
181
|
+
<p>If you're on windows then please install the devkit first so that it
|
182
|
+
can compile.</p>
|
183
183
|
|
184
|
-
<h2 id="label-Usage">Usage<span><a href="#label-Usage">¶</a> <a href="#
|
184
|
+
<h2 id="label-Usage">Usage<span><a href="#label-Usage">¶</a> <a href="#top">↑</a></span></h2>
|
185
185
|
|
186
186
|
<p>There are two ways of running ruby-prof, via the command line or via its
|
187
187
|
API.</p>
|
188
188
|
|
189
|
-
<h3 id="label-ruby-prof+executable">ruby-prof executable<span><a href="#label-ruby-prof+executable">¶</a> <a href="#
|
189
|
+
<h3 id="label-ruby-prof+executable">ruby-prof executable<span><a href="#label-ruby-prof+executable">¶</a> <a href="#top">↑</a></span></h3>
|
190
190
|
|
191
191
|
<p>The first is to use ruby-prof to run the Ruby program you want to profile.
|
192
192
|
For more information refer to the documentation of the ruby-prof command.</p>
|
193
193
|
|
194
|
-
<h3 id="label-ruby-prof+API">ruby-prof API<span><a href="#label-ruby-prof+API">¶</a> <a href="#
|
194
|
+
<h3 id="label-ruby-prof+API">ruby-prof API<span><a href="#label-ruby-prof+API">¶</a> <a href="#top">↑</a></span></h3>
|
195
195
|
|
196
196
|
<p>The second way is to use the ruby-prof API to profile particular segments
|
197
197
|
of code.</p>
|
198
198
|
|
199
|
-
<pre
|
199
|
+
<pre>require 'ruby-prof'
|
200
200
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
[
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
</pre>
|
201
|
+
# Profile the code
|
202
|
+
RubyProf.start
|
203
|
+
...
|
204
|
+
[code to profile]
|
205
|
+
...
|
206
|
+
result = RubyProf.stop
|
207
|
+
|
208
|
+
# Print a flat profile to text
|
209
|
+
printer = RubyProf::FlatPrinter.new(result)
|
210
|
+
printer.print(STDOUT)</pre>
|
212
211
|
|
213
212
|
<p>Alternatively, you can use a block to tell ruby-prof what to profile:</p>
|
214
213
|
|
215
|
-
<pre
|
214
|
+
<pre>require 'ruby-prof'
|
216
215
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
[
|
221
|
-
|
222
|
-
|
216
|
+
# Profile the code
|
217
|
+
result = RubyProf.profile do
|
218
|
+
...
|
219
|
+
[code to profile]
|
220
|
+
...
|
221
|
+
end
|
223
222
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
</pre>
|
223
|
+
# Print a graph profile to text
|
224
|
+
printer = RubyProf::GraphPrinter.new(result)
|
225
|
+
printer.print(STDOUT, {})</pre>
|
228
226
|
|
229
227
|
<p>ruby-prof also supports pausing and resuming profiling runs.</p>
|
230
228
|
|
231
|
-
<pre
|
229
|
+
<pre>require 'ruby-prof'
|
232
230
|
|
233
|
-
|
234
|
-
|
235
|
-
[
|
236
|
-
|
237
|
-
[
|
238
|
-
|
239
|
-
[
|
240
|
-
|
241
|
-
</pre>
|
231
|
+
# Profile the code
|
232
|
+
RubyProf.start
|
233
|
+
[code to profile]
|
234
|
+
RubyProf.pause
|
235
|
+
[other code]
|
236
|
+
RubyProf.resume
|
237
|
+
[code to profile]
|
238
|
+
result = RubyProf.stop</pre>
|
242
239
|
|
243
240
|
<p>Note that resume will automatically call start if a profiling run has not
|
244
241
|
yet started. In addition, resume can also take a block:</p>
|
245
242
|
|
246
|
-
<pre
|
243
|
+
<pre>require 'ruby-prof'
|
247
244
|
|
248
|
-
|
249
|
-
|
250
|
-
[
|
251
|
-
|
245
|
+
# Profile the code
|
246
|
+
RubyProf.resume do
|
247
|
+
[code to profile]
|
248
|
+
end
|
252
249
|
|
253
|
-
|
254
|
-
</pre>
|
250
|
+
data = RubyProf.stop</pre>
|
255
251
|
|
256
252
|
<p>With this usage, resume will automatically call pause at the end of the
|
257
253
|
block.</p>
|
258
254
|
|
259
|
-
<h2 id="label-Method+and+Thread+Elimination">Method and Thread Elimination<span><a href="#label-Method+and+Thread+Elimination">¶</a> <a href="#
|
255
|
+
<h2 id="label-Method+and+Thread+Elimination">Method and Thread Elimination<span><a href="#label-Method+and+Thread+Elimination">¶</a> <a href="#top">↑</a></span></h2>
|
260
256
|
|
261
257
|
<p>ruby-prof supports eliminating specific methods and threads from profiling
|
262
258
|
results. This is useful for reducing connectivity in the call graph, making
|
263
259
|
it easier to identify the source of performance problems when using a graph
|
264
260
|
printer.</p>
|
265
261
|
|
266
|
-
<p>For example, consider Integer#times: it
|
267
|
-
much time is spent in the method itself. We
|
268
|
-
much the passed in block contributes to the time spent in the method
|
269
|
-
contains the Integer#times call.</p>
|
262
|
+
<p>For example, consider Integer#times: it's hardly ever useful to know
|
263
|
+
how much time is spent in the method itself. We're much more interested
|
264
|
+
in how much the passed in block contributes to the time spent in the method
|
265
|
+
which contains the Integer#times call.</p>
|
270
266
|
|
271
267
|
<p>Methods are eliminated from the collected data by calling
|
272
268
|
`eliminate_methods!` on the profiling result, before submitting it to a
|
273
269
|
printer.</p>
|
274
270
|
|
275
|
-
<pre>result = RubyProf
|
276
|
-
result
|
271
|
+
<pre class="ruby"><span class="ruby-identifier">result</span> = <span class="ruby-constant">RubyProf</span>.<span class="ruby-identifier">stop</span>
|
272
|
+
<span class="ruby-identifier">result</span>.<span class="ruby-identifier">eliminate_methods!</span>([<span class="ruby-node">/Integer#times/</span>])
|
273
|
+
</pre>
|
277
274
|
|
278
275
|
<p>The argument given to `eliminate_methods!` is either an array of regular
|
279
276
|
expressions, or the name of a file containing a list of regular expressions
|
@@ -285,17 +282,19 @@ those methods had been inlined at their call sites.</p>
|
|
285
282
|
<p>In a similar manner, threads can be excluded so they are not profiled at
|
286
283
|
all. To do this, pass an array of threads to exclude to ruby-prof:</p>
|
287
284
|
|
288
|
-
<pre>RubyProf
|
289
|
-
RubyProf
|
285
|
+
<pre class="ruby"><span class="ruby-constant">RubyProf</span><span class="ruby-operator">::</span><span class="ruby-identifier">exclude_threads</span> = [ <span class="ruby-identifier">thread2</span> ]
|
286
|
+
<span class="ruby-constant">RubyProf</span>.<span class="ruby-identifier">start</span>
|
287
|
+
</pre>
|
290
288
|
|
291
289
|
<p>Note that the excluded threads must be specified <strong>before</strong>
|
292
290
|
profiling.</p>
|
293
291
|
|
294
|
-
<h2 id="label-Benchmarking+full+load+time+including+rubygems+startup+cost">Benchmarking full load time including rubygems startup cost<span><a href="#label-Benchmarking+full+load+time+including+rubygems+startup+cost">¶</a> <a href="#
|
292
|
+
<h2 id="label-Benchmarking+full+load+time+including+rubygems+startup+cost">Benchmarking full load time including rubygems startup cost<span><a href="#label-Benchmarking+full+load+time+including+rubygems+startup+cost">¶</a> <a href="#top">↑</a></span></h2>
|
295
293
|
|
296
|
-
<p>If you want to get a more accurate measurement of what takes all of a
|
297
|
-
bin/xxx command to load, you may want to also measure
|
298
|
-
penalty. You can do this by calling into
|
294
|
+
<p>If you want to get a more accurate measurement of what takes all of a
|
295
|
+
gem's bin/xxx command to load, you may want to also measure
|
296
|
+
rubygems' startup penalty. You can do this by calling into
|
297
|
+
bin/ruby-prof directly, ex:</p>
|
299
298
|
|
300
299
|
<p>$ gem which ruby-prof</p>
|
301
300
|
|
@@ -311,10 +310,10 @@ g:192binsome_installed_gem_command</p>
|
|
311
310
|
<p>$ ruby g:/192/lib/ruby/gems/1.9.1/gems/ruby-prof-0.10.2/bin/ruby-prof
|
312
311
|
./some_file_that_does_a_require_rubygems_at_the_beginning.rb</p>
|
313
312
|
|
314
|
-
<h2 id="label-Profiling+Rails">Profiling Rails<span><a href="#label-Profiling+Rails">¶</a> <a href="#
|
313
|
+
<h2 id="label-Profiling+Rails">Profiling Rails<span><a href="#label-Profiling+Rails">¶</a> <a href="#top">↑</a></span></h2>
|
315
314
|
|
316
315
|
<p>To profile a Rails application it is vital to run it using production like
|
317
|
-
settings (cache classes, cache view lookups, etc.). Otherwise, Rail
|
316
|
+
settings (cache classes, cache view lookups, etc.). Otherwise, Rail's
|
318
317
|
dependency loading code will overwhelm any time spent in the application
|
319
318
|
itself (our tests show that Rails dependency loading causes a roughly 6x
|
320
319
|
slowdown). The best way to do this is create a new Rails environment,
|
@@ -329,15 +328,16 @@ likely turn off caching.</p>
|
|
329
328
|
</li><li>
|
330
329
|
<p>Add the ruby-prof to your gemfile:</p>
|
331
330
|
|
332
|
-
<pre>group
|
333
|
-
gem
|
334
|
-
end</
|
331
|
+
<pre class="ruby"><span class="ruby-identifier">group</span> :<span class="ruby-identifier">profile</span> <span class="ruby-keyword">do</span>
|
332
|
+
<span class="ruby-identifier">gem</span> <span class="ruby-string">'ruby-prof'</span>
|
333
|
+
<span class="ruby-keyword">end</span>
|
334
|
+
</pre>
|
335
335
|
</li><li>
|
336
336
|
<p>Add the ruby prof rack adapter to your middleware stack. One way to do
|
337
337
|
this is by adding the following code to config.ru:</p>
|
338
338
|
|
339
339
|
<pre class="ruby"><span class="ruby-keyword">if</span> <span class="ruby-constant">Rails</span>.<span class="ruby-identifier">env</span>.<span class="ruby-identifier">profile?</span>
|
340
|
-
<span class="ruby-identifier">use</span> <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">RubyProf</span>, :<span class="ruby-identifier">path</span> =<span class="ruby-operator">></span> <span class="ruby-string"
|
340
|
+
<span class="ruby-identifier">use</span> <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">RubyProf</span>, :<span class="ruby-identifier">path</span> =<span class="ruby-operator">></span> <span class="ruby-string">'/temp/profile'</span>
|
341
341
|
<span class="ruby-keyword">end</span>
|
342
342
|
</pre>
|
343
343
|
|
@@ -349,7 +349,7 @@ be generated for each request. Note that each request will overwrite the
|
|
349
349
|
profiling reports created by the previous request!</p>
|
350
350
|
</li></ol>
|
351
351
|
|
352
|
-
<h2 id="label-Reports">Reports<span><a href="#label-Reports">¶</a> <a href="#
|
352
|
+
<h2 id="label-Reports">Reports<span><a href="#label-Reports">¶</a> <a href="#top">↑</a></span></h2>
|
353
353
|
|
354
354
|
<p>ruby-prof can generate a number of different reports:</p>
|
355
355
|
<ul><li>
|
@@ -399,13 +399,13 @@ href="http://github.com/ruby-prof/ruby-prof/tree/master/examples/call_stack.html
|
|
399
399
|
<p>Another good example: [<a
|
400
400
|
href="http://twitpic.com/28z94a">twitpic.com/28z94a</a>]</p>
|
401
401
|
|
402
|
-
<p>Finally, there
|
402
|
+
<p>Finally, there's a so called MultiPrinter which can generate several
|
403
403
|
reports in one profiling run. See <a
|
404
404
|
href="http://github.com/ruby-prof/ruby-prof/tree/master/examples/multi.stack.html">examples/multi.stack.html</a>.</p>
|
405
405
|
|
406
406
|
<p>There is also a graphviz .dot visualiser.</p>
|
407
407
|
|
408
|
-
<h2 id="label-Printers">Printers<span><a href="#label-Printers">¶</a> <a href="#
|
408
|
+
<h2 id="label-Printers">Printers<span><a href="#label-Printers">¶</a> <a href="#top">↑</a></span></h2>
|
409
409
|
|
410
410
|
<p>Reports are created by printers. Supported printers include:</p>
|
411
411
|
<ul><li>
|
@@ -423,7 +423,7 @@ call graph report in text format</p>
|
|
423
423
|
Creates a call graph report in HTML (separate files per thread)</p>
|
424
424
|
</li><li>
|
425
425
|
<p><a href="RubyProf/DotPrinter.html">RubyProf::DotPrinter</a> - Creates a
|
426
|
-
call graph report in GraphViz
|
426
|
+
call graph report in GraphViz's DOT format which can be converted to an
|
427
427
|
image</p>
|
428
428
|
</li><li>
|
429
429
|
<p><a href="RubyProf/CallTreePrinter.html">RubyProf::CallTreePrinter</a> -
|
@@ -440,11 +440,10 @@ other printers to create several reports in one profiling run</p>
|
|
440
440
|
|
441
441
|
<p>To use a printer:</p>
|
442
442
|
|
443
|
-
<pre
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
</pre>
|
443
|
+
<pre>...
|
444
|
+
result = RubyProf.stop
|
445
|
+
printer = RubyProf::GraphPrinter.new(result)
|
446
|
+
printer.print(STDOUT, :min_percent => 2)</pre>
|
448
447
|
|
449
448
|
<p>The first parameter is any writable IO object such as STDOUT or a file. The
|
450
449
|
second parameter, specifies the minimum percentage a method must take to be
|
@@ -462,7 +461,7 @@ directory path and a basename for the files it produces.</p>
|
|
462
461
|
<span class="ruby-identifier">printer</span>.<span class="ruby-identifier">print</span>(:<span class="ruby-identifier">path</span> =<span class="ruby-operator">></span> <span class="ruby-string">"."</span>, :<span class="ruby-identifier">profile</span> =<span class="ruby-operator">></span> <span class="ruby-string">"profile"</span>)
|
463
462
|
</pre>
|
464
463
|
|
465
|
-
<h2 id="label-Measurements">Measurements<span><a href="#label-Measurements">¶</a> <a href="#
|
464
|
+
<h2 id="label-Measurements">Measurements<span><a href="#label-Measurements">¶</a> <a href="#top">↑</a></span></h2>
|
466
465
|
|
467
466
|
<p>Depending on the mode and platform, ruby-prof can measure various aspects
|
468
467
|
of a Ruby program. Supported measurements include:</p>
|
@@ -493,8 +492,8 @@ significant CPU or disk time during a profiling run then the reported
|
|
493
492
|
results will be too large.</p>
|
494
493
|
|
495
494
|
<p>CPU time uses the CPU clock counter to measure time. The returned values
|
496
|
-
are dependent on the correctly setting the CPU
|
497
|
-
only supported on Pentium or PowerPC platforms (linux only).</p>
|
495
|
+
are dependent on the correctly setting the CPU's frequency. This mode
|
496
|
+
is only supported on Pentium or PowerPC platforms (linux only).</p>
|
498
497
|
|
499
498
|
<p>Object allocation reports show how many objects each method in a program
|
500
499
|
allocates. This support was added by Sylvain Joyeux and requires a patched
|
@@ -504,13 +503,13 @@ Ruby interpreter. See below.</p>
|
|
504
503
|
This support was added by Alexander Dymo and requires a patched Ruby
|
505
504
|
interpreter. See below.</p>
|
506
505
|
|
507
|
-
<p>Garbage collection runs report how many times Ruby
|
508
|
-
invoked during a profiling session. This support was added by Jeremy
|
506
|
+
<p>Garbage collection runs report how many times Ruby's garbage collector
|
507
|
+
is invoked during a profiling session. This support was added by Jeremy
|
509
508
|
Kemper and requires a patched Ruby interpreter. See below.</p>
|
510
509
|
|
511
|
-
<p>Garbage collection time reports how much time is spent in Ruby
|
512
|
-
collector during a profiling session. This support was added by
|
513
|
-
Kemper and requires a patched Ruby interpreter. See below.</p>
|
510
|
+
<p>Garbage collection time reports how much time is spent in Ruby's
|
511
|
+
garbage collector during a profiling session. This support was added by
|
512
|
+
Jeremy Kemper and requires a patched Ruby interpreter. See below.</p>
|
514
513
|
|
515
514
|
<p>Ruby patches: all of the patches to Ruby are included in the railsexpress
|
516
515
|
patchsets for rvm, see <a
|
@@ -580,7 +579,7 @@ profiling run and is otherwise quiescent.</p>
|
|
580
579
|
|
581
580
|
<p>On both platforms, cpu time is measured using the RDTSC assembly function
|
582
581
|
provided by the Pentium and PowerPC platforms. CPU time is dependent on the
|
583
|
-
cpu
|
582
|
+
cpu's frequency. On Linux, ruby-prof attempts to read this value from
|
584
583
|
“/proc/cpuinfo.” On Windows, you must manually specify the clock
|
585
584
|
frequency. This can be done using the RUBY_PROF_CPU_FREQUENCY environment
|
586
585
|
variable:</p>
|
@@ -591,30 +590,30 @@ variable:</p>
|
|
591
590
|
|
592
591
|
<pre>RubyProf.cpu_frequency = <value></pre>
|
593
592
|
|
594
|
-
<h2 id="label-Multi-threaded+Applications">Multi-threaded Applications<span><a href="#label-Multi-threaded+Applications">¶</a> <a href="#
|
593
|
+
<h2 id="label-Multi-threaded+Applications">Multi-threaded Applications<span><a href="#label-Multi-threaded+Applications">¶</a> <a href="#top">↑</a></span></h2>
|
595
594
|
|
596
595
|
<p>Unfortunately, Ruby does not provide an internal api for detecting thread
|
597
596
|
context switches in 1.8. As a result, the timings ruby-prof reports for
|
598
597
|
each thread may be slightly inaccurate. In particular, this will happen
|
599
598
|
for newly spawned threads that go to sleep immediately (their first call).
|
600
|
-
For instance, if you use Ruby
|
601
|
-
2 seconds will be assigned to the foreground thread and not the newly
|
599
|
+
For instance, if you use Ruby's timeout library to wait for 2 seconds,
|
600
|
+
the 2 seconds will be assigned to the foreground thread and not the newly
|
602
601
|
created background thread. These errors can largely be avoided if the
|
603
602
|
background thread performs any operation before going to sleep.</p>
|
604
603
|
|
605
|
-
<h2 id="label-Performance">Performance<span><a href="#label-Performance">¶</a> <a href="#
|
604
|
+
<h2 id="label-Performance">Performance<span><a href="#label-Performance">¶</a> <a href="#top">↑</a></span></h2>
|
606
605
|
|
607
|
-
<p>Significant effort has been put into reducing ruby-prof
|
608
|
-
as possible. Our tests show that the overhead associated with
|
609
|
-
code varies considerably with the code being profiled. Most
|
610
|
-
run approximately twice as slow while highly recursive
|
611
|
-
fibonacci series test) will run three times slower.</p>
|
606
|
+
<p>Significant effort has been put into reducing ruby-prof's overhead as
|
607
|
+
much as possible. Our tests show that the overhead associated with
|
608
|
+
profiling code varies considerably with the code being profiled. Most
|
609
|
+
programs will run approximately twice as slow while highly recursive
|
610
|
+
programs (like the fibonacci series test) will run three times slower.</p>
|
612
611
|
|
613
|
-
<h2 id="label-License">License<span><a href="#label-License">¶</a> <a href="#
|
612
|
+
<h2 id="label-License">License<span><a href="#label-License">¶</a> <a href="#top">↑</a></span></h2>
|
614
613
|
|
615
614
|
<p>See <a href="LICENSE.html">LICENSE</a> for license information.</p>
|
616
615
|
|
617
|
-
<h2 id="label-Development">Development<span><a href="#label-Development">¶</a> <a href="#
|
616
|
+
<h2 id="label-Development">Development<span><a href="#label-Development">¶</a> <a href="#top">↑</a></span></h2>
|
618
617
|
|
619
618
|
<p>Code is located at <a
|
620
619
|
href="https://github.com/ruby-prof/ruby-prof">github.com/ruby-prof/ruby-prof</a></p>
|
@@ -628,7 +627,7 @@ or start a github issue.</p>
|
|
628
627
|
|
629
628
|
<footer id="validator-badges" role="contentinfo">
|
630
629
|
<p><a href="http://validator.w3.org/check/referer">Validate</a>
|
631
|
-
<p>Generated by <a href="http://
|
632
|
-
<p>Based on <a href="http://deveiate.org/projects/Darkfish-
|
630
|
+
<p>Generated by <a href="http://docs.seattlerb.org/rdoc/">RDoc</a> 4.2.0.
|
631
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
633
632
|
</footer>
|
634
633
|
|