# HG changeset patch # User Josef Eisl # Date 1454581794 -3600 # Node ID 40a929274cca0a03b712d60d6ea95c47d9d329d3 # Parent 7b9a9c419f583c6ebf70576be46911f02f4ae350 BenchmarkCounters: add BenchmarkCountersFile option. diff -r 7b9a9c419f58 -r 40a929274cca graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java Thu Feb 04 11:26:13 2016 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java Thu Feb 04 11:29:54 2016 +0100 @@ -22,6 +22,7 @@ */ package com.oracle.graal.hotspot.debug; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; @@ -102,6 +103,8 @@ public static final OptionValue DynamicCountersPrintGroupSeparator = new OptionValue<>(true); @Option(help = "Print in human readable format", type = OptionType.Debug) public static final OptionValue DynamicCountersHumanReadable = new OptionValue<>(true); + @Option(help = "Benchmark counters log file (default is stdout)", type = OptionType.Debug) + public static final OptionValue BenchmarkCountersFile = new OptionValue<>(null); @Option(help = "Dump dynamic counters", type = OptionType.Debug) public static final StableOptionValue BenchmarkCountersDumpDynamic = new StableOptionValue<>(true); @Option(help = "Dump static counters", type = OptionType.Debug) @@ -364,7 +367,7 @@ if (waitingForEnd) { waitingForEnd = false; running = false; - BenchmarkCounters.dump(delegate, (System.nanoTime() - startTime) / 1000000000d, jvmciRuntime.collectCounters(), 100); + BenchmarkCounters.dump(getPrintStream(), (System.nanoTime() - startTime) / 1000000000d, jvmciRuntime.collectCounters(), 100); } break; } @@ -393,7 +396,7 @@ if (Options.TimedDynamicCounters.getValue() > 0) { Thread thread = new Thread() { long lastTime = System.nanoTime(); - PrintStream out = TTY.out; + PrintStream out = getPrintStream(); @Override public void run() { @@ -420,7 +423,19 @@ public static void shutdown(HotSpotJVMCIRuntime jvmciRuntime, long compilerStartTime) { if (Options.GenericDynamicCounters.getValue()) { - dump(TTY.out, (System.nanoTime() - compilerStartTime) / 1000000000d, jvmciRuntime.collectCounters(), 100); + dump(getPrintStream(), (System.nanoTime() - compilerStartTime) / 1000000000d, jvmciRuntime.collectCounters(), 100); } } + + private static PrintStream getPrintStream() { + if (Options.BenchmarkCountersFile.getValue() != null) { + try { + return new PrintStream(Options.BenchmarkCountersFile.getValue()); + } catch (FileNotFoundException e) { + TTY.out().println(e.getMessage()); + TTY.out().println("Fallback to default"); + } + } + return TTY.out; + } }