Skip to content

Commit 8b0d1e5

Browse files
committed
JT: add jt format_time_metrics < input for formatting time metrics collected outside jt
1 parent 9f8af33 commit 8b0d1e5

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

tool/jt.rb

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,13 +1657,10 @@ def metrics_native_instructions(*args)
16571657
end
16581658
end
16591659

1660-
def metrics_time(*args)
1661-
use_json = args.delete '--json'
1662-
flamegraph = args.delete '--flamegraph'
1660+
def metrics_time_measure(use_json, *args)
16631661
native = args.include? '--native'
16641662
metrics_time_option = "#{native ? '--native.D' : '-J-D'}truffleruby.metrics.time=true"
16651663
verbose_gc_flag = native ? '--native.XX:+PrintGC' : '-J-verbose:gc' unless use_json
1666-
min_time = Float(ENV.fetch("TRUFFLERUBY_METRICS_MIN_TIME", "-1"))
16671664
args = [metrics_time_option, *verbose_gc_flag, '--no-core-load-path', *args]
16681665

16691666
samples = METRICS_REPS.times.map do
@@ -1674,6 +1671,32 @@ def metrics_time(*args)
16741671
get_times(out, (finish - start) * 1000.0)
16751672
end
16761673
log "\n", nil
1674+
samples
1675+
end
1676+
private :metrics_time_measure
1677+
1678+
def metrics_time(*args)
1679+
use_json = args.delete '--json'
1680+
flamegraph = args.delete '--flamegraph'
1681+
1682+
samples = metrics_time_measure(use_json, *args)
1683+
metrics_time_format_results(samples, use_json, flamegraph)
1684+
end
1685+
1686+
def format_time_metrics(*args)
1687+
use_json = args.delete '--json'
1688+
flamegraph = args.delete '--flamegraph'
1689+
1690+
data = STDIN.read
1691+
times = data.lines.grep(/^(before|after)\b/)
1692+
total = times.last.split.last.to_f - times.first.split.last.to_f
1693+
samples = [get_times(data, total)]
1694+
1695+
metrics_time_format_results(samples, use_json, flamegraph)
1696+
end
1697+
1698+
def metrics_time_format_results(samples, use_json, flamegraph)
1699+
min_time = Float(ENV.fetch("TRUFFLERUBY_METRICS_MIN_TIME", "-1"))
16771700

16781701
results = {}
16791702
mean_by_stack = {}
@@ -1716,6 +1739,7 @@ def metrics_time(*args)
17161739
sh "#{repo}/flamegraph.pl", "--flamechart", "--countname", "ms", path, out: "time_metrics_flamegraph.svg"
17171740
end
17181741
end
1742+
private :metrics_time_format_results
17191743

17201744
def get_times(trace, total)
17211745
result = Hash.new(0)
@@ -1724,7 +1748,7 @@ def get_times(trace, total)
17241748
result[stack.map(&:first)] = total
17251749
result[%w[total jvm]] = 0
17261750

1727-
trace.lines do |line|
1751+
trace.each_line do |line|
17281752
if line =~ /^(.+) (\d+)$/
17291753
region = $1
17301754
time = Float($2)

0 commit comments

Comments
 (0)