ruby-prof 0.8.1-x86-mswin32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. data/CHANGES +221 -0
  2. data/LICENSE +23 -0
  3. data/README +432 -0
  4. data/Rakefile +159 -0
  5. data/bin/ruby-prof +224 -0
  6. data/examples/flat.txt +55 -0
  7. data/examples/graph.html +823 -0
  8. data/examples/graph.txt +170 -0
  9. data/ext/ruby_prof/measure_allocations.h +58 -0
  10. data/ext/ruby_prof/measure_cpu_time.h +152 -0
  11. data/ext/ruby_prof/measure_gc_runs.h +76 -0
  12. data/ext/ruby_prof/measure_gc_time.h +57 -0
  13. data/ext/ruby_prof/measure_memory.h +101 -0
  14. data/ext/ruby_prof/measure_process_time.h +52 -0
  15. data/ext/ruby_prof/measure_wall_time.h +53 -0
  16. data/ext/ruby_prof/mingw/Rakefile +23 -0
  17. data/ext/ruby_prof/mingw/build.rake +38 -0
  18. data/ext/ruby_prof/ruby_prof.c +1747 -0
  19. data/ext/ruby_prof/ruby_prof.h +188 -0
  20. data/ext/ruby_prof/version.h +4 -0
  21. data/lib/1.8/ruby_prof.so +0 -0
  22. data/lib/1.9/ruby_prof.so +0 -0
  23. data/lib/ruby-prof.rb +56 -0
  24. data/lib/ruby-prof/abstract_printer.rb +41 -0
  25. data/lib/ruby-prof/aggregate_call_info.rb +62 -0
  26. data/lib/ruby-prof/call_info.rb +47 -0
  27. data/lib/ruby-prof/call_tree_printer.rb +84 -0
  28. data/lib/ruby-prof/flat_printer.rb +78 -0
  29. data/lib/ruby-prof/flat_printer_with_line_numbers.rb +72 -0
  30. data/lib/ruby-prof/graph_html_printer.rb +256 -0
  31. data/lib/ruby-prof/graph_printer.rb +157 -0
  32. data/lib/ruby-prof/method_info.rb +111 -0
  33. data/lib/ruby-prof/symbol_to_proc.rb +8 -0
  34. data/lib/ruby-prof/task.rb +146 -0
  35. data/lib/ruby-prof/test.rb +148 -0
  36. data/lib/unprof.rb +8 -0
  37. data/rails/environment/profile.rb +24 -0
  38. data/rails/example/example_test.rb +9 -0
  39. data/rails/profile_test_helper.rb +21 -0
  40. data/test/aggregate_test.rb +121 -0
  41. data/test/basic_test.rb +290 -0
  42. data/test/current_failures_windows +8 -0
  43. data/test/do_nothing.rb +0 -0
  44. data/test/duplicate_names_test.rb +32 -0
  45. data/test/enumerable_test.rb +16 -0
  46. data/test/exceptions_test.rb +15 -0
  47. data/test/exclude_threads_test.rb +54 -0
  48. data/test/exec_test.rb +14 -0
  49. data/test/line_number_test.rb +73 -0
  50. data/test/measurement_test.rb +121 -0
  51. data/test/module_test.rb +54 -0
  52. data/test/no_method_class_test.rb +13 -0
  53. data/test/prime.rb +58 -0
  54. data/test/prime_test.rb +13 -0
  55. data/test/printers_test.rb +130 -0
  56. data/test/recursive_test.rb +275 -0
  57. data/test/ruby-prof-bin +20 -0
  58. data/test/singleton_test.rb +37 -0
  59. data/test/stack_test.rb +138 -0
  60. data/test/start_stop_test.rb +95 -0
  61. data/test/test_suite.rb +23 -0
  62. data/test/thread_test.rb +173 -0
  63. data/test/unique_call_path_test.rb +225 -0
  64. metadata +143 -0
data/CHANGES ADDED
@@ -0,0 +1,221 @@
1
+ 0.7.10 (2009-01-22)
2
+ =======================
3
+ * fix SEGFAULT in 1.9
4
+ * add new printer flat_printer_with_line_numbers
5
+
6
+ 0.7.7 (2009-01-13)
7
+ ======================
8
+ * "fix" multi threading support for 1.9 http://redmine.ruby-lang.org/issues/show/2012
9
+ * speedups
10
+
11
+ 0.7.6 (2009-12-31)
12
+ ======================
13
+ * fix some tests for 1.9 (no real code changes)
14
+
15
+ 0.7.5 (2009-12)
16
+ ========================
17
+ * fix a GC collection bug (nobu's patch).
18
+ * correctly report recursive call depths (Kevin Scaldeferri).
19
+ * sort methods on output (Kevin Scaldeferri).
20
+
21
+ 0.7.3 (2008-12-09)
22
+ ========================
23
+ * Fixed compile error with new x86_64 code using GCC.
24
+
25
+ 0.7.2 (2008-12-08)
26
+ ========================
27
+ * Fixed major bug in printing child methods in graph reports.
28
+
29
+ * Fixes for supporting x86_64 machines (Diego Pettenò)
30
+
31
+
32
+ 0.7.1 (2008-11-28)
33
+ ========================
34
+ * Added new AggregateCallInfo class for printers to
35
+ make results easier to read. Take this call sequence
36
+ for example:
37
+
38
+ A B C
39
+ | | |
40
+ Z A A
41
+ | |
42
+ Z Z
43
+
44
+ By default, ruby-prof will show that Z was called by 3 separate
45
+ instances of A. In an IDE that is helpful but in a text report
46
+ it is not since it makes the report much harder to read.
47
+ As a result, printers now aggregate together callers (and children),
48
+ matching ruby-prof's output from versions prior to 0.7.0.
49
+
50
+ * Fixes for supporting x86_64 machines (Matt Sanford)
51
+
52
+
53
+ 0.7.0 (2008-11-04)
54
+ ========================
55
+
56
+ Features
57
+ --------
58
+ * Added two new methods - RubyProf.resume and RubyProf.pause.
59
+ RubyProf.resume takes an optional block, which ensures that
60
+ RubyProf.pause is called. For example:
61
+
62
+ 10.times do |i|
63
+ RubyProf.resume do
64
+ # Some long process
65
+ end
66
+ end
67
+
68
+ result = RubyProf.stop
69
+
70
+ * Added support for profiling tests that use Ruby's built-in
71
+ unit test framework (ie, test derived from
72
+ Test::Unit::TestCase). To enable profiling simply add
73
+ the following line of code to your test class:
74
+
75
+ include RubyProf::Test
76
+
77
+ By default, profiling results are written to the current
78
+ processes working directory. To change this, or other
79
+ profiling options, simply modify the PROFILE_OPTIONS hash
80
+ table as needed.
81
+
82
+ * Used the new support for profiling test cases to revamp
83
+ the way that Rails profiling works. For more information
84
+ please refer to RubyProf's documentation.
85
+
86
+ * Keep track of call stack for each method to enable more
87
+ powerful profile visualizations in Integrated Development
88
+ Environments (Hin Boean, work supported by CodeGear).
89
+
90
+ * Expose measurements to Ruby (Jeremy Kemper).
91
+
92
+ * Add support for additional memory measurements modes in Ruby 1.9 (Jeremy Kemper).
93
+
94
+ * Add support for Lloyd Hilaiel's Ruby patch for measuring total heap size.
95
+ See http://lloydforge.org/projects/ruby. (Jeremy Kemper).
96
+
97
+
98
+ Fixes
99
+ -------
100
+ * RubyProf.profile no longer crashes if an exception is
101
+ thrown during a profiling run.
102
+
103
+ * Measure memory in fractional kilobytes rather than rounding down (Jeremy Kemper)
104
+
105
+
106
+ 0.6.0 (2008-02-03)
107
+ ========================
108
+
109
+ ruby-prof 0.6.0 adds support for Ruby 1.9 and memory profiling.
110
+
111
+ Features
112
+ --------
113
+ * Added support for ruby 1.9 (Shugo Maeda)
114
+ * Added support for outputting printer results to a String, Array or IO
115
+ object (Michael Granger)
116
+ * Add new memory profiling mode. Note this mode depends on a
117
+ patched Ruby interpreter (Alexander Dymo)
118
+
119
+ Fixes
120
+ -------
121
+ * Improvements to GraphHtmlPrinter including updated documentation,
122
+ fixes for min_time support, ability to specify templates using
123
+ strings or filenames, and table layout fixes (Makoto Kuwata)
124
+ * Fixes to scaling factor for calltrees so that precision is not lost
125
+ due to the conversion to doubles (Sylvain Joyeux)
126
+ * Changed constant ALLOCATED_OBJECTS to ALLOCATIONS in the C code to
127
+ match the Ruby code (Sylvain Joyeux)
128
+ * Added support for calltree printer to ruby-prof binary script (Sylvain Joyeux)
129
+ * Fix support for the allocator measure mode to extconf.rb (Sylvain Joyeux)
130
+ * Honor measure mode when specified on the command line (Sylvain Joyeux)
131
+ * Sorting of methods by total time was incorrect (Dan Fitch, Charlie Savage)
132
+ * Fix ruby-prof to work with the latest version of GEMS (Alexander Dymo)
133
+ * Always define MEASURE_CPU_TIME and MEASURE_ALLOCATIONS in Ruby code, but
134
+ set their values to nil if the functionality is not available.
135
+
136
+
137
+ 0.5.2 (2007-07-19)
138
+ ========================
139
+
140
+ ruby-prof 0.5.2 is a bug fix release.
141
+
142
+ Fixes
143
+ -------
144
+ * Include missing rails plugin
145
+
146
+
147
+ 0.5.1 (2007-07-18)
148
+ ========================
149
+
150
+ ruby-prof 0.5.1 is a bug fix and performance release.
151
+
152
+ Performance
153
+ --------
154
+ * Significantly reduced the number of thread lookups by
155
+ caching the last executed thread.
156
+
157
+ Fixes
158
+ -------
159
+ * Properly escape method names in HTML reports
160
+ * Fix use of -m and --min-percent command line switches
161
+ * Default source file information to ruby_runtime#0 for c calls
162
+ * Moved rails_plugin to top level so it is more obvious
163
+ * Updated rails_plugin to write reports to the current
164
+ Rails log directory
165
+ * Added additional tests
166
+
167
+
168
+ 0.5.0 (2007-07-09)
169
+ ========================
170
+
171
+ Features
172
+ --------
173
+ * Added support for timing multi-threaded applications
174
+ * Added support for 64 bit systems (patch from Diego 'Flameeyes' Petten)
175
+ * Added suport for outputting data in the format used by
176
+ KCacheGrind (patch from Carl Shimer)
177
+ * Add filename and line numbers to call tree information (patch from Carl Shimer)
178
+ * Added Visual Studio 2005 project file.
179
+ * Added replace-progname switch, als rcov.
180
+ * Added better support for recursive methods
181
+ * Added better support for profiling Rails applications
182
+
183
+ Fixes
184
+ -------
185
+ * Fixes bug when the type of an attached object (singleton) is inherited
186
+ from T_OBJECT as opposed to being a T_OBJECT (identified by Francis Cianfrocca)
187
+ * ruby-prof now works in IRB.
188
+ * Fix sort order in reports.
189
+ * Fixed rdoc compile error.
190
+ * Fix tabs in erb template for graph html report on windows.
191
+
192
+ 0.4.1 (2006-06-26)
193
+ ========================
194
+
195
+ Features
196
+ --------
197
+ * Added a RubyProf.running? method to indicate whether a profile is in progress.
198
+ * Added tgz and zip archives to release
199
+
200
+ Fixes
201
+ -------
202
+ * Duplicate method names are now allowed
203
+ * The documentation has been updated to show the correct API usage is RubyProf.stop not RubyProf.end
204
+
205
+
206
+ 0.4.0 (2006-06-16)
207
+ ========================
208
+ Features
209
+ --------
210
+ * added support for call graphs
211
+ * added support for printers. Currently there is a FlatPrinter,
212
+ GraphPrinter and GraphHtmlPrinter.
213
+ * added support for recursive methods
214
+ * added Windows support
215
+ * now packaged as a RubyGem
216
+
217
+ Fixes
218
+ -------
219
+ * Fixes bug where RubyProf would crash depending on the
220
+ way it was invoked - for example, it did not run when
221
+ used with Arachno Ruby's customized version of Ruby.
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (C) 2005 Shugo Maeda <shugo@ruby-lang.org>
2
+ All rights reserved.
3
+ *
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions
6
+ are met:
7
+ 1. Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above copyright
10
+ notice, this list of conditions and the following disclaimer in the
11
+ documentation and/or other materials provided with the distribution.
12
+ *
13
+ THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16
+ ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
17
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23
+ SUCH DAMAGE.
data/README ADDED
@@ -0,0 +1,432 @@
1
+ = ruby-prof
2
+
3
+ == Overview
4
+
5
+ ruby-prof is a fast code profiler for Ruby. Its features include:
6
+
7
+ * Speed - it is a C extension and therefore many times faster than the standard Ruby profiler.
8
+ * Modes - Ruby prof can measure a number of different parameters, including
9
+ call times, memory usage and object allocations.
10
+ * Reports - can generate text and cross-referenced html reports
11
+ - Flat Profiles - similar to the reports generated by the standard Ruby profiler
12
+ - Graph profiles - similar to GProf, these show how long a method runs, which methods call it and which methods it calls.
13
+ - Call tree profiles - outputs results in the calltree format suitable for the KCacheGrind profiling tool.
14
+ * Threads - supports profiling multiple threads simultaneously
15
+ * Recursive calls - supports profiling recursive method calls
16
+
17
+
18
+ == Requirements
19
+
20
+ ruby-prof requires Ruby 1.8.4 or higher.
21
+
22
+ If you are running Linux or Unix you'll need a C compiler so the extension
23
+ can be compiled when it is installed.
24
+
25
+ If you are running Windows, then you may need to install the
26
+ Windows specific RubyGem which includes an already built extension (see below).
27
+
28
+ == Install
29
+
30
+ The easiest way to install ruby-prof is by using Ruby Gems. To install:
31
+
32
+ <tt>gem install ruby-prof</tt>
33
+
34
+ If you on windows mswin [not mingw] (check via ruby -v) and
35
+ don't have an MSVC compiler, please install v0.7.3 which
36
+ has a prebuilt binary
37
+ C:> gem install ruby-prof -v0.7.3
38
+
39
+ If you're on mingw, please install the devkit first, then install the latest version (gem install ruby-prof).
40
+
41
+ == Usage
42
+
43
+ There are three ways of running ruby-prof.
44
+
45
+ === ruby-prof executable
46
+
47
+ The first is to use ruby-prof to run the Ruby program
48
+ you want to profile. For more information refer to
49
+ the ruby-prof documentation[link:files/bin/ruby-prof.html].
50
+
51
+
52
+ === ruby-prof API
53
+
54
+ The second way is to use the ruby-prof API to profile
55
+ particular segments of code.
56
+
57
+ require 'ruby-prof'
58
+
59
+ # Profile the code
60
+ RubyProf.start
61
+ ...
62
+ [code to profile]
63
+ ...
64
+ result = RubyProf.stop
65
+
66
+ # Print a flat profile to text
67
+ printer = RubyProf::FlatPrinter.new(result)
68
+ printer.print(STDOUT)
69
+
70
+ Alternatively, you can use a block to tell ruby-prof what
71
+ to profile:
72
+
73
+ require 'ruby-prof'
74
+
75
+ # Profile the code
76
+ result = RubyProf.profile do
77
+ ...
78
+ [code to profile]
79
+ ...
80
+ end
81
+
82
+ # Print a graph profile to text
83
+ printer = RubyProf::GraphPrinter.new(result)
84
+ printer.print(STDOUT, 0)
85
+
86
+ Starting with the 0.6.1 release, ruby-prof also supports pausing and resuming
87
+ profiling runs.
88
+
89
+ require 'ruby-prof'
90
+
91
+ # Profile the code
92
+ RubyProf.start
93
+ [code to profile]
94
+ RubyProf.pause
95
+ [other code]
96
+ RubyProf.resume
97
+ [code to profile]
98
+ result = RubyProf.stop
99
+
100
+ Note that resume will automatically call start if a profiling run
101
+ has not yet started. In addition, resume can also take a block:
102
+
103
+ require 'ruby-prof'
104
+
105
+ # Profile the code
106
+ RubyProf.resume do
107
+ [code to profile]
108
+ end
109
+
110
+ data = RubyProf.stop
111
+
112
+ With this usage, resume will automatically call pause at the
113
+ end of the block.
114
+
115
+
116
+ === require unprof
117
+
118
+ The third way of using ruby-prof is by requiring unprof.rb:
119
+
120
+ require 'unprof'
121
+
122
+ This will start profiling immediately and will output the results
123
+ using a flat profile report.
124
+
125
+ This method is provided for backwards compatibility. Using
126
+ {ruby-prof}[link:files/bin/ruby-prof.html] provides more flexibility.
127
+
128
+
129
+ == Profiling Tests
130
+
131
+ Starting with the 0.6.1 release, ruby-prof supports profiling tests cases
132
+ written using Ruby's built-in unit test framework (ie, test derived from
133
+ Test::Unit::TestCase). To enable profiling simply add the following line
134
+ of code to within your test class:
135
+
136
+ include RubyProf::Test
137
+
138
+ Each test method is profiled separately. ruby-prof will run each test method
139
+ once as a warmup and then ten additional times to gather profile data.
140
+ Note that the profile data will *not* include the class's setup or
141
+ teardown methods.
142
+
143
+ Separate reports are generated for each method and saved, by default,
144
+ in the test process's working directory. To change this, or other profiling
145
+ options, modify your test class's PROFILE_OPTIONS hash table. To globally
146
+ change test profiling options, modify RubyProf::Test::PROFILE_OPTIONS.
147
+
148
+
149
+ == Profiling Rails
150
+
151
+ To profile a Rails application it is vital to run it using production like
152
+ settings (cache classes, cache view lookups, etc.). Otherwise, Rail's
153
+ dependency loading code will overwhelm any time spent in the application
154
+ itself (our tests show that Rails dependency loading causes a roughly 6x
155
+ slowdown). The best way to do this is create a new Rails environment,
156
+ profile.rb.
157
+
158
+ So to profile Rails:
159
+
160
+ 1. Create a new profile.rb environment - or simply copy the example file
161
+ in ruby-prof/rails/environment/profile.rb
162
+
163
+ 2. Copy the file:
164
+
165
+ ruby-prof/rails/profile_test_helper.rb
166
+
167
+ To:
168
+
169
+ your_rails_app/test/profile_test_helper.rb
170
+
171
+ 3. Create a new test directory for profiling:
172
+
173
+ your_rails_app/test/profile
174
+
175
+
176
+ 4. Write unit, functional or integration tests specifically designed
177
+ to profile some part of your Rails application. At the top
178
+ of each test, replace this line:
179
+
180
+ require File.dirname(__FILE__) + '/../test_helper'
181
+
182
+ With:
183
+
184
+ require File.dirname(__FILE__) + '/../profile_test_helper'
185
+
186
+ For example:
187
+
188
+ require File.dirname(__FILE__) + '/../profile_test_helper'
189
+
190
+ class ExampleTest < Test::Unit::TestCase
191
+ include RubyProf::Test
192
+ fixtures ....
193
+
194
+ def test_stuff
195
+ puts "Test method"
196
+ end
197
+ end
198
+
199
+ 5. Now run your tests. Results will be written to:
200
+
201
+ your_rails_app/tmp/profile
202
+
203
+
204
+ == Reports
205
+
206
+ ruby-prof can generate a number of different reports:
207
+
208
+ * Flat Reports
209
+ * Graph Reports
210
+ * HTML Graph Reports
211
+ * Call graphs
212
+
213
+ Flat profiles show the overall time spent in each method. They
214
+ are a good of quickly identifying which methods take the most time.
215
+ An example of a flat profile and an explanation can be found in
216
+ {examples/flat.txt}[link:files/examples/flat_txt.html].
217
+
218
+ Graph profiles also show the overall time spent in each method.
219
+ In addition, they also show which methods call the current
220
+ method and which methods its calls. Thus they are good for
221
+ understanding how methods gets called and provide insight into
222
+ the flow of your program. An example text graph profile
223
+ is located at {examples/graph.txt}[link:files/examples/graph_txt.html].
224
+
225
+ HTML Graph profiles are the same as graph profiles, except
226
+ output is generated in hyper-linked HTML. Since graph profiles
227
+ can be quite large, the embedded links make it much easier to
228
+ navigate the results. An example html graph profile
229
+ is located at {examples/graph.html}[link:files/examples/graph_html.html].
230
+
231
+ HTML Graph profiles are the same as graph profiles, except
232
+ output is generated in hyper-linked HTML. Since graph profiles
233
+ can be quite large, the embedded links make it much easier to
234
+ navigate the results. An example html graph profile
235
+ is located at {examples/graph.html}[link:files/examples/graph_html.html].
236
+
237
+ Call graphs output results in the calltree profile format which is used
238
+ by KCachegrind. Call graph support was generously donated by Carl Shimer.
239
+ More information about the format can be found at
240
+ the {KCachegrind}[link:http://kcachegrind.sourceforge.net/cgi-bin/show.cgi/KcacheGrindCalltreeFormat] site.
241
+
242
+
243
+ == Printers
244
+
245
+ Reports are created by printers. Supported printers include:
246
+
247
+ * RubyProf::FlatPrinter - Creates a flat report in text format
248
+ * RubyProf::FlatPrinterWithLineNumbers - same as above but more verbose
249
+ * RubyProf::GraphPrinter - Creates a call graph report in text format
250
+ * RubyProf::GraphHtmlPrinter - Creates a call graph report in HTML (separate files per thread)
251
+ * RubyProf::CallTreePrinter - Creates a call tree report compatible with KCachegrind.
252
+
253
+ To use a printer:
254
+
255
+ ...
256
+ result = RubyProf.end
257
+ printer = RubyProf::GraphPrinter.new(result)
258
+ printer.print(STDOUT, :min_percent => 2)
259
+
260
+ The first parameter is any writable IO object such as STDOUT or a file.
261
+ The second parameter, specifies the minimum percentage a method must take
262
+ to be printed. Percentages should be specified as integers in the range 0 to 100.
263
+ For more information please see the documentation for the different printers.
264
+
265
+ The other option is :print_file => true (default false), which adds the filename to the
266
+ output (GraphPrinter only).
267
+
268
+ == Measurements
269
+
270
+ Depending on the mode and platform, ruby-prof can measure various
271
+ aspects of a Ruby program. Supported measurements include:
272
+
273
+ * process time (RubyProf::PROCESS_TIME)
274
+ * wall time (RubyProf::WALL_TIME)
275
+ * cpu time (RubyProf::CPU_TIME)
276
+ * object allocations (RubyProf::ALLOCATIONS)
277
+ * memory usage (RubyProf::MEMORY)
278
+ * garbage collections runs (RubyProf::GC_RUNS)
279
+ * garbage collection time (RubyProf::GC_TIME)
280
+
281
+ Process time measures the time used by a process between any two moments.
282
+ It is unaffected by other processes concurrently running
283
+ on the system. Note that Windows does not support measuring process
284
+ times - therefore, measurements on Windows defaults to wall time.
285
+
286
+ Wall time measures the real-world time elapsed between any two moments.
287
+ If there are other processes concurrently running on the system
288
+ that use significant CPU or disk time during a profiling run
289
+ then the reported results will be too large.
290
+
291
+ CPU time uses the CPU clock counter to measure time. The returned
292
+ values are dependent on the correctly setting the CPU's frequency.
293
+ This mode is only supported on Pentium or PowerPC platforms (linux only).
294
+
295
+ Object allocation reports show how many objects each method in
296
+ a program allocates. This support was added by Sylvain Joyeux
297
+ and requires a patched Ruby interpreter. For more information and
298
+ the patch, please see:
299
+ http://rubyforge.org/tracker/index.php?func=detail&aid=11497&group_id=426&atid=1700
300
+
301
+ Memory usage reports show how much memory each method in a program
302
+ uses. This support was added by Alexander Dymo and requires a
303
+ patched Ruby interpreter. For more information, see:
304
+ http://rubyforge.org/tracker/index.php?func=detail&aid=17676&group_id=1814&atid=7062
305
+
306
+ Garbage collection runs report how many times Ruby's garbage collector
307
+ is invoked during a profiling session. This support was added by Jeremy
308
+ Kemper and requires a patched Ruby interpreter. For more information, see:
309
+ http://rubyforge.org/tracker/index.php?func=detail&aid=17676&group_id=1814&atid=7062
310
+
311
+ Garbage collection time reports how much time is spent in Ruby's garbage collector
312
+ during a profiling session. This support was added by Jeremy Kemper
313
+ and requires a patched Ruby interpreter. For more information, see:
314
+ http://rubyforge.org/tracker/index.php?func=detail&aid=17676&group_id=1814&atid=7062
315
+
316
+ To set the measurement:
317
+
318
+ * RubyProf.measure_mode = RubyProf::PROCESS_TIME
319
+ * RubyProf.measure_mode = RubyProf::WALL_TIME
320
+ * RubyProf.measure_mode = RubyProf::CPU_TIME
321
+ * RubyProf.measure_mode = RubyProf::ALLOCATIONS
322
+ * RubyProf.measure_mode = RubyProf::MEMORY
323
+ * RubyProf.measure_mode = RubyProf::GC_RUNS
324
+ * RubyProf.measure_mode = RubyProf::GC_TIME
325
+
326
+ The default value is RubyProf::PROCESS_TIME.
327
+
328
+ You may also specify the measure_mode by using the RUBY_PROF_MEASURE_MODE
329
+ environment variable:
330
+
331
+ * export RUBY_PROF_MEASURE_MODE=process
332
+ * export RUBY_PROF_MEASURE_MODE=wall
333
+ * export RUBY_PROF_MEASURE_MODE=cpu
334
+ * export RUBY_PROF_MEASURE_MODE=allocations
335
+ * export RUBY_PROF_MEASURE_MODE=memory
336
+ * export RUBY_PROF_MEASURE_MODE=gc_runs
337
+ * export RUBY_PROF_MEASURE_MODE=gc_time
338
+
339
+ Note that these values have changed since ruby-prof-0.3.0.
340
+
341
+ On Linux, process time is measured using the clock method provided
342
+ by the C runtime library. Note that the clock method does not
343
+ report time spent in the kernel or child processes and therefore
344
+ does not measure time spent in methods such as Kernel.sleep method.
345
+ If you need to measure these values, then use wall time. Wall time
346
+ is measured using the gettimeofday kernel method.
347
+
348
+ On Windows, timings default to wall times. If you set the clock
349
+ mode to PROCESS_TIME, then timing are read using the clock method
350
+ provided by the C runtime library. Note though, these values are
351
+ wall times on Windows and not process times like on Linux.
352
+ Wall time is measured using the GetLocalTime API.
353
+
354
+ If you use wall time, the results will be affected by other
355
+ processes running on your computer, network delays, disk access,
356
+ etc. As result, for the best results, try to make sure your
357
+ computer is only performing your profiling run and is
358
+ otherwise quiescent.
359
+
360
+ On both platforms, cpu time is measured using the RDTSC assembly
361
+ function provided by the Pentium and PowerPC platforms. CPU time
362
+ is dependent on the cpu's frequency. On Linux, ruby-prof attempts
363
+ to read this value from "/proc/cpuinfo." On Windows, you must
364
+ manually specify the clock frequency. This can be done using the
365
+ RUBY_PROF_CPU_FREQUENCY environment variable:
366
+
367
+ export RUBY_PROF_CPU_FREQUENCY=<value>
368
+
369
+ You can also directly set the cpu frequency by calling:
370
+
371
+ RubyProf.cpu_frequency = <value>
372
+
373
+
374
+ == Recursive Calls
375
+
376
+ Recursive calls occur when method A calls method A and cycles
377
+ occur when method A calls method B calls method C calls method A.
378
+ ruby-prof detects both direct recursive calls and cycles. Both
379
+ are indicated in reports by a "d number" in parentheses following a method
380
+ name. For example, here is a flat profile from the test method
381
+
382
+ RecursiveTest#test_recursive:
383
+
384
+ %self total self wait child calls name
385
+ 100.00 2.00 2.00 0.00 0.00 2 Kernel#sleep
386
+ 0.00 2.00 0.00 0.00 2.00 0 RecursiveTest#test_cycle
387
+ 0.00 0.00 0.00 0.00 0.00 2 Fixnum#==
388
+ 0.00 0.00 0.00 0.00 0.00 2 Fixnum#-
389
+ 0.00 1.00 0.00 0.00 1.00 1 Object#sub_cycle(d1)
390
+ 0.00 2.00 0.00 0.00 2.00 1 Object#sub_cycle
391
+ 0.00 2.00 0.00 0.00 2.00 1 Object#cycle
392
+ 0.00 1.00 0.00 0.00 1.00 1 Object#cycle(d1)
393
+
394
+ Notice the presence of Object#cycle and Object#cycle(d1). The d1 means
395
+ depth 1 -- the method was either recursively called (directly or indirectly).
396
+
397
+ However, the self time values for recursive calls should always
398
+ be accurate. It is also believed that the total times are
399
+ accurate, but these should be carefully analyzed to verify their veracity.
400
+
401
+ == Multi-threaded Applications
402
+
403
+ Unfortunately, Ruby does not provide an internal api
404
+ for detecting thread context switches in 1.8. As a result, the
405
+ timings ruby-prof reports for each thread may be slightly
406
+ inaccurate. In particular, this will happen for newly
407
+ spawned threads that go to sleep immediately (their first call).
408
+ For instance, if you use Ruby's timeout library to wait for 2 seconds,
409
+ the 2 seconds will be assigned to the foreground thread
410
+ and not the newly created background thread. These errors
411
+ can largely be avoided if the background thread performs any
412
+ operation before going to sleep.
413
+
414
+ == Performance
415
+
416
+ Significant effort has been put into reducing ruby-prof's overhead
417
+ as much as possible. Our tests show that the overhead associated
418
+ with profiling code varies considerably with the code being
419
+ profiled. Most programs will run approximately twice as slow
420
+ while highly recursive programs (like the fibonacci series test)
421
+ will run three times slower.
422
+
423
+ Because of some threading difficulties in 1.9, it currently runs a bit slower there.
424
+ http://www.ruby-forum.com/topic/201329
425
+
426
+ == License
427
+
428
+ See LICENSE for license information.
429
+
430
+ == Development
431
+
432
+ Code is located at http://github.com/rdp/ruby-prof