src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/debug/BenchmarkCounters.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File
*** old/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/debug/BenchmarkCounters.java	Mon Mar 20 17:38:38 2017
--- new/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/debug/BenchmarkCounters.java	Mon Mar 20 17:38:38 2017

*** 44,56 **** --- 44,56 ---- import org.graalvm.compiler.debug.TTY; import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; import org.graalvm.compiler.hotspot.replacements.HotspotSnippetsOptions; import org.graalvm.compiler.nodes.debug.DynamicCounterNode; import org.graalvm.compiler.options.Option; + import org.graalvm.compiler.options.OptionKey; import org.graalvm.compiler.options.OptionType; ! import org.graalvm.compiler.options.OptionValues; import org.graalvm.compiler.options.StableOptionValue; import org.graalvm.compiler.options.UniquePathUtilities; import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; //JaCoCo Exclude
*** 91,120 **** --- 91,120 ---- static class Options { //@formatter:off @Option(help = "Turn on the benchmark counters, and displays the results on VM shutdown", type = OptionType.Debug) ! public static final OptionValue<Boolean> GenericDynamicCounters = new OptionValue<>(false); ! public static final OptionKey<Boolean> GenericDynamicCounters = new OptionKey<>(false); @Option(help = "Turn on the benchmark counters, and displays the results every n milliseconds", type = OptionType.Debug) ! public static final OptionValue<Integer> TimedDynamicCounters = new OptionValue<>(-1); ! public static final OptionKey<Integer> TimedDynamicCounters = new OptionKey<>(-1); @Option(help = "Turn on the benchmark counters, and listen for specific patterns on System.out/System.err:%n" + "Format: (err|out),start pattern,end pattern (~ matches multiple digits)%n" + "Examples:%n" + " dacapo = 'err, starting =====, PASSED in'%n" + " specjvm2008 = 'out,Iteration ~ (~s) begins:,Iteration ~ (~s) ends:'", type = OptionType.Debug) ! public static final OptionValue<String> BenchmarkDynamicCounters = new OptionValue<>(null); ! public static final OptionKey<String> BenchmarkDynamicCounters = new OptionKey<>(null); @Option(help = "Use grouping separators for number printing", type = OptionType.Debug) ! public static final OptionValue<Boolean> DynamicCountersPrintGroupSeparator = new OptionValue<>(true); ! public static final OptionKey<Boolean> DynamicCountersPrintGroupSeparator = new OptionKey<>(true); @Option(help = "Print in human readable format", type = OptionType.Debug) ! public static final OptionValue<Boolean> DynamicCountersHumanReadable = new OptionValue<>(true); ! public static final OptionKey<Boolean> DynamicCountersHumanReadable = new OptionKey<>(true); @Option(help = "Benchmark counters log file (default is stdout)", type = OptionType.Debug) ! public static final OptionValue<String> BenchmarkCountersFile = new OptionValue<>(null); ! public static final OptionKey<String> BenchmarkCountersFile = new OptionKey<>(null); @Option(help = "Dump dynamic counters", type = OptionType.Debug) ! public static final StableOptionValue<Boolean> BenchmarkCountersDumpDynamic = new StableOptionValue<>(true); ! public static final OptionKey<Boolean> BenchmarkCountersDumpDynamic = new OptionKey<>(true); @Option(help = "Dump static counters", type = OptionType.Debug) ! public static final StableOptionValue<Boolean> BenchmarkCountersDumpStatic = new StableOptionValue<>(false); ! public static final OptionKey<Boolean> BenchmarkCountersDumpStatic = new OptionKey<>(false); //@formatter:on } public static boolean enabled = false;
*** 166,193 **** --- 166,193 ---- throw new GraalError("too many counters, reduce number of counters or increase -XX:JVMCICounterSize=... (current value: " + countersSize + ")"); } return counter; } ! private static synchronized void dump(OptionValues options, PrintStream out, double seconds, long[] counters, int maxRows) { if (!counterMap.isEmpty()) { ! if (Options.DynamicCountersHumanReadable.getValue(options)) { out.println("====== dynamic counters (" + counterMap.size() + " in total) ======"); } TreeSet<String> set = new TreeSet<>(); counterMap.forEach((nameGroup, counter) -> set.add(counter.group)); for (String group : set) { if (group != null) { ! if (Options.BenchmarkCountersDumpStatic.getValue(options)) { ! dumpCounters(options, out, seconds, counters, true, group, maxRows); } ! if (Options.BenchmarkCountersDumpDynamic.getValue(options)) { ! dumpCounters(options, out, seconds, counters, false, group, maxRows); } } } ! if (Options.DynamicCountersHumanReadable.getValue(options)) { out.println("============================"); } clear(counters); }
*** 195,205 **** --- 195,205 ---- private static synchronized void clear(long[] counters) { delta = counters; } ! private static synchronized void dumpCounters(OptionValues options, PrintStream out, double seconds, long[] counters, boolean staticCounter, String group, int maxRows) { // collect the numbers long[] array; if (staticCounter) { array = new long[counterMap.size()];
*** 211,232 **** --- 211,233 ---- for (int i = 0; i < array.length; i++) { array[i] -= delta[i]; } } Set<Entry<String, Counter>> counterEntrySet = counterMap.entrySet(); ! if (Options.DynamicCountersHumanReadable.getValue(options)) { ! dumpHumanReadable(options, out, seconds, staticCounter, group, maxRows, array, counterEntrySet); } else { dumpComputerReadable(out, staticCounter, group, array, counterEntrySet); } } private static String getName(String nameGroup, String group) { return nameGroup.substring(0, nameGroup.length() - group.length() - 1); } ! private static void dumpHumanReadable(PrintStream out, double seconds, boolean staticCounter, String group, int maxRows, long[] array, Set<Entry<String, Counter>> counterEntrySet) { ! private static void dumpHumanReadable(OptionValues options, PrintStream out, double seconds, boolean staticCounter, String group, int maxRows, long[] array, + Set<Entry<String, Counter>> counterEntrySet) { // sort the counters by putting them into a sorted map TreeMap<Long, String> sorted = new TreeMap<>(); long sum = 0; for (Map.Entry<String, Counter> entry : counterEntrySet) { Counter counter = entry.getValue();
*** 250,260 **** --- 251,261 ---- iter.remove(); } cnt--; } ! String numFmt = Options.DynamicCountersPrintGroupSeparator.getValue(options) ? "%,19d" : "%19d"; if (staticCounter) { out.println("=========== " + group + " (static counters):"); for (Map.Entry<Long, String> entry : sorted.entrySet()) { long counter = entry.getKey() / array.length; out.format(Locale.US, numFmt + " %3d%% %s\n", counter, percentage(counter, sum), entry.getValue());
*** 346,356 **** --- 347,357 ---- throw e; } } } ! public static void initialize(final HotSpotJVMCIRuntime jvmciRuntime, OptionValues options) { final class BenchmarkCountersOutputStream extends CallbackOutputStream { private long startTime; private boolean running; private boolean waitingForEnd;
*** 374,392 **** --- 375,393 ---- break; case 0: if (waitingForEnd) { waitingForEnd = false; running = false; ! BenchmarkCounters.dump(options, getPrintStream(options), (System.nanoTime() - startTime) / 1000000000d, jvmciRuntime.collectCounters(), 100); } break; } } } ! if (Options.BenchmarkDynamicCounters.getValue(options) != null) { ! String[] arguments = Options.BenchmarkDynamicCounters.getValue(options).split(","); if (arguments.length == 0 || (arguments.length % 3) != 0) { throw new GraalError("invalid arguments to BenchmarkDynamicCounters: (err|out),start,end,(err|out),start,end,... (~ matches multiple digits)"); } for (int i = 0; i < arguments.length; i += 3) { if (arguments[i].equals("err")) {
*** 397,423 **** --- 398,424 ---- throw new GraalError("invalid arguments to BenchmarkDynamicCounters: err|out"); } } enabled = true; } ! if (Options.GenericDynamicCounters.getValue(options)) { enabled = true; } ! if (Options.TimedDynamicCounters.getValue(options) > 0) { Thread thread = new Thread() { long lastTime = System.nanoTime(); ! PrintStream out = getPrintStream(options); @Override public void run() { while (true) { try { ! Thread.sleep(Options.TimedDynamicCounters.getValue(options)); } catch (InterruptedException e) { } long time = System.nanoTime(); ! dump(options, out, (time - lastTime) / 1000000000d, jvmciRuntime.collectCounters(), 10); lastTime = time; } } }; thread.setDaemon(true);
*** 428,447 **** --- 429,448 ---- if (enabled) { clear(jvmciRuntime.collectCounters()); } } ! public static void shutdown(HotSpotJVMCIRuntime jvmciRuntime, OptionValues options, long compilerStartTime) { ! if (Options.GenericDynamicCounters.getValue(options)) { ! dump(options, getPrintStream(options), (System.nanoTime() - compilerStartTime) / 1000000000d, jvmciRuntime.collectCounters(), 100); } } ! private static PrintStream getPrintStream(OptionValues options) { ! if (Options.BenchmarkCountersFile.getValue(options) != null) { try { ! Path path = UniquePathUtilities.getPathGlobal(options, Options.BenchmarkCountersFile, GraalDebugConfig.Options.DumpPath, "csv"); TTY.println("Writing benchmark counters to '%s'", path); return new PrintStream(path.toFile()); } catch (FileNotFoundException e) { TTY.out().println(e.getMessage()); TTY.out().println("Fallback to default");

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/debug/BenchmarkCounters.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File