Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve stackprof measure #243

Merged
merged 1 commit into from
Jun 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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