ruby-prof 0.9.2 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/CHANGES +13 -0
  2. data/README.rdoc +23 -9
  3. data/Rakefile +7 -62
  4. data/bin/ruby-prof +47 -38
  5. data/examples/empty.png +0 -0
  6. data/examples/minus.png +0 -0
  7. data/examples/plus.png +0 -0
  8. data/ext/ruby_prof/extconf.rb +15 -1
  9. data/ext/ruby_prof/measure_allocations.h +25 -0
  10. data/ext/ruby_prof/measure_process_time.h +12 -1
  11. data/ext/ruby_prof/ruby_prof.c +1 -1
  12. data/ext/ruby_prof/version.h +2 -2
  13. data/lib/ruby-prof.rb +9 -15
  14. data/lib/ruby-prof/call_stack_printer.rb +27 -1
  15. data/lib/ruby-prof/call_tree_printer.rb +12 -1
  16. data/lib/ruby-prof/dot_printer.rb +0 -1
  17. data/lib/ruby-prof/empty.png +0 -0
  18. data/lib/ruby-prof/flat_printer.rb +1 -2
  19. data/lib/ruby-prof/flat_printer_with_line_numbers.rb +2 -3
  20. data/lib/ruby-prof/graph_html_printer.rb +7 -1
  21. data/lib/ruby-prof/graph_printer.rb +1 -2
  22. data/lib/ruby-prof/minus.png +0 -0
  23. data/lib/ruby-prof/plus.png +0 -0
  24. data/lib/ruby-prof/rack.rb +7 -5
  25. data/lib/ruby-prof/task.rb +0 -0
  26. data/test/aggregate_test.rb +0 -0
  27. data/test/basic_test.rb +0 -0
  28. data/test/duplicate_names_test.rb +0 -0
  29. data/test/enumerable_test.rb +0 -0
  30. data/test/exceptions_test.rb +0 -0
  31. data/test/exclude_threads_test.rb +0 -0
  32. data/test/exec_test.rb +0 -0
  33. data/test/line_number_test.rb +0 -0
  34. data/test/measurement_test.rb +0 -0
  35. data/test/module_test.rb +1 -1
  36. data/test/multi_printer_test.rb +0 -0
  37. data/test/no_method_class_test.rb +0 -0
  38. data/test/printers_test.rb +0 -0
  39. data/test/recursive_test.rb +0 -0
  40. data/test/singleton_test.rb +0 -0
  41. data/test/stack_printer_test.rb +0 -0
  42. data/test/stack_test.rb +0 -0
  43. data/test/start_stop_test.rb +0 -0
  44. data/test/thread_test.rb +0 -0
  45. data/test/unique_call_path_test.rb +0 -0
  46. metadata +10 -7
  47. data/test/bad.rb +0 -6
  48. data/test/basic2_test.rb +0 -20
data/CHANGES CHANGED
@@ -1,3 +1,16 @@
1
+ 0.10.2
2
+ =======================
3
+ Fix for 1.9.2, os x for latest commits (thanks skaes!)
4
+
5
+ 0.10.1
6
+ =======================
7
+ Fix bug in linux wall time, also load with only relative paths so that you can use it to benchmark rubygems startup overhead,
8
+ itself.
9
+
10
+ 0.10.0
11
+ =======================
12
+ Some rdoc changes, for linux wall time attempt to use higher granularity (thanks to all the contributors for this round!)
13
+
1
14
  0.9.2
2
15
  =======================
3
16
  Make graphviz work on 1.8.6
data/README.rdoc CHANGED
@@ -12,7 +12,6 @@ ruby-prof is a fast code profiler for Ruby. Its features include:
12
12
  - Call tree profiles - outputs results in the calltree format suitable for the KCacheGrind profiling tool.
13
13
  * Threads - supports profiling multiple threads simultaneously
14
14
 
15
-
16
15
  == Requirements
17
16
 
18
17
  ruby-prof requires Ruby 1.8.4 or higher.
@@ -21,7 +20,7 @@ If you are running Linux or Unix you'll need a C compiler so the extension
21
20
  can be compiled when it is installed.
22
21
 
23
22
  If you are running Windows, then you may need to install the
24
- Windows specific RubyGem which includes an already built extension (see below).
23
+ Windows specific RubyGem which includes an already built extension (see Install section).
25
24
 
26
25
  == Install
27
26
 
@@ -32,9 +31,9 @@ The easiest way to install ruby-prof is by using Ruby Gems. To install:
32
31
  If you on windows mswin [not mingw] (check via ruby -v) and
33
32
  don't have an MSVC compiler, please install v0.7.3 which
34
33
  has a prebuilt binary
35
- C:> gem install ruby-prof -v0.7.3
34
+ C:> gem install ruby-prof -v0.8.1
36
35
 
37
- If you're on mingw, please install the devkit first, then install the latest version (gem install ruby-prof).
36
+ If you're on mingw, please install the devkit first, then install the latest gem version (gem install ruby-prof).
38
37
 
39
38
  == Usage
40
39
 
@@ -79,7 +78,7 @@ to profile:
79
78
 
80
79
  # Print a graph profile to text
81
80
  printer = RubyProf::GraphPrinter.new(result)
82
- printer.print(STDOUT, 0)
81
+ printer.print(STDOUT, {})
83
82
 
84
83
  Starting with the 0.6.1 release, ruby-prof also supports pausing and resuming
85
84
  profiling runs.
@@ -117,11 +116,22 @@ The third way of using ruby-prof is by requiring unprof.rb:
117
116
 
118
117
  require 'unprof'
119
118
 
120
- This will start profiling immediately and will output the results
121
- using a flat profile report.
119
+ This will start profiling immediately at that point and will output the results
120
+ using a flat profile report after the process ends.
121
+
122
+
123
+ == Benchmarking full load time ==
124
+
125
+ If you want to get a more accurate measurement of what takes a gem's bin/xxx
126
+ command its time to load, you may want to also measure rubygems' startup penalty.
127
+ You can do this by calling into bin/ruby-prof directly, ex:
122
128
 
123
- This method is provided for backwards compatibility. Using the
124
- ruby-prof command provides more flexibility.
129
+
130
+ $ ruby C:/installs/Ruby187/lib/ruby/gems/1.8/gems/ruby-prof-0.10.0/bin/ruby-prof D:\Ruby192\bin\ruby-prof
131
+
132
+ or
133
+
134
+ $ ruby C:/installs/Ruby187/lib/ruby/gems/1.8/gems/ruby-prof-0.10.0/bin/ruby-prof some_file_that_does_a_require_rubygems_at_the_beginning
125
135
 
126
136
  == Method Elimination
127
137
 
@@ -230,6 +240,7 @@ ruby-prof can generate a number of different reports:
230
240
  * HTML Graph Reports
231
241
  * Call graphs
232
242
  * Call stack reports
243
+ * More!
233
244
 
234
245
  Flat profiles show the overall time spent in each method. They
235
246
  are a good of quickly identifying which methods take the most time.
@@ -276,6 +287,7 @@ Reports are created by printers. Supported printers include:
276
287
  * RubyProf::CallTreePrinter - Creates a call tree report compatible with KCachegrind.
277
288
  * RubyProf::CallStackPrinter - Creates a HTML visualization of the Ruby stack
278
289
  * RubyProf::MultiPrinter - Uses the other printers to create several reports in one profiling run
290
+ * More!
279
291
 
280
292
  To use a printer:
281
293
 
@@ -437,3 +449,5 @@ See LICENSE for license information.
437
449
  == Development
438
450
 
439
451
  Code is located at http://github.com/rdp/ruby-prof
452
+
453
+ Google group/mailing list: http://groups.google.com/group/ruby-prof
data/Rakefile CHANGED
@@ -4,68 +4,14 @@ require 'rake/rdoctask'
4
4
  require 'rake/testtask'
5
5
  require 'date'
6
6
 
7
- # ------- Version ----
8
- # Read version from header file
9
- version_header = File.read('ext/ruby_prof/version.h')
10
- match = version_header.match(/RUBY_PROF_VERSION\s*["](\d.+)["]/)
11
- raise(RuntimeError, "Could not determine RUBY_PROF_VERSION") if not match
12
- RUBY_PROF_VERSION = match[1]
13
7
 
8
+ # to release it, do a git tag, then rake cleanr default and publish that
9
+ # git tag 0.10.1
10
+ # git push origin 0.10.1
11
+ # rake cleanr default
12
+ # gem push pkg/ruby-prof-0.10.1.gem
14
13
 
15
- # ------- Default Package ----------
16
- FILES = FileList[
17
- 'Rakefile',
18
- 'README.rdoc',
19
- 'LICENSE',
20
- 'CHANGES',
21
- 'bin/*',
22
- 'doc/**/*',
23
- 'examples/*',
24
- 'ext/ruby_prof/*.c',
25
- 'ext/ruby_prof/*.h',
26
- 'ext/ruby_prof/mingw/Rakefile',
27
- 'ext/ruby_prof/mingw/build.rake',
28
- 'ext/vc/*.sln',
29
- 'ext/vc/*.vcproj',
30
- 'lib/**/*',
31
- 'rails/**/*',
32
- 'test/*'
33
- ]
34
-
35
- # Default GEM Specification
36
- default_spec = Gem::Specification.new do |spec|
37
- spec.name = "ruby-prof"
38
-
39
- spec.homepage = "http://rubyforge.org/projects/ruby-prof/"
40
- spec.summary = "Fast Ruby profiler"
41
- spec.description = <<-EOF
42
- ruby-prof is a fast code profiler for Ruby. It is a C extension and
43
- therefore is many times faster than the standard Ruby profiler. It
44
- supports both flat and graph profiles. For each method, graph profiles
45
- show how long the method ran, which methods called it and which
46
- methods it called. RubyProf generate both text and html and can output
47
- it to standard out or to a file.
48
- EOF
49
-
50
- spec.version = RUBY_PROF_VERSION
51
-
52
- spec.author = "Shugo Maeda, Charlie Savage, Roger Pack, Stefan Kaes"
53
- spec.email = "shugo@ruby-lang.org, cfis@savagexi.com, rogerdpack@gmail.com, skaes@railsexpress.de"
54
- spec.platform = Gem::Platform::RUBY
55
- spec.require_path = "lib"
56
- spec.bindir = "bin"
57
- spec.executables = ["ruby-prof"]
58
- spec.extensions = ["ext/ruby_prof/extconf.rb"]
59
- spec.files = FILES.to_a
60
- spec.test_files = Dir["test/test_*.rb"]
61
- spec.required_ruby_version = '>= 1.8.4'
62
- spec.date = DateTime.now
63
- spec.rubyforge_project = 'ruby-prof'
64
- spec.add_development_dependency 'os'
65
- spec.add_development_dependency 'rake-compiler'
66
-
67
- end
68
-
14
+ default_spec = eval File.read(File.expand_path('../ruby-prof.gemspec', __FILE__))
69
15
 
70
16
  desc 'build native .gem files -- use like "native_gems clobber cross native gem"--for non native gem creation use "native_gems clobber" then "clean gem"'
71
17
  task :native_gems do
@@ -133,8 +79,7 @@ end
133
79
 
134
80
  desc 'clean stuff'
135
81
  task :cleanr do
136
- FileUtils.rm 'lib/ruby_prof.so' if File.exist? 'lib/ruby_prof.so'
137
- FileUtils.rm 'lib/ruby_prof.bundle' if File.exist? 'lib/ruby_prof.bundle'
82
+ Dir['**/*.{so,bundle}'].each{|f| File.delete f}
138
83
  Dir.chdir('ext/ruby_prof') do
139
84
  if File.exist? 'Makefile'
140
85
  system("make clean")
data/bin/ruby-prof CHANGED
@@ -9,37 +9,7 @@
9
9
  # ruby_prof [options] <script.rb> [--] [script-options]"
10
10
  #
11
11
  # Options:
12
- # -p, --printer=printer Select a printer:
13
- # flat - Prints a flat profile as text (default).
14
- # flat_with_line_numbers - Above, with line numbers
15
- # graph - Prints a graph profile as text.
16
- # graph_html - Prints a graph profile as html.
17
- # call_tree - format for KCacheGrind
18
- # call_stack - prints a HTML visualization of the call tree
19
- # dot - Prints a graph profile as a dot file
20
- # -f, --file=path Output results to a file instead of standard out.
21
- # -m, --min_percent=min_percent The minimum percent a method must take before ',
22
- # being included in output reports. Should be an
23
- # integer between 1 and 100. 0 means all methods are printed.
24
- # --mode=measure_mode Select a measurement mode:
25
- # process - Use process time (default).
26
- # wall - Use wall time.
27
- # cpu - Use the CPU clock counter
28
- # (only supported on Pentium and PowerPCs).
29
- # allocations - Tracks object allocations
30
- # (requires a patched Ruby interpreter).
31
- # memory - Tracks total memory size
32
- # (requires a patched Ruby interpreter).
33
- # gc_runs - Tracks number of garbage collection runs
34
- # (requires a patched Ruby interpreter).
35
- # gc_time - Tracks time spent doing garbage collection
36
- # (requires a patched Ruby interpreter).
37
- # --replace-progname Replace $0 when loading the .rb files.
38
- # --specialized-instruction Turn on specialized instruction.
39
- # -h, --help Show help message
40
- # --version Show version
41
- # -v Show version, set $VERBOSE to true, run file
42
- # -d Set $DEBUG to true
12
+ # run "$ ruby-prof --help" to see them
43
13
  #
44
14
  #
45
15
  # See also: {flat profiles}[link:files/examples/flat_txt.html], {graph profiles}[link:files/examples/graph_txt.html], {html graph profiles}[link:files/examples/graph_html.html]
@@ -47,7 +17,7 @@
47
17
 
48
18
  require 'ostruct'
49
19
  require 'optparse'
50
- require 'ruby-prof'
20
+ require File.dirname(__FILE__) + "/../lib/ruby-prof"
51
21
 
52
22
  options = OpenStruct.new
53
23
  options.measure_mode = RubyProf::PROCESS_TIME
@@ -59,7 +29,7 @@ options.specialized_instruction = false
59
29
 
60
30
  opts = OptionParser.new do |opts|
61
31
  opts.banner = "ruby_prof #{RubyProf::VERSION}\n" +
62
- "Usage: ruby_prof [options] <script.rb> [--] [script-options]"
32
+ "Usage: ruby-prof [options] <script.rb> [--] [script-options]"
63
33
 
64
34
  opts.separator ""
65
35
  opts.separator "Options:"
@@ -158,14 +128,33 @@ opts = OptionParser.new do |opts|
158
128
  end
159
129
 
160
130
  opts.on("-v","Show version, set $VERBOSE to true, profile script") do
161
- puts "ruby_prof " + RubyProf::VERSION
162
- puts "ruby " + RUBY_DESCRIPTION
163
- $VERBOSE= true
131
+ puts "ruby version: " + RUBY_DESCRIPTION
132
+ $VERBOSE = true
164
133
  end
165
134
 
166
135
  opts.on("-d", "Set $DEBUG to true") do
167
136
  $DEBUG = true
168
137
  end
138
+
139
+ opts.on('-R lib', '--require-noprof lib', 'require a specific library (not profiled)') do |lib|
140
+ options.pre_libs ||= []
141
+ options.pre_libs << lib
142
+ end
143
+
144
+ opts.on('-E code', '--eval-noprof code', 'execute the ruby statements (not profiled)') do |code|
145
+ options.pre_exec ||= []
146
+ options.pre_exec << code
147
+ end
148
+
149
+ opts.on('-r lib', '--require lib', 'require a specific library') do |lib|
150
+ options.libs ||= []
151
+ options.libs << lib
152
+ end
153
+
154
+ opts.on('-e code', '--eval', 'execute the ruby statements') do |code|
155
+ options.exec ||= []
156
+ options.exec << code
157
+ end
169
158
  end
170
159
 
171
160
  begin
@@ -179,7 +168,7 @@ rescue OptionParser::InvalidOption, OptionParser::InvalidArgument,
179
168
  end
180
169
 
181
170
  # Make sure the user specified at least one file
182
- if ARGV.length < 1
171
+ if ARGV.length < 1 and not options.exec
183
172
  puts opts
184
173
  puts ""
185
174
  puts "Must specify a script to run"
@@ -229,8 +218,28 @@ if options.replace_prog_name
229
218
  $0 = File.expand_path(script)
230
219
  end
231
220
 
221
+ if options.pre_libs
222
+ options.pre_libs.each { |l| require l }
223
+ end
224
+
225
+ if options.pre_exec
226
+ options.pre_exec.each { |c| eval c }
227
+ end
228
+
229
+ # do not pollute profiling report with OpenStruct#libs
230
+ ol = options.libs
231
+ oe = options.exec
232
+
232
233
  # Start profiling
233
234
  RubyProf.start
234
235
 
236
+ if ol
237
+ ol.each { |l| require l }
238
+ end
239
+
240
+ if oe
241
+ oe.each { |c| eval c }
242
+ end
243
+
235
244
  # Load the script
236
- load script
245
+ load script if script
data/examples/empty.png CHANGED
File without changes
data/examples/minus.png CHANGED
File without changes
data/examples/plus.png CHANGED
File without changes
@@ -38,6 +38,20 @@ def add_define(name, value = nil)
38
38
  $defs.push("-D#{name}")
39
39
  end
40
40
  end
41
-
41
+ require 'rubygems'
42
+ unless Gem.win_platform? || RUBY_PLATFORM =~ /darwin/
43
+ $LDFLAGS += " -lrt" # for clock_gettime
44
+ end
42
45
  add_define("RUBY_VERSION", RUBY_VERSION.gsub('.', ''))
46
+
47
+ # for ruby 1.9, determine whether threads inherit trace flags (skaes patched 1.9 rubies do)
48
+ if RUBY_VERSION > "1.9"
49
+ require 'set'
50
+ threads = Set.new
51
+ set_trace_func lambda { |*args| threads << Thread.current.object_id }
52
+ Thread.new{1}.join
53
+ set_trace_func nil
54
+ add_define("THREADS_INHERIT_EVENT_FLAGS", (threads.size == 2) ? "1" : "0")
55
+ end
56
+
43
57
  create_makefile("ruby_prof")
@@ -46,6 +46,31 @@ convert_allocations(prof_measure_t c)
46
46
  measure_allocations -> int
47
47
 
48
48
  Returns the total number of object allocations since Ruby started.*/
49
+ static VALUE
50
+ prof_measure_allocations(VALUE self)
51
+ {
52
+ #if defined(HAVE_LONG_LONG)
53
+ return ULL2NUM(rb_os_allocated_objects());
54
+ #else
55
+ return ULONG2NUM(rb_os_allocated_objects());
56
+ #endif
57
+ }
58
+
59
+ #elif defined(HAVE_RB_GC_MALLOC_ALLOCATIONS)
60
+ #define MEASURE_ALLOCATIONS 3
61
+
62
+ static prof_measure_t
63
+ measure_allocations()
64
+ {
65
+ return rb_gc_malloc_allocations();
66
+ }
67
+
68
+ static double
69
+ convert_allocations(prof_measure_t c)
70
+ {
71
+ return c;
72
+ }
73
+
49
74
  static VALUE
50
75
  prof_measure_allocations(VALUE self)
51
76
  {
@@ -31,13 +31,24 @@
31
31
  static prof_measure_t
32
32
  measure_process_time()
33
33
  {
34
- return clock(); // cpu usage (with poor precision) in linux (TODO), wall time in doze (TODO)
34
+ #if defined(__linux__)
35
+ struct timespec time;
36
+ clock_gettime(CLOCK_PROCESS_CPUTIME_ID , &time);
37
+ return time.tv_sec * 1000000000 + time.tv_nsec ;
38
+ #else
39
+ return clock();
40
+ #endif
35
41
  }
36
42
 
43
+
37
44
  static double
38
45
  convert_process_time(prof_measure_t c)
39
46
  {
47
+ #if defined(__linux__)
48
+ return (double) c / 1000000000;
49
+ #else
40
50
  return (double) c / CLOCKS_PER_SEC;
51
+ #endif
41
52
  }
42
53
 
43
54
  /* Document-method: measure_process_time
@@ -1160,7 +1160,7 @@ prof_event_hook(rb_event_flag_t event, NODE *node, VALUE self, ID mid, VALUE kla
1160
1160
  thread = rb_thread_current();
1161
1161
  thread_id = rb_obj_id(thread);
1162
1162
 
1163
- # if RUBY_VERSION >= 191
1163
+ # if RUBY_VERSION >= 191 && THREADS_INHERIT_EVENT_FLAGS==0
1164
1164
  /* ensure that new threads are hooked [sigh] (bug in core) */
1165
1165
  prof_remove_hook();
1166
1166
  prof_install_hook();
@@ -1,4 +1,4 @@
1
- #define RUBY_PROF_VERSION "0.9.2" // for easy parsing from rake files
1
+ #define RUBY_PROF_VERSION "0.10.2" // for easy parsing from rake files
2
2
  #define RUBY_PROF_VERSION_MAJ 0
3
- #define RUBY_PROF_VERSION_MIN 9
3
+ #define RUBY_PROF_VERSION_MIN 10
4
4
  #define RUBY_PROF_VERSION_MIC 2
data/lib/ruby-prof.rb CHANGED
@@ -1,4 +1,4 @@
1
- # require the .so file...
1
+ # require the .so (ext) file...
2
2
 
3
3
  me = File.dirname(__FILE__) + '/'
4
4
  begin
@@ -8,20 +8,14 @@ rescue Exception
8
8
  require "#{me}/../ext/ruby_prof/ruby_prof"
9
9
  end
10
10
 
11
- require "ruby-prof/result"
12
- require "ruby-prof/method_info"
13
- require "ruby-prof/call_info"
14
- require "ruby-prof/aggregate_call_info"
15
- require "ruby-prof/flat_printer"
16
- require "ruby-prof/flat_printer_with_line_numbers"
17
- require "ruby-prof/graph_printer"
18
- require "ruby-prof/graph_html_printer"
19
- require "ruby-prof/call_tree_printer"
20
- require "ruby-prof/call_stack_printer"
21
- require "ruby-prof/multi_printer"
22
- require "ruby-prof/dot_printer"
23
- require "ruby-prof/symbol_to_proc" # for 1.8's backward compatibility benefit
24
- require "ruby-prof/rack"
11
+ # have to load them by hand since we don't want to load 'unprof'
12
+
13
+ for file in ['abstract_printer', 'result', 'method_info', 'call_info', 'aggregate_call_info', 'flat_printer', 'flat_printer_with_line_numbers',
14
+ 'graph_printer', 'graph_html_printer', 'call_tree_printer', 'call_stack_printer', 'multi_printer', 'dot_printer', 'symbol_to_proc', # for 1.8's backward compatible benefit
15
+ 'rack']
16
+
17
+ require File.dirname(__FILE__) + '/ruby-prof/' + file
18
+ end
25
19
 
26
20
  module RubyProf
27
21
  # See if the user specified the clock mode via
@@ -1,4 +1,3 @@
1
- require 'ruby-prof/abstract_printer'
2
1
  require 'erb'
3
2
  require 'fileutils'
4
3
 
@@ -11,6 +10,33 @@ module RubyProf
11
10
  super(result)
12
11
  end
13
12
 
13
+ # Specify print options.
14
+ #
15
+ # options - Hash table
16
+ # :min_percent - Number 0 to 100 that specifes the minimum
17
+ # %self (the methods self time divided by the
18
+ # overall total time) that a method must take
19
+ # for it to be printed out in the report.
20
+ # Default value is 0.
21
+ #
22
+ # :print_file - True or false. Specifies if a method's source
23
+ # file should be printed. Default value if false.
24
+ #
25
+ # :threshold - a float from 0 to 100 that sets the threshold of
26
+ # results displayed.
27
+ # Default value is 1.0
28
+ #
29
+ # :title - a String to overide the default "ruby-prof call tree"
30
+ # title of the report.
31
+ #
32
+ # :expansion - a float from 0 to 100 that sets the threshold of
33
+ # results that are expanded, if the percent_total
34
+ # exceeds it.
35
+ # Default value is 10.0
36
+ #
37
+ # :application - a String to overide the name of the application,
38
+ # as it appears on the report.
39
+ #
14
40
  def print(output = STDOUT, options = {})
15
41
  @output = output
16
42
  setup_options(options)
@@ -1,10 +1,21 @@
1
- require 'ruby-prof/abstract_printer'
2
1
 
3
2
  module RubyProf
4
3
  # Generate profiling information in calltree format
5
4
  # for use by kcachegrind and similar tools.
6
5
 
7
6
  class CallTreePrinter < AbstractPrinter
7
+ # Specify print options.
8
+ #
9
+ # options - Hash table
10
+ # :min_percent - Number 0 to 100 that specifes the minimum
11
+ # %self (the methods self time divided by the
12
+ # overall total time) that a method must take
13
+ # for it to be printed out in the report.
14
+ # Default value is 0.
15
+ #
16
+ # :print_file - True or false. Specifies if a method's source
17
+ # file should be printed. Default value if false.
18
+ #
8
19
  def print(output = STDOUT, options = {})
9
20
  @output = output
10
21
  setup_options(options)
@@ -1,5 +1,4 @@
1
1
  require 'set'
2
- require 'ruby-prof/abstract_printer'
3
2
 
4
3
  module RubyProf
5
4
  # Generates a graphviz graph in dot format.
File without changes
@@ -1,4 +1,3 @@
1
- require 'ruby-prof/abstract_printer'
2
1
 
3
2
  module RubyProf
4
3
  # Generates flat[link:files/examples/flat_txt.html] profile reports as text.
@@ -9,7 +8,7 @@ module RubyProf
9
8
  # end
10
9
  #
11
10
  # printer = RubyProf::FlatPrinter.new(result)
12
- # printer.print(STDOUT, 0)
11
+ # printer.print(STDOUT, {})
13
12
  #
14
13
  class FlatPrinter < AbstractPrinter
15
14
  # Print a flat profile report to the provided output.
@@ -1,5 +1,4 @@
1
- require 'ruby-prof/abstract_printer'
2
- require 'pathname'
1
+
3
2
  module RubyProf
4
3
  # Generates flat[link:files/examples/flat_txt.html] profile reports as text.
5
4
  # To use the flat printer with line numbers:
@@ -9,7 +8,7 @@ module RubyProf
9
8
  # end
10
9
  #
11
10
  # printer = RubyProf::FlatPrinterWithLineNumbers.new(result)
12
- # printer.print(STDOUT, 0)
11
+ # printer.print(STDOUT, {})
13
12
  #
14
13
  class FlatPrinterWithLineNumbers < FlatPrinter
15
14
 
@@ -1,4 +1,3 @@
1
- require 'ruby-prof/abstract_printer'
2
1
  require 'erb'
3
2
 
4
3
  module RubyProf
@@ -43,6 +42,13 @@ module RubyProf
43
42
  # options - Hash of print options. See #setup_options
44
43
  # for more information.
45
44
  #
45
+ # unique options are:
46
+ # :filename - specify a file to use that contains the ERB
47
+ # template to use, instead of the built-in self.template
48
+ #
49
+ # :template - specify an ERB template to use, instead of the
50
+ # built-in self.template
51
+ #
46
52
  def print(output = STDOUT, options = {})
47
53
  @output = output
48
54
  setup_options(options)
@@ -1,4 +1,3 @@
1
- require 'ruby-prof/abstract_printer'
2
1
 
3
2
  module RubyProf
4
3
  # Generates graph[link:files/examples/graph_txt.html] profile reports as text.
@@ -9,7 +8,7 @@ module RubyProf
9
8
  # end
10
9
  #
11
10
  # printer = RubyProf::GraphPrinter.new(result, 5)
12
- # printer.print(STDOUT, 0)
11
+ # printer.print(STDOUT, {})
13
12
  #
14
13
  # The constructor takes two arguments. See the README
15
14
 
File without changes
File without changes
@@ -1,3 +1,5 @@
1
+ require 'tmpdir'
2
+
1
3
  module Rack
2
4
  class RubyProf
3
5
  def initialize(app)
@@ -13,13 +15,13 @@ module Rack
13
15
  result
14
16
  end
15
17
 
16
- def print
17
- printers = {::RubyProf::FlatPrinter => 'c:/temp/profile.txt',
18
- ::RubyProf::GraphHtmlPrinter => 'c:/temp/profile.html'}
18
+ def print(data)
19
+ printers = {::RubyProf::FlatPrinter => ::File.join(Dir.tmpdir, 'profile.txt'),
20
+ ::RubyProf::GraphHtmlPrinter => ::File.join(Dir.tmpdir, 'profile.html')}
19
21
 
20
22
  printers.each do |printer_klass, file_name|
21
- printer = printer_klass.new(result)
22
- ::File.open(file_name, 'wb') do |file|
23
+ printer = printer_klass.new(data)
24
+ ::File.open(file_name, 'wb') do |file|
23
25
  printer.print(file, :min_percent => 0.00000001 )
24
26
  end
25
27
  end
File without changes
File without changes
data/test/basic_test.rb CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
data/test/exec_test.rb CHANGED
File without changes
File without changes
File without changes
data/test/module_test.rb CHANGED
@@ -38,7 +38,7 @@ class ModuleTest < Test::Unit::TestCase
38
38
 
39
39
  # these methods should be in there... (hard to tell order though).
40
40
  for name in ['ModuleTest#test_nested_modules','Bar#hello','Kernel#sleep','<Module::Bar>#hello','<Module::Foo>#hello']
41
- assert methods.map(&:full_name).include? name
41
+ assert methods.map(&:full_name).include?( name )
42
42
  end
43
43
  end
44
44
  end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/test/stack_test.rb CHANGED
File without changes
File without changes
data/test/thread_test.rb CHANGED
File without changes
File without changes
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-prof
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 51
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
- - 9
8
+ - 10
8
9
  - 2
9
- version: 0.9.2
10
+ version: 0.10.2
10
11
  platform: ruby
11
12
  authors:
12
13
  - Shugo Maeda, Charlie Savage, Roger Pack, Stefan Kaes
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-08-26 00:00:00 -06:00
18
+ date: 2011-04-11 00:00:00 -06:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -25,6 +26,7 @@ dependencies:
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 3
28
30
  segments:
29
31
  - 0
30
32
  version: "0"
@@ -38,6 +40,7 @@ dependencies:
38
40
  requirements:
39
41
  - - ">="
40
42
  - !ruby/object:Gem::Version
43
+ hash: 3
41
44
  segments:
42
45
  - 0
43
46
  version: "0"
@@ -115,8 +118,6 @@ files:
115
118
  - rails/example/example_test.rb
116
119
  - rails/profile_test_helper.rb
117
120
  - test/aggregate_test.rb
118
- - test/bad.rb
119
- - test/basic2_test.rb
120
121
  - test/basic_test.rb
121
122
  - test/current_failures_windows
122
123
  - test/do_nothing.rb
@@ -158,6 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
159
  requirements:
159
160
  - - ">="
160
161
  - !ruby/object:Gem::Version
162
+ hash: 63
161
163
  segments:
162
164
  - 1
163
165
  - 8
@@ -168,13 +170,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
170
  requirements:
169
171
  - - ">="
170
172
  - !ruby/object:Gem::Version
173
+ hash: 3
171
174
  segments:
172
175
  - 0
173
176
  version: "0"
174
177
  requirements: []
175
178
 
176
179
  rubyforge_project: ruby-prof
177
- rubygems_version: 1.3.7
180
+ rubygems_version: 1.6.2
178
181
  signing_key:
179
182
  specification_version: 3
180
183
  summary: Fast Ruby profiler
data/test/bad.rb DELETED
@@ -1,6 +0,0 @@
1
- require 'tracer'
2
- Tracer.on
3
- a = [1,2,3]
4
- a.each{|n|
5
- p n
6
- }
data/test/basic2_test.rb DELETED
@@ -1,20 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'test/unit'
4
- require 'ruby-prof'
5
-
6
- # test for http://redmine.ruby-lang.org/issues/show/3660 and others that show 1.9.1 not having correct return methods..
7
-
8
- class SingletonTest < Test::Unit::TestCase
9
- def test_singleton
10
- result = RubyProf.profile do
11
- a = [1,2,3]
12
- a.each{ |n|
13
- }
14
- end
15
- printer = RubyProf::FlatPrinter.new(result)
16
- output = ENV['SHOW_RUBY_PROF_PRINTER_OUTPUT'] == "1" ? STDOUT : ''
17
- output = STDOUT
18
- printer.print(output)
19
- end
20
- end