[Swift-commit] r6185 - branches/faster/src/org/griphyn/vdl/karajan/lib

hategan at ci.uchicago.edu hategan at ci.uchicago.edu
Tue Jan 29 16:24:14 CST 2013


Author: hategan
Date: 2013-01-29 16:24:14 -0600 (Tue, 29 Jan 2013)
New Revision: 6185

Modified:
   branches/faster/src/org/griphyn/vdl/karajan/lib/Log.java
   branches/faster/src/org/griphyn/vdl/karajan/lib/UnitStart.java
Log:
Don't compile log statements if they would produce no output; avoid useless string concatenation in unitStart if logging is not enabled

Modified: branches/faster/src/org/griphyn/vdl/karajan/lib/Log.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/lib/Log.java	2013-01-29 22:20:22 UTC (rev 6184)
+++ branches/faster/src/org/griphyn/vdl/karajan/lib/Log.java	2013-01-29 22:24:14 UTC (rev 6185)
@@ -31,8 +31,12 @@
 import org.apache.log4j.Logger;
 import org.globus.cog.karajan.analyzer.ArgRef;
 import org.globus.cog.karajan.analyzer.ChannelRef;
+import org.globus.cog.karajan.analyzer.CompilationException;
+import org.globus.cog.karajan.analyzer.Scope;
 import org.globus.cog.karajan.analyzer.Signature;
 import org.globus.cog.karajan.compiled.nodes.InternalFunction;
+import org.globus.cog.karajan.compiled.nodes.Node;
+import org.globus.cog.karajan.parser.WrapperNode;
 
 public class Log extends InternalFunction {
 	private ArgRef<String> level;
@@ -57,8 +61,24 @@
     public static Level getLevel(String lvl) {
 		return priorities.get(lvl);
 	}
-	
-	protected void runBody(LWThread thr) {
+    
+    
+    
+    @Override
+    public Node compile(WrapperNode w, Scope scope) throws CompilationException {
+        Node n = super.compile(w, scope);
+        String sLvl = this.level.getValue();
+        if (sLvl != null) {
+            // don't compile this if it won't produce output
+            if (!logger.isEnabledFor(getLevel(sLvl))) {
+                return null;
+            }
+        }
+        return n;
+    }
+
+
+    protected void runBody(LWThread thr) {
 		Stack stack = thr.getStack();
 		Level lvl = getLevel(this.level.getValue(stack));
 		if (logger.isEnabledFor(lvl)) {

Modified: branches/faster/src/org/griphyn/vdl/karajan/lib/UnitStart.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/lib/UnitStart.java	2013-01-29 22:20:22 UTC (rev 6184)
+++ branches/faster/src/org/griphyn/vdl/karajan/lib/UnitStart.java	2013-01-29 22:24:14 UTC (rev 6185)
@@ -33,32 +33,33 @@
 import org.griphyn.vdl.mapping.DSHandle;
 
 public class UnitStart extends InternalFunction {
-	public static final Logger uslogger = Logger.getLogger(UnitStart.class);
+    public static final Logger uslogger = Logger.getLogger(UnitStart.class);
     // keep compatibility with log()
     public static final Logger logger = Logger.getLogger("swift");
-    
+
     private ArgRef<String> type;
     private ArgRef<String> name;
     private ArgRef<String> line;
     private ArgRef<String> arguments;
     private ArgRef<String> outputs;
-    
+
     @Override
     protected Signature getSignature() {
-        return new Signature(params("type", optional("name", null), optional("line", null), 
+        return new Signature(params("type", optional("name", null),
+            optional("line", null),
             optional("outputs", null), optional("arguments", null)));
     }
-    
+
     private static class NamedRef {
         public final String name;
         public final VarRef<DSHandle> ref;
-        
+
         public NamedRef(String name, VarRef<DSHandle> ref) {
             this.name = name;
             this.ref = ref;
         }
     }
-    
+
     private Tracer tracer;
     private List<NamedRef> inputArgs, outputArgs;
 
@@ -84,7 +85,7 @@
         if (outs != null && outs.length() > 0) {
             outputArgs = new ArrayList<NamedRef>();
             for (String name : outs.split(",")) {
-                VarRef<DSHandle> ref = scope.getVarRef(name); 
+                VarRef<DSHandle> ref = scope.getVarRef(name);
                 outputArgs.add(new NamedRef(name, ref));
                 outNames.add(name);
             }
@@ -106,27 +107,27 @@
         else {
             inputArgs = null;
         }
-        
-    }    
-    
-    
+
+    }
+
     @Override
     protected void runBody(LWThread thr) {
         String type = this.type.getValue();
         String name = this.name.getValue();
         String line = this.line.getValue();
-        
+
         if (tracer != null && tracer.isEnabled()) {
-            tracer.trace(thr, Karajan.demangle(name) + "(" + formatArguments(thr.getStack()) + ")");
+            tracer.trace(thr, Karajan.demangle(name) + "("
+                    + formatArguments(thr.getStack()) + ")");
         }
-        
+
         log(true, type, thr, name, line);
-        
+
         if (outputArgs != null) {
             trackOutputs(thr);
         }
     }
-    
+
     private String formatArguments(Stack stack) {
         if (inputArgs != null) {
             StringBuilder sb = new StringBuilder();
@@ -153,40 +154,56 @@
 
     private void trackOutputs(LWThread thr) {
         Stack stack = thr.getStack();
-    	if (!outputArgs.isEmpty()) {
+        if (!outputArgs.isEmpty()) {
             List<DSHandle> l = new LinkedList<DSHandle>();
             for (NamedRef nr : outputArgs) {
                 l.add(nr.ref.getValue(stack));
             }
             WaitingThreadsMonitor.addOutput(thr, l);
-    	}
+        }
     }
 
-    protected static void log(boolean start, String type, LWThread thread, String name, String line) {
-        if (type.equals("COMPOUND")) {
-            logger.info((start ? "START" : "END") + type + " thread=" + thread.getName() + " name=" + name);
-        }
-        else if (type.equals("PROCEDURE")) {
-            if (start) {
-                logger.debug("PROCEDURE line=" + line + " thread=" + thread.getName() + " name=" + name);
+    protected static void log(boolean start, String type, LWThread thread,
+            String name, String line) {
+        if (logger.isInfoEnabled()) {
+            if (type.equals("COMPOUND")) {
+                logger.info((start ? "START" : "END") + type + " thread="
+                        + thread.getName() + " name=" + name);
             }
             else {
-                logger.debug("PROCEDURE_END line=" + line + " thread=" + thread.getName() + " name=" + name);
+                if (logger.isDebugEnabled()) {
+                    if (type.equals("PROCEDURE")) {
+                        if (start) {
+                            logger.debug("PROCEDURE line=" + line + " thread="
+                                    + thread.getName() + " name=" + name);
+                        }
+                        else {
+                            logger.debug("PROCEDURE_END line=" + line
+                                    + " thread="
+                                    + thread.getName() + " name=" + name);
+                        }
+                    }
+                    else if (type.equals("FOREACH_IT")) {
+                        logger.debug("FOREACH_IT_" + (start ? "START" : "END")
+                                + " line=" + line + " thread="
+                                + thread.getName());
+                        if (start) {
+                            logger.debug("SCOPE thread=" + thread.getName());
+                        }
+                    }
+                    else if (type.equals("INTERNALPROC")) {
+                        logger.debug("INTERNALPROC_"
+                                + (start ? "START" : "END")
+                                + " thread=" + thread.getName() + " name="
+                                + name);
+                    }
+                    else if (type.equals("CONDITION_BLOCK")) {
+                        if (start) {
+                            logger.debug("SCOPE thread=" + thread.getName());
+                        }
+                    }
+                }
             }
         }
-        else if (type.equals("FOREACH_IT")) {
-            logger.debug("FOREACH_IT_" + (start ? "START" : "END") + " line=" + line + " thread=" + thread.getName());
-            if (start) {
-                logger.debug("SCOPE thread=" + thread.getName());
-            }
-        }
-        else if (type.equals("INTERNALPROC")) {
-            logger.debug("INTERNALPROC_" + (start ? "START" : "END") + " thread=" + thread.getName() + " name=" + name);
-        }
-        else if (type.equals("CONDITION_BLOCK")) {
-            if (start) {
-                logger.debug("SCOPE thread=" + thread.getName());
-            }
-        }
     }
 }




More information about the Swift-commit mailing list