Skip to content

Commit 34af70a

Browse files
committed
More fixes for metrics in GraalVM
PullRequest: truffleruby/557
2 parents e3a61d5 + 8b0d1e5 commit 34af70a

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

src/main/java/org/truffleruby/RubyLanguage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class RubyLanguage extends TruffleLanguage<RubyContext> {
6767
@Override
6868
public RubyContext createContext(Env env) {
6969
// We need to initialize the Metrics class of the language classloader
70-
Metrics.begin();
70+
Metrics.initializeOption();
7171

7272
LOGGER.fine("createContext()");
7373
Metrics.printTime("before-create-context");
@@ -88,7 +88,7 @@ protected void initializeContext(RubyContext context) throws Exception {
8888
@Override
8989
protected boolean patchContext(RubyContext context, Env newEnv) {
9090
// We need to initialize the Metrics class of the language classloader
91-
Metrics.begin();
91+
Metrics.initializeOption();
9292

9393
LOGGER.fine("patchContext()");
9494
Metrics.printTime("before-patch-context");

src/shared/java/org/truffleruby/shared/Metrics.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,26 @@ private static void printMemory(boolean isAOT) {
4343
}
4444
}
4545

46-
public static void end(boolean isAOT) {
47-
printTime("after-main");
48-
printMemory(isAOT);
46+
/**
47+
* Assigned here so the property is read after processing the --native.D... options. It needs to
48+
* be called in each classloader using the Metrics class.
49+
*/
50+
public static void initializeOption() {
51+
METRICS_TIME = Boolean.getBoolean("truffleruby.metrics.time");
4952
}
5053

51-
public static void begin() {
52-
// Assigned here so the property is read after processing the --native.D... options
53-
METRICS_TIME = Boolean.getBoolean("truffleruby.metrics.time");
54+
public static boolean getMetricsTime() {
55+
return METRICS_TIME;
56+
}
5457

58+
public static void begin() {
59+
initializeOption();
5560
printTime("before-main");
5661
}
5762

58-
public static boolean getMetricsTime() {
59-
return METRICS_TIME;
63+
public static void end(boolean isAOT) {
64+
printTime("after-main");
65+
printMemory(isAOT);
6066
}
67+
6168
}

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)