From b3f30cb5f3882268364f5aae236164fb017f6aa1 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Wed, 9 Oct 2019 18:01:22 -0500 Subject: [PATCH] Add optional IO arg for .print_stackcollapse Like the other methods in the class, it allows for choosing a IO object to have the data written to. This can allow for writing to a IO object in the current ruby process and then processing it in the same process without having to do crazy STDOUT constant overwriting to achieve it. --- lib/stackprof/report.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/stackprof/report.rb b/lib/stackprof/report.rb index 2f8177b6..afcbd928 100644 --- a/lib/stackprof/report.rb +++ b/lib/stackprof/report.rb @@ -73,15 +73,15 @@ def print_json(f=STDOUT) f.puts JSON.generate(@data, max_nesting: false) end - def print_stackcollapse + def print_stackcollapse(f=STDOUT) raise "profile does not include raw samples (add `raw: true` to collecting StackProf.run)" unless raw = data[:raw] while len = raw.shift frames = raw.slice!(0, len) weight = raw.shift - print frames.map{ |a| data[:frames][a][:name] }.join(';') - puts " #{weight}" + f.print frames.map{ |a| data[:frames][a][:name] }.join(';') + f.puts " #{weight}" end end