summaryrefslogtreecommitdiff
path: root/lib/irb/init.rb
diff options
context:
space:
mode:
authorUlysse Buonomo <buonomo.ulysse@gmail.com>2021-05-27 07:35:09 +0200
committeraycabta <aycabta@gmail.com>2021-06-21 18:03:49 +0900
commit5cc11845b2feb609a54fd1be8748da590eeebdb3 (patch)
tree6e9a946782f9e19f92e0084ed974add963342880 /lib/irb/init.rb
parent90df42642628340a6826053d2db606b425833964 (diff)
[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
Diffstat (limited to 'lib/irb/init.rb')
-rw-r--r--lib/irb/init.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/irb/init.rb b/lib/irb/init.rb
index 3a5f3de26c..5923c54a29 100644
--- a/lib/irb/init.rb
+++ b/lib/irb/init.rb
@@ -120,7 +120,11 @@ module IRB # :nodoc:
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'
@@ -130,10 +134,18 @@ module IRB # :nodoc:
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.()