# HG changeset patch # User Gilles Duboscq # Date 1355758728 -3600 # Node ID 1706be855f0e71f83a09b88502b3d9bc8003d017 # Parent cccec951cb76c0f4291f9650ba4a12abb6d82136 Use ThreadMXBean to get CPU time instead of Wallclock time for Timers if possible Fix debug metric summary Cosmetic alignement in GraalOptions diff -r cccec951cb76 -r 1706be855f0e graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/TimerImpl.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/TimerImpl.java Mon Dec 17 16:02:43 2012 +0100 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/TimerImpl.java Mon Dec 17 16:38:48 2012 +0100 @@ -22,9 +22,12 @@ */ package com.oracle.graal.debug.internal; +import java.lang.management.*; + import com.oracle.graal.debug.*; public final class TimerImpl extends DebugValue implements DebugTimer { + private static final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); public static final TimerCloseable VOID_CLOSEABLE = new TimerCloseable() { @Override @@ -41,20 +44,22 @@ @Override public TimerCloseable start() { if (Debug.isTimeEnabled()) { - final long startTime = System.nanoTime(); + long startTime; + if (threadMXBean.isCurrentThreadCpuTimeSupported()) { + startTime = threadMXBean.getCurrentThreadCpuTime(); + } else { + startTime = System.nanoTime(); + } if (valueToSubstract.get() == null) { valueToSubstract.set(0L); } - final long previousValueToSubstract = valueToSubstract.get(); - TimerCloseable result = new TimerCloseable() { - @Override - public void close() { - long timeSpan = System.nanoTime() - startTime; - long oldValueToSubstract = valueToSubstract.get(); - valueToSubstract.set(timeSpan + previousValueToSubstract); - TimerImpl.this.addToCurrentValue(timeSpan - oldValueToSubstract); - } - }; + long previousValueToSubstract = valueToSubstract.get(); + AbstractTimer result; + if (threadMXBean.isCurrentThreadCpuTimeSupported()) { + result = new CpuTimeTimer(startTime, previousValueToSubstract); + } else { + result = new SystemNanosTimer(startTime, previousValueToSubstract); + } valueToSubstract.set(0L); return result; } else { @@ -66,4 +71,46 @@ public String toString(long value) { return String.format("%d.%d ms", value / 1000000, (value / 100000) % 10); } + + private abstract class AbstractTimer implements TimerCloseable { + private final long startTime; + private final long previousValueToSubstract; + + private AbstractTimer(long startTime, long previousValueToSubstract) { + this.startTime = startTime; + this.previousValueToSubstract = previousValueToSubstract; + } + + @Override + public void close() { + long timeSpan = currentTime() - startTime; + long oldValueToSubstract = valueToSubstract.get(); + valueToSubstract.set(timeSpan + previousValueToSubstract); + TimerImpl.this.addToCurrentValue(timeSpan - oldValueToSubstract); + } + + protected abstract long currentTime(); + } + + private final class SystemNanosTimer extends AbstractTimer { + public SystemNanosTimer(long startTime, long previousValueToSubstract) { + super(startTime, previousValueToSubstract); + } + + @Override + protected long currentTime() { + return System.nanoTime(); + } + } + + private final class CpuTimeTimer extends AbstractTimer { + public CpuTimeTimer(long startTime, long previousValueToSubstract) { + super(startTime, previousValueToSubstract); + } + + @Override + protected long currentTime() { + return threadMXBean.getCurrentThreadCpuTime(); + } + } } diff -r cccec951cb76 -r 1706be855f0e graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Mon Dec 17 16:02:43 2012 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Mon Dec 17 16:38:48 2012 +0100 @@ -339,13 +339,8 @@ long total = 0; for (int i = 0; i < maps.size(); i++) { DebugValueMap map = maps.get(i); - // the top level accumulates some counters -> do not process the children if we find a value - long value = map.getCurrentValue(index); - if (value == 0) { - total += collectTotal(map.getChildren(), index); - } else { - total += value; - } + total += map.getCurrentValue(index); + total += collectTotal(map.getChildren(), index); } return total; } diff -r cccec951cb76 -r 1706be855f0e graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java --- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java Mon Dec 17 16:02:43 2012 +0100 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java Mon Dec 17 16:38:48 2012 +0100 @@ -124,12 +124,12 @@ public static boolean PerThreadDebugValues = ____; public static boolean SummarizeDebugValues = ____; public static boolean SummarizePerPhase = ____; - public static String Dump = null; - public static String Meter = null; - public static String Time = null; - public static String Log = null; - public static String LogFile = null; - public static String MethodFilter = null; + public static String Dump = null; + public static String Meter = null; + public static String Time = null; + public static String Log = null; + public static String LogFile = null; + public static String MethodFilter = null; public static boolean DumpOnError = ____; // Ideal graph visualizer output settings