ruby-prof 0.10.8 → 0.11.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/CHANGES +38 -18
  2. data/LICENSE +4 -3
  3. data/README.rdoc +30 -66
  4. data/Rakefile +47 -54
  5. data/bin/ruby-prof +24 -4
  6. data/ext/ruby_prof/extconf.rb +9 -16
  7. data/ext/ruby_prof/rp_call_info.c +369 -0
  8. data/ext/ruby_prof/rp_call_info.h +46 -0
  9. data/ext/ruby_prof/rp_measure.c +48 -0
  10. data/ext/ruby_prof/rp_measure.h +45 -0
  11. data/ext/ruby_prof/rp_measure_allocations.c +86 -0
  12. data/ext/ruby_prof/rp_measure_cpu_time.c +112 -0
  13. data/ext/ruby_prof/rp_measure_gc_runs.c +87 -0
  14. data/ext/ruby_prof/rp_measure_gc_time.c +73 -0
  15. data/ext/ruby_prof/rp_measure_memory.c +81 -0
  16. data/ext/ruby_prof/rp_measure_process_time.c +71 -0
  17. data/ext/ruby_prof/rp_measure_wall_time.c +42 -0
  18. data/ext/ruby_prof/rp_method.c +363 -0
  19. data/ext/ruby_prof/rp_method.h +55 -0
  20. data/ext/ruby_prof/rp_stack.c +61 -0
  21. data/ext/ruby_prof/rp_stack.h +40 -0
  22. data/ext/ruby_prof/rp_thread.c +113 -0
  23. data/ext/ruby_prof/rp_thread.h +20 -0
  24. data/ext/ruby_prof/ruby_prof.c +259 -1398
  25. data/ext/ruby_prof/ruby_prof.h +54 -190
  26. data/ext/ruby_prof/version.h +6 -3
  27. data/lib/1.8/ruby_prof.so +0 -0
  28. data/lib/1.9/ruby_prof.exp +0 -0
  29. data/lib/1.9/ruby_prof.ilk +0 -0
  30. data/lib/1.9/ruby_prof.lib +0 -0
  31. data/lib/1.9/ruby_prof.pdb +0 -0
  32. data/lib/1.9/ruby_prof.so +0 -0
  33. data/lib/ruby-prof.rb +14 -11
  34. data/lib/ruby-prof/abstract_printer.rb +10 -0
  35. data/lib/ruby-prof/aggregate_call_info.rb +2 -0
  36. data/lib/ruby-prof/call_info.rb +2 -0
  37. data/lib/ruby-prof/call_stack_printer.rb +2 -4
  38. data/lib/ruby-prof/call_tree_printer.rb +1 -0
  39. data/lib/ruby-prof/compatibility.rb +134 -0
  40. data/lib/ruby-prof/dot_printer.rb +7 -7
  41. data/lib/ruby-prof/flat_printer.rb +7 -7
  42. data/lib/ruby-prof/flat_printer_with_line_numbers.rb +2 -5
  43. data/lib/ruby-prof/graph_html_printer.rb +4 -2
  44. data/lib/ruby-prof/graph_printer.rb +4 -3
  45. data/lib/ruby-prof/method_info.rb +2 -0
  46. data/lib/ruby-prof/multi_printer.rb +2 -0
  47. data/lib/ruby-prof/{result.rb → profile.rb} +3 -1
  48. data/lib/ruby-prof/rack.rb +1 -0
  49. data/lib/ruby-prof/symbol_to_proc.rb +2 -0
  50. data/lib/ruby-prof/task.rb +1 -0
  51. data/lib/ruby-prof/test.rb +2 -0
  52. data/lib/ruby_prof.exp +0 -0
  53. data/lib/ruby_prof.ilk +0 -0
  54. data/lib/ruby_prof.lib +0 -0
  55. data/lib/ruby_prof.pdb +0 -0
  56. data/lib/ruby_prof.so +0 -0
  57. data/lib/unprof.rb +2 -0
  58. data/test/aggregate_test.rb +8 -8
  59. data/test/basic_test.rb +3 -251
  60. data/test/bug_test.rb +6 -0
  61. data/test/duplicate_names_test.rb +2 -2
  62. data/test/dynamic_method_test.rb +61 -0
  63. data/test/enumerable_test.rb +2 -2
  64. data/test/exceptions_test.rb +4 -3
  65. data/test/exclude_threads_test.rb +2 -2
  66. data/test/exec_test.rb +3 -3
  67. data/test/line_number_test.rb +5 -5
  68. data/test/measure_allocations_test.rb +25 -0
  69. data/test/measure_cpu_time_test.rb +212 -0
  70. data/test/measure_gc_runs_test.rb +29 -0
  71. data/test/measure_gc_time_test.rb +29 -0
  72. data/test/measure_memory_test.rb +36 -0
  73. data/test/measure_process_time_test.rb +205 -0
  74. data/test/measure_wall_time_test.rb +209 -0
  75. data/test/method_elimination_test.rb +2 -2
  76. data/test/module_test.rb +3 -2
  77. data/test/multi_printer_test.rb +2 -2
  78. data/test/no_method_class_test.rb +3 -1
  79. data/test/prime_test.rb +3 -3
  80. data/test/printers_test.rb +106 -8
  81. data/test/recursive_test.rb +7 -6
  82. data/test/singleton_test.rb +2 -2
  83. data/test/stack_printer_test.rb +2 -3
  84. data/test/stack_test.rb +2 -2
  85. data/test/start_stop_test.rb +2 -2
  86. data/test/test_helper.rb +81 -0
  87. data/test/test_suite.rb +34 -29
  88. data/test/thread_test.rb +24 -23
  89. data/test/unique_call_path_test.rb +2 -2
  90. metadata +101 -69
  91. data/ext/ruby_prof/measure_allocations.h +0 -83
  92. data/ext/ruby_prof/measure_cpu_time.h +0 -152
  93. data/ext/ruby_prof/measure_gc_runs.h +0 -76
  94. data/ext/ruby_prof/measure_gc_time.h +0 -57
  95. data/ext/ruby_prof/measure_memory.h +0 -101
  96. data/ext/ruby_prof/measure_process_time.h +0 -63
  97. data/ext/ruby_prof/measure_wall_time.h +0 -53
  98. data/ext/ruby_prof/mingw/Rakefile +0 -23
  99. data/ext/ruby_prof/mingw/build.rake +0 -38
  100. data/rails/environment/profile.rb +0 -24
  101. data/rails/example/example_test.rb +0 -9
  102. data/rails/profile_test_helper.rb +0 -21
  103. data/test/current_failures_windows +0 -8
  104. data/test/measurement_test.rb +0 -132
  105. data/test/ruby-prof-bin +0 -20
data/CHANGES CHANGED
@@ -1,48 +1,68 @@
1
- 0.10.8
1
+ 0.11.0.rc1 (2012-03-24)
2
2
  ======================
3
- rename extension to ruby_prof_ext to avoid confusion when people ran require 'ruby_prof' accidentally.
3
+ * On Windows, use QueryPerformanceCounter and QueryPerformanceFrequency to measure CPU time instead
4
+ of rdtsc. This change is based on Microsoft's recommendation (Charlie Savage).
5
+ * On Windows use GetProcessTimes to return real PROCESS_TIME times instead of wall times (Charlie Savage).
6
+ * Big internal refactoring of C code to make RubyProf easier to understand and extend (Charlie Savage).
7
+ * Profile results are now returned as instances of a new class RubyProf::Profile. The old api
8
+ is supported via a compatability layer that at some point will be deprecated. (Charlie Savage).
9
+ * Split out tests for cpu_time, process_time and wall_time into separate files (Charlie Savage).
10
+ * Dropped support for Ruby 1.8.4 and 1.8.6 - does anybody still use these? (Charlie Savage).
11
+ * Added support for sorting results by total, self, wait and child times (Jan Suchal)
12
+ * Added tests for sorting behaviour & removed options from constructor to print method (Jan Suchal)
13
+ * Fix line number tests due to changes at top of file (Charlie Savage).
14
+ * Add encoding statement to top of all files for Ruby 1.9.x compatability (Charlie Savage).
15
+ * Add def file for VC to avoid the whole declspec annoyance (Charlie Savage).
16
+ * Update test suite to ensure current working directory is correct (Charlie Savage).
17
+ * Modernize gem file and remove various custom/home grown solutions that aren't needed anymore (Charlie Savage).
18
+ * Remove custom mingw build scripts, use rake compiler instead (Charlie Savage).
19
+ * Fixes for compiling with VC 2010 (Charlie Savage).
20
+
21
+ 0.10.8 (2011-07-06)
22
+ ======================
23
+ * 1.9.3 super class (Roger Pack)
4
24
 
5
- 0.10.7
25
+ 0.10.7 (2011-05-09)
6
26
  ======================
7
- Fix a bug with REE's GC stats. Issue #53 [thanks graaff]
27
+ * Fix a bug with REE's GC stats. Issue #53 [thanks graaff]
8
28
 
9
- 0.10.6
29
+ 0.10.6 (2011-04-29)
10
30
  ======================
11
- Slightly more normalized url for linux/windows links to files.
31
+ * Slightly more normalized url for linux/windows links to files.
12
32
 
13
- 0.10.5
33
+ 0.10.5 (2011-04-20)
14
34
  =======================
15
- 1.8.6 compat for -v command (bug fix)
35
+ * 1.8.6 compat for -v command (bug fix)
16
36
 
17
- 0.10.4
37
+ 0.10.4 (2011-04-20)
18
38
  =======================
19
- Faster load time for ruby-prof itself.
39
+ * Faster load time for ruby-prof itself.
20
40
 
21
41
  0.10.3
22
42
  =======================
23
- Can cleanly load before rubygems now.
43
+ * Can cleanly load before rubygems now.
24
44
 
25
45
  0.10.2
26
46
  =======================
27
- Fix for 1.9.2, os x for latest commits (thanks skaes!)
47
+ * Fix for 1.9.2, os x for latest commits (thanks skaes!)
28
48
 
29
49
  0.10.1
30
50
  =======================
31
- Fix bug in linux wall time, also load with only relative paths so that you can use it to benchmark rubygems startup overhead,
32
- itself.
51
+ * Fix bug in linux wall time, also load with only relative paths so that you can use it to benchmark rubygems startup overhead,
52
+ itself.
33
53
 
34
54
  0.10.0
35
55
  =======================
36
- Some rdoc changes, for linux wall time attempt to use higher granularity (thanks to all the contributors for this round!)
56
+ * Some rdoc changes, for linux wall time attempt to use higher granularity (thanks to all the contributors for this round!)
37
57
 
38
58
  0.9.2
39
59
  =======================
40
- Make graphviz work on 1.8.6
41
- roll back some 1.9.2 optimizations until I can figure out what caused them.
60
+ * Make graphviz work on 1.8.6
61
+ * Roll back some 1.9.2 optimizations until I can figure out what caused them.
42
62
 
43
63
  0.9.1
44
64
  =======================
45
- Add a graphviz output
65
+ * Add a graphviz output
46
66
 
47
67
  0.9.0
48
68
  =======================
data/LICENSE CHANGED
@@ -1,15 +1,16 @@
1
- Copyright (C) 2005 Shugo Maeda <shugo@ruby-lang.org>
1
+ Copyright (C) 2005 - 20011 Shugo Maeda <shugo@ruby-lang.org> and Charlie Savage <cfis@savagexi.com>
2
2
  All rights reserved.
3
- *
3
+
4
4
  Redistribution and use in source and binary forms, with or without
5
5
  modification, are permitted provided that the following conditions
6
6
  are met:
7
+
7
8
  1. Redistributions of source code must retain the above copyright
8
9
  notice, this list of conditions and the following disclaimer.
9
10
  2. Redistributions in binary form must reproduce the above copyright
10
11
  notice, this list of conditions and the following disclaimer in the
11
12
  documentation and/or other materials provided with the distribution.
12
- *
13
+
13
14
  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
14
15
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
16
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -15,7 +15,7 @@ ruby-prof is a fast code profiler for Ruby. Its features include:
15
15
 
16
16
  == Requirements
17
17
 
18
- ruby-prof requires Ruby 1.8.4 or higher.
18
+ ruby-prof requires Ruby 1.8.7 or 1.9.1 and higher.
19
19
 
20
20
  If you are running Linux or Unix you'll need a C compiler so the extension
21
21
  can be compiled when it is installed.
@@ -29,16 +29,12 @@ The easiest way to install ruby-prof is by using Ruby Gems. To install:
29
29
 
30
30
  gem install ruby-prof
31
31
 
32
- If you on windows mswin [not mingw] (check via ruby -v) and
33
- don't have an MSVC compiler, please install v0.8.1 which
34
- has a prebuilt binary
35
- C:> gem install ruby-prof -v0.8.1
36
-
37
- If you're on mingw, please install the devkit first, then install the latest gem version (via gem install ruby-prof).
32
+ If you're on windows then a prebuilt binary gem is available. You may of course
33
+ compile it yourself via use of devkit on MinGW.
38
34
 
39
35
  == Usage
40
36
 
41
- There are three ways of running ruby-prof.
37
+ There are two ways of running ruby-prof, via the command line or via its API.
42
38
 
43
39
  === ruby-prof executable
44
40
 
@@ -81,8 +77,7 @@ to profile:
81
77
  printer = RubyProf::GraphPrinter.new(result)
82
78
  printer.print(STDOUT, {})
83
79
 
84
- Starting with the 0.6.1 release, ruby-prof also supports pausing and resuming
85
- profiling runs.
80
+ ruby-prof also supports pausing and resuming profiling runs.
86
81
 
87
82
  require 'ruby-prof'
88
83
 
@@ -110,18 +105,10 @@ has not yet started. In addition, resume can also take a block:
110
105
  With this usage, resume will automatically call pause at the
111
106
  end of the block.
112
107
 
113
- === require unprof
114
-
115
- The third way of using ruby-prof is by requiring unprof.rb:
116
-
117
- require 'unprof'
118
-
119
- This will start profiling immediately at that point and will output the results
120
- using a flat profile report when the process ends.
121
108
 
122
- == Method Elimination
109
+ == Method and Thread Elimination
123
110
 
124
- Starting with release 0.9.0, ruby-prof supports eliminating methods from profiling
111
+ ruby-prof supports eliminating specific methods and threads from profiling
125
112
  results. This is useful for reducing connectivity in the call graph, making it easier to
126
113
  identify the source of performance problems when using a graph printer.
127
114
 
@@ -141,6 +128,15 @@ the name of a file containing a list of regular expressions (line separated text
141
128
  After eliminating methods the resulting profile will appear exactly as if those methods
142
129
  had been inlined at their call sites.
143
130
 
131
+ In a similar manner, threads can be excluded so they are not profiled at all. To do this,
132
+ pass an array of threads to exclude to ruby-prof:
133
+
134
+ RubyProf::exclude_threads = [ thread2 ]
135
+ RubyProf.start
136
+
137
+ Note that the excluded threads must be specified *before* profiling.
138
+
139
+
144
140
  == Benchmarking full load time including rubygems startup cost ==
145
141
 
146
142
  If you want to get a more accurate measurement of what takes all of a gem's bin/xxx
@@ -160,7 +156,7 @@ $ ruby g:/192/lib/ruby/gems/1.9.1/gems/ruby-prof-0.10.2/bin/ruby-prof ./some_fil
160
156
 
161
157
  == Profiling Tests
162
158
 
163
- Starting with the 0.6.1 release, ruby-prof supports profiling tests cases
159
+ ruby-prof supports profiling tests cases
164
160
  written using Ruby's built-in unit test framework (ie, test derived from
165
161
  Test::Unit::TestCase). To enable profiling simply add the following line
166
162
  of code to within your test class:
@@ -189,49 +185,23 @@ profile.rb.
189
185
 
190
186
  So to profile Rails:
191
187
 
192
- 1. Create a new profile.rb environment - or simply copy the example file
193
- in ruby-prof/rails/environment/profile.rb
194
-
195
- 2. Copy the file:
196
-
197
- ruby-prof/rails/profile_test_helper.rb
198
-
199
- To:
200
-
201
- your_rails_app/test/profile_test_helper.rb
188
+ 1. Create a new profile.rb environment. Make sure to turn on cache_classes
189
+ and cache_template_loading. Otherwise your profiling results will be
190
+ overwhelemed by the time Rails spends loading required files.
202
191
 
203
- 3. Create a new test directory for profiling:
192
+ 2. Add the ruby prof rack adapter to your middleware stack. One way to
193
+ do this is by adding the following code to config.ru:
204
194
 
205
- your_rails_app/test/profile
206
-
207
-
208
- 4. Write unit, functional or integration tests specifically designed
209
- to profile some part of your Rails application. At the top
210
- of each test, replace this line:
211
-
212
- require File.dirname(__FILE__) + '/../test_helper'
213
-
214
- With:
215
-
216
- require File.dirname(__FILE__) + '/../profile_test_helper'
217
-
218
- For example:
219
-
220
- require File.dirname(__FILE__) + '/../profile_test_helper'
221
-
222
- class ExampleTest < Test::Unit::TestCase
223
- include RubyProf::Test
224
- fixtures ....
225
-
226
- def test_stuff
227
- puts "Test method"
228
- end
229
- end
230
-
231
- 5. Now run your tests. Results will be written to:
195
+ if Rails.env.profile?
196
+ use Rack::RubyProf, :path => '/temp/profile'
197
+ end
232
198
 
233
- your_rails_app/tmp/profile
199
+ The path is where you want profiling results to be stored. By default the
200
+ rack adapter will generate a html call graph report and flat text report.
234
201
 
202
+ 3. Now make a request to your running server. New profiling information will
203
+ be generated for each request. Note that each request will overwrite
204
+ the profiling reports created by the previous request!
235
205
 
236
206
  == Reports
237
207
 
@@ -389,8 +359,6 @@ environment variable:
389
359
  * export RUBY_PROF_MEASURE_MODE=gc_runs
390
360
  * export RUBY_PROF_MEASURE_MODE=gc_time
391
361
 
392
- Note that these values have changed since ruby-prof-0.3.0.
393
-
394
362
  On Linux, process time is measured using the clock method provided
395
363
  by the C runtime library. Note that the clock method does not
396
364
  report time spent in the kernel or child processes and therefore
@@ -446,10 +414,6 @@ profiled. Most programs will run approximately twice as slow
446
414
  while highly recursive programs (like the fibonacci series test)
447
415
  will run three times slower.
448
416
 
449
- Because of some threading difficulties in 1.9, it currently runs a
450
- bit slower there, as well.
451
- http://www.ruby-forum.com/topic/201329
452
-
453
417
  == License
454
418
 
455
419
  See LICENSE for license information.
data/Rakefile CHANGED
@@ -1,38 +1,61 @@
1
- require 'rubygems'
2
- require 'rake/gempackagetask'
3
- require 'rake/rdoctask'
4
- require 'rake/testtask'
5
- require 'date'
1
+ # encoding: utf-8
6
2
 
7
- # to release a version of ruby-prof, do a git tag, then rake cleanr default and publish that
8
- # git tag 0.10.1
9
- # git push origin 0.10.1
10
- # rake cleanr default
11
- # gem push pkg/ruby-prof-0.10.1.gem
3
+ require "rubygems/package_task"
4
+ require "rake/extensiontask"
5
+ require "rake/testtask"
6
+ require "rdoc/task"
7
+ require "date"
12
8
 
13
- default_spec = eval File.read(File.expand_path('../ruby-prof.gemspec', __FILE__))
9
+ # To release a version of ruby-prof:
10
+ # * Update version.h
11
+ # * Update CHANGES
12
+ # * Update rdocs
13
+ # * git commit to commit files
14
+ # * rake clobber to remove extra files
15
+ # * rake compile to build windows gems
16
+ # * rake package to create the gems
17
+ # * Tag the release in git (tag 0.10.1)
18
+ # * Push to ruybgems.org (gem push pkg/<gem files>)
14
19
 
15
- desc 'deprecated--build native .gem files -- use like "native_gems clobber cross native gem"--for non native gem creation use "native_gems clobber" then "clean gem"'
16
- task :native_gems do
17
- # we don't do cross compiler anymore, now that mingw has devkit
18
- ENV['RUBY_CC_VERSION'] = '1.8.6:1.9.1'
19
- require 'rake/extensiontask'
20
- Rake::ExtensionTask.new('ruby_prof', default_spec) do |ext|
21
- ext.cross_compile = true
22
- ext.cross_platform = ['x86-mswin32-60', 'x86-mingw32-60']
23
- end
20
+ GEM_NAME = 'ruby-prof'
21
+ SO_NAME = 'ruby_prof'
22
+
23
+ default_spec = Gem::Specification.load("#{GEM_NAME}.gemspec")
24
+
25
+ Rake::ExtensionTask.new do |ext|
26
+ ext.gem_spec = default_spec
27
+ ext.name = SO_NAME
28
+ ext.ext_dir = "ext/#{SO_NAME}"
29
+ ext.lib_dir = "lib/#{RUBY_VERSION.sub(/\.\d$/, '')}"
30
+ ext.cross_compile = true
31
+ ext.cross_platform = ['x86-mswin32-60', 'x86-mingw32-60']
24
32
  end
25
33
 
26
34
  # Rake task to build the default package
27
- Rake::GemPackageTask.new(default_spec) do |pkg|
35
+ Gem::PackageTask.new(default_spec) do |pkg|
28
36
  pkg.need_tar = true
29
- #pkg.need_zip = true
30
37
  end
31
38
 
39
+ # Setup Windows Gem
40
+ if RUBY_PLATFORM.match(/win32|mingw32/)
41
+ # Windows specification
42
+ win_spec = default_spec.clone
43
+ win_spec.platform = Gem::Platform::CURRENT
44
+ win_spec.files += Dir.glob('lib/**/*.so')
45
+ win_spec.instance_variable_set(:@cache_file, nil) # Hack to work around gem issue
46
+
47
+ # Unset extensions
48
+ win_spec.extensions = nil
49
+
50
+ # Rake task to build the windows package
51
+ Gem::PackageTask.new(win_spec) do |pkg|
52
+ pkg.need_tar = false
53
+ end
54
+ end
32
55
 
33
56
  # --------- RDoc Documentation ------
34
57
  desc "Generate rdoc documentation"
35
- Rake::RDocTask.new("rdoc") do |rdoc|
58
+ RDoc::Task.new("rdoc") do |rdoc|
36
59
  rdoc.rdoc_dir = 'doc'
37
60
  rdoc.title = "ruby-prof"
38
61
  # Show source inline with line numbers
@@ -60,34 +83,4 @@ Rake::TestTask.new do |t|
60
83
  t.test_files = Dir['test/test_suite.rb']
61
84
  t.verbose = true
62
85
  t.warning = true
63
- end
64
-
65
- require 'fileutils'
66
-
67
- desc 'Build ruby_prof.so'
68
- task :build do
69
- Dir.chdir('ext/ruby_prof') do
70
- unless File.exist? 'Makefile'
71
- system(Gem.ruby + " extconf.rb")
72
- system("make clean")
73
- end
74
- raise 'make failed' unless system("make")
75
- FileUtils.cp 'ruby_prof.so', '../../lib' if File.exist? 'lib/ruby_prof.so'
76
- FileUtils.cp 'ruby_prof.bundle', '../../lib' if File.exist? 'lib/ruby_prof.bundle'
77
- end
78
- end
79
-
80
- desc 'clean stuff'
81
- task :cleanr do
82
- Dir['**/*.{so,bundle}'].each{|f| File.delete f}
83
- Dir.chdir('ext/ruby_prof') do
84
- if File.exist? 'Makefile'
85
- system("make clean")
86
- FileUtils.rm 'Makefile'
87
- end
88
- Dir.glob('*~') do |file|
89
- FileUtils.rm file
90
- end
91
- end
92
- system("rm -rf pkg")
93
- end
86
+ end
@@ -15,7 +15,7 @@
15
15
 
16
16
  require 'ostruct'
17
17
  require 'optparse'
18
- require File.dirname(__FILE__) + "/../lib/ruby-prof"
18
+ require File.expand_path('../../lib/ruby-prof', __FILE__)
19
19
 
20
20
  options = OpenStruct.new
21
21
  options.measure_mode = RubyProf::PROCESS_TIME
@@ -104,7 +104,26 @@ opts = OptionParser.new do |opts|
104
104
  options.measure_mode = RubyProf::GC_TIME
105
105
  end
106
106
  end
107
-
107
+
108
+ opts.on('-s sort_mode', '--sort=sort_mode', [:total, :self, :wait, :child],
109
+ 'Select how ruby-prof results should be sorted:',
110
+ ' total - Total time',
111
+ ' self - Self time',
112
+ ' wait - Wait time',
113
+ ' child - Child time') do |sort_mode|
114
+
115
+ options.sort_method = case sort_mode
116
+ when :total
117
+ :total_time
118
+ when :self
119
+ :self_time
120
+ when :wait
121
+ :wait_time
122
+ when :child
123
+ :children_time
124
+ end
125
+ end
126
+
108
127
  opts.on("--replace-progname", "Replace $0 when loading the .rb files.") do
109
128
  options.replace_prog_name = true
110
129
  end
@@ -184,18 +203,19 @@ at_exit {
184
203
 
185
204
  # Create a printer
186
205
  printer = options.printer.new(result)
206
+ printer_options = {:min_percent => options.min_percent, :sort_method => options.sort_method}
187
207
 
188
208
  # Get output
189
209
  if options.file
190
210
  # 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.
191
211
  Dir.chdir(options.old_wd) do
192
212
  File.open(options.file, 'w') do |file|
193
- printer.print(file, {:min_percent => options.min_percent})
213
+ printer.print(file, printer_options)
194
214
  end
195
215
  end
196
216
  else
197
217
  # Print out results
198
- printer.print(STDOUT, {:min_percent => options.min_percent})
218
+ printer.print(STDOUT, printer_options)
199
219
  end
200
220
  }
201
221