ruby-prof 2.0.3 → 2.0.4

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.
@@ -1,143 +1,143 @@
1
- # encoding: utf-8
2
-
3
- module RubyProf
4
- # This is the base class for all Printers. It is never used directly.
5
- class AbstractPrinter
6
- # :stopdoc:
7
- def self.needs_dir?
8
- false
9
- end
10
- # :startdoc:
11
-
12
- # Create a new printer.
13
- #
14
- # result should be the output generated from a profiling run
15
- def initialize(result)
16
- @result = result
17
- @output = nil
18
- end
19
-
20
- attr_reader :min_percent, :max_percent, :filter_by, :sort_method
21
-
22
- # Returns the time format used to show when a profile was run
23
- def time_format
24
- '%A, %B %-d at %l:%M:%S %p (%Z)'
25
- end
26
-
27
- # Prints a report to the provided output.
28
- #
29
- # output - Any IO object, including STDOUT or a file.
30
- # The default value is STDOUT.
31
- #
32
- # Keyword arguments:
33
- # min_percent - Number 0 to 100 that specifies the minimum
34
- # %self (the methods self time divided by the
35
- # overall total time) that a method must take
36
- # for it to be printed out in the report.
37
- # Default value is 0.
38
- #
39
- # max_percent - Number 0 to 100 that specifies the maximum
40
- # %self for methods to include.
41
- # Default value is 100.
42
- #
43
- # filter_by - Which time metric to use when applying
44
- # min_percent and max_percent filters.
45
- # Default value is :self_time.
46
- #
47
- # sort_method - Specifies method used for sorting method infos.
48
- # Available values are :total_time, :self_time,
49
- # :wait_time, :children_time.
50
- # Default value depends on the printer.
51
- def print(output = STDOUT, min_percent: 0, max_percent: 100, filter_by: :self_time, sort_method: nil, max_depth: nil, **)
52
- @output = output
53
- @min_percent = min_percent
54
- @max_percent = max_percent
55
- @filter_by = filter_by
56
- @sort_method = sort_method
57
- @max_depth = max_depth
58
- print_threads
59
- end
60
-
61
- def method_location(method)
62
- if method.source_file
63
- "#{method.source_file}:#{method.line}"
64
- end
65
- end
66
-
67
- def method_href(thread, method)
68
- h(method.full_name.gsub(/[><#\.\?=:]/,"_") + "_" + thread.fiber_id.to_s)
69
- end
70
-
71
- def open_asset(file)
72
- path = File.join(File.expand_path('../../assets', __FILE__), file)
73
- File.open(path, 'rb').read
74
- end
75
-
76
- def print_threads
77
- @result.threads.each do |thread|
78
- print_thread(thread)
79
- end
80
- end
81
-
82
- def print_thread(thread)
83
- print_header(thread)
84
- print_methods(thread)
85
- print_footer(thread)
86
- end
87
-
88
- def print_header(thread)
89
- @output << "Measure Mode: %s\n" % @result.measure_mode_string
90
- @output << "Thread ID: %d\n" % thread.id
91
- @output << "Fiber ID: %d\n" % thread.fiber_id unless thread.id == thread.fiber_id
92
- @output << "Total: %0.6f\n" % thread.total_time
93
- @output << "Sort by: #{sort_method}\n"
94
- @output << "\n"
95
- print_column_headers
96
- end
97
-
98
- def print_column_headers
99
- end
100
-
101
- def print_footer(thread)
102
- metric_data = {
103
- 0 => { label: "time", prefix: "", suffix: "spent" },
104
- 1 => { label: "time", prefix: "", suffix: "spent" },
105
- 2 => { label: "allocations", prefix: "number of ", suffix: "made" },
106
- 3 => { label: "memory", prefix: "", suffix: "used" }
107
- }
108
-
109
- metric = metric_data[@result.measure_mode]
110
-
111
- metric_label = metric[:label]
112
- metric_suffix = metric[:suffix]
113
- metric_prefix = metric[:prefix]
114
-
115
- metric1 = "#{metric_label} #{metric_suffix}"
116
- metric2 = "#{metric_prefix}#{metric1}"
117
- metric3 = metric_label
118
-
119
- # Output the formatted text
120
- @output << <<~EOT
121
-
122
- * recursively called methods
123
-
124
- Columns are:
125
-
126
- %self - The percentage of #{metric1} by this method relative to the total #{metric3} in the entire program.
127
- total - The total #{metric2} by this method and its children.
128
- self - The #{metric2} by this method.
129
- wait - The time this method spent waiting for other threads.
130
- child - The #{metric2} by this method's children.
131
- calls - The number of times this method was called.
132
- name - The name of the method.
133
- location - The location of the method.
134
-
135
- The interpretation of method names is:
136
-
137
- * MyObject#test - An instance method "test" of the class "MyObject"
138
- * <Object:MyObject>#test - The <> characters indicate a method on a singleton class.
139
-
140
- EOT
141
- end
142
- end
143
- end
1
+ # encoding: utf-8
2
+
3
+ module RubyProf
4
+ # This is the base class for all Printers. It is never used directly.
5
+ class AbstractPrinter
6
+ # :stopdoc:
7
+ def self.needs_dir?
8
+ false
9
+ end
10
+ # :startdoc:
11
+
12
+ # Create a new printer.
13
+ #
14
+ # result should be the output generated from a profiling run
15
+ def initialize(result)
16
+ @result = result
17
+ @output = nil
18
+ end
19
+
20
+ attr_reader :min_percent, :max_percent, :filter_by, :sort_method
21
+
22
+ # Returns the time format used to show when a profile was run
23
+ def time_format
24
+ '%A, %B %-d at %l:%M:%S %p (%Z)'
25
+ end
26
+
27
+ # Prints a report to the provided output.
28
+ #
29
+ # output - Any IO object, including STDOUT or a file.
30
+ # The default value is STDOUT.
31
+ #
32
+ # Keyword arguments:
33
+ # min_percent - Number 0 to 100 that specifies the minimum
34
+ # %self (the methods self time divided by the
35
+ # overall total time) that a method must take
36
+ # for it to be printed out in the report.
37
+ # Default value is 0.
38
+ #
39
+ # max_percent - Number 0 to 100 that specifies the maximum
40
+ # %self for methods to include.
41
+ # Default value is 100.
42
+ #
43
+ # filter_by - Which time metric to use when applying
44
+ # min_percent and max_percent filters.
45
+ # Default value is :self_time.
46
+ #
47
+ # sort_method - Specifies method used for sorting method infos.
48
+ # Available values are :total_time, :self_time,
49
+ # :wait_time, :children_time.
50
+ # Default value depends on the printer.
51
+ def print(output = STDOUT, min_percent: 0, max_percent: 100, filter_by: :self_time, sort_method: nil, max_depth: nil, **)
52
+ @output = output
53
+ @min_percent = min_percent
54
+ @max_percent = max_percent
55
+ @filter_by = filter_by
56
+ @sort_method = sort_method || :total_time
57
+ @max_depth = max_depth
58
+ print_threads
59
+ end
60
+
61
+ def method_location(method)
62
+ if method.source_file
63
+ "#{method.source_file}:#{method.line}"
64
+ end
65
+ end
66
+
67
+ def method_href(thread, method)
68
+ h(method.full_name.gsub(/[><#\.\?=:]/,"_") + "_" + thread.fiber_id.to_s)
69
+ end
70
+
71
+ def open_asset(file)
72
+ path = File.join(File.expand_path('../../assets', __FILE__), file)
73
+ File.open(path, 'rb').read
74
+ end
75
+
76
+ def print_threads
77
+ @result.threads.each do |thread|
78
+ print_thread(thread)
79
+ end
80
+ end
81
+
82
+ def print_thread(thread)
83
+ print_header(thread)
84
+ print_methods(thread)
85
+ print_footer(thread)
86
+ end
87
+
88
+ def print_header(thread)
89
+ @output << "Measure Mode: %s\n" % @result.measure_mode_string
90
+ @output << "Thread ID: %d\n" % thread.id
91
+ @output << "Fiber ID: %d\n" % thread.fiber_id unless thread.id == thread.fiber_id
92
+ @output << "Total: %0.6f\n" % thread.total_time
93
+ @output << "Sort by: #{sort_method}\n"
94
+ @output << "\n"
95
+ print_column_headers
96
+ end
97
+
98
+ def print_column_headers
99
+ end
100
+
101
+ def print_footer(thread)
102
+ metric_data = {
103
+ 0 => { label: "time", prefix: "", suffix: "spent" },
104
+ 1 => { label: "time", prefix: "", suffix: "spent" },
105
+ 2 => { label: "allocations", prefix: "number of ", suffix: "made" },
106
+ 3 => { label: "memory", prefix: "", suffix: "used" }
107
+ }
108
+
109
+ metric = metric_data[@result.measure_mode]
110
+
111
+ metric_label = metric[:label]
112
+ metric_suffix = metric[:suffix]
113
+ metric_prefix = metric[:prefix]
114
+
115
+ metric1 = "#{metric_label} #{metric_suffix}"
116
+ metric2 = "#{metric_prefix}#{metric1}"
117
+ metric3 = metric_label
118
+
119
+ # Output the formatted text
120
+ @output << <<~EOT
121
+
122
+ * recursively called methods
123
+
124
+ Columns are:
125
+
126
+ %self - The percentage of #{metric1} by this method relative to the total #{metric3} in the entire program.
127
+ total - The total #{metric2} by this method and its children.
128
+ self - The #{metric2} by this method.
129
+ wait - The time this method spent waiting for other threads.
130
+ child - The #{metric2} by this method's children.
131
+ calls - The number of times this method was called.
132
+ name - The name of the method.
133
+ location - The location of the method.
134
+
135
+ The interpretation of method names is:
136
+
137
+ * MyObject#test - An instance method "test" of the class "MyObject"
138
+ * <Object:MyObject>#test - The <> characters indicate a method on a singleton class.
139
+
140
+ EOT
141
+ end
142
+ end
143
+ end
@@ -1,3 +1,3 @@
1
- module RubyProf
2
- VERSION = "2.0.3"
3
- end
1
+ module RubyProf
2
+ VERSION = "2.0.4"
3
+ end
data/ruby-prof.gemspec CHANGED
@@ -1,66 +1,66 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- $:.push File.expand_path("../lib", __FILE__)
4
- require "ruby-prof/version"
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "ruby-prof"
8
-
9
- spec.homepage = "https://github.com/ruby-prof/ruby-prof/"
10
- spec.summary = "Fast Ruby profiler"
11
- spec.description = <<-EOF
12
- ruby-prof is a fast code profiler for Ruby. It is a C extension and
13
- therefore is many times faster than the standard Ruby profiler. It
14
- supports both flat and graph profiles. For each method, graph profiles
15
- show how long the method ran, which methods called it and which
16
- methods it called. RubyProf generate both text and html and can output
17
- it to standard out or to a file.
18
- EOF
19
- spec.license = 'BSD-2-Clause'
20
- spec.version = RubyProf::VERSION
21
-
22
- spec.metadata = {
23
- "bug_tracker_uri" => "https://github.com/ruby-prof/ruby-prof/issues",
24
- "changelog_uri" => "https://github.com/ruby-prof/ruby-prof/blob/master/CHANGELOG.md",
25
- "documentation_uri" => "https://ruby-prof.github.io/",
26
- "source_code_uri" => "https://github.com/ruby-prof/ruby-prof/tree/v#{spec.version}",
27
- }
28
-
29
- spec.author = "Shugo Maeda, Charlie Savage, Roger Pack, Stefan Kaes"
30
- spec.email = "shugo@ruby-lang.org, cfis@savagexi.com, rogerdpack@gmail.com, skaes@railsexpress.de"
31
- spec.platform = Gem::Platform::RUBY
32
- spec.require_path = "lib"
33
- spec.bindir = "bin"
34
- spec.executables = ["ruby-prof", "ruby-prof-check-trace"]
35
- spec.extensions = ["ext/ruby_prof/extconf.rb"]
36
- spec.files = Dir['CHANGELOG.md',
37
- 'LICENSE',
38
- 'Rakefile',
39
- 'README.md',
40
- 'ruby-prof.gemspec',
41
- 'bin/ruby-prof',
42
- 'bin/ruby-prof-check-trace',
43
- 'docs/**/*',
44
- 'ext/ruby_prof/extconf.rb',
45
- 'ext/ruby_prof/*.c',
46
- 'ext/ruby_prof/*.h',
47
- 'ext/ruby_prof/vc/*.sln',
48
- 'ext/ruby_prof/vc/*.vcxproj',
49
- 'lib/ruby-prof.rb',
50
- 'lib/unprof.rb',
51
- 'lib/ruby-prof/*.rb',
52
- 'lib/ruby-prof/assets/*',
53
- 'lib/ruby-prof/profile/*.rb',
54
- 'lib/ruby-prof/printers/*.rb',
55
- 'test/*.rb']
56
-
57
- spec.test_files = Dir["test/test_*.rb"]
58
- spec.required_ruby_version = '>= 3.2.0'
59
- spec.date = Time.now.strftime('%Y-%m-%d')
60
- spec.homepage = 'https://github.com/ruby-prof/ruby-prof'
61
- spec.add_dependency('base64')
62
- spec.add_dependency('ostruct')
63
- spec.add_development_dependency('minitest')
64
- spec.add_development_dependency('rake-compiler')
65
- spec.add_development_dependency('rdoc')
66
- end
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+ require "ruby-prof/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruby-prof"
8
+
9
+ spec.homepage = "https://github.com/ruby-prof/ruby-prof/"
10
+ spec.summary = "Fast Ruby profiler"
11
+ spec.description = <<-EOF
12
+ ruby-prof is a fast code profiler for Ruby. It is a C extension and
13
+ therefore is many times faster than the standard Ruby profiler. It
14
+ supports both flat and graph profiles. For each method, graph profiles
15
+ show how long the method ran, which methods called it and which
16
+ methods it called. RubyProf generate both text and html and can output
17
+ it to standard out or to a file.
18
+ EOF
19
+ spec.license = 'BSD-2-Clause'
20
+ spec.version = RubyProf::VERSION
21
+
22
+ spec.metadata = {
23
+ "bug_tracker_uri" => "https://github.com/ruby-prof/ruby-prof/issues",
24
+ "changelog_uri" => "https://github.com/ruby-prof/ruby-prof/blob/master/CHANGELOG.md",
25
+ "documentation_uri" => "https://ruby-prof.github.io/",
26
+ "source_code_uri" => "https://github.com/ruby-prof/ruby-prof/tree/#{spec.version}",
27
+ }
28
+
29
+ spec.author = "Shugo Maeda, Charlie Savage, Roger Pack, Stefan Kaes"
30
+ spec.email = "shugo@ruby-lang.org, cfis@savagexi.com, rogerdpack@gmail.com, skaes@railsexpress.de"
31
+ spec.platform = Gem::Platform::RUBY
32
+ spec.require_path = "lib"
33
+ spec.bindir = "bin"
34
+ spec.executables = ["ruby-prof", "ruby-prof-check-trace"]
35
+ spec.extensions = ["ext/ruby_prof/extconf.rb"]
36
+ spec.files = Dir['CHANGELOG.md',
37
+ 'LICENSE',
38
+ 'Rakefile',
39
+ 'README.md',
40
+ 'ruby-prof.gemspec',
41
+ 'bin/ruby-prof',
42
+ 'bin/ruby-prof-check-trace',
43
+ 'docs/**/*',
44
+ 'ext/ruby_prof/extconf.rb',
45
+ 'ext/ruby_prof/*.c',
46
+ 'ext/ruby_prof/*.h',
47
+ 'ext/ruby_prof/vc/*.sln',
48
+ 'ext/ruby_prof/vc/*.vcxproj',
49
+ 'lib/ruby-prof.rb',
50
+ 'lib/unprof.rb',
51
+ 'lib/ruby-prof/*.rb',
52
+ 'lib/ruby-prof/assets/*',
53
+ 'lib/ruby-prof/profile/*.rb',
54
+ 'lib/ruby-prof/printers/*.rb',
55
+ 'test/*.rb']
56
+
57
+ spec.test_files = Dir["test/test_*.rb"]
58
+ spec.required_ruby_version = '>= 3.2.0'
59
+ spec.date = Time.now.strftime('%Y-%m-%d')
60
+ spec.homepage = 'https://github.com/ruby-prof/ruby-prof'
61
+ spec.add_dependency('base64')
62
+ spec.add_dependency('ostruct')
63
+ spec.add_development_dependency('minitest')
64
+ spec.add_development_dependency('rake-compiler')
65
+ spec.add_development_dependency('rdoc')
66
+ end
@@ -96,4 +96,15 @@ class PrinterFlatTest < TestCase
96
96
 
97
97
  assert self_percents.min >= 0.1
98
98
  end
99
+
100
+ def test_flat_result_nil_sort_method
101
+ printer = RubyProf::FlatPrinter.new(self.run_profile)
102
+
103
+ output = StringIO.new
104
+ printer.print(output, sort_method: nil)
105
+ total_times = flat_output_nth_column_values(output.string, 2)
106
+
107
+ # nil sort_method should fall back to default (total_time)
108
+ assert_sorted total_times
109
+ end
99
110
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-prof
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shugo Maeda, Charlie Savage, Roger Pack, Stefan Kaes
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-02-28 00:00:00.000000000 Z
10
+ date: 2026-03-03 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: base64
@@ -236,7 +236,7 @@ metadata:
236
236
  bug_tracker_uri: https://github.com/ruby-prof/ruby-prof/issues
237
237
  changelog_uri: https://github.com/ruby-prof/ruby-prof/blob/master/CHANGELOG.md
238
238
  documentation_uri: https://ruby-prof.github.io/
239
- source_code_uri: https://github.com/ruby-prof/ruby-prof/tree/v2.0.3
239
+ source_code_uri: https://github.com/ruby-prof/ruby-prof/tree/2.0.4
240
240
  rdoc_options: []
241
241
  require_paths:
242
242
  - lib