ruby-prof 0.15.4 → 0.15.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES +7 -1
  3. data/README.rdoc +1 -1
  4. data/bin/ruby-prof +16 -4
  5. data/doc/LICENSE.html +114 -0
  6. data/doc/README_rdoc.html +592 -0
  7. data/doc/Rack.html +95 -0
  8. data/doc/Rack/RubyProf.html +264 -0
  9. data/doc/RubyProf.html +962 -0
  10. data/doc/RubyProf/AbstractPrinter.html +546 -0
  11. data/doc/RubyProf/AggregateCallInfo.html +537 -0
  12. data/doc/RubyProf/CallInfo.html +468 -0
  13. data/doc/RubyProf/CallInfoPrinter.html +120 -0
  14. data/doc/RubyProf/CallInfoVisitor.html +200 -0
  15. data/doc/RubyProf/CallStackPrinter.html +1604 -0
  16. data/doc/RubyProf/CallTreePrinter.html +359 -0
  17. data/doc/RubyProf/Cmd.html +631 -0
  18. data/doc/RubyProf/DotPrinter.html +257 -0
  19. data/doc/RubyProf/FlatPrinter.html +163 -0
  20. data/doc/RubyProf/FlatPrinterWithLineNumbers.html +208 -0
  21. data/doc/RubyProf/GraphHtmlPrinter.html +575 -0
  22. data/doc/RubyProf/GraphPrinter.html +139 -0
  23. data/doc/RubyProf/MethodInfo.html +685 -0
  24. data/doc/RubyProf/MultiPrinter.html +358 -0
  25. data/doc/RubyProf/Profile.html +764 -0
  26. data/doc/RubyProf/ProfileTask.html +490 -0
  27. data/doc/RubyProf/Thread.html +199 -0
  28. data/doc/created.rid +14 -14
  29. data/doc/examples/flat_txt.html +149 -0
  30. data/doc/examples/graph_html.html +850 -0
  31. data/doc/examples/graph_txt.html +274 -0
  32. data/doc/images/add.png +0 -0
  33. data/doc/images/arrow_up.png +0 -0
  34. data/doc/images/brick.png +0 -0
  35. data/doc/images/brick_link.png +0 -0
  36. data/doc/images/bug.png +0 -0
  37. data/doc/images/bullet_black.png +0 -0
  38. data/doc/images/bullet_toggle_minus.png +0 -0
  39. data/doc/images/bullet_toggle_plus.png +0 -0
  40. data/doc/images/date.png +0 -0
  41. data/doc/images/delete.png +0 -0
  42. data/doc/images/find.png +0 -0
  43. data/doc/images/macFFBgHack.png +0 -0
  44. data/doc/images/package.png +0 -0
  45. data/doc/images/page_green.png +0 -0
  46. data/doc/images/page_white_text.png +0 -0
  47. data/doc/images/page_white_width.png +0 -0
  48. data/doc/images/plugin.png +0 -0
  49. data/doc/images/ruby.png +0 -0
  50. data/doc/images/tag_blue.png +0 -0
  51. data/doc/images/tag_green.png +0 -0
  52. data/doc/images/transparent.png +0 -0
  53. data/doc/images/wrench.png +0 -0
  54. data/doc/images/wrench_orange.png +0 -0
  55. data/doc/images/zoom.png +0 -0
  56. data/doc/index.html +618 -0
  57. data/doc/js/search_index.js.gz +0 -0
  58. data/doc/table_of_contents.html +859 -0
  59. data/lib/ruby-prof/printers/flat_printer_with_line_numbers.rb +21 -14
  60. data/lib/ruby-prof/printers/graph_printer.rb +1 -0
  61. data/lib/ruby-prof/version.rb +1 -1
  62. data/test/measure_cpu_time_test.rb +1 -1
  63. metadata +54 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dad7c2ed1d68e57959ca77403a8ac342aca2e109
4
- data.tar.gz: 386143d988c94f456253ad76526dc217a86c8177
3
+ metadata.gz: 6bca6fbb93e0558298aa5d30d8a8771d116ddbf5
4
+ data.tar.gz: 8b908920d2cc8192011c43eea35f84bc2042a0a3
5
5
  SHA512:
6
- metadata.gz: ac5904bacc7110dd78a0f75b86095ee1767e337abb22399f4476b0644056279515f0c1e6e13d32518d0ef3392a39acee3a9b2aa507f91598f57cfa8b3a32aca7
7
- data.tar.gz: 9090e101f0dd1cc78c6125d57386324d6da3288bf88afc7b3618fd8c71f37fdc68211e06d6e0512df6149ca6fddd137100efe8c40248f5a505050839a4207b5f
6
+ metadata.gz: 1a358dd828584635f1d2141696971ca50db1829171f8808a8c00a1783b2a43ff91b1148269f0146b7d10cbf972401013085db4c3ff91b8b845947784558bdc1e
7
+ data.tar.gz: 7e4564d1c5d452561f1067faac32cab8dd896ee8d5627b6534c3894fb122860779e73d40fe95822ec2d63cd4ff60908233510ff867e430d772b824495fce87df
data/CHANGES CHANGED
@@ -1,4 +1,10 @@
1
- 0.15.4 (2014-05-20)
1
+ 0.15.5 (2015-02-22)
2
+ ======================
3
+ * improved upon computing children time in graph printers
4
+ * changed output format of flat_printer_with_line_number
5
+ * support using multi printer from command line (Dov Murik)
6
+
7
+ 0.15.4 (2015-02-14)
2
8
  ======================
3
9
  * using env variable to specify mesaurement mode work again
4
10
  * measuring memory/object allocations works for 2.1 adn 2.2 again
@@ -203,7 +203,7 @@ ruby-prof can generate a number of different reports:
203
203
  * More!
204
204
 
205
205
  Flat profiles show the overall time spent in each method. They
206
- are a good of quickly identifying which methods take the most time.
206
+ are a good way of quickly identifying which methods take the most time.
207
207
  An example of a flat profile and an explanation can be found in
208
208
  {examples/flat.txt}[http://github.com/ruby-prof/ruby-prof/tree/master/examples/flat.txt].
209
209
 
@@ -53,7 +53,7 @@ module RubyProf
53
53
  opts.separator ""
54
54
  opts.separator "Options:"
55
55
 
56
- opts.on('-p printer', '--printer=printer', [:flat, :flat_with_line_numbers, :graph, :graph_html, :call_tree, :call_stack, :dot],
56
+ opts.on('-p printer', '--printer=printer', [:flat, :flat_with_line_numbers, :graph, :graph_html, :call_tree, :call_stack, :dot, :multi],
57
57
  'Select a printer:',
58
58
  ' flat - Prints a flat profile as text (default).',
59
59
  ' flat_with_line_numbers - same as flat, with line numbers.',
@@ -61,7 +61,8 @@ module RubyProf
61
61
  ' graph_html - Prints a graph profile as html.',
62
62
  ' call_tree - format for KCacheGrind',
63
63
  ' call_stack - prints a HTML visualization of the call tree',
64
- ' dot - Prints a graph profile as a dot file'
64
+ ' dot - Prints a graph profile as a dot file',
65
+ ' multi - Creates several reports in output directory'
65
66
  ) do |printer|
66
67
 
67
68
 
@@ -80,6 +81,8 @@ module RubyProf
80
81
  options.printer = RubyProf::CallStackPrinter
81
82
  when :dot
82
83
  options.printer = RubyProf::DotPrinter
84
+ when :multi
85
+ options.printer = RubyProf::MultiPrinter
83
86
  end
84
87
  end
85
88
 
@@ -246,6 +249,11 @@ module RubyProf
246
249
  end
247
250
 
248
251
  self.option_parser.parse! ARGV
252
+
253
+ if options.printer == RubyProf::MultiPrinter
254
+ options.file ||= "."
255
+ options.old_wd ||= Dir.pwd
256
+ end
249
257
  rescue OptionParser::InvalidOption, OptionParser::InvalidArgument, OptionParser::MissingArgument => e
250
258
  puts self.option_parser
251
259
  puts e.message
@@ -314,8 +322,12 @@ at_exit {
314
322
  if cmd.options.file
315
323
  # write it relative to the dir they *started* in, as it's a bit surprising to write it in the dir they end up in.
316
324
  Dir.chdir(cmd.options.old_wd) do
317
- File.open(cmd.options.file, 'w') do |file|
318
- printer.print(file, printer_options)
325
+ if printer.is_a?(RubyProf::MultiPrinter)
326
+ printer.print(printer_options.merge(:path => cmd.options.file))
327
+ else
328
+ File.open(cmd.options.file, 'w') do |file|
329
+ printer.print(file, printer_options)
330
+ end
319
331
  end
320
332
  end
321
333
  else
@@ -0,0 +1,114 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta charset="UTF-8">
6
+
7
+ <title>LICENSE - ruby-prof</title>
8
+
9
+ <script type="text/javascript">
10
+ var rdoc_rel_prefix = "./";
11
+ </script>
12
+
13
+ <script src="./js/jquery.js"></script>
14
+ <script src="./js/darkfish.js"></script>
15
+
16
+ <link href="./css/fonts.css" rel="stylesheet">
17
+ <link href="./css/rdoc.css" rel="stylesheet">
18
+
19
+
20
+
21
+ <body id="top" role="document" class="file">
22
+ <nav role="navigation">
23
+ <div id="project-navigation">
24
+ <div id="home-section" role="region" title="Quick navigation" class="nav-section">
25
+ <h2>
26
+ <a href="./index.html" rel="home">Home</a>
27
+ </h2>
28
+
29
+ <div id="table-of-contents-navigation">
30
+ <a href="./table_of_contents.html#pages">Pages</a>
31
+ <a href="./table_of_contents.html#classes">Classes</a>
32
+ <a href="./table_of_contents.html#methods">Methods</a>
33
+ </div>
34
+ </div>
35
+
36
+ <div id="search-section" role="search" class="project-section initially-hidden">
37
+ <form action="#" method="get" accept-charset="utf-8">
38
+ <div id="search-field-wrapper">
39
+ <input id="search-field" role="combobox" aria-label="Search"
40
+ aria-autocomplete="list" aria-controls="search-results"
41
+ type="text" name="search" placeholder="Search" spellcheck="false"
42
+ title="Type to search, Up and Down to navigate, Enter to load">
43
+ </div>
44
+
45
+ <ul id="search-results" aria-label="Search Results"
46
+ aria-busy="false" aria-expanded="false"
47
+ aria-atomic="false" class="initially-hidden"></ul>
48
+ </form>
49
+ </div>
50
+
51
+ </div>
52
+
53
+
54
+
55
+ <div id="project-metadata">
56
+ <div id="fileindex-section" class="nav-section">
57
+ <h3>Pages</h3>
58
+
59
+ <ul class="link-list">
60
+
61
+ <li><a href="./LICENSE.html">LICENSE</a>
62
+
63
+ <li><a href="./README_rdoc.html">README</a>
64
+
65
+ <li><a href="./examples/flat_txt.html">flat</a>
66
+
67
+ <li><a href="./examples/graph_html.html">graph.html</a>
68
+
69
+ <li><a href="./examples/graph_txt.html">graph</a>
70
+
71
+ </ul>
72
+ </div>
73
+
74
+ </div>
75
+ </nav>
76
+
77
+ <main role="main" aria-label="Page LICENSE">
78
+
79
+ <p>Copyright (C) 2005 - 2014 Shugo Maeda &lt;shugo@ruby-lang.org&gt; and
80
+ Charlie Savage &lt;cfis@savagexi.com&gt; Copyright (C) 2010 - 2014 Stefan
81
+ Kaes &lt;skaes@railsepxress.de&gt; All rights reserved.</p>
82
+
83
+ <p>Redistribution and use in source and binary forms, with or without
84
+ modification, are permitted provided that the following conditions are met:</p>
85
+ <ol><li>
86
+ <p>Redistributions of source code must retain the above copyright notice, this
87
+ list of conditions and the following disclaimer.</p>
88
+ </li><li>
89
+ <p>Redistributions in binary form must reproduce the above copyright notice,
90
+ this list of conditions and the following disclaimer in the documentation
91
+ and/or other materials provided with the distribution.</p>
92
+ </li></ol>
93
+
94
+ <p>THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS “AS IS&#39;&#39;
95
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
96
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
97
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
98
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
99
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
100
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
101
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
102
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
103
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
104
+ DAMAGE.</p>
105
+ </main>
106
+
107
+
108
+
109
+ <footer id="validator-badges" role="contentinfo">
110
+ <p><a href="http://validator.w3.org/check/referer">Validate</a>
111
+ <p>Generated by <a href="http://docs.seattlerb.org/rdoc/">RDoc</a> 4.2.0.
112
+ <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
113
+ </footer>
114
+
@@ -0,0 +1,592 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta charset="UTF-8">
6
+
7
+ <title>README - ruby-prof</title>
8
+
9
+ <script type="text/javascript">
10
+ var rdoc_rel_prefix = "./";
11
+ </script>
12
+
13
+ <script src="./js/jquery.js"></script>
14
+ <script src="./js/darkfish.js"></script>
15
+
16
+ <link href="./css/fonts.css" rel="stylesheet">
17
+ <link href="./css/rdoc.css" rel="stylesheet">
18
+
19
+
20
+
21
+ <body id="top" role="document" class="file">
22
+ <nav role="navigation">
23
+ <div id="project-navigation">
24
+ <div id="home-section" role="region" title="Quick navigation" class="nav-section">
25
+ <h2>
26
+ <a href="./index.html" rel="home">Home</a>
27
+ </h2>
28
+
29
+ <div id="table-of-contents-navigation">
30
+ <a href="./table_of_contents.html#pages">Pages</a>
31
+ <a href="./table_of_contents.html#classes">Classes</a>
32
+ <a href="./table_of_contents.html#methods">Methods</a>
33
+ </div>
34
+ </div>
35
+
36
+ <div id="search-section" role="search" class="project-section initially-hidden">
37
+ <form action="#" method="get" accept-charset="utf-8">
38
+ <div id="search-field-wrapper">
39
+ <input id="search-field" role="combobox" aria-label="Search"
40
+ aria-autocomplete="list" aria-controls="search-results"
41
+ type="text" name="search" placeholder="Search" spellcheck="false"
42
+ title="Type to search, Up and Down to navigate, Enter to load">
43
+ </div>
44
+
45
+ <ul id="search-results" aria-label="Search Results"
46
+ aria-busy="false" aria-expanded="false"
47
+ aria-atomic="false" class="initially-hidden"></ul>
48
+ </form>
49
+ </div>
50
+
51
+ </div>
52
+
53
+
54
+ <div class="nav-section">
55
+ <h3>Table of Contents</h3>
56
+
57
+ <ul class="link-list" role="directory">
58
+ <li><a href="#label-ruby-prof">ruby-prof</a>
59
+ <li><a href="#label-Overview">Overview</a>
60
+ <li><a href="#label-Requirements">Requirements</a>
61
+ <li><a href="#label-Install">Install</a>
62
+ <li><a href="#label-Usage">Usage</a>
63
+ <li><a href="#label-ruby-prof+executable">ruby-prof executable</a>
64
+ <li><a href="#label-ruby-prof+API">ruby-prof API</a>
65
+ <li><a href="#label-Method+and+Thread+Elimination">Method and Thread Elimination</a>
66
+ <li><a href="#label-Benchmarking+full+load+time+including+rubygems+startup+cost">Benchmarking full load time including rubygems startup cost</a>
67
+ <li><a href="#label-Profiling+Rails">Profiling Rails</a>
68
+ <li><a href="#label-Reports">Reports</a>
69
+ <li><a href="#label-Printers">Printers</a>
70
+ <li><a href="#label-Measurements">Measurements</a>
71
+ <li><a href="#label-Multi-threaded+Applications">Multi-threaded Applications</a>
72
+ <li><a href="#label-Performance">Performance</a>
73
+ <li><a href="#label-License">License</a>
74
+ <li><a href="#label-Development">Development</a>
75
+ </ul>
76
+ </div>
77
+
78
+
79
+ <div id="project-metadata">
80
+ <div id="fileindex-section" class="nav-section">
81
+ <h3>Pages</h3>
82
+
83
+ <ul class="link-list">
84
+
85
+ <li><a href="./LICENSE.html">LICENSE</a>
86
+
87
+ <li><a href="./README_rdoc.html">README</a>
88
+
89
+ <li><a href="./examples/flat_txt.html">flat</a>
90
+
91
+ <li><a href="./examples/graph_html.html">graph.html</a>
92
+
93
+ <li><a href="./examples/graph_txt.html">graph</a>
94
+
95
+ </ul>
96
+ </div>
97
+
98
+ </div>
99
+ </nav>
100
+
101
+ <main role="main" aria-label="Page README.rdoc">
102
+
103
+ <h1 id="label-ruby-prof">ruby-prof<span><a href="#label-ruby-prof">&para;</a> <a href="#top">&uarr;</a></span></h1>
104
+
105
+ <p><a href="https://travis-ci.org/ruby-prof/ruby-prof"><img
106
+ src="https://travis-ci.org/ruby-prof/ruby-prof.png?branch=master"
107
+ alt="Build Status" /></a></p>
108
+
109
+ <h2 id="label-Overview">Overview<span><a href="#label-Overview">&para;</a> <a href="#top">&uarr;</a></span></h2>
110
+
111
+ <p>ruby-prof is a fast code profiler for Ruby. Its features include:</p>
112
+ <ul><li>
113
+ <p>Speed - it is a C extension and therefore many times faster than the
114
+ standard Ruby profiler.</p>
115
+ </li><li>
116
+ <p>Modes - Ruby prof can measure a number of different parameters, including
117
+ call times, memory usage and object allocations.</p>
118
+ </li><li>
119
+ <p>Reports - can generate text and cross-referenced html reports</p>
120
+ <ul><li>
121
+ <p>Flat Profiles - similar to the reports generated by the standard Ruby
122
+ profiler</p>
123
+ </li><li>
124
+ <p>Graph profiles - similar to GProf, these show how long a method runs, which
125
+ methods call it and which methods it calls.</p>
126
+ </li><li>
127
+ <p>Call tree profiles - outputs results in the calltree format suitable for
128
+ the KCacheGrind profiling tool.</p>
129
+ </li><li>
130
+ <p>Many more – see reports section of this <a
131
+ href="README_rdoc.html">README</a>.</p>
132
+ </li></ul>
133
+ </li><li>
134
+ <p>Threads - supports profiling multiple threads simultaneously</p>
135
+ </li></ul>
136
+
137
+ <h2 id="label-Requirements">Requirements<span><a href="#label-Requirements">&para;</a> <a href="#top">&uarr;</a></span></h2>
138
+
139
+ <p>ruby-prof requires Ruby 1.9.3 or higher.</p>
140
+
141
+ <p>If you are running Linux or Unix you&#39;ll need a C compiler so the
142
+ extension can be compiled when it is installed.</p>
143
+
144
+ <p>If you are running Windows, then you may need to install the Windows
145
+ specific RubyGem which includes an already built extension (see Install
146
+ section).</p>
147
+
148
+ <h2 id="label-Install">Install<span><a href="#label-Install">&para;</a> <a href="#top">&uarr;</a></span></h2>
149
+
150
+ <p>The easiest way to install ruby-prof is by using Ruby Gems. To install:</p>
151
+
152
+ <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>
153
+ </pre>
154
+
155
+ <p>If you&#39;re on windows then please install the devkit first so that it
156
+ can compile.</p>
157
+
158
+ <h2 id="label-Usage">Usage<span><a href="#label-Usage">&para;</a> <a href="#top">&uarr;</a></span></h2>
159
+
160
+ <p>There are two ways of running ruby-prof, via the command line or via its
161
+ API.</p>
162
+
163
+ <h3 id="label-ruby-prof+executable">ruby-prof executable<span><a href="#label-ruby-prof+executable">&para;</a> <a href="#top">&uarr;</a></span></h3>
164
+
165
+ <p>The first is to use ruby-prof to run the Ruby program you want to profile.
166
+ For more information refer to the documentation of the ruby-prof command.</p>
167
+
168
+ <h3 id="label-ruby-prof+API">ruby-prof API<span><a href="#label-ruby-prof+API">&para;</a> <a href="#top">&uarr;</a></span></h3>
169
+
170
+ <p>The second way is to use the ruby-prof API to profile particular segments
171
+ of code.</p>
172
+
173
+ <pre>require &#39;ruby-prof&#39;
174
+
175
+ # Profile the code
176
+ RubyProf.start
177
+ ...
178
+ [code to profile]
179
+ ...
180
+ result = RubyProf.stop
181
+
182
+ # Print a flat profile to text
183
+ printer = RubyProf::FlatPrinter.new(result)
184
+ printer.print(STDOUT)</pre>
185
+
186
+ <p>Alternatively, you can use a block to tell ruby-prof what to profile:</p>
187
+
188
+ <pre>require &#39;ruby-prof&#39;
189
+
190
+ # Profile the code
191
+ result = RubyProf.profile do
192
+ ...
193
+ [code to profile]
194
+ ...
195
+ end
196
+
197
+ # Print a graph profile to text
198
+ printer = RubyProf::GraphPrinter.new(result)
199
+ printer.print(STDOUT, {})</pre>
200
+
201
+ <p>ruby-prof also supports pausing and resuming profiling runs.</p>
202
+
203
+ <pre>require &#39;ruby-prof&#39;
204
+
205
+ # Profile the code
206
+ RubyProf.start
207
+ [code to profile]
208
+ RubyProf.pause
209
+ [other code]
210
+ RubyProf.resume
211
+ [code to profile]
212
+ result = RubyProf.stop</pre>
213
+
214
+ <p>Note that resume will automatically call start if a profiling run has not
215
+ yet started. In addition, resume can also take a block:</p>
216
+
217
+ <pre>require &#39;ruby-prof&#39;
218
+
219
+ # Profile the code
220
+ RubyProf.resume do
221
+ [code to profile]
222
+ end
223
+
224
+ data = RubyProf.stop</pre>
225
+
226
+ <p>With this usage, resume will automatically call pause at the end of the
227
+ block.</p>
228
+
229
+ <h2 id="label-Method+and+Thread+Elimination">Method and Thread Elimination<span><a href="#label-Method+and+Thread+Elimination">&para;</a> <a href="#top">&uarr;</a></span></h2>
230
+
231
+ <p>ruby-prof supports eliminating specific methods and threads from profiling
232
+ results. This is useful for reducing connectivity in the call graph, making
233
+ it easier to identify the source of performance problems when using a graph
234
+ printer.</p>
235
+
236
+ <p>For example, consider Integer#times: it&#39;s hardly ever useful to know
237
+ how much time is spent in the method itself. We&#39;re much more interested
238
+ in how much the passed in block contributes to the time spent in the method
239
+ which contains the Integer#times call.</p>
240
+
241
+ <p>Methods are eliminated from the collected data by calling
242
+ `eliminate_methods!` on the profiling result, before submitting it to a
243
+ printer.</p>
244
+
245
+ <pre class="ruby"><span class="ruby-identifier">result</span> = <span class="ruby-constant">RubyProf</span>.<span class="ruby-identifier">stop</span>
246
+ <span class="ruby-identifier">result</span>.<span class="ruby-identifier">eliminate_methods!</span>([<span class="ruby-node">/Integer#times/</span>])
247
+ </pre>
248
+
249
+ <p>The argument given to `eliminate_methods!` is either an array of regular
250
+ expressions, or the name of a file containing a list of regular expressions
251
+ (line separated text).</p>
252
+
253
+ <p>After eliminating methods the resulting profile will appear exactly as if
254
+ those methods had been inlined at their call sites.</p>
255
+
256
+ <p>In a similar manner, threads can be excluded so they are not profiled at
257
+ all. To do this, pass an array of threads to exclude to ruby-prof:</p>
258
+
259
+ <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> ]
260
+ <span class="ruby-constant">RubyProf</span>.<span class="ruby-identifier">start</span>
261
+ </pre>
262
+
263
+ <p>Note that the excluded threads must be specified <strong>before</strong>
264
+ profiling.</p>
265
+
266
+ <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">&para;</a> <a href="#top">&uarr;</a></span></h2>
267
+
268
+ <p>If you want to get a more accurate measurement of what takes all of a
269
+ gem&#39;s bin/xxx command to load, you may want to also measure
270
+ rubygems&#39; startup penalty. You can do this by calling into
271
+ bin/ruby-prof directly, ex:</p>
272
+
273
+ <p>$ gem which ruby-prof</p>
274
+
275
+ <pre>g:/192/lib/ruby/gems/1.9.1/gems/ruby-prof-0.10.2/lib/ruby-prof.rb</pre>
276
+
277
+ <p>now run it thus (substitute lib/ruby-prof.rb with bin/ruby-prof):</p>
278
+
279
+ <p>$ ruby g:/192/lib/ruby/gems/1.9.1/gems/ruby-prof-0.10.2/bin/ruby-prof
280
+ g:192binsome_installed_gem_command</p>
281
+
282
+ <p>or</p>
283
+
284
+ <p>$ ruby g:/192/lib/ruby/gems/1.9.1/gems/ruby-prof-0.10.2/bin/ruby-prof
285
+ ./some_file_that_does_a_require_rubygems_at_the_beginning.rb</p>
286
+
287
+ <h2 id="label-Profiling+Rails">Profiling Rails<span><a href="#label-Profiling+Rails">&para;</a> <a href="#top">&uarr;</a></span></h2>
288
+
289
+ <p>To profile a Rails application it is vital to run it using production like
290
+ settings (cache classes, cache view lookups, etc.). Otherwise, Rail&#39;s
291
+ dependency loading code will overwhelm any time spent in the application
292
+ itself (our tests show that Rails dependency loading causes a roughly 6x
293
+ slowdown). The best way to do this is create a new Rails environment,
294
+ profile.rb.</p>
295
+
296
+ <p>So to profile Rails:</p>
297
+ <ol><li>
298
+ <p>Create a new profile.rb environment. Make sure to turn on cache_classes
299
+ and cache_template_loading. Otherwise your profiling results will be
300
+ overwhelemed by the time Rails spends loading required files. You should
301
+ likely turn off caching.</p>
302
+ </li><li>
303
+ <p>Add the ruby-prof to your gemfile:</p>
304
+
305
+ <pre class="ruby"><span class="ruby-identifier">group</span> :<span class="ruby-identifier">profile</span> <span class="ruby-keyword">do</span>
306
+ <span class="ruby-identifier">gem</span> <span class="ruby-string">&#39;ruby-prof&#39;</span>
307
+ <span class="ruby-keyword">end</span>
308
+ </pre>
309
+ </li><li>
310
+ <p>Add the ruby prof rack adapter to your middleware stack. One way to do
311
+ this is by adding the following code to config.ru:</p>
312
+
313
+ <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>
314
+ <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">&gt;</span> <span class="ruby-string">&#39;/temp/profile&#39;</span>
315
+ <span class="ruby-keyword">end</span>
316
+ </pre>
317
+
318
+ <p>The path is where you want profiling results to be stored. By default the
319
+ rack adapter will generate a html call graph report and flat text report.</p>
320
+ </li><li>
321
+ <p>Now make a request to your running server. New profiling information will
322
+ be generated for each request. Note that each request will overwrite the
323
+ profiling reports created by the previous request!</p>
324
+ </li></ol>
325
+
326
+ <h2 id="label-Reports">Reports<span><a href="#label-Reports">&para;</a> <a href="#top">&uarr;</a></span></h2>
327
+
328
+ <p>ruby-prof can generate a number of different reports:</p>
329
+ <ul><li>
330
+ <p>Flat Reports</p>
331
+ </li><li>
332
+ <p>Graph Reports</p>
333
+ </li><li>
334
+ <p>HTML Graph Reports</p>
335
+ </li><li>
336
+ <p>Call graphs</p>
337
+ </li><li>
338
+ <p>Call stack reports</p>
339
+ </li><li>
340
+ <p>More!</p>
341
+ </li></ul>
342
+
343
+ <p>Flat profiles show the overall time spent in each method. They are a good
344
+ way of quickly identifying which methods take the most time. An example of
345
+ a flat profile and an explanation can be found in <a
346
+ href="http://github.com/ruby-prof/ruby-prof/tree/master/examples/flat.txt">examples/flat.txt</a>.</p>
347
+
348
+ <p>There are several varieties of these – run $ ruby-prof –help</p>
349
+
350
+ <p>Graph profiles also show the overall time spent in each method. In
351
+ addition, they also show which methods call the current method and which
352
+ methods its calls. Thus they are good for understanding how methods gets
353
+ called and provide insight into the flow of your program. An example text
354
+ graph profile is located at <a
355
+ href="http://github.com/ruby-prof/ruby-prof/tree/master/examples/graph.txt">examples/graph.txt</a>.</p>
356
+
357
+ <p>HTML Graph profiles are the same as graph profiles, except output is
358
+ generated in hyper-linked HTML. Since graph profiles can be quite large,
359
+ the embedded links make it much easier to navigate the results. An example
360
+ html graph profile is located at <a
361
+ href="http://github.com/ruby-prof/ruby-prof/tree/master/examples/graph.html">examples/graph.html</a>.</p>
362
+
363
+ <p>Call graphs output results in the calltree profile format which is used by
364
+ KCachegrind. Call graph support was generously donated by Carl Shimer. More
365
+ information about the format can be found at the <a
366
+ href="http://kcachegrind.sourceforge.net/cgi-bin/show.cgi/KcacheGrindCalltreeFormat">KCachegrind</a>
367
+ site.</p>
368
+
369
+ <p>Call stack reports produce a HTML visualization of the time spent in each
370
+ execution path of the profiled code. An example can be found at <a
371
+ href="http://github.com/ruby-prof/ruby-prof/tree/master/examples/stack.html">examples/stack.html</a>.</p>
372
+
373
+ <p>Another good example: [<a
374
+ href="http://twitpic.com/28z94a">twitpic.com/28z94a</a>]</p>
375
+
376
+ <p>Finally, there&#39;s a so called MultiPrinter which can generate several
377
+ reports in one profiling run. See <a
378
+ href="http://github.com/ruby-prof/ruby-prof/tree/master/examples/multi.stack.html">examples/multi.stack.html</a>.</p>
379
+
380
+ <p>There is also a graphviz .dot visualiser.</p>
381
+
382
+ <h2 id="label-Printers">Printers<span><a href="#label-Printers">&para;</a> <a href="#top">&uarr;</a></span></h2>
383
+
384
+ <p>Reports are created by printers. Supported printers include:</p>
385
+ <ul><li>
386
+ <p><a href="RubyProf/FlatPrinter.html">RubyProf::FlatPrinter</a> - Creates a
387
+ flat report in text format</p>
388
+ </li><li>
389
+ <p><a
390
+ href="RubyProf/FlatPrinterWithLineNumbers.html">RubyProf::FlatPrinterWithLineNumbers</a>
391
+ - same as above but more verbose</p>
392
+ </li><li>
393
+ <p><a href="RubyProf/GraphPrinter.html">RubyProf::GraphPrinter</a> - Creates a
394
+ call graph report in text format</p>
395
+ </li><li>
396
+ <p><a href="RubyProf/GraphHtmlPrinter.html">RubyProf::GraphHtmlPrinter</a> -
397
+ Creates a call graph report in HTML (separate files per thread)</p>
398
+ </li><li>
399
+ <p><a href="RubyProf/DotPrinter.html">RubyProf::DotPrinter</a> - Creates a
400
+ call graph report in GraphViz&#39;s DOT format which can be converted to an
401
+ image</p>
402
+ </li><li>
403
+ <p><a href="RubyProf/CallTreePrinter.html">RubyProf::CallTreePrinter</a> -
404
+ Creates a call tree report compatible with KCachegrind.</p>
405
+ </li><li>
406
+ <p><a href="RubyProf/CallStackPrinter.html">RubyProf::CallStackPrinter</a> -
407
+ Creates a HTML visualization of the Ruby stack</p>
408
+ </li><li>
409
+ <p><a href="RubyProf/MultiPrinter.html">RubyProf::MultiPrinter</a> - Uses the
410
+ other printers to create several reports in one profiling run</p>
411
+ </li><li>
412
+ <p>More!</p>
413
+ </li></ul>
414
+
415
+ <p>To use a printer:</p>
416
+
417
+ <pre>...
418
+ result = RubyProf.stop
419
+ printer = RubyProf::GraphPrinter.new(result)
420
+ printer.print(STDOUT, :min_percent =&gt; 2)</pre>
421
+
422
+ <p>The first parameter is any writable IO object such as STDOUT or a file. The
423
+ second parameter, specifies the minimum percentage a method must take to be
424
+ printed. Percentages should be specified as integers in the range 0 to
425
+ 100. For more information please see the documentation for the different
426
+ printers.</p>
427
+
428
+ <p>The other option is :print_file =&gt; true (default false), which adds the
429
+ filename to the output (GraphPrinter only).</p>
430
+
431
+ <p>The MultiPrinter differs from the other printers in that it requires a
432
+ directory path and a basename for the files it produces.</p>
433
+
434
+ <pre class="ruby"><span class="ruby-identifier">printer</span> = <span class="ruby-constant">RubyProf</span><span class="ruby-operator">::</span><span class="ruby-constant">MultiPrinter</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">result</span>)
435
+ <span class="ruby-identifier">printer</span>.<span class="ruby-identifier">print</span>(:<span class="ruby-identifier">path</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">&quot;.&quot;</span>, :<span class="ruby-identifier">profile</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">&quot;profile&quot;</span>)
436
+ </pre>
437
+
438
+ <h2 id="label-Measurements">Measurements<span><a href="#label-Measurements">&para;</a> <a href="#top">&uarr;</a></span></h2>
439
+
440
+ <p>Depending on the mode and platform, ruby-prof can measure various aspects
441
+ of a Ruby program. Supported measurements include:</p>
442
+ <ul><li>
443
+ <p>wall time (RubyProf::WALL_TIME)</p>
444
+ </li><li>
445
+ <p>process time (RubyProf::PROCESS_TIME)</p>
446
+ </li><li>
447
+ <p>cpu time (RubyProf::CPU_TIME)</p>
448
+ </li><li>
449
+ <p>object allocations (RubyProf::ALLOCATIONS)</p>
450
+ </li><li>
451
+ <p>memory usage (RubyProf::MEMORY)</p>
452
+ </li><li>
453
+ <p>garbage collection time (RubyProf::GC_TIME)</p>
454
+ </li><li>
455
+ <p>garbage collections runs (RubyProf::GC_RUNS)</p>
456
+ </li></ul>
457
+
458
+ <p>Wall time measures the real-world time elapsed between any two moments. If
459
+ there are other processes concurrently running on the system that use
460
+ significant CPU or disk time during a profiling run then the reported
461
+ results will be larger than expected.</p>
462
+
463
+ <p>Process time measures the time used by a process between any two moments.
464
+ It is unaffected by other processes concurrently running on the system.
465
+ Note that Windows does not support measuring process times.</p>
466
+
467
+ <p>CPU time uses the CPU clock counter to measure time. The returned values
468
+ are dependent on the correctly setting the CPU&#39;s frequency. This mode
469
+ is only supported on Pentium or PowerPC platforms (linux only).</p>
470
+
471
+ <p>Object allocation reports show how many objects each method in a program
472
+ allocates. This support was added by Sylvain Joyeux and requires a patched
473
+ Ruby interpreter. See below.</p>
474
+
475
+ <p>Memory usage reports show how much memory each method in a program uses.
476
+ This support was added by Alexander Dymo and requires a patched Ruby
477
+ interpreter. See below.</p>
478
+
479
+ <p>Garbage collection time reports how much time is spent in Ruby&#39;s
480
+ garbage collector during a profiling session. This support was added by
481
+ Jeremy Kemper and requires a patched Ruby interpreter. See below.</p>
482
+
483
+ <p>Garbage collection runs report how many times Ruby&#39;s garbage collector
484
+ is invoked during a profiling session. This support was added by Jeremy
485
+ Kemper and requires a patched Ruby interpreter. See below.</p>
486
+
487
+ <p>Ruby patches: all of the patches to Ruby are included in the railsexpress
488
+ patchsets for rvm, see <a
489
+ href="https://github.com/skaes/rvm-patchsets">github.com/skaes/rvm-patchsets</a></p>
490
+
491
+ <p>To set the measurement:</p>
492
+ <ul><li>
493
+ <p><a href="RubyProf.html#method-c-measure_mode">RubyProf.measure_mode</a> =
494
+ RubyProf::WALL_TIME</p>
495
+ </li><li>
496
+ <p><a href="RubyProf.html#method-c-measure_mode">RubyProf.measure_mode</a> =
497
+ RubyProf::PROCESS_TIME</p>
498
+ </li><li>
499
+ <p><a href="RubyProf.html#method-c-measure_mode">RubyProf.measure_mode</a> =
500
+ RubyProf::CPU_TIME</p>
501
+ </li><li>
502
+ <p><a href="RubyProf.html#method-c-measure_mode">RubyProf.measure_mode</a> =
503
+ RubyProf::ALLOCATIONS</p>
504
+ </li><li>
505
+ <p><a href="RubyProf.html#method-c-measure_mode">RubyProf.measure_mode</a> =
506
+ RubyProf::MEMORY</p>
507
+ </li><li>
508
+ <p><a href="RubyProf.html#method-c-measure_mode">RubyProf.measure_mode</a> =
509
+ RubyProf::GC_TIME</p>
510
+ </li><li>
511
+ <p><a href="RubyProf.html#method-c-measure_mode">RubyProf.measure_mode</a> =
512
+ RubyProf::GC_RUNS</p>
513
+ </li></ul>
514
+
515
+ <p>The default value is RubyProf::WALL_TIME.</p>
516
+
517
+ <p>You may also specify the measure_mode by using the RUBY_PROF_MEASURE_MODE
518
+ environment variable:</p>
519
+ <ul><li>
520
+ <p>export RUBY_PROF_MEASURE_MODE=wall</p>
521
+ </li><li>
522
+ <p>export RUBY_PROF_MEASURE_MODE=process</p>
523
+ </li><li>
524
+ <p>export RUBY_PROF_MEASURE_MODE=cpu</p>
525
+ </li><li>
526
+ <p>export RUBY_PROF_MEASURE_MODE=allocations</p>
527
+ </li><li>
528
+ <p>export RUBY_PROF_MEASURE_MODE=memory</p>
529
+ </li><li>
530
+ <p>export RUBY_PROF_MEASURE_MODE=gc_time</p>
531
+ </li><li>
532
+ <p>export RUBY_PROF_MEASURE_MODE=gc_runs</p>
533
+ </li></ul>
534
+
535
+ <p>On Linux, process time is measured using the clock method provided by the C
536
+ runtime library. Note that the clock method does not report time spent in
537
+ the kernel or child processes and therefore does not measure time spent in
538
+ methods such as Kernel.sleep method. If you need to measure these values,
539
+ then use wall time. Wall time is measured using the gettimeofday kernel
540
+ method.</p>
541
+
542
+ <p>If you set the clock mode to PROCESS_TIME, then timings are read using the
543
+ clock method provided by the C runtime library. Note though, these values
544
+ are wall times on Windows and not process times like on Linux. Wall time
545
+ is measured using the GetLocalTime API.</p>
546
+
547
+ <p>If you use wall time, the results will be affected by other processes
548
+ running on your computer, network delays, disk access, etc. As result, for
549
+ the best results, try to make sure your computer is only performing your
550
+ profiling run and is otherwise quiescent.</p>
551
+
552
+ <h2 id="label-Multi-threaded+Applications">Multi-threaded Applications<span><a href="#label-Multi-threaded+Applications">&para;</a> <a href="#top">&uarr;</a></span></h2>
553
+
554
+ <p>Unfortunately, Ruby does not provide an internal api for detecting thread
555
+ context switches in 1.8. As a result, the timings ruby-prof reports for
556
+ each thread may be slightly inaccurate. In particular, this will happen
557
+ for newly spawned threads that go to sleep immediately (their first call).
558
+ For instance, if you use Ruby&#39;s timeout library to wait for 2 seconds,
559
+ the 2 seconds will be assigned to the foreground thread and not the newly
560
+ created background thread. These errors can largely be avoided if the
561
+ background thread performs any operation before going to sleep.</p>
562
+
563
+ <h2 id="label-Performance">Performance<span><a href="#label-Performance">&para;</a> <a href="#top">&uarr;</a></span></h2>
564
+
565
+ <p>Significant effort has been put into reducing ruby-prof&#39;s overhead as
566
+ much as possible. Our tests show that the overhead associated with
567
+ profiling code varies considerably with the code being profiled. Most
568
+ programs will run approximately twice as slow while highly recursive
569
+ programs (like the fibonacci series test) will run three times slower.</p>
570
+
571
+ <h2 id="label-License">License<span><a href="#label-License">&para;</a> <a href="#top">&uarr;</a></span></h2>
572
+
573
+ <p>See <a href="LICENSE.html">LICENSE</a> for license information.</p>
574
+
575
+ <h2 id="label-Development">Development<span><a href="#label-Development">&para;</a> <a href="#top">&uarr;</a></span></h2>
576
+
577
+ <p>Code is located at <a
578
+ href="https://github.com/ruby-prof/ruby-prof">github.com/ruby-prof/ruby-prof</a></p>
579
+
580
+ <p>Google group/mailing list: <a
581
+ href="http://groups.google.com/group/ruby-optimization">groups.google.com/group/ruby-optimization</a>
582
+ or start a github issue.</p>
583
+ </main>
584
+
585
+
586
+
587
+ <footer id="validator-badges" role="contentinfo">
588
+ <p><a href="http://validator.w3.org/check/referer">Validate</a>
589
+ <p>Generated by <a href="http://docs.seattlerb.org/rdoc/">RDoc</a> 4.2.0.
590
+ <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
591
+ </footer>
592
+