Skip to content

Commit 758004f

Browse files
committed
[GR-19220] Allow jt to create flamegraphs for CRuby (#3059)
PullRequest: truffleruby/3853
2 parents 4d54975 + 878f9eb commit 758004f

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

tool/jt.rb

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,19 +2094,36 @@ def profile(*args)
20942094
Dir.mkdir(PROFILES_DIR) unless Dir.exist?(PROFILES_DIR)
20952095

20962096
time = Time.now.strftime('%Y%m%d-%H%M%S')
2097-
svg_filename = "#{PROFILES_DIR}/flamegraph_#{time}.svg"
2097+
suffix = "_#{ENV.fetch('JT_PROFILE_SUFFIX') { truffleruby? ? @ruby_name : 'cruby' } }"
2098+
flame_file_prefix = "#{PROFILES_DIR}/flamegraph_#{time}#{suffix}"
2099+
svg_filename = "#{flame_file_prefix}.svg"
20982100

20992101
if stdin
21002102
File.write(svg_filename, STDIN.read)
21012103
else
21022104
require 'benchmark'
21032105
FileUtils.rm_f(svg_filename)
2104-
run_args = DEFAULT_PROFILE_OPTIONS + ["--cpusampler.OutputFile=#{svg_filename}"] + args
2106+
run_args = if truffleruby?
2107+
DEFAULT_PROFILE_OPTIONS + ["--cpusampler.OutputFile=#{svg_filename}"] + args
2108+
else
2109+
flame_file = "#{flame_file_prefix}.html"
2110+
flame_file_dump = "#{flame_file_prefix}.dump"
2111+
ENV['STACKPROF_RAW'] = 'true'
2112+
ENV['STACKPROF_OUT'] = flame_file_dump
2113+
2114+
['-rstackprof/autorun'] + args
2115+
end
21052116
puts Benchmark.measure {
21062117
run_ruby(env, *run_args)
21072118
}
21082119
end
2109-
app_open svg_filename
2120+
2121+
if truffleruby?
2122+
app_open svg_filename
2123+
else
2124+
run_ruby(env, '-S', 'stackprof', '--d3-flamegraph', flame_file_dump, out: flame_file)
2125+
app_open flame_file
2126+
end
21102127
end
21112128

21122129
def graph(*args)

0 commit comments

Comments
 (0)