rdp-ruby-prof 0.7.4

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