public FlightRecordingProfiler() throws IOException { jfrData = FileUtils.tempFile("jfrData").getAbsolutePath(); }
@Override public Collection<? extends Result> afterTrial(BenchmarkResult benchmarkResult, long l, File stdOut, File stdErr) { String target = Paths.get(SAVE_FLIGHT_OUTPUT_TO).resolve(benchmarkResult.getParams().getBenchmark() + "-" + currentId++ + ".jfr").toAbsolutePath().toString(); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); try { FileUtils.copy(jfrData, target); pw.println("Flight Recording output saved to " + target); } catch (IOException e) { e.printStackTrace(); pw.println("Unable to save flight output to " + target); pw.println("Did you miss the system property: -Djmh.jfr.saveTo ?"); } pw.flush(); pw.close(); NoResult r = new NoResult(sw.toString()); return Collections.singleton(r); }
@Override public void write(OutputFormat output, Collection<RunResult> results) { String report; try { report = createReport(results); } catch (Exception e) { StringWriter trace = new StringWriter(); e.printStackTrace(new PrintWriter(trace)); output.println("Report creation failed: " + trace.toString()); return; } output.println(report); File file = new File(uri.substring("csv:".length())); output.println(System.lineSeparator()); output.println("Writing result to file: " + file); file.getParentFile().mkdirs(); if (file.getParentFile().exists()) { try { FileUtils.writeLines(file, Collections.singleton(report)); } catch (IOException e) { output.println("Write failed: " + e.getMessage()); } } }