changeset 7247:1706be855f0e

Use ThreadMXBean to get CPU time instead of Wallclock time for Timers if possible Fix debug metric summary Cosmetic alignement in GraalOptions
author Gilles Duboscq <duboscq@ssw.jku.at>
date Mon, 17 Dec 2012 16:38:48 +0100
parents cccec951cb76
children b903c1099f41
files graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/TimerImpl.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java
diffstat 3 files changed, 66 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- 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();
+        }
+    }
 }
--- 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;
     }
--- 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