[ruby/irb] Improve stackprof measure
Allow usage of more detailed args when setting stackprof callback. Signed-off-by: Ulysse Buonomo <buonomo.ulysse@gmail.com> https://github.com/ruby/irb/commit/c9d101f450
This commit is contained in:
parent
90df426426
commit
5cc11845b2
@ -120,7 +120,11 @@ module IRB # :nodoc:
|
|||||||
puts 'processing time: %fs' % (now - time) if IRB.conf[:MEASURE]
|
puts 'processing time: %fs' % (now - time) if IRB.conf[:MEASURE]
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
# arg can be either a symbol for the mode (:cpu, :wall, ..) or a hash for
|
||||||
|
# a more complete configuration.
|
||||||
|
# See https://github.com/tmm1/stackprof#all-options.
|
||||||
@CONF[:MEASURE_PROC][:STACKPROF] = proc { |context, code, line_no, arg, &block|
|
@CONF[:MEASURE_PROC][:STACKPROF] = proc { |context, code, line_no, arg, &block|
|
||||||
|
return block.() unless IRB.conf[:MEASURE]
|
||||||
success = false
|
success = false
|
||||||
begin
|
begin
|
||||||
require 'stackprof'
|
require 'stackprof'
|
||||||
@ -130,10 +134,18 @@ module IRB # :nodoc:
|
|||||||
end
|
end
|
||||||
if success
|
if success
|
||||||
result = nil
|
result = nil
|
||||||
stackprof_result = StackProf.run(mode: arg ? arg : :cpu) do
|
arg = { mode: arg || :cpu } unless arg.is_a?(Hash)
|
||||||
|
stackprof_result = StackProf.run(**arg) do
|
||||||
result = block.()
|
result = block.()
|
||||||
end
|
end
|
||||||
StackProf::Report.new(stackprof_result).print_text if IRB.conf[:MEASURE]
|
case stackprof_result
|
||||||
|
when File
|
||||||
|
puts "StackProf report saved to #{stackprof_result.path}"
|
||||||
|
when Hash
|
||||||
|
StackProf::Report.new(stackprof_result).print_text
|
||||||
|
else
|
||||||
|
puts "Stackprof ran with #{arg.inspect}"
|
||||||
|
end
|
||||||
result
|
result
|
||||||
else
|
else
|
||||||
block.()
|
block.()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user