changeset 11599:d9342daa5078

added timer for each phase; imposed regex pattern check on phase names
author Doug Simon <doug.simon@oracle.com>
date Tue, 10 Sep 2013 22:06:18 +0200
parents ecbeceacca98
children 60f4c505993e
files graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/LoweringPhase.java graal/com.oracle.graal.phases/src/com/oracle/graal/phases/BasePhase.java
diffstat 2 files changed, 34 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/LoweringPhase.java	Tue Sep 10 22:05:17 2013 +0200
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/LoweringPhase.java	Tue Sep 10 22:06:18 2013 +0200
@@ -167,7 +167,7 @@
         private final SchedulePhase schedule;
 
         private Round(int iteration, PhaseContext context) {
-            super(String.format("Lowering iteration %d", iteration));
+            super("LoweringIteration" + iteration);
             this.context = context;
             this.schedule = new SchedulePhase();
         }
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/BasePhase.java	Tue Sep 10 22:05:17 2013 +0200
+++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/BasePhase.java	Tue Sep 10 22:06:18 2013 +0200
@@ -22,7 +22,10 @@
  */
 package com.oracle.graal.phases;
 
+import java.util.regex.*;
+
 import com.oracle.graal.debug.*;
+import com.oracle.graal.debug.internal.*;
 import com.oracle.graal.nodes.*;
 
 /**
@@ -32,19 +35,33 @@
  */
 public abstract class BasePhase<C> {
 
-    private String name;
+    private final String name;
 
     private static final DebugMetric metricPhaseRuns = Debug.metric("Runs");
+    private final DebugTimer phaseTimer;
+
+    private static final Pattern NAME_PATTERN = Pattern.compile("[A-Z][A-Za-z0-9]+");
+
+    private static boolean checkName(String name) {
+        assert NAME_PATTERN.matcher(name).matches() : "illegal phase name: " + name;
+        return true;
+    }
 
     protected BasePhase() {
-        this.name = this.getClass().getSimpleName();
-        if (name.endsWith("Phase")) {
-            name = name.substring(0, name.length() - "Phase".length());
+        String nm = this.getClass().getSimpleName();
+        if (nm.endsWith("Phase")) {
+            name = nm.substring(0, nm.length() - "Phase".length());
+        } else {
+            name = nm;
         }
+        assert checkName(name);
+        phaseTimer = Debug.timer("Phase_" + name);
     }
 
     protected BasePhase(String name) {
+        assert checkName(name);
         this.name = name;
+        phaseTimer = Debug.timer("Phase_" + name);
     }
 
     protected String getDetailedName() {
@@ -56,17 +73,20 @@
     }
 
     public final void apply(final StructuredGraph graph, final C context, final boolean dumpGraph) {
-        Debug.scope(name, this, new Runnable() {
+        try (TimerCloseable a = phaseTimer.start()) {
+
+            Debug.scope(name, this, new Runnable() {
 
-            public void run() {
-                BasePhase.this.run(graph, context);
-                metricPhaseRuns.increment();
-                if (dumpGraph) {
-                    Debug.dump(graph, "After phase %s", name);
+                public void run() {
+                    BasePhase.this.run(graph, context);
+                    metricPhaseRuns.increment();
+                    if (dumpGraph) {
+                        Debug.dump(graph, "After phase %s", name);
+                    }
+                    assert graph.verify();
                 }
-                assert graph.verify();
-            }
-        });
+            });
+        }
     }
 
     public final String getName() {