Skip to content

Commit d90e3fb

Browse files
committed
change option layout for report hot metrics phase
1 parent be8b52f commit d90e3fb

File tree

3 files changed

+39
-23
lines changed

3 files changed

+39
-23
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/BasePhase.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.graalvm.collections.EconomicMap;
3838

3939
import jdk.graal.compiler.core.GraalCompilerOptions;
40+
import jdk.graal.compiler.core.common.CompilationIdentifier;
4041
import jdk.graal.compiler.core.common.util.CompilationAlarm;
4142
import jdk.graal.compiler.debug.CounterKey;
4243
import jdk.graal.compiler.debug.DebugCloseable;
@@ -66,6 +67,7 @@
6667
import jdk.graal.compiler.phases.contract.NodeCostUtil;
6768
import jdk.graal.compiler.phases.contract.PhaseSizeContract;
6869
import jdk.graal.compiler.serviceprovider.GraalServices;
70+
import jdk.vm.ci.meta.JavaMethod;
6971
import jdk.vm.ci.meta.SpeculationLog;
7072

7173
/**
@@ -205,11 +207,11 @@ public static class PhaseOptions {
205207
@Option(help = "Exclude certain phases from compilation based on the given phase filter(s)." + PhaseFilterKey.HELP, type = OptionType.Debug)
206208
public static final PhaseFilterKey CompilationExcludePhases = new PhaseFilterKey(null, null);
207209
@Option(help = "Report hot metrics after each phase matching the given phase filter(s).", type = OptionType.Debug)
208-
public static final PhaseFilterKey ReportHotMetricsAfterPhases = new PhaseFilterKey(null, null);
210+
public static final OptionKey<String> ReportHotMetricsAfterPhases = new OptionKey<>(null);;
209211
@Option(help = "Report hot metrics before each phase matching the given phase filter(s).", type = OptionType.Debug)
210-
public static final PhaseFilterKey ReportHotMetricsBeforePhases = new PhaseFilterKey("HighTierLoweringPhase=*", null);
212+
public static final OptionKey<String> ReportHotMetricsBeforePhases = new OptionKey<String>("HighTierLoweringPhase");
211213
@Option(help = "Report hot metrics extracted from compiler IR.", type = OptionType.Debug)
212-
public static final OptionKey<Boolean> ReportHotMetrics = new OptionKey<>(false);
214+
public static final OptionKey<String> ReportHotMetrics = new OptionKey<>(null);
213215
// @formatter:on
214216
}
215217

@@ -456,12 +458,23 @@ public final void apply(final StructuredGraph graph, final C context, final bool
456458
dumpedBefore = dumpBefore(graph, context, isTopLevel, true);
457459
}
458460

459-
if (PhaseOptions.ReportHotMetrics.getValue(options) && PhaseOptions.ReportHotMetricsBeforePhases.matches(options, this, graph)) {
460-
// if there is a method filter set we must also match that one
461-
if (graph.getDebug().methodFilterMatchesCurrentMethod()) {
462-
String label = graph.name != null ? graph.name : graph.method().format("%H.%n(%p)");
463-
TTY.println("Reporting hot metrics before " + getName() + " during compilation of " + label);
464-
new ReportHotCodePhase().apply(graph, context);
461+
String reportHotMetricsMethodFilter = PhaseOptions.ReportHotMetrics.getValue(options);
462+
boolean logHotMetricsForGraph = false;
463+
if (reportHotMetricsMethodFilter != null) {
464+
jdk.graal.compiler.debug.MethodFilter hotMetricsMethodFilter = null;
465+
hotMetricsMethodFilter = jdk.graal.compiler.debug.MethodFilter.parse(reportHotMetricsMethodFilter);
466+
logHotMetricsForGraph = graph.method() != null && hotMetricsMethodFilter.matches(graph.method());
467+
if (!logHotMetricsForGraph) {
468+
CompilationIdentifier id = graph.compilationId();
469+
JavaMethod idMethod = id.asJavaMethod();
470+
logHotMetricsForGraph = idMethod != null && hotMetricsMethodFilter.matches(idMethod);
471+
}
472+
if (logHotMetricsForGraph) {
473+
if (PhaseOptions.ReportHotMetricsBeforePhases.getValue(graph.getOptions()).equals(getClass().getSimpleName())) {
474+
String label = graph.name != null ? graph.name : graph.method().format("%H.%n(%p)");
475+
TTY.println("Reporting hot metrics before " + getName() + " during compilation of " + label);
476+
new ReportHotCodePhase().apply(graph, context);
477+
}
465478
}
466479
}
467480

@@ -511,9 +524,9 @@ public final void apply(final StructuredGraph graph, final C context, final bool
511524
}
512525
}
513526

514-
if (PhaseOptions.ReportHotMetrics.getValue(options) && PhaseOptions.ReportHotMetricsAfterPhases.matches(options, this, graph)) {
515-
// if there is a method filter set we must also match that one
516-
if (graph.getDebug().methodFilterMatchesCurrentMethod()) {
527+
if (logHotMetricsForGraph) {
528+
String reportAfterPhase = PhaseOptions.ReportHotMetricsAfterPhases.getValue(graph.getOptions());
529+
if (reportAfterPhase != null && reportAfterPhase.equals(getClass().getSimpleName())) {
517530
String label = graph.name != null ? graph.name : graph.method().format("%H.%n(%p)");
518531
TTY.println("Reporting hot metrics after " + getName() + " during compilation of " + label);
519532
new ReportHotCodePhase().apply(graph, context);

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/phases/common/ReportHotCodePhase.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import jdk.graal.compiler.debug.TTY;
3333
import jdk.graal.compiler.graph.Node;
34+
import jdk.graal.compiler.graph.NodeSourcePosition;
3435
import jdk.graal.compiler.nodes.FixedGuardNode;
3536
import jdk.graal.compiler.nodes.FixedNode;
3637
import jdk.graal.compiler.nodes.GraphState;
@@ -280,9 +281,15 @@ protected void run(StructuredGraph graph, C c) {
280281
private static void reportUnknownProfile(Loop l, Node inside, ControlFlowGraph cfg) {
281282
if (inside instanceof IfNode ifNode) {
282283
if (ifNode.profileSource().isUnknown()) {
283-
warn("Unknown profile for %s with f=%s in hot loop %s, nsp is %n%s%n\tPotential Action Item: Add profile to the top-of-stack source location.%n", ifNode,
284-
cfg.blockFor(inside).getRelativeFrequency(), l,
285-
ifNode.getNodeSourcePosition().toString("\t"));
284+
NodeSourcePosition nsp = ifNode.getNodeSourcePosition();
285+
if (nsp == null) {
286+
warn("Unknown profile for %s with f=%s in hot loop %s, NO NODE SOURCE POSITION%n\tPotential Action Item: Determine lack of node source position and profile.%n", ifNode,
287+
cfg.blockFor(inside).getRelativeFrequency(), l);
288+
} else {
289+
warn("Unknown profile for %s with f=%s in hot loop %s, nsp is %n%s%n\tPotential Action Item: Add profile to the top-of-stack source location.%n", ifNode,
290+
cfg.blockFor(inside).getRelativeFrequency(), l,
291+
ifNode.getNodeSourcePosition().toString("\t"));
292+
}
286293
}
287294
}
288295
}

truffle/docs/Optimizing.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -822,19 +822,15 @@ These are similar to Truffle performance warnings but may surface later in the p
822822
### Enabling Compiler-Level Metrics
823823
To enable reporting of these metrics, launch your application with:
824824
```
825-
--vm.Djdk.graal.ReportHotMetrics=true
825+
--vm.Djdk.graal.ReportHotMetrics=<method filter>
826826
```
827827
This prints warnings and hot spots to `stdout` for all compilation units.
828828
829-
To narrow output to specific methods or functions, combine with:
829+
To narrow output to specific methods or functions use known method names like:
830830
```
831-
--vm.Djdk.graal.MethodFilter='<filter>'
831+
--vm.Djdk.graal.ReportHotMetrics='*wasm-function:5311*'
832832
```
833-
For example:
834-
```
835-
--vm.Djdk.graal.MethodFilter='*wasm-function:3708*'
836-
```
837-
833+
To improve the quality of the generated data run with node source position tracking `--vm.Djdk.graal.TrackNodeSourcePosition=true`.
838834
839835
### Example Output
840836
```

0 commit comments

Comments
 (0)