ruby-prof 1.7.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/{CHANGES → CHANGELOG.md} +112 -178
  3. data/README.md +5 -5
  4. data/bin/ruby-prof +1 -4
  5. data/docs/advanced-usage.md +132 -0
  6. data/docs/alternatives.md +98 -0
  7. data/docs/architecture.md +122 -0
  8. data/docs/best-practices.md +27 -0
  9. data/docs/getting-started.md +130 -0
  10. data/docs/history.md +11 -0
  11. data/docs/index.md +45 -0
  12. data/docs/profiling-rails.md +64 -0
  13. data/docs/public/examples/example.rb +33 -0
  14. data/docs/public/examples/generate_reports.rb +92 -0
  15. data/docs/public/examples/reports/call_info.txt +27 -0
  16. data/docs/public/examples/reports/call_stack.html +835 -0
  17. data/docs/public/examples/reports/callgrind.out +150 -0
  18. data/docs/public/examples/reports/flame_graph.html +408 -0
  19. data/docs/public/examples/reports/flat.txt +45 -0
  20. data/docs/public/examples/reports/graph.dot +129 -0
  21. data/docs/public/examples/reports/graph.html +1319 -0
  22. data/docs/public/examples/reports/graph.txt +100 -0
  23. data/docs/public/examples/reports/graphviz_viewer.html +1 -0
  24. data/docs/public/images/call_stack.png +0 -0
  25. data/docs/public/images/class_diagram.png +0 -0
  26. data/docs/public/images/dot_printer.png +0 -0
  27. data/docs/public/images/flame_graph.png +0 -0
  28. data/docs/public/images/flat.png +0 -0
  29. data/docs/public/images/graph.png +0 -0
  30. data/docs/public/images/graph_html.png +0 -0
  31. data/docs/public/images/ruby-prof-logo.svg +1 -0
  32. data/docs/reports.md +150 -0
  33. data/docs/stylesheets/extra.css +80 -0
  34. data/ext/ruby_prof/rp_allocation.c +0 -15
  35. data/ext/ruby_prof/rp_allocation.h +29 -33
  36. data/ext/ruby_prof/rp_call_tree.c +3 -0
  37. data/ext/ruby_prof/rp_call_tree.h +1 -4
  38. data/ext/ruby_prof/rp_call_trees.h +1 -4
  39. data/ext/ruby_prof/rp_measurement.c +0 -5
  40. data/ext/ruby_prof/rp_measurement.h +49 -53
  41. data/ext/ruby_prof/rp_method.c +3 -0
  42. data/ext/ruby_prof/rp_method.h +1 -4
  43. data/ext/ruby_prof/rp_profile.c +1 -1
  44. data/ext/ruby_prof/rp_profile.h +1 -5
  45. data/ext/ruby_prof/rp_stack.h +50 -53
  46. data/ext/ruby_prof/rp_thread.h +1 -4
  47. data/ext/ruby_prof/ruby_prof.h +1 -4
  48. data/ext/ruby_prof/vc/ruby_prof.vcxproj +7 -8
  49. data/lib/ruby-prof/assets/call_stack_printer.html.erb +746 -711
  50. data/lib/ruby-prof/assets/flame_graph_printer.html.erb +412 -0
  51. data/lib/ruby-prof/assets/graph_printer.html.erb +355 -355
  52. data/lib/ruby-prof/call_tree.rb +57 -57
  53. data/lib/ruby-prof/call_tree_visitor.rb +36 -36
  54. data/lib/ruby-prof/measurement.rb +17 -17
  55. data/lib/ruby-prof/printers/abstract_printer.rb +19 -33
  56. data/lib/ruby-prof/printers/call_info_printer.rb +53 -53
  57. data/lib/ruby-prof/printers/call_stack_printer.rb +168 -180
  58. data/lib/ruby-prof/printers/call_tree_printer.rb +132 -145
  59. data/lib/ruby-prof/printers/dot_printer.rb +177 -132
  60. data/lib/ruby-prof/printers/flame_graph_printer.rb +79 -0
  61. data/lib/ruby-prof/printers/flat_printer.rb +52 -52
  62. data/lib/ruby-prof/printers/graph_html_printer.rb +62 -63
  63. data/lib/ruby-prof/printers/graph_printer.rb +112 -113
  64. data/lib/ruby-prof/printers/multi_printer.rb +134 -127
  65. data/lib/ruby-prof/profile.rb +13 -0
  66. data/lib/ruby-prof/rack.rb +114 -105
  67. data/lib/ruby-prof/task.rb +147 -147
  68. data/lib/ruby-prof/thread.rb +20 -20
  69. data/lib/ruby-prof/version.rb +1 -1
  70. data/lib/ruby-prof.rb +50 -52
  71. data/lib/unprof.rb +10 -10
  72. data/ruby-prof.gemspec +5 -5
  73. data/test/abstract_printer_test.rb +25 -27
  74. data/test/alias_test.rb +203 -117
  75. data/test/call_tree_builder.rb +126 -126
  76. data/test/call_tree_visitor_test.rb +27 -27
  77. data/test/call_trees_test.rb +66 -66
  78. data/test/duplicate_names_test.rb +32 -32
  79. data/test/dynamic_method_test.rb +50 -50
  80. data/test/exceptions_test.rb +24 -24
  81. data/test/exclude_threads_test.rb +48 -48
  82. data/test/fiber_test.rb +72 -72
  83. data/test/inverse_call_tree_test.rb +174 -174
  84. data/test/line_number_test.rb +138 -1
  85. data/test/marshal_test.rb +144 -145
  86. data/test/measure_allocations.rb +26 -26
  87. data/test/measure_allocations_test.rb +340 -1
  88. data/test/measure_process_time_test.rb +3098 -3142
  89. data/test/measure_times.rb +56 -56
  90. data/test/measure_wall_time_test.rb +511 -372
  91. data/test/measurement_test.rb +82 -82
  92. data/test/merge_test.rb +48 -48
  93. data/test/multi_printer_test.rb +52 -66
  94. data/test/no_method_class_test.rb +15 -15
  95. data/test/pause_resume_test.rb +171 -171
  96. data/test/prime.rb +54 -54
  97. data/test/prime_script.rb +5 -5
  98. data/test/printer_call_stack_test.rb +28 -27
  99. data/test/printer_call_tree_test.rb +30 -30
  100. data/test/printer_flame_graph_test.rb +82 -0
  101. data/test/printer_flat_test.rb +99 -99
  102. data/test/printer_graph_html_test.rb +62 -59
  103. data/test/printer_graph_test.rb +42 -40
  104. data/test/printers_test.rb +28 -44
  105. data/test/printing_recursive_graph_test.rb +81 -81
  106. data/test/profile_test.rb +101 -101
  107. data/test/rack_test.rb +103 -93
  108. data/test/recursive_test.rb +139 -139
  109. data/test/scheduler.rb +4 -0
  110. data/test/singleton_test.rb +39 -38
  111. data/test/stack_printer_test.rb +61 -61
  112. data/test/start_stop_test.rb +106 -106
  113. data/test/test_helper.rb +4 -0
  114. data/test/thread_test.rb +29 -29
  115. data/test/unique_call_path_test.rb +123 -123
  116. data/test/yarv_test.rb +56 -56
  117. metadata +53 -11
  118. data/ext/ruby_prof/rp_measure_memory.c +0 -46
  119. data/lib/ruby-prof/compatibility.rb +0 -113
  120. data/test/compatibility_test.rb +0 -49
  121. data/test/measure_memory_test.rb +0 -1193
@@ -1,105 +1,114 @@
1
- # encoding: utf-8
2
- require 'tmpdir'
3
-
4
- module Rack
5
- class RubyProf
6
- def initialize(app, options = {})
7
- @app = app
8
- @options = options
9
-
10
- @tmpdir = options[:path] || Dir.tmpdir
11
- FileUtils.mkdir_p(@tmpdir)
12
-
13
- @printer_klasses = @options[:printers] || {::RubyProf::FlatPrinter => 'flat.txt',
14
- ::RubyProf::GraphPrinter => 'graph.txt',
15
- ::RubyProf::GraphHtmlPrinter => 'graph.html',
16
- ::RubyProf::CallStackPrinter => 'call_stack.html'}
17
-
18
- @skip_paths = options[:skip_paths] || [%r{^/assets}, %r{\.(css|js|png|jpeg|jpg|gif)$}]
19
- @only_paths = options[:only_paths]
20
- end
21
-
22
- def call(env)
23
- request = Rack::Request.new(env)
24
-
25
- if should_profile?(request.path)
26
- begin
27
- result = nil
28
- profile = ::RubyProf::Profile.profile(profiling_options) do
29
- result = @app.call(env)
30
- end
31
-
32
- if @options[:merge_fibers]
33
- profile.merge!
34
- end
35
-
36
-
37
- path = request.path.gsub('/', '-')
38
- path.slice!(0)
39
-
40
- print(profile, path)
41
- result
42
- end
43
- else
44
- @app.call(env)
45
- end
46
- end
47
-
48
- private
49
-
50
- def should_profile?(path)
51
- return false if paths_match?(path, @skip_paths)
52
-
53
- @only_paths ? paths_match?(path, @only_paths) : true
54
- end
55
-
56
- def paths_match?(path, paths)
57
- paths.any? { |skip_path| skip_path =~ path }
58
- end
59
-
60
- def profiling_options
61
- result = {}
62
- result[:measure_mode] = @options[:measure_mode] || ::RubyProf::WALL_TIME
63
- result[:track_allocations] = @options[:track_allocations] || false
64
- result[:exclude_common] = @options[:exclude_common] || false
65
-
66
- if @options[:ignore_existing_threads]
67
- result[:exclude_threads] = Thread.list.select {|thread| thread != Thread.current}
68
- end
69
-
70
- if @options[:request_thread_only]
71
- result[:include_threads] = [Thread.current]
72
- end
73
-
74
- result
75
- end
76
-
77
- def print_options
78
- result = {}
79
- result[:min_percent] = @options[:min_percent] || 1
80
- result[:sort_method] = @options[:sort_method] || :total_time
81
- result
82
- end
83
-
84
- def print(profile, path)
85
- @printer_klasses.each do |printer_klass, base_name|
86
- printer = printer_klass.new(profile)
87
-
88
- if base_name.respond_to?(:call)
89
- base_name = base_name.call
90
- end
91
-
92
- if printer_klass == ::RubyProf::MultiPrinter
93
- printer.print(print_options.merge(:profile => "#{path}-#{base_name}"))
94
- elsif printer_klass == ::RubyProf::CallTreePrinter
95
- printer.print(print_options.merge(:profile => "#{path}-#{base_name}"))
96
- else
97
- file_name = ::File.join(@tmpdir, "#{path}-#{base_name}")
98
- ::File.open(file_name, 'wb') do |file|
99
- printer.print(file, print_options)
100
- end
101
- end
102
- end
103
- end
104
- end
105
- end
1
+ # encoding: utf-8
2
+ require 'tmpdir'
3
+
4
+ module Rack
5
+ class RubyProf
6
+ def initialize(app, path: Dir.tmpdir, printers: nil, skip_paths: nil,
7
+ only_paths: nil, merge_fibers: false,
8
+ measure_mode: ::RubyProf::WALL_TIME, track_allocations: false,
9
+ exclude_common: false, ignore_existing_threads: false,
10
+ request_thread_only: false, min_percent: 1,
11
+ sort_method: :total_time)
12
+ @app = app
13
+
14
+ @tmpdir = path.to_s
15
+ FileUtils.mkdir_p(@tmpdir)
16
+
17
+ @printer_klasses = printers || {::RubyProf::FlatPrinter => 'flat.txt',
18
+ ::RubyProf::GraphPrinter => 'graph.txt',
19
+ ::RubyProf::GraphHtmlPrinter => 'graph.html',
20
+ ::RubyProf::CallStackPrinter => 'call_stack.html'}
21
+
22
+ @skip_paths = skip_paths || [%r{^/assets}, %r{\.(css|js|png|jpeg|jpg|gif)$}]
23
+ @only_paths = only_paths
24
+ @merge_fibers = merge_fibers
25
+ @measure_mode = measure_mode
26
+ @track_allocations = track_allocations
27
+ @exclude_common = exclude_common
28
+ @ignore_existing_threads = ignore_existing_threads
29
+ @request_thread_only = request_thread_only
30
+ @min_percent = min_percent
31
+ @sort_method = sort_method
32
+ end
33
+
34
+ def call(env)
35
+ request = Rack::Request.new(env)
36
+
37
+ if should_profile?(request.path)
38
+ begin
39
+ result = nil
40
+ profile = ::RubyProf::Profile.profile(**profiling_options) do
41
+ result = @app.call(env)
42
+ end
43
+
44
+ if @merge_fibers
45
+ profile.merge!
46
+ end
47
+
48
+
49
+ path = request.path.gsub('/', '-')
50
+ path.slice!(0)
51
+
52
+ print(profile, path)
53
+ result
54
+ end
55
+ else
56
+ @app.call(env)
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def should_profile?(path)
63
+ return false if paths_match?(path, @skip_paths)
64
+
65
+ @only_paths ? paths_match?(path, @only_paths) : true
66
+ end
67
+
68
+ def paths_match?(path, paths)
69
+ paths.any? { |skip_path| skip_path =~ path }
70
+ end
71
+
72
+ def profiling_options
73
+ result = {}
74
+ result[:measure_mode] = @measure_mode
75
+ result[:track_allocations] = @track_allocations
76
+ result[:exclude_common] = @exclude_common
77
+
78
+ if @ignore_existing_threads
79
+ result[:exclude_threads] = Thread.list.select {|thread| thread != Thread.current}
80
+ end
81
+
82
+ if @request_thread_only
83
+ result[:include_threads] = [Thread.current]
84
+ end
85
+
86
+ result
87
+ end
88
+
89
+ def print_options
90
+ {min_percent: @min_percent, sort_method: @sort_method}
91
+ end
92
+
93
+ def print(profile, path)
94
+ @printer_klasses.each do |printer_klass, base_name|
95
+ printer = printer_klass.new(profile)
96
+
97
+ if base_name.respond_to?(:call)
98
+ base_name = base_name.call
99
+ end
100
+
101
+ if printer_klass == ::RubyProf::MultiPrinter
102
+ printer.print(profile: "#{path}-#{base_name}", **print_options)
103
+ elsif printer_klass == ::RubyProf::CallTreePrinter
104
+ printer.print(profile: "#{path}-#{base_name}", **print_options)
105
+ else
106
+ file_name = ::File.join(@tmpdir, "#{path}-#{base_name}")
107
+ ::File.open(file_name, 'wb') do |file|
108
+ printer.print(file, **print_options)
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -1,147 +1,147 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
-
4
- require 'rake'
5
- require 'rake/testtask'
6
- require 'fileutils'
7
-
8
- module RubyProf
9
-
10
- # Define a task library for profiling unit tests with ruby-prof.
11
- #
12
- # All of the options provided by
13
- # the Rake:TestTask are supported except the loader
14
- # which is set to ruby-prof. For detailed information
15
- # please refer to the Rake:TestTask documentation.
16
- #
17
- # ruby-prof specific options include:
18
- #
19
- # output_dir - For each file specified an output
20
- # file with profile information will be
21
- # written to the output directory.
22
- # By default, the output directory is
23
- # called "profile" and is created underneath
24
- # the current working directory.
25
- #
26
- # printer - Specifies the output printer. Valid values include
27
- # :flat, :graph, :graph_html and :call_tree.
28
- #
29
- # min_percent - Methods that take less than the specified percent
30
- # will not be written out.
31
- #
32
- # Example:
33
- #
34
- # require 'ruby-prof/task'
35
- #
36
- # RubyProf::ProfileTask.new do |t|
37
- # t.test_files = FileList['test/test*.rb']
38
- # t.output_dir = "c:/temp"
39
- # t.printer = :graph
40
- # t.min_percent = 10
41
- # end
42
- #
43
- # If rake is invoked with a "TEST=filename" command line option,
44
- # then the list of test files will be overridden to include only the
45
- # filename specified on the command line. This provides an easy way
46
- # to run just one test.
47
- #
48
- # If rake is invoked with a "TESTOPTS=options" command line option,
49
- # then the given options are passed to the test process after a
50
- # '--'. This allows Test::Unit options to be passed to the test
51
- # suite.
52
- #
53
- # Examples:
54
- #
55
- # rake profile # run tests normally
56
- # rake profile TEST=just_one_file.rb # run just one test file.
57
- # rake profile TESTOPTS="-v" # run in verbose mode
58
- # rake profile TESTOPTS="--runner=fox" # use the fox test runner
59
-
60
- class ProfileTask < Rake::TestTask
61
- attr_accessor :output_dir
62
- attr_accessor :min_percent
63
- attr_accessor :printer
64
-
65
- def initialize(name = :profile)
66
- super(name)
67
- end
68
-
69
- # Create the tasks defined by this task lib.
70
- def define
71
- lib_path = @libs.join(File::PATH_SEPARATOR)
72
- desc "Profile" + (@name==:profile ? "" : " for #{@name}")
73
-
74
- task @name do
75
- create_output_directory
76
-
77
- @ruby_opts.unshift( "-I#{lib_path}" )
78
- @ruby_opts.unshift( "-w" ) if @warning
79
- @ruby_opts.push("-S ruby-prof")
80
- @ruby_opts.push("--printer #{@printer}")
81
- @ruby_opts.push("--min_percent #{@min_percent}")
82
-
83
- file_list.each do |file_path|
84
- run_script(file_path)
85
- end
86
- end
87
- self
88
- end
89
-
90
- # Run script
91
- def run_script(script_path)
92
- run_code = ''
93
- RakeFileUtils.verbose(@verbose) do
94
- file_name = File.basename(script_path, File.extname(script_path))
95
- case @printer
96
- when :flat, :graph, :call_tree
97
- file_name += ".txt"
98
- when :graph_html
99
- file_name += ".html"
100
- else
101
- file_name += ".txt"
102
- end
103
-
104
- output_file_path = File.join(output_directory, file_name)
105
-
106
- command_line = @ruby_opts.join(" ") +
107
- " --file=" + output_file_path +
108
- " " + script_path
109
-
110
- puts "ruby " + command_line
111
- # We have to catch the exeption to continue on. However,
112
- # the error message will have been output to STDERR
113
- # already by the time we get here so we don't have to
114
- # do that again
115
- begin
116
- ruby command_line
117
- rescue => e
118
- STDOUT << e << "\n"
119
- STDOUT.flush
120
- end
121
- puts ""
122
- puts ""
123
- end
124
- end
125
-
126
- def output_directory
127
- File.expand_path(@output_dir)
128
- end
129
-
130
- def create_output_directory
131
- if not File.exist?(output_directory)
132
- Dir.mkdir(output_directory)
133
- end
134
- end
135
-
136
- def clean_output_directory
137
- if File.exist?(output_directory)
138
- files = Dir.glob(output_directory + '/*')
139
- FileUtils.rm(files)
140
- end
141
- end
142
-
143
- def option_list # :nodoc:
144
- ENV['OPTIONS'] || @options.join(" ") || ""
145
- end
146
- end
147
- end
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'rake'
5
+ require 'rake/testtask'
6
+ require 'fileutils'
7
+
8
+ module RubyProf
9
+
10
+ # Define a task library for profiling unit tests with ruby-prof.
11
+ #
12
+ # All of the options provided by
13
+ # the Rake:TestTask are supported except the loader
14
+ # which is set to ruby-prof. For detailed information
15
+ # please refer to the Rake:TestTask documentation.
16
+ #
17
+ # ruby-prof specific options include:
18
+ #
19
+ # output_dir - For each file specified an output
20
+ # file with profile information will be
21
+ # written to the output directory.
22
+ # By default, the output directory is
23
+ # called "profile" and is created underneath
24
+ # the current working directory.
25
+ #
26
+ # printer - Specifies the output printer. Valid values include
27
+ # :flat, :graph, :graph_html and :call_tree.
28
+ #
29
+ # min_percent - Methods that take less than the specified percent
30
+ # will not be written out.
31
+ #
32
+ # Example:
33
+ #
34
+ # require 'ruby-prof/task'
35
+ #
36
+ # RubyProf::ProfileTask.new do |t|
37
+ # t.test_files = FileList['test/test*.rb']
38
+ # t.output_dir = "c:/temp"
39
+ # t.printer = :graph
40
+ # t.min_percent = 10
41
+ # end
42
+ #
43
+ # If rake is invoked with a "TEST=filename" command line option,
44
+ # then the list of test files will be overridden to include only the
45
+ # filename specified on the command line. This provides an easy way
46
+ # to run just one test.
47
+ #
48
+ # If rake is invoked with a "TESTOPTS=options" command line option,
49
+ # then the given options are passed to the test process after a
50
+ # '--'. This allows Test::Unit options to be passed to the test
51
+ # suite.
52
+ #
53
+ # Examples:
54
+ #
55
+ # rake profile # run tests normally
56
+ # rake profile TEST=just_one_file.rb # run just one test file.
57
+ # rake profile TESTOPTS="-v" # run in verbose mode
58
+ # rake profile TESTOPTS="--runner=fox" # use the fox test runner
59
+
60
+ class ProfileTask < Rake::TestTask
61
+ attr_accessor :output_dir
62
+ attr_accessor :min_percent
63
+ attr_accessor :printer
64
+
65
+ def initialize(name = :profile)
66
+ super(name)
67
+ end
68
+
69
+ # Create the tasks defined by this task lib.
70
+ def define
71
+ lib_path = @libs.join(File::PATH_SEPARATOR)
72
+ desc "Profile" + (@name==:profile ? "" : " for #{@name}")
73
+
74
+ task @name do
75
+ create_output_directory
76
+
77
+ @ruby_opts.unshift( "-I#{lib_path}" )
78
+ @ruby_opts.unshift( "-w" ) if @warning
79
+ @ruby_opts.push("-S ruby-prof")
80
+ @ruby_opts.push("--printer #{@printer}")
81
+ @ruby_opts.push("--min_percent #{@min_percent}")
82
+
83
+ file_list.each do |file_path|
84
+ run_script(file_path)
85
+ end
86
+ end
87
+ self
88
+ end
89
+
90
+ # Run script
91
+ def run_script(script_path)
92
+ run_code = ''
93
+ RakeFileUtils.verbose(@verbose) do
94
+ file_name = File.basename(script_path, File.extname(script_path))
95
+ case @printer
96
+ when :flat, :graph, :call_tree
97
+ file_name += ".txt"
98
+ when :graph_html
99
+ file_name += ".html"
100
+ else
101
+ file_name += ".txt"
102
+ end
103
+
104
+ output_file_path = File.join(output_directory, file_name)
105
+
106
+ command_line = @ruby_opts.join(" ") +
107
+ " --file=" + output_file_path +
108
+ " " + script_path
109
+
110
+ puts "ruby " + command_line
111
+ # We have to catch the exeption to continue on. However,
112
+ # the error message will have been output to STDERR
113
+ # already by the time we get here so we don't have to
114
+ # do that again
115
+ begin
116
+ ruby command_line
117
+ rescue => e
118
+ STDOUT << e << "\n"
119
+ STDOUT.flush
120
+ end
121
+ puts ""
122
+ puts ""
123
+ end
124
+ end
125
+
126
+ def output_directory
127
+ File.expand_path(@output_dir)
128
+ end
129
+
130
+ def create_output_directory
131
+ if not File.exist?(output_directory)
132
+ Dir.mkdir(output_directory)
133
+ end
134
+ end
135
+
136
+ def clean_output_directory
137
+ if File.exist?(output_directory)
138
+ files = Dir.glob(output_directory + '/*')
139
+ FileUtils.rm(files)
140
+ end
141
+ end
142
+
143
+ def option_list # :nodoc:
144
+ ENV['OPTIONS'] || @options.join(" ") || ""
145
+ end
146
+ end
147
+ end
@@ -1,20 +1,20 @@
1
- module RubyProf
2
- class Thread
3
- # Returns the total time this thread was executed.
4
- def total_time
5
- self.call_tree.total_time
6
- end
7
-
8
- # Returns the amount of time this thread waited while other thread executed.
9
- def wait_time
10
- # wait_time, like self:time, is always method local
11
- # thus we need to sum over all methods and call infos
12
- self.methods.inject(0) do |sum, method_info|
13
- method_info.callers.each do |call_tree|
14
- sum += call_tree.wait_time
15
- end
16
- sum
17
- end
18
- end
19
- end
20
- end
1
+ module RubyProf
2
+ class Thread
3
+ # Returns the total time this thread was executed.
4
+ def total_time
5
+ self.call_tree.total_time
6
+ end
7
+
8
+ # Returns the amount of time this thread waited while other thread executed.
9
+ def wait_time
10
+ # wait_time, like self:time, is always method local
11
+ # thus we need to sum over all methods and call infos
12
+ self.methods.inject(0) do |sum, method_info|
13
+ method_info.callers.each do |call_tree|
14
+ sum += call_tree.wait_time
15
+ end
16
+ sum
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module RubyProf
2
- VERSION = "1.7.2"
2
+ VERSION = "2.0.0"
3
3
  end
data/lib/ruby-prof.rb CHANGED
@@ -1,52 +1,50 @@
1
- # encoding: utf-8
2
- require 'rubygems/version'
3
-
4
- # Load the C-based binding.
5
- begin
6
- version = Gem::Version.new(RUBY_VERSION)
7
- require "#{version.segments[0..1].join('.')}/ruby_prof.so"
8
- rescue LoadError
9
- require "ruby_prof.so"
10
- end
11
-
12
- require 'ruby-prof/version'
13
- require 'ruby-prof/call_tree'
14
- require 'ruby-prof/compatibility'
15
- require 'ruby-prof/measurement'
16
- require 'ruby-prof/method_info'
17
- require 'ruby-prof/profile'
18
- require 'ruby-prof/rack'
19
- require 'ruby-prof/thread'
20
-
21
- module RubyProf
22
- autoload :CallTreeVisitor, 'ruby-prof/call_tree_visitor'
23
- autoload :AbstractPrinter, 'ruby-prof/printers/abstract_printer'
24
- autoload :CallInfoPrinter, 'ruby-prof/printers/call_info_printer'
25
- autoload :CallStackPrinter, 'ruby-prof/printers/call_stack_printer'
26
- autoload :CallTreePrinter, 'ruby-prof/printers/call_tree_printer'
27
- autoload :DotPrinter, 'ruby-prof/printers/dot_printer'
28
- autoload :FlatPrinter, 'ruby-prof/printers/flat_printer'
29
- autoload :GraphHtmlPrinter, 'ruby-prof/printers/graph_html_printer'
30
- autoload :GraphPrinter, 'ruby-prof/printers/graph_printer'
31
- autoload :MultiPrinter, 'ruby-prof/printers/multi_printer'
32
-
33
- # :nodoc:
34
- # Checks if the user specified the clock mode via
35
- # the RUBY_PROF_MEASURE_MODE environment variable
36
- def self.figure_measure_mode
37
- case ENV["RUBY_PROF_MEASURE_MODE"]
38
- when "wall", "wall_time"
39
- RubyProf.measure_mode = RubyProf::WALL_TIME
40
- when "allocations"
41
- RubyProf.measure_mode = RubyProf::ALLOCATIONS
42
- when "memory"
43
- RubyProf.measure_mode = RubyProf::MEMORY
44
- when "process", "process_time"
45
- RubyProf.measure_mode = RubyProf::PROCESS_TIME
46
- else
47
- # the default is defined in the measure_mode reader
48
- end
49
- end
50
- end
51
-
52
- RubyProf::figure_measure_mode
1
+ # encoding: utf-8
2
+ require 'rubygems/version'
3
+
4
+ # Load the C-based binding.
5
+ begin
6
+ version = Gem::Version.new(RUBY_VERSION)
7
+ require "#{version.segments[0..1].join('.')}/ruby_prof.so"
8
+ rescue LoadError
9
+ require "ruby_prof.so"
10
+ end
11
+
12
+ require 'ruby-prof/version'
13
+ require 'ruby-prof/call_tree'
14
+ require 'ruby-prof/measurement'
15
+ require 'ruby-prof/method_info'
16
+ require 'ruby-prof/profile'
17
+ require 'ruby-prof/rack'
18
+ require 'ruby-prof/thread'
19
+
20
+ module RubyProf
21
+ autoload :CallTreeVisitor, 'ruby-prof/call_tree_visitor'
22
+ autoload :AbstractPrinter, 'ruby-prof/printers/abstract_printer'
23
+ autoload :CallInfoPrinter, 'ruby-prof/printers/call_info_printer'
24
+ autoload :CallStackPrinter, 'ruby-prof/printers/call_stack_printer'
25
+ autoload :CallTreePrinter, 'ruby-prof/printers/call_tree_printer'
26
+ autoload :DotPrinter, 'ruby-prof/printers/dot_printer'
27
+ autoload :FlameGraphPrinter, 'ruby-prof/printers/flame_graph_printer'
28
+ autoload :FlatPrinter, 'ruby-prof/printers/flat_printer'
29
+ autoload :GraphHtmlPrinter, 'ruby-prof/printers/graph_html_printer'
30
+ autoload :GraphPrinter, 'ruby-prof/printers/graph_printer'
31
+ autoload :MultiPrinter, 'ruby-prof/printers/multi_printer'
32
+
33
+ # :nodoc:
34
+ # Checks if the user specified the clock mode via
35
+ # the RUBY_PROF_MEASURE_MODE environment variable
36
+ def self.figure_measure_mode
37
+ case ENV["RUBY_PROF_MEASURE_MODE"]
38
+ when "wall", "wall_time"
39
+ RubyProf.measure_mode = RubyProf::WALL_TIME
40
+ when "allocations"
41
+ RubyProf.measure_mode = RubyProf::ALLOCATIONS
42
+ when "process", "process_time"
43
+ RubyProf.measure_mode = RubyProf::PROCESS_TIME
44
+ else
45
+ # the default is defined in the measure_mode reader
46
+ end
47
+ end
48
+ end
49
+
50
+ RubyProf::figure_measure_mode