adamh-ruby-prof 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/CHANGES +202 -0
  2. data/LICENSE +23 -0
  3. data/README +436 -0
  4. data/Rakefile +123 -0
  5. data/bin/ruby-prof +217 -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/extconf.rb +34 -0
  10. data/ext/measure_allocations.h +58 -0
  11. data/ext/measure_cpu_time.h +152 -0
  12. data/ext/measure_gc_runs.h +76 -0
  13. data/ext/measure_gc_time.h +57 -0
  14. data/ext/measure_memory.h +101 -0
  15. data/ext/measure_process_time.h +52 -0
  16. data/ext/measure_wall_time.h +53 -0
  17. data/ext/mingw/Rakefile +23 -0
  18. data/ext/mingw/build.rake +38 -0
  19. data/ext/ruby_prof.c +1747 -0
  20. data/ext/ruby_prof.h +189 -0
  21. data/ext/vc/ruby_prof.sln +20 -0
  22. data/ext/vc/ruby_prof.vcproj +241 -0
  23. data/ext/version.h +4 -0
  24. data/lib/ruby-prof.rb +48 -0
  25. data/lib/ruby-prof/abstract_printer.rb +41 -0
  26. data/lib/ruby-prof/aggregate_call_info.rb +62 -0
  27. data/lib/ruby-prof/call_info.rb +47 -0
  28. data/lib/ruby-prof/call_tree_printer.rb +84 -0
  29. data/lib/ruby-prof/flat_printer.rb +79 -0
  30. data/lib/ruby-prof/graph_html_printer.rb +256 -0
  31. data/lib/ruby-prof/graph_printer.rb +164 -0
  32. data/lib/ruby-prof/method_info.rb +111 -0
  33. data/lib/ruby-prof/task.rb +146 -0
  34. data/lib/ruby-prof/test.rb +148 -0
  35. data/lib/unprof.rb +8 -0
  36. data/rails/environment/profile.rb +24 -0
  37. data/rails/example/example_test.rb +9 -0
  38. data/rails/profile_test_helper.rb +21 -0
  39. data/test/aggregate_test.rb +121 -0
  40. data/test/basic_test.rb +309 -0
  41. data/test/duplicate_names_test.rb +32 -0
  42. data/test/exceptions_test.rb +15 -0
  43. data/test/exclude_threads_test.rb +54 -0
  44. data/test/line_number_test.rb +73 -0
  45. data/test/measurement_test.rb +121 -0
  46. data/test/module_test.rb +54 -0
  47. data/test/no_method_class_test.rb +13 -0
  48. data/test/prime.rb +58 -0
  49. data/test/prime_test.rb +13 -0
  50. data/test/printers_test.rb +71 -0
  51. data/test/recursive_test.rb +254 -0
  52. data/test/singleton_test.rb +37 -0
  53. data/test/stack_test.rb +138 -0
  54. data/test/start_stop_test.rb +95 -0
  55. data/test/test_suite.rb +23 -0
  56. data/test/thread_test.rb +159 -0
  57. data/test/unique_call_path_test.rb +206 -0
  58. metadata +114 -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,436 @@
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
+ ruby-prof is also available as a tarred gzip archive and zip archive.
41
+
42
+ == Usage
43
+
44
+ There are three ways of running ruby-prof.
45
+
46
+
47
+ === ruby-prof executable
48
+
49
+ The first is to use ruby-prof to run the Ruby program
50
+ you want to profile. For more information refer to
51
+ the ruby-prof documentation[link:files/bin/ruby-prof.html].
52
+
53
+
54
+ === ruby-prof API
55
+
56
+ The second way is to use the ruby-prof API to profile
57
+ particular segments of code.
58
+
59
+ require 'ruby-prof'
60
+
61
+ # Profile the code
62
+ RubyProf.start
63
+ ...
64
+ [code to profile]
65
+ ...
66
+ result = RubyProf.stop
67
+
68
+ # Print a flat profile to text
69
+ printer = RubyProf::FlatPrinter.new(result)
70
+ printer.print(STDOUT, 0)
71
+
72
+ Alternatively, you can use a block to tell ruby-prof what
73
+ to profile:
74
+
75
+ require 'ruby-prof'
76
+
77
+ # Profile the code
78
+ result = RubyProf.profile do
79
+ ...
80
+ [code to profile]
81
+ ...
82
+ end
83
+
84
+ # Print a graph profile to text
85
+ printer = RubyProf::GraphPrinter.new(result)
86
+ printer.print(STDOUT, 0)
87
+
88
+ Starting with the 0.6.1 release, ruby-prof also supports pausing and resuming
89
+ profiling runs.
90
+
91
+ require 'ruby-prof'
92
+
93
+ # Profile the code
94
+ RubyProf.start
95
+ [code to profile]
96
+ RubyProf.pause
97
+ [other code]
98
+ RubyProf.resume
99
+ [code to profile]
100
+ result = RubyProf.stop
101
+
102
+ Note that resume will automatically call start if a profiling run
103
+ has not yet started. In addition, resume can also take a block:
104
+
105
+ require 'ruby-prof'
106
+
107
+ # Profile the code
108
+ RubyProf.resume do
109
+ [code to profile]
110
+ end
111
+
112
+ data = RubyProf.stop
113
+
114
+ With this usage, resume will automatically call pause at the
115
+ end of the block.
116
+
117
+
118
+ === require unprof
119
+
120
+ The third way of using ruby-prof is by requiring unprof.rb:
121
+
122
+ require 'unprof'
123
+
124
+ This will start profiling immediately and will output the results
125
+ using a flat profile report.
126
+
127
+ This method is provided for backwards compatibility. Using
128
+ {ruby-prof}[link:files/bin/ruby-prof.html] provides more flexibility.
129
+
130
+
131
+ == Profiling Tests
132
+
133
+ Starting with the 0.6.1 release, ruby-prof supports profiling tests cases
134
+ written using Ruby's built-in unit test framework (ie, test derived from
135
+ Test::Unit::TestCase). To enable profiling simply add the following line
136
+ of code to your test class:
137
+
138
+ include RubyProf::Test
139
+
140
+ Each test method is profiled separately. ruby-prof will run each test method
141
+ once as a warmup and then ten additional times to gather profile data.
142
+ Note that the profile data will *not* include the class's setup or
143
+ teardown methods.
144
+
145
+ Separate reports are generated for each method and saved, by default,
146
+ in the test process's working directory. To change this, or other profiling
147
+ options, modify your test class's PROFILE_OPTIONS hash table. To globally
148
+ change test profiling options, modify RubyProf::Test::PROFILE_OPTIONS.
149
+
150
+
151
+ == Profiling Rails
152
+
153
+ To profile a Rails application it is vital to run it using production like
154
+ settings (cache classes, cache view lookups, etc.). Otherwise, Rail's
155
+ dependency loading code will overwhelm any time spent in the application
156
+ itself (our tests show that Rails dependency loading causes a roughly 6x
157
+ slowdown). The best way to do this is create a new Rails environment,
158
+ profile.rb.
159
+
160
+ So to profile Rails:
161
+
162
+ 1. Create a new profile.rb environment - or simply copy the example file
163
+ in ruby-prof/rails/environment/profile.rb
164
+
165
+ 2. Copy the file:
166
+
167
+ ruby-prof/rails/profile_test_helper.rb
168
+
169
+ To:
170
+
171
+ your_rails_app/test/profile_test_helper.rb
172
+
173
+ 3. Create a new test directory for profiling:
174
+
175
+ your_rails_app/test/profile
176
+
177
+
178
+ 4. Write unit, functional or integration tests specifically designed
179
+ to profile some part of your Rails application. At the top
180
+ of each test, replace this line:
181
+
182
+ require File.dirname(__FILE__) + '/../test_helper'
183
+
184
+ With:
185
+
186
+ require File.dirname(__FILE__) + '/../profile_test_helper'
187
+
188
+ For example:
189
+
190
+ require File.dirname(__FILE__) + '/../profile_test_helper'
191
+
192
+ class ExampleTest < Test::Unit::TestCase
193
+ include RubyProf::Test
194
+ fixtures ....
195
+
196
+ def test_stuff
197
+ puts "Test method"
198
+ end
199
+ end
200
+
201
+ 5. Now run your tests. Results will be written to:
202
+
203
+ your_rails_app/tmp/profile
204
+
205
+
206
+ == Reports
207
+
208
+ ruby-prof can generate a number of different reports:
209
+
210
+ * Flat Reports
211
+ * Graph Reports
212
+ * HTML Graph Reports
213
+ * Call graphs
214
+
215
+ Flat profiles show the overall time spent in each method. They
216
+ are a good of quickly identifying which methods take the most time.
217
+ An example of a flat profile and an explanation can be found in
218
+ {examples/flat.txt}[link:files/examples/flat_txt.html].
219
+
220
+ Graph profiles also show the overall time spent in each method.
221
+ In addition, they also show which methods call the current
222
+ method and which methods its calls. Thus they are good for
223
+ understanding how methods gets called and provide insight into
224
+ the flow of your program. An example text graph profile
225
+ is located at {examples/graph.txt}[link:files/examples/graph_txt.html].
226
+
227
+ HTML Graph profiles are the same as graph profiles, except
228
+ output is generated in hyper-linked HTML. Since graph profiles
229
+ can be quite large, the embedded links make it much easier to
230
+ navigate the results. An example html graph profile
231
+ is located at {examples/graph.html}[link:files/examples/graph_html.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
+ Call graphs output results in the calltree profile format which is used
240
+ by KCachegrind. Call graph support was generously donated by Carl Shimer.
241
+ More information about the format can be found at
242
+ the {KCachegrind}[link:http://kcachegrind.sourceforge.net/cgi-bin/show.cgi/KcacheGrindCalltreeFormat] site.
243
+
244
+
245
+ == Printers
246
+
247
+ Reports are created by printers. Supported printers include:
248
+
249
+ * RubyProf::FlatPrinter - Creates a flat report in text format
250
+ * RubyProf::GraphPrinter - Creates a call graph report in text format
251
+ * RubyProf::GraphHtmlPrinter - Creates a call graph report in HTML (separate files per thread)
252
+ * RubyProf::CallTreePrinter - Creates a call tree report compatible with KCachegrind.
253
+
254
+ To use a printer:
255
+
256
+ result = RubyProf.end
257
+ printer = RubyProf::GraphPrinter.new(result)
258
+ printer.print(STDOUT, 0)
259
+
260
+ The first parameter is any writable IO object such as STDOUT or a file.
261
+ The second parameter, which has a default value of 0, specifies
262
+ the minimum percentage a method must take to be printed. Percentages
263
+ should be specified as integers in the range 0 to 100. For more
264
+ information please see the documentation for the different printers.
265
+
266
+
267
+ == Measurements
268
+
269
+ Depending on the mode and platform, ruby-prof can measure various
270
+ aspects of a Ruby program. Supported measurements include:
271
+
272
+ * process time (RubyProf::PROCESS_TIME)
273
+ * wall time (RubyProf::WALL_TIME)
274
+ * cpu time (RubyProf::CPU_TIME)
275
+ * object allocations (RubyProf::ALLOCATIONS)
276
+ * memory usage (RubyProf::MEMORY)
277
+ * garbage collections runs (RubyProf::GC_RUNS)
278
+ * garbage collection time (RubyProf::GC_TIME)
279
+
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, all measurements on Windows use 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.
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 are always 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
+ 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 dash and number following a method
380
+ name. For example, here is a flat profile from the test method
381
+ RecursiveTest#test_recursive:
382
+
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-1
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-1
393
+
394
+ Notice the presence of Object#cycle and Object#cycle-1. The -1 means
395
+ 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
+
402
+ == Multi-threaded Applications
403
+
404
+ Unfortunately, Ruby does not provide an internal api
405
+ for detecting thread context switches. As a result, the
406
+ timings ruby-prof reports for each thread may be slightly
407
+ inaccurate. In particular, this will happen for newly
408
+ spanned threads that immediately go to sleep. For instance,
409
+ if you use Ruby's timeout library to wait for 2 seconds,
410
+ the 2 seconds will be assigned to the foreground thread
411
+ and not the newly created background thread. These errors
412
+ can largely be avoided if the background thread performs an
413
+ operation before going to sleeep.
414
+
415
+
416
+ == Performance
417
+
418
+ Significant effort has been put into reducing ruby-prof's overhead
419
+ as much as possible. Our tests show that the overhead associated
420
+ with profiling code varies considerably with the code being
421
+ profiled. Most programs will run approximately twice as slow
422
+ while highly recursive programs (like the fibonacci series test)
423
+ will run three times slower.
424
+
425
+
426
+ == Windows Binary
427
+
428
+ The Windows binary is built with the latest version of MinGW. The source
429
+ repository also includes a Microsoft VC++ 2005 solution. If you wish to run
430
+ a debug version of ruby-prof on Windows, then it is highly recommended
431
+ you use VC++.
432
+
433
+
434
+ == License
435
+
436
+ See LICENSE for license information.