Skip to content

Commit

Permalink
Fold output of each benchmark (#10914)
Browse files Browse the repository at this point in the history
(cherry picked from commit 89c5b31)
  • Loading branch information
JaroslavTulach authored and jdunkerley committed Sep 9, 2024
1 parent 97af4f3 commit b9a8ab3
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 4 deletions.
16 changes: 15 additions & 1 deletion build/ci_utils/src/program/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,21 @@ pub fn spawn_log_processor(
match String::from_utf8(line_bytes) {
Ok(line) => {
let line = line.trim_end_matches('\r');
info!("{prefix} {line}");
let mut command = false;
if let Some(command_at) = line.find("::") {
if let Some(group_at) = line.find("group") {
// we support: `::group` and `::endgroup` right now
if command_at < group_at && group_at < command_at + 10 {
let line_without_prefix = &line[command_at..];
// intentionally using println to avoid info!'s prefix
println!("{line_without_prefix}");
command = true;
}
}
}
if !command {
info!("{prefix} {line}");
}
}
Err(e) => {
error!("{prefix} Failed to decode a line from output: {e}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import org.openjdk.jmh.infra.BenchmarkParams;
import org.openjdk.jmh.infra.IterationParams;
import org.openjdk.jmh.results.BenchmarkResult;
import org.openjdk.jmh.results.IterationResult;
import org.openjdk.jmh.results.RunResult;
import org.openjdk.jmh.runner.Defaults;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.format.OutputFormat;
import org.openjdk.jmh.runner.format.OutputFormatFactory;
import org.openjdk.jmh.runner.options.CommandLineOptionException;
import org.openjdk.jmh.runner.options.CommandLineOptions;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;

Expand All @@ -18,6 +26,9 @@ public class BenchmarksRunner {
public static final File REPORT_FILE = new File("./bench-report.xml");

public static void run(String[] args) throws RunnerException {
if (args.length == 0) {
args = new String[] {"--jvmArgs=-Dbench.all=true"};
}
CommandLineOptions cmdOpts = null;
try {
cmdOpts = new CommandLineOptions(args);
Expand All @@ -31,7 +42,7 @@ public static void run(String[] args) throws RunnerException {
// Do not report results from `compileOnly` mode
runCompileOnly(cmdOpts.getIncludes());
} else {
Runner jmhRunner = new Runner(cmdOpts);
var jmhRunner = createRunner(cmdOpts);

if (cmdOpts.shouldHelp()) {
System.err.println("Enso benchmark runner: A modified JMH runner for Enso benchmarks.");
Expand Down Expand Up @@ -82,7 +93,7 @@ private static void runCompileOnly(List<String> includes) {
.forks(0);
includes.forEach(optsBuilder::include);
var opts = optsBuilder.build();
var runner = new Runner(opts);
var runner = createRunner(opts);
try {
runner.run();
System.out.println(
Expand All @@ -107,4 +118,84 @@ private static BenchmarkItem reportResult(String label, RunResult result) throws
Report.writeToFile(report, REPORT_FILE);
return benchItem;
}

private static Runner createRunner(Options cmdOpts) {
var output =
OutputFormatFactory.createFormatInstance(
System.out, cmdOpts.verbosity().orElse(Defaults.VERBOSITY));
Runner jmhRunner = new Runner(cmdOpts, new GitHubActionsFormat(output));
return jmhRunner;
}

private static final class GitHubActionsFormat implements OutputFormat {
private final OutputFormat output;

GitHubActionsFormat(OutputFormat output) {
this.output = output;
}

@Override
public void iteration(BenchmarkParams benchParams, IterationParams params, int iteration) {
output.iteration(benchParams, params, iteration);
}

@Override
public void iterationResult(
BenchmarkParams benchParams, IterationParams params, int iteration, IterationResult data) {
output.iterationResult(benchParams, params, iteration, data);
}

@Override
public void startBenchmark(BenchmarkParams benchParams) {
output.println("::group::" + benchParams.getBenchmark());
}

@Override
public void endBenchmark(BenchmarkResult result) {
output.println("::endgroup::");
}

@Override
public void startRun() {
output.startRun();
}

@Override
public void endRun(Collection<RunResult> result) {
output.endRun(result);
}

@Override
public void print(String s) {
output.print(s);
}

@Override
public void println(String s) {
output.println(s);
}

@Override
public void flush() {
output.flush();
}

@Override
public void close() {}

@Override
public void verbosePrintln(String s) {
output.verbosePrintln(s);
}

@Override
public void write(int b) {
output.write(b);
}

@Override
public void write(byte[] b) throws IOException {
output.write(b);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,19 @@ public void dumpCompilationMessages(IterationParams it) {
@TearDown
public void checkNoTruffleCompilation(BenchmarkParams params) {
if (compilationMessagesFound) {
System.err.println(compilationLog.toString());
var limit = Boolean.getBoolean("bench.all") ? 10 : Integer.MAX_VALUE;
for (var l : compilationLog.toString().split("\\n")) {
var pipe = l.indexOf('|');
if (pipe > 0) {
l = l.substring(0, pipe);
}
System.out.println(l);
if (limit-- <= 0) {
System.out.println("... to see more use:");
System.out.println("benchOnly " + params.getBenchmark());
break;
}
}
}
}
Expand Down

0 comments on commit b9a8ab3

Please sign in to comment.