Skip to content

Commit

Permalink
enable counters and timers during compilation retry (GR-45257)
Browse files Browse the repository at this point in the history
  • Loading branch information
dougxc committed Apr 1, 2023
1 parent 2224f3f commit 734f621
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import static org.graalvm.compiler.core.GraalCompilerOptions.MaxCompilationProblemsPerAction;
import static org.graalvm.compiler.core.common.GraalOptions.TrackNodeSourcePosition;
import static org.graalvm.compiler.debug.DebugOptions.Dump;
import static org.graalvm.compiler.debug.DebugOptions.Time;
import static org.graalvm.compiler.debug.DebugOptions.Count;
import static org.graalvm.compiler.debug.DebugOptions.DumpPath;
import static org.graalvm.compiler.debug.DebugOptions.MethodFilter;
import static org.graalvm.compiler.debug.DebugOptions.PrintBackendCFG;
Expand Down Expand Up @@ -336,33 +338,47 @@ protected T handleFailure(DebugContext initialDebug, Throwable cause) {
OptionValues retryOptions = new OptionValues(initialOptions,
Dump, ":" + DebugOptions.DiagnoseDumpLevel.getValue(initialOptions),
MethodFilter, null,
Count, "",
Time, "",
DumpPath, dumpPath,
PrintBackendCFG, true,
TrackNodeSourcePosition, true);

ByteArrayOutputStream logBaos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(logBaos);
try (DebugContext retryDebug = createRetryDebugContext(initialDebug, retryOptions, ps)) {
T res = performCompilation(retryDebug);
T res;
try {
res = performCompilation(retryDebug);
} finally {
ps.println("<Metrics>");
retryDebug.printMetrics(initialDebug.getDescription(), ps, true);
ps.println("</Metrics>");
}
ps.println("There was no exception during retry.");
return postRetry(action, retryLogFile, logBaos, ps, res);
finalizeRetryLog(retryLogFile, logBaos, ps);
return postRetry(action, res);
} catch (Throwable e) {
ps.println("Exception during retry:");
e.printStackTrace(ps);
return postRetry(action, retryLogFile, logBaos, ps, handleException(cause));
finalizeRetryLog(retryLogFile, logBaos, ps);
return postRetry(action, handleException(cause));
}
}
}

private T postRetry(ExceptionAction action, String retryLogFile, ByteArrayOutputStream logBaos, PrintStream ps, T res) {
private T postRetry(ExceptionAction action, T res) {
maybeExitVM(action);
return res;
}

private static void finalizeRetryLog(String retryLogFile, ByteArrayOutputStream logBaos, PrintStream ps) {
ps.close();
try (OutputStream fos = PathUtilities.openOutputStream(retryLogFile, true)) {
fos.write(logBaos.toByteArray());
} catch (Throwable e) {
TTY.printf("Error writing to %s: %s%n", retryLogFile, e);
}
maybeExitVM(action);
return res;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2301,7 +2301,22 @@ private void printMetricsCSV(PrintStream out, Object compilable, Integer identit
}

/**
* Appends metrics in a human readable format to {@code out} for a single method compilation.
* Prints the metrics in a human-readable format to {@code out} for a single method compilation.
*
* @param clear specifies if the metrics should be cleared after printing
*/
public void printMetrics(Description desc, PrintStream out, boolean clear) {
if (metricValues == null) {
return;
}
printMetrics(out, desc.compilable, 0, 0, desc.identifier);
if (clear) {
metricValues = null;
}
}

/**
* Appends metrics in a human-readable format to {@code out} for a single method compilation.
*
* @param identity the identity hash code of {@code compilable}
* @param compilationNr where this compilation lies in the ordered sequence of all compilations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void testTruffleCompilation3() throws IOException, InterruptedException {
"org.graalvm.compiler.truffle.test.SLTruffleGraalTestSuite", "test");
}

private static final boolean VERBOSE = Boolean.getBoolean(CompilationWrapperTest.class.getSimpleName() + ".verbose");
private static final boolean VERBOSE = Boolean.getBoolean("CompilationWrapperTest.verbose");

private static void testHelper(List<Probe> initialProbes, List<String> extraVmArgs, String... mainClassAndArgs) throws IOException, InterruptedException {
final File dumpPath = new File(CompilationWrapperTest.class.getSimpleName() + "_" + System.currentTimeMillis()).getAbsoluteFile();
Expand Down Expand Up @@ -262,6 +262,12 @@ String test() {
entries.add(name);
if (name.endsWith(".bgv") || name.endsWith(".cfg")) {
bgvOrCfgFiles++;
} else if (name.endsWith("retry.log")) {
String log = new String(dd.getInputStream(ze).readAllBytes());
Pattern re = Pattern.compile("<Metrics>.*</Metrics>", Pattern.DOTALL);
if (!re.matcher(log).find()) {
Assert.fail(String.format("Could not find %s in %s:%n%s", re.pattern(), name, log));
}
}
}
if (bgvOrCfgFiles == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ public final class SubprocessUtil {
/**
* The name of the boolean system property that can be set to preserve temporary files created
* as arguments files passed to the java launcher.
*
* @see "https://docs.oracle.com/javase/9/tools/java.htm#JSWOR-GUID-4856361B-8BFD-4964-AE84-121F5F6CF111"
*/
public static final String KEEP_TEMPORARY_ARGUMENT_FILES_PROPERTY_NAME = "test." + SubprocessUtil.class.getSimpleName() + ".keepTempArgumentFiles";
public static final String KEEP_TEMPORARY_ARGUMENT_FILES_PROPERTY_NAME = "test.SubprocessUtil.keepTempArgumentFiles";

private SubprocessUtil() {
}
Expand Down

0 comments on commit 734f621

Please sign in to comment.