[Swift-commit] r2762 - trunk/src/org/griphyn/vdl/karajan/lib
noreply at svn.ci.uchicago.edu
noreply at svn.ci.uchicago.edu
Sun Mar 29 14:32:56 CDT 2009
Author: hategan
Date: 2009-03-29 14:32:55 -0500 (Sun, 29 Mar 2009)
New Revision: 2762
Modified:
trunk/src/org/griphyn/vdl/karajan/lib/RuntimeStats.java
Log:
cleaned up runtime stats
Modified: trunk/src/org/griphyn/vdl/karajan/lib/RuntimeStats.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/RuntimeStats.java 2009-03-29 19:32:13 UTC (rev 2761)
+++ trunk/src/org/griphyn/vdl/karajan/lib/RuntimeStats.java 2009-03-29 19:32:55 UTC (rev 2762)
@@ -8,6 +8,7 @@
import java.util.Map;
import org.globus.cog.karajan.arguments.Arg;
+import org.globus.cog.karajan.stack.VariableNotFoundException;
import org.globus.cog.karajan.stack.VariableStack;
import org.globus.cog.karajan.util.TypeUtil;
import org.globus.cog.karajan.workflow.ExecutionException;
@@ -18,6 +19,9 @@
proof of concept. */
public class RuntimeStats extends FunctionsCollection {
+
+ public static final String TICKER = "#swift-runtime-progress-ticker";
+ public static final String PROGRESS = "#swift-runtime-progress";
public static final Arg PA_STATE = new Arg.Positional("state");
public static final int MIN_PERIOD_MS=1000;
@@ -43,12 +47,28 @@
setArguments("vdl_setprogress", new Arg[] { PA_STATE } );
setArguments("vdl_initprogressstate", new Arg[] { PA_STATE });
}
+
+ public static void setTicker(VariableStack stack, ProgressTicker ticker) {
+ stack.setGlobal(TICKER, ticker);
+ }
+
+ public static ProgressTicker getTicker(VariableStack stack) {
+ return (ProgressTicker) stack.getGlobal(TICKER);
+ }
+
+ public static void setProgress(VariableStack stack, RuntimeProgress p) {
+ stack.parentFrame().setVar(PROGRESS, p);
+ }
+
+ public static RuntimeProgress getProgress(VariableStack stack) throws VariableNotFoundException {
+ return (RuntimeProgress) stack.getDeepVar(PROGRESS);
+ }
public Object vdl_startprogressticker(VariableStack stack) throws ExecutionException {
ProgressTicker t = new ProgressTicker();
t.setDaemon(true);
t.start();
- stack.parentFrame().setVar("#swift-runtime-progress-ticker",t);
+ setTicker(stack, t);
return null;
}
@@ -59,27 +79,25 @@
}
static public void setProgress(VariableStack stack, String newState) throws ExecutionException {
- RuntimeProgress rp = (RuntimeProgress)stack.getVar("#swift-runtime-progress");
- rp.status = newState;
- ProgressTicker p = (ProgressTicker)stack.getVar("#swift-runtime-progress-ticker");
- p.dumpState();
+ getProgress(stack).status = newState;
+ getTicker(stack).dumpState();
}
public Object vdl_initprogressstate(VariableStack stack) throws ExecutionException {
RuntimeProgress rp = new RuntimeProgress();
- ProgressTicker p = (ProgressTicker)stack.getVar("#swift-runtime-progress-ticker");
+ ProgressTicker p = getTicker(stack);
synchronized (p.states) {
p.states.add(rp);
}
- stack.parentFrame().setVar("#swift-runtime-progress",rp);
+ setProgress(stack, rp);
p.dumpState();
return null;
}
public synchronized Object vdl_stopprogressticker(VariableStack stack) throws ExecutionException {
- ProgressTicker p = (ProgressTicker)stack.getVar("#swift-runtime-progress-ticker");
+ ProgressTicker p = getTicker(stack);
p.finalDumpState();
- p.stop();
+ p.shutdown();
return null;
}
@@ -90,6 +108,7 @@
long lastDumpTime = 0;
private boolean disabled;
+ private boolean shutdown;
public ProgressTicker() {
super("Progress ticker");
@@ -108,17 +127,20 @@
if (disabled) {
return;
}
- while(true) {
+ while(!shutdown) {
dumpState();
try {
Thread.sleep(MAX_PERIOD_MS);
} catch(InterruptedException e) {
-
System.err.println("Runtime ticker interrupted. Looping immediately.");
}
}
}
+
+ void shutdown() {
+ shutdown = true;
+ }
void dumpState() {
if (disabled) {
@@ -136,26 +158,30 @@
}
printStates("Final status: ");
}
+
+ public Map getSummary() {
+ Map summary = new HashMap();
+ synchronized(states) {
+ Iterator stateIterator = states.iterator();
+ // summarize details of known states into summary, with
+ // one entry per state type, storing the number of
+ // jobs in that state.
+ while(stateIterator.hasNext()) {
+ String key = ((RuntimeProgress)stateIterator.next()).status;
+ Integer count = (Integer) summary.get(key);
+ if(count == null) {
+ summary.put(key,new Integer(1));
+ } else {
+ summary.put(key,new Integer(count.intValue()+1));
+ }
+ }
+ }
+ return summary;
+ }
+
void printStates(String header) {
- Map summary = new HashMap();
- synchronized(states) {
- Iterator stateIterator = states.iterator();
-
- // summarize details of known states into summary, with
- // one entry per state type, storing the number of
- // jobs in that state.
- while(stateIterator.hasNext()) {
- String key = ((RuntimeProgress)stateIterator.next()).status;
- Integer count = (Integer) summary.get(key);
- if(count == null) {
- summary.put(key,new Integer(1));
- } else {
- summary.put(key,new Integer(count.intValue()+1));
- }
- }
- }
-
+ Map summary = getSummary();
// output the results of summarization, in a relatively
// pretty form - first the preferred order listed elements,
// and then anything remaining
@@ -182,5 +208,4 @@
class RuntimeProgress {
String status = "uninitialized";
}
-
}
More information about the Swift-commit
mailing list