changeset 4349:7e974a026889

More work on debug framework.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Fri, 13 Jan 2012 11:04:30 +0100
parents d49c90e641cb
children 685cbfb8e08e
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/Interval.java graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/Debug.java graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/ScopeChild.java
diffstat 3 files changed, 66 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/Interval.java	Wed Jan 11 15:46:58 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/Interval.java	Fri Jan 13 11:04:30 2012 +0100
@@ -663,7 +663,7 @@
     private static final Debug.Metric instanceMetric = Debug.metric("LSRAIntervalsCreated");
 
     Interval(GraalContext context, CiValue operand, int operandNumber) {
-        instanceMetric.increment();
+        //instanceMetric.increment();
         assert operand != null;
         this.operand = operand;
         this.operandNumber = operandNumber;
--- a/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/Debug.java	Wed Jan 11 15:46:58 2012 +0100
+++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/Debug.java	Fri Jan 13 11:04:30 2012 +0100
@@ -24,71 +24,89 @@
 
 
 public class Debug {
-    public static boolean ENABLED = false;
-
-    public static void log(String msg, Object... args) {
-        if (ENABLED) {
-            DebugContext.getInstance().log(msg, args);
-        }
-    }
+    public static boolean SCOPE = false;
+    public static boolean LOG = false;
+    public static boolean METER = false;
+    public static boolean TIME = false;
 
     public static void scope(String name, Runnable runnable, Object... context) {
-        if (ENABLED) {
+        if (SCOPE) {
             DebugContext.getInstance().scope(name, runnable, context);
         } else {
             runnable.run();
         }
     }
 
-    private static final Scope VOID_SCOPE = new Scope(null);
-
-
-    public static final class Scope implements AutoCloseable {
-        private String name;
-        private Object[] context;
+    public static void log(String msg, Object... args) {
+        if (LOG) {
+            DebugContext.getInstance().log(msg, args);
+        }
+    }
 
-        private Scope(String name, Object... context) {
-            this.name = name;
-            this.context = context;
-        }
-
-        @Override
-        public void close() {
+    public static Metric metric(String name) {
+        if (METER) {
+            return new MetricImpl(name);
+        } else {
+            return VOID_METRIC;
         }
     }
 
-    private static class ScopeChild {
-        private String name;
+    public interface Metric {
+        void increment();
+        void add(int value);
+    }
 
-        protected ScopeChild(String name) {
-            this.name = name;
+    private static final Metric VOID_METRIC = new Metric() {
+        public void increment() { }
+        public void add(int value) { }
+    };
+
+    public static Timer timer(String name) {
+        if (TIME) {
+            return new TimerImpl(name);
+        } else {
+            return VOID_TIMER;
         }
     }
 
-    public static final class Metric extends ScopeChild {
-        private Metric(String name) {
+    public interface Timer {
+        void start();
+        void stop();
+    }
+
+    private static final Timer VOID_TIMER = new Timer() {
+        public void start() { };
+        public void stop() { };
+    };
+
+    private static final class MetricImpl extends ScopeChild implements Metric {
+        private MetricImpl(String name) {
             super(name);
         }
 
         public void increment() {
-            // TODO Auto-generated method stub
-
         }
 
-        public void add(int targetCodeSize) {
-            // TODO Auto-generated method stub
-
+        public void add(int value) {
         }
 
     }
 
-    public static final class Timer extends ScopeChild {
-        private Timer(String name) {
+    public static final class TimerImpl extends ScopeChild implements Timer {
+        private TimerImpl(String name) {
             super(name);
         }
+
+        @Override
+        public void start() {
+            // TODO Auto-generated method stub
+
+        }
+
+        @Override
+        public void stop() {
+            // TODO Auto-generated method stub
+
+        }
     }
-
-    public static Metric metric(String string) {
-        return new Metric(string);
-    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/ScopeChild.java	Fri Jan 13 11:04:30 2012 +0100
@@ -0,0 +1,9 @@
+package com.oracle.max.graal.debug;
+
+class ScopeChild {
+    private String name;
+
+    protected ScopeChild(String name) {
+        this.name = name;
+    }
+}
\ No newline at end of file