ruby-prof 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 382fb19115df1fa6e8ac2da32cea739768fceba7228e04cd3e72009185954545
4
- data.tar.gz: 4047e3e6f69c7a8b2750346837e264ae786185f07bd1aec666ecf6cd84a08c0f
3
+ metadata.gz: fc5b4b0b4220c987ae0168f276545ade540de7ec54965edafdb528b0c83cc208
4
+ data.tar.gz: 4b7d92a744ccf7f545d5c19c73dbc8a9294465a261512bc7b9578dccde3194e5
5
5
  SHA512:
6
- metadata.gz: 41057a0f80b47b0477cd394c26bc693e6574e496b8d607004cbc0523f89f45b247569fe9af66e54c236ebc6025ff7636188b6314298db995c6d70ecda3ff5a5b
7
- data.tar.gz: 8df4a3e9dbc3fd82f65892e63a0c41f124d0c749e12b4fd120fb4bca42a4f09a5aac689f9906161e024aca9f495e75d47bf8d9fe7a9088fb1e7df5e305eb9e3f
6
+ metadata.gz: 7891771f81dfc0b4b377ff008b645ba63e5ce3b75901b5b497a6c6c8a5ed2b87eea6a201f155ab6ad646440d6d1bd3ed982acdf872a17d8486c9b5eb665741ff
7
+ data.tar.gz: a364fa0592341790d49c6c9649498a2dee553cbc4a2c6971d464b3aed350515adf84a479cd93aa925763d783e5d648528a2ad6f293628f00dd9466ac80463fef
data/CHANGES CHANGED
@@ -1,3 +1,9 @@
1
+ 1.6.2 (2023-04-17)
2
+ =====================
3
+ * Fix Profile#merge! implementation (asksurya)
4
+ * Fix ruby-prof command line program (Charlie Savage)
5
+ * Added CMakeLists.txt file (Charlie Savage)
6
+
1
7
  1.6.1 (2023-02-21)
2
8
  =====================
3
9
  * Fix loading C extension for MacOS (Charlie Savage)
data/bin/ruby-prof CHANGED
@@ -1,5 +1,10 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
+ # To make testing/debugging easier test within this source tree versus an installed gem
4
+ require 'bundler/setup'
5
+ ext_path = File.expand_path(File.join(__dir__, '..', 'ext', 'ruby_prof'))
6
+ $LOAD_PATH.unshift(File.expand_path(ext_path))
7
+
3
8
  # First require ruby-prof
4
9
  require 'ruby-prof'
5
10
 
@@ -16,37 +21,38 @@ module RubyProf
16
21
  # ruby-prof [options] <script.rb> [--] [profiled-script-command-line-options]
17
22
  #
18
23
  # Options:
19
- # -p, --printer=printer Select a printer:
20
- # flat - Prints a flat profile as text (default).
21
- # graph - Prints a graph profile as text.
22
- # graph_html - Prints a graph profile as html.
23
- # call_tree - format for KCacheGrind
24
- # call_stack - prints a HTML visualization of the call tree
25
- # dot - Prints a graph profile as a dot file
26
- # multi - Creates several reports in output directory
24
+ # --allow_exceptions Raise exceptions encountered during profiling (true) or suppress them (false)
25
+ # -E, --eval-noprof=code execute the ruby statements (not profiled)
26
+ # --exclude=methods A comma separated list of methods to exclude.
27
+ # Specify instance methods via # (Integer#times)
28
+ # Specify class methods via . (Integer.superclass)
29
+ # --exclude-common Remove common methods from the profile
30
+ # -f, --file=path Output results to a file instead of standard out.
27
31
  # -m, --min_percent=min_percent The minimum percent a method must take before
28
32
  # being included in output reports.
29
33
  # This option is not supported for call tree.
30
- # -f, --file=path Output results to a file instead of standard out.
31
34
  # --mode=measure_mode Select what ruby-prof should measure:
32
35
  # wall - Wall time (default).
33
36
  # process - Process time.
34
37
  # allocations - Object allocations (requires patched Ruby interpreter).
35
38
  # memory - Allocated memory in KB (requires patched Ruby interpreter).
39
+ # -p, --printer=printer Select a printer:
40
+ # flat - Prints a flat profile as text (default).
41
+ # graph - Prints a graph profile as text.
42
+ # graph_html - Prints a graph profile as html.
43
+ # call_tree - format for KCacheGrind
44
+ # call_stack - prints a HTML visualization of the call tree
45
+ # dot - Prints a graph profile as a dot file
46
+ # multi - Creates several reports in output directory
47
+ # -R, --require-noprof=lib require a specific library (not profiled)
36
48
  # -s, --sort=sort_mode Select how ruby-prof results should be sorted:
37
49
  # total - Total time
38
50
  # self - Self time
39
51
  # wait - Wait time
40
52
  # child - Child time
41
- # --allow_exceptions Raise exceptions encountered during profiling (true) or suppress them (false)
42
- # -R, --require-noprof=lib require a specific library (not profiled)
43
- # -E, --eval-noprof=code execute the ruby statements (not profiled)
44
- # --exclude=methods A comma separated list of methods to exclude.
45
- # Specify instance methods via # (Integer#times)
46
- # Specify class methods via . (Integer.superclass)
47
- # --exclude-common Remove common methods from the profile
48
- # -h, --help Show help message
53
+ # --track_allocations Track allocations while profiling
49
54
  # -v, --version version Show version (1.1.0)
55
+ # -h, --help Show help message
50
56
 
51
57
  class Cmd
52
58
  # :enddoc:
@@ -63,15 +69,16 @@ module RubyProf
63
69
 
64
70
  def setup_options
65
71
  @options = OpenStruct.new
66
- options.printer = RubyProf::FlatPrinter
67
- options.measure_mode = RubyProf::WALL_TIME
68
- options.min_percent = 0
69
- options.file = nil
70
72
  options.allow_exceptions = false
71
- options.exclude_common = false
72
73
  options.exclude = Array.new
74
+ options.exclude_common = false
75
+ options.file = nil
76
+ options.measure_mode = RubyProf::WALL_TIME
77
+ options.min_percent = 0
73
78
  options.pre_libs = Array.new
74
79
  options.pre_execs = Array.new
80
+ options.printer = RubyProf::FlatPrinter
81
+ options.track_allocations = false
75
82
  end
76
83
 
77
84
  # This is copied from ActiveSupport:
@@ -118,40 +125,31 @@ module RubyProf
118
125
  opts.separator ""
119
126
  opts.separator "Options:"
120
127
 
121
- opts.on('-p printer', '--printer=printer', [:flat, :flat_with_line_numbers, :graph, :graph_html, :call_tree, :call_stack, :dot, :multi],
122
- 'Select a printer:',
123
- ' flat - Prints a flat profile as text (default).',
124
- ' graph - Prints a graph profile as text.',
125
- ' graph_html - Prints a graph profile as html.',
126
- ' call_tree - format for KCacheGrind',
127
- ' call_stack - prints a HTML visualization of the call tree',
128
- ' dot - Prints a graph profile as a dot file',
129
- ' multi - Creates several reports in output directory'
130
- ) do |printer|
128
+ opts.on('--allow_exceptions', 'Raise exceptions encountered during profiling (true) or suppress them (false)') do
129
+ options.allow_exceptions = true
130
+ end
131
131
 
132
- case printer
133
- when :flat
134
- options.printer = RubyProf::FlatPrinter
135
- when :graph
136
- options.printer = RubyProf::GraphPrinter
137
- when :graph_html
138
- options.printer = RubyProf::GraphHtmlPrinter
139
- when :call_tree
140
- options.printer = RubyProf::CallTreePrinter
141
- when :call_stack
142
- options.printer = RubyProf::CallStackPrinter
143
- when :dot
144
- options.printer = RubyProf::DotPrinter
145
- when :multi
146
- options.printer = RubyProf::MultiPrinter
132
+ opts.on('-E code', '--eval-noprof=code', 'execute the ruby statements (not profiled)') do |code|
133
+ options.pre_execs << code
134
+ end
135
+
136
+ opts.on('--exclude=methods', String,
137
+ 'A comma separated list of methods to exclude.',
138
+ ' Specify instance methods via # (Integer#times)',
139
+ ' Specify class methods via . (Integer.superclass)') do |exclude_string|
140
+ exclude_string.split(',').each do |string|
141
+ match = string.strip.match(/(.*)(#|\.)(.*)/)
142
+ klass = constantize(match[1])
143
+ if match[2] == '.'
144
+ klass = klass.singleton_class
145
+ end
146
+ method = match[3].to_sym
147
+ options.exclude << [klass, method]
147
148
  end
148
149
  end
149
150
 
150
- opts.on('-m min_percent', '--min_percent=min_percent', Float,
151
- 'The minimum percent a method must take before ',
152
- ' being included in output reports.',
153
- ' This option is not supported for call tree.') do |min_percent|
154
- options.min_percent = min_percent
151
+ opts.on('--exclude-common', 'Remove common methods from the profile') do
152
+ options.exclude_common = true
155
153
  end
156
154
 
157
155
  opts.on('-f path', '--file=path',
@@ -160,6 +158,13 @@ module RubyProf
160
158
  options.old_wd = Dir.pwd
161
159
  end
162
160
 
161
+ opts.on('-m min_percent', '--min_percent=min_percent', Float,
162
+ 'The minimum percent a method must take before ',
163
+ ' being included in output reports.',
164
+ ' This option is not supported for call tree.') do |min_percent|
165
+ options.min_percent = min_percent
166
+ end
167
+
163
168
  opts.on('--mode=measure_mode',
164
169
  [:process, :wall, :allocations, :memory],
165
170
  'Select what ruby-prof should measure:',
@@ -180,6 +185,39 @@ module RubyProf
180
185
  end
181
186
  end
182
187
 
188
+ opts.on('-p printer', '--printer=printer', [:flat, :flat_with_line_numbers, :graph, :graph_html, :call_tree, :call_stack, :dot, :multi],
189
+ 'Select a printer:',
190
+ ' flat - Prints a flat profile as text (default).',
191
+ ' graph - Prints a graph profile as text.',
192
+ ' graph_html - Prints a graph profile as html.',
193
+ ' call_tree - format for KCacheGrind',
194
+ ' call_stack - prints a HTML visualization of the call tree',
195
+ ' dot - Prints a graph profile as a dot file',
196
+ ' multi - Creates several reports in output directory'
197
+ ) do |printer|
198
+
199
+ case printer
200
+ when :flat
201
+ options.printer = RubyProf::FlatPrinter
202
+ when :graph
203
+ options.printer = RubyProf::GraphPrinter
204
+ when :graph_html
205
+ options.printer = RubyProf::GraphHtmlPrinter
206
+ when :call_tree
207
+ options.printer = RubyProf::CallTreePrinter
208
+ when :call_stack
209
+ options.printer = RubyProf::CallStackPrinter
210
+ when :dot
211
+ options.printer = RubyProf::DotPrinter
212
+ when :multi
213
+ options.printer = RubyProf::MultiPrinter
214
+ end
215
+ end
216
+
217
+ opts.on('-R lib', '--require-noprof=lib', 'require a specific library (not profiled)') do |lib|
218
+ options.pre_libs << lib
219
+ end
220
+
183
221
  opts.on('-s sort_mode', '--sort=sort_mode', [:total, :self, :wait, :child],
184
222
  'Select how ruby-prof results should be sorted:',
185
223
  ' total - Total time',
@@ -199,9 +237,8 @@ module RubyProf
199
237
  end
200
238
  end
201
239
 
202
- opts.on_tail("-h", "--help", "Show help message") do
203
- puts opts
204
- exit
240
+ opts.on('--track_allocations', 'Track allocations while profiling') do
241
+ options.track_allocations = true
205
242
  end
206
243
 
207
244
  opts.on_tail("-v version", "--version", "Show version (#{RubyProf::VERSION})") do
@@ -209,35 +246,9 @@ module RubyProf
209
246
  exit
210
247
  end
211
248
 
212
- opts.on('--allow_exceptions', 'Raise exceptions encountered during profiling (true) or suppress them (false)') do
213
- options.allow_exceptions = true
214
- end
215
-
216
- opts.on('-R lib', '--require-noprof=lib', 'require a specific library (not profiled)') do |lib|
217
- options.pre_libs << lib
218
- end
219
-
220
- opts.on('-E code', '--eval-noprof=code', 'execute the ruby statements (not profiled)') do |code|
221
- options.pre_execs << code
222
- end
223
-
224
- opts.on('--exclude=methods', String,
225
- 'A comma separated list of methods to exclude.',
226
- ' Specify instance methods via # (Integer#times)',
227
- ' Specify class methods via . (Integer.superclass)') do |exclude_string|
228
- exclude_string.split(',').each do |string|
229
- match = string.strip.match(/(.*)(#|\.)(.*)/)
230
- klass = constantize(match[1])
231
- if match[2] == '.'
232
- klass = klass.singleton_class
233
- end
234
- method = match[3].to_sym
235
- options.exclude << [klass, method]
236
- end
237
- end
238
-
239
- opts.on('--exclude-common', 'Remove common methods from the profile') do
240
- options.exclude_common = true
249
+ opts.on_tail("-h", "--help", "Show help message") do
250
+ puts opts
251
+ exit
241
252
  end
242
253
  end
243
254
  end
@@ -281,12 +292,18 @@ module RubyProf
281
292
  end
282
293
 
283
294
  def run
284
- script = ARGV.shift
285
- @profile = Profile.new(options.to_h)
295
+ profile_options = {:allow_exceptions => options.allow_exceptions,
296
+ :exclude_common => options.exclude_common,
297
+ :measure_mode => options.measure_mode,
298
+ :track_allocations => options.track_allocations}
299
+
300
+ @profile = Profile.new(**profile_options)
301
+
286
302
  options.exclude.each do |klass, method|
287
303
  @profile.exclude_method!(klass, method)
288
304
  end
289
305
 
306
+ script = ARGV.shift
290
307
  profile.profile do
291
308
  load script
292
309
  end
@@ -304,7 +321,8 @@ cmd = RubyProf::Cmd.new
304
321
  at_exit {
305
322
  # Create a printer
306
323
  printer = cmd.options.printer.new(cmd.profile)
307
- printer_options = {:min_percent => cmd.options.min_percent, :sort_method => cmd.options.sort_method}
324
+ printer_options = {:min_percent => cmd.options.min_percent,
325
+ :sort_method => cmd.options.sort_method}
308
326
 
309
327
  # Get output
310
328
  if cmd.options.file