Skip to content

Commit

Permalink
Improve stackprof measure
Browse files Browse the repository at this point in the history
Allow usage of more detailed args when setting stackprof callback.

Signed-off-by: Ulysse Buonomo <buonomo.ulysse@gmail.com>
  • Loading branch information
BuonOmo committed Jun 2, 2021
1 parent 9c19899 commit c9d101f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ group :development do
gem 'vterm', '>= 0.0.5' if is_unix && ENV['WITH_VTERM']
gem 'yamatanooroti', '>= 0.0.6'
gem "rake"
gem "stackprof" if is_unix
end
16 changes: 14 additions & 2 deletions lib/irb/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ def IRB.init_config(ap_path)
puts 'processing time: %fs' % (now - time) if IRB.conf[:MEASURE]
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|
return block.() unless IRB.conf[:MEASURE]
success = false
begin
require 'stackprof'
Expand All @@ -130,10 +134,18 @@ def IRB.init_config(ap_path)
end
if success
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.()
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
else
block.()
Expand Down

0 comments on commit c9d101f

Please sign in to comment.