[Swift-commit] r6398 - in branches/faster/src/org/griphyn/vdl/karajan: . monitor monitor/items monitor/monitors monitor/monitors/ansi monitor/monitors/ansi/tui monitor/monitors/swing
hategan at ci.uchicago.edu
hategan at ci.uchicago.edu
Mon Mar 18 19:28:44 CDT 2013
Author: hategan
Date: 2013-03-18 19:28:44 -0500 (Mon, 18 Mar 2013)
New Revision: 6398
Modified:
branches/faster/src/org/griphyn/vdl/karajan/Loader.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/StateUpdater.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/SystemState.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/SystemStateListener.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/items/AbstractStatefulItem.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/items/StatefulItem.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/items/SummaryItem.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/items/TraceItem.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/Monitor.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/MonitorFactory.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/TextMonitor.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/ANSIMonitor.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/AbstractANSIDisplay.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/BensCellRenderer.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/BensModel.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/SchedulerInfoPane.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/SummaryPane.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/ANSIContext.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/LevelBar.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/LevelBars.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/swing/GanttChart.java
branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/swing/SwingMonitor.java
Log:
added ui command line argument to accept one of the (future) possible types of ui and cleaned up TUI a bit
Modified: branches/faster/src/org/griphyn/vdl/karajan/Loader.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/Loader.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/Loader.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -83,7 +83,7 @@
public static final String ARG_LOGFILE = "logfile";
public static final String ARG_CDMFILE = "cdm.file";
public static final String ARG_RUNID = "runid";
- public static final String ARG_TUI = "tui";
+ public static final String ARG_UI = "ui";
public static final String ARG_RECOMPILE = "recompile";
public static final String ARG_REDUCED_LOGGING = "reduced.logging";
public static final String ARG_MINIMAL_LOGGING = "minimal.logging";
@@ -233,7 +233,7 @@
else {
logger.info("Swift finished with no errors");
}
- if (ap.isPresent(ARG_TUI)) {
+ if (ma != null) {
ma.close();
}
System.exit(runerror ? 2 : 0);
@@ -505,7 +505,16 @@
ARG_RUNID,
"Specifies the run identifier. This must be unique for every invocation of a workflow and is used in several places to keep files from different executions cleanly separated. By default, a datestamp and random number are used to generate a run identifier.",
"string", ArgumentParser.OPTIONAL);
- ap.addFlag(ARG_TUI);
+ ap.addOption(
+ ARG_UI,
+ "Indicates how swift should display run-time information. The following are valid values:" +
+ "\n\t'summary' (default) - causesSswift to regularly print a count of jobs for each state that a job can be in" +
+ "\n\t'text' - regularly prints a more detailed table with Swift run-time information" +
+ "\n\t'TUI' - displays Swift run-time information using an interactive text user interface." +
+ " The terminal must standard ANSI/VT100 escape sequences. If a port is specified," +
+ " the interface will also be available via telnet at the specified port." +
+ "\n\t'http' - enables an http server allowing access to swift run-time information using a web browser",
+ "<summary|text|TUI[:port]|http[:[password@]port]>", ArgumentParser.OPTIONAL);
ap.addFlag(ARG_REDUCED_LOGGING, "Makes logging more terse by disabling provenance " +
"information and low-level task messages");
ap.addFlag(ARG_MINIMAL_LOGGING, "Makes logging much more terse: " +
@@ -566,8 +575,8 @@
ca.activateOptions();
}
Logger.getLogger(Log.class).setLevel(Level.INFO);
- if (ap.isPresent(ARG_TUI)) {
- ma = new MonitorAppender(projectName);
+ if (ap.isPresent(ARG_UI) && !"summary".equals(ap.getStringValue(ARG_UI))) {
+ ma = new MonitorAppender(projectName, ap.getStringValue(ARG_UI));
Logger.getRootLogger().addAppender(ma);
Logger.getLogger(Log.class).setLevel(Level.DEBUG);
Logger.getLogger(AbstractGridNode.class).setLevel(Level.DEBUG);
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/StateUpdater.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/StateUpdater.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/StateUpdater.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -28,7 +28,6 @@
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
-import org.apache.log4j.Priority;
import org.griphyn.vdl.karajan.monitor.processors.LogMessageProcessor;
public class StateUpdater {
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/SystemState.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/SystemState.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/SystemState.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -30,8 +30,6 @@
import org.griphyn.vdl.karajan.monitor.items.StatefulItem;
import org.griphyn.vdl.karajan.monitor.items.StatefulItemClass;
-import com.sun.org.apache.xpath.internal.VariableStack;
-
public class SystemState {
private Map<StatefulItemClass, StatefulItemClassSet<? extends StatefulItem>> classes;
private Set<SystemStateListener> listeners;
@@ -50,7 +48,7 @@
public void addItem(StatefulItem item) {
getItemClassSet(item.getItemClass()).add(item);
- notifyListeners(SystemStateListener.ITEM_ADDED, item);
+ notifyListeners(SystemStateListener.UpdateType.ITEM_ADDED, item);
}
@SuppressWarnings("unchecked")
@@ -68,7 +66,7 @@
public void removeItem(StatefulItem item) {
getItemClassSet(item.getItemClass()).remove(item);
- notifyListeners(SystemStateListener.ITEM_REMOVED, item);
+ notifyListeners(SystemStateListener.UpdateType.ITEM_REMOVED, item);
}
public void setParent(StatefulItem item, StatefulItem parent) {
@@ -84,10 +82,10 @@
}
public void itemUpdated(StatefulItem item) {
- notifyListeners(SystemStateListener.ITEM_UPDATED, item);
+ notifyListeners(SystemStateListener.UpdateType.ITEM_UPDATED, item);
}
- protected void notifyListeners(int updateType, StatefulItem item) {
+ protected void notifyListeners(SystemStateListener.UpdateType updateType, StatefulItem item) {
for (SystemStateListener l : listeners) {
l.itemUpdated(updateType, item);
}
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/SystemStateListener.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/SystemStateListener.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/SystemStateListener.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -23,9 +23,9 @@
import org.griphyn.vdl.karajan.monitor.items.StatefulItem;
public interface SystemStateListener {
- public static final int ITEM_ADDED = 0;
- public static final int ITEM_REMOVED = 1;
- public static final int ITEM_UPDATED = 2;
+ public enum UpdateType {
+ ITEM_ADDED, ITEM_REMOVED, ITEM_UPDATED;
+ }
- void itemUpdated(int updateType, StatefulItem item);
+ void itemUpdated(UpdateType updateType, StatefulItem item);
}
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/items/AbstractStatefulItem.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/items/AbstractStatefulItem.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/items/AbstractStatefulItem.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -26,7 +26,7 @@
public abstract class AbstractStatefulItem implements StatefulItem {
private StatefulItem parent;
- private Set children;
+ private Set<StatefulItem> children;
private final String id;
public AbstractStatefulItem(String id) {
@@ -39,7 +39,7 @@
public void addChild(StatefulItem child) {
synchronized (this) {
if (children == null) {
- children = new HashSet();
+ children = new HashSet<StatefulItem>();
}
}
synchronized (children) {
@@ -47,7 +47,7 @@
}
}
- public Collection getChildren() {
+ public Collection<StatefulItem> getChildren() {
return children;
}
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/items/StatefulItem.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/items/StatefulItem.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/items/StatefulItem.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -28,7 +28,7 @@
void addChild(StatefulItem child);
void removeChild(StatefulItem child);
- Collection getChildren();
+ Collection<StatefulItem> getChildren();
StatefulItemClass getItemClass();
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/items/SummaryItem.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/items/SummaryItem.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/items/SummaryItem.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -24,8 +24,6 @@
import java.util.HashMap;
import java.util.Map;
-import org.griphyn.vdl.karajan.lib.RuntimeStats;
-import org.griphyn.vdl.karajan.lib.RuntimeStats.ProgressTicker;
import org.griphyn.vdl.karajan.monitor.SystemState;
public class SummaryItem extends AbstractStatefulItem {
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/items/TraceItem.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/items/TraceItem.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/items/TraceItem.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -55,4 +55,9 @@
public void setEnded(int ended) {
this.ended = ended;
}
+
+ @Override
+ public String toString() {
+ return this.getID() + ": " + ended + "/" + started;
+ }
}
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/Monitor.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/Monitor.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/Monitor.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -32,4 +32,6 @@
void setOffline(boolean offline);
TimelineController getTimelineController();
+
+ void setParams(String params);
}
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/MonitorFactory.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/MonitorFactory.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/MonitorFactory.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -33,16 +33,27 @@
classes = new HashMap<String, Class<? extends Monitor>>();
classes.put("text", TextMonitor.class);
classes.put("ANSI", ANSIMonitor.class);
+ classes.put("TUI", ANSIMonitor.class);
classes.put("Swing", SwingMonitor.class);
}
public static Monitor newInstance(String type) throws InstantiationException,
IllegalAccessException {
+ String params = null;
+ if (type.contains(":")) {
+ int index = type.indexOf(':');
+ type = type.substring(0, index);
+ params = type.substring(index + 1, type.length());
+ }
Class<? extends Monitor> cls = classes.get(type);
if (cls == null) {
throw new IllegalArgumentException("Unsupported monitor type (" + type
+ "). The supported types are: " + classes.keySet());
}
- return cls.newInstance();
+ Monitor m = cls.newInstance();
+ if (params != null) {
+ m.setParams(params);
+ }
+ return m;
}
}
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/TextMonitor.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/TextMonitor.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/TextMonitor.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -20,10 +20,21 @@
*/
package org.griphyn.vdl.karajan.monitor.monitors;
+import org.griphyn.vdl.karajan.monitor.SystemStateListener;
+import org.griphyn.vdl.karajan.monitor.items.StatefulItem;
+
public class TextMonitor extends AbstractMonitor {
+
+ @Override
+ public void itemUpdated(SystemStateListener.UpdateType updateType, StatefulItem item) {
+ System.out.println(updateType + " -> " + item);
+ }
public void shutdown() {
}
+ @Override
+ public void setParams(String params) {
+ }
}
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/ANSIMonitor.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/ANSIMonitor.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/ANSIMonitor.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -24,10 +24,10 @@
import java.net.ServerSocket;
import java.net.Socket;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.Set;
import org.apache.log4j.Logger;
+import org.griphyn.vdl.karajan.monitor.SystemStateListener;
import org.griphyn.vdl.karajan.monitor.items.StatefulItem;
import org.griphyn.vdl.karajan.monitor.monitors.AbstractMonitor;
@@ -35,11 +35,12 @@
public static final Logger logger = Logger.getLogger(ANSIMonitor.class);
private ServerSocket socket;
- private Set connections;
+ private Set<RemoteANSIConnection> connections;
private AbstractANSIDisplay disp;
+ private int port;
public ANSIMonitor() {
- connections = new HashSet();
+ connections = new HashSet<RemoteANSIConnection>();
new Thread(this).start();
}
@@ -47,14 +48,16 @@
try {
disp = new LocalANSIDisplay(this);
disp.start();
- socket = new ServerSocket(11010);
- while (true) {
- Socket s = socket.accept();
- RemoteANSIConnection c = new RemoteANSIConnection(this, s);
- synchronized (connections) {
- connections.add(c);
- }
- c.start();
+ if (port != 0) {
+ socket = new ServerSocket(port);
+ while (true) {
+ Socket s = socket.accept();
+ RemoteANSIConnection c = new RemoteANSIConnection(this, s);
+ synchronized (connections) {
+ connections.add(c);
+ }
+ c.start();
+ }
}
}
catch (Exception e) {
@@ -62,15 +65,14 @@
}
}
- public void itemUpdated(int updateType, StatefulItem item) {
+ public void itemUpdated(SystemStateListener.UpdateType updateType, StatefulItem item) {
if (disp != null) {
disp.itemUpdated(updateType, item);
}
synchronized (connections) {
- Iterator i = connections.iterator();
- while (i.hasNext()) {
- ((RemoteANSIConnection) i.next()).itemUpdated(updateType, item);
- }
+ for (RemoteANSIConnection c : connections) {
+ c.itemUpdated(updateType, item);
+ }
}
}
@@ -100,4 +102,9 @@
e.printStackTrace();
}
}
+
+ @Override
+ public void setParams(String params) {
+ port = Integer.parseInt(params);
+ }
}
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/AbstractANSIDisplay.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/AbstractANSIDisplay.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/AbstractANSIDisplay.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -28,6 +28,7 @@
import org.apache.log4j.Logger;
import org.griphyn.vdl.karajan.monitor.StatefulItemClassSet;
import org.griphyn.vdl.karajan.monitor.SystemState;
+import org.griphyn.vdl.karajan.monitor.SystemStateListener;
import org.griphyn.vdl.karajan.monitor.items.ApplicationItem;
import org.griphyn.vdl.karajan.monitor.items.StatefulItem;
import org.griphyn.vdl.karajan.monitor.items.StatefulItemClass;
@@ -257,7 +258,7 @@
return ben;
}
- public void itemUpdated(int updateType, StatefulItem item) {
+ public void itemUpdated(SystemStateListener.UpdateType updateType, StatefulItem item) {
StatefulItemClass cls = item.getItemClass();
if (cls.equals(StatefulItemClass.APPLICATION)) {
if (appsTable != null) {
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/BensCellRenderer.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/BensCellRenderer.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/BensCellRenderer.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -32,10 +32,10 @@
public class BensCellRenderer extends DefaultTableCellRenderer implements
SystemStateListener {
- private Map lastUpdated;
+ private Map<String, Long> lastUpdated;
public BensCellRenderer(SystemState state) {
- lastUpdated = new HashMap();
+ lastUpdated = new HashMap<String, Long>();
state.addListener(this);
}
@@ -50,7 +50,7 @@
l.setJustification(Label.LEFT);
}
long now = System.currentTimeMillis();
- Long then = (Long) lastUpdated.get(String.valueOf(row + 1));
+ Long then = lastUpdated.get(String.valueOf(row + 1));
if (then != null) {
long t = then.longValue();
if (now - t < 2000) {
@@ -69,7 +69,7 @@
return l;
}
- public void itemUpdated(int updateType, StatefulItem item) {
+ public void itemUpdated(SystemStateListener.UpdateType updateType, StatefulItem item) {
if (item.getItemClass().equals(StatefulItemClass.TRACE)) {
lastUpdated.put(item.getID(), new Long(System.currentTimeMillis()));
}
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/BensModel.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/BensModel.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/BensModel.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -100,7 +100,7 @@
public void setValueAt(Object value, int rowIndex, int columnIndex) {
}
- public void itemUpdated(int updateType, StatefulItem item) {
+ public void itemUpdated(SystemStateListener.UpdateType updateType, StatefulItem item) {
if (item.getItemClass().equals(StatefulItemClass.TRACE)) {
fireTableDataChanged();
}
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/SchedulerInfoPane.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/SchedulerInfoPane.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/SchedulerInfoPane.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -78,7 +78,7 @@
hosts.dataChanged();
}
- public void itemUpdated(int updateType, StatefulItem item) {
+ public void itemUpdated(SystemStateListener.UpdateType updateType, StatefulItem item) {
if (item.getItemClass().equals(StatefulItemClass.HOST)) {
update();
}
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/SummaryPane.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/SummaryPane.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/SummaryPane.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -18,8 +18,9 @@
package org.griphyn.vdl.karajan.monitor.monitors.ansi;
import java.io.IOException;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
import java.util.Map;
-import java.util.TimerTask;
import org.griphyn.vdl.karajan.monitor.SystemState;
import org.griphyn.vdl.karajan.monitor.items.StatefulItemClass;
@@ -29,6 +30,7 @@
import org.griphyn.vdl.karajan.monitor.monitors.ansi.tui.Container;
import org.griphyn.vdl.karajan.monitor.monitors.ansi.tui.Dialog;
import org.griphyn.vdl.karajan.monitor.monitors.ansi.tui.Label;
+import org.griphyn.vdl.karajan.monitor.monitors.ansi.tui.LevelBar;
import org.griphyn.vdl.karajan.monitor.monitors.ansi.tui.LevelBars;
public class SummaryPane extends Container {
@@ -38,19 +40,23 @@
"Stage in", "Submitting", "Submitted", "Active", "Stage out",
"Failed", "Replicating", "Finished successfully" };
- private Label[] labels;
private LevelBars bars;
+ private LevelBar memory;
+ private Label memlabel;
public SummaryPane(SystemState state) {
this.state = state;
bars = new LevelBars(STATES.length);
- bars.setLocation(34, 2);
+ bars.setLocation(26, 2);
add(bars);
- labels = new Label[STATES.length];
for (int i = 0; i < STATES.length; i++) {
addLabel(STATES[i] + ": ", 2, 2 + i, 24);
- labels[i] = addLabel("0", 25, 2 + i, 8);
}
+
+ memlabel = addLabel("Heap: ", 2, 4 + STATES.length, 24);
+ memory = new LevelBar();
+ memory.setLocation(26, 4 + STATES.length);
+ add(memory);
GlobalTimer.getTimer().schedule(new SafeTimerTask(getScreen()) {
public void runTask() {
@@ -67,22 +73,57 @@
for (int i = 0; i < STATES.length; i++) {
Integer v = counts.get(STATES[i]);
if (v != null) {
- labels[i].setText(v.toString());
bars.setValue(i, v);
+ bars.setText(i, v.toString());
}
else {
- labels[i].setText("0");
bars.setValue(i, 0);
+ bars.setText(i, "0");
}
}
}
+ // mem
+ Runtime r = Runtime.getRuntime();
+ long heapMax = r.maxMemory();
+ long heapCrt = r.totalMemory() - r.freeMemory();
+ double fraction = (double) heapCrt / heapMax;
+ memory.setValue((float) fraction);
+ memory.setText(formatMemory(heapCrt) + " / " + formatMemory(heapMax));
redraw();
}
catch (Exception e) {
Dialog.displaySimpleDialog(getScreen(), "Error", e.toString(), new String[] {"Close"});
}
}
+
+ private static final NumberFormat NF = new DecimalFormat("###.##");
+ private String formatMemory(long v) {
+ int l = 1;
+ while (v > 512 * 1024) {
+ v = v / 1024;
+ l++;
+ }
+ return NF.format(v / 1024.0) + unit(l);
+ }
+
+ private String unit(int l) {
+ switch(l) {
+ case 0:
+ return "b";
+ case 1:
+ return "Kb";
+ case 2:
+ return "Mb";
+ case 3:
+ return "Gb";
+ case 4:
+ return "Tb";
+ default:
+ return "?";
+ }
+ }
+
private Label addLabel(String text, int x, int y, int w) {
Label l = new Label(text);
l.setLocation(x, y);
@@ -99,7 +140,8 @@
}
protected void validate() {
- bars.setSize(width - 35, STATES.length);
+ bars.setSize(width - 27, STATES.length);
+ memory.setSize(width - 27, 1);
super.validate();
}
}
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/ANSIContext.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/ANSIContext.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/ANSIContext.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -193,7 +193,9 @@
int[] sz = new int[2];
sz[0] = ((Integer) nums.get(1)).intValue();
sz[1] = ((Integer) nums.get(0)).intValue();
- logger.info("Terminal size is " + sz[0] + "x" + sz[1]);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Terminal size is " + sz[0] + "x" + sz[1]);
+ }
return sz;
}
catch (Exception e) {
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/LevelBar.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/LevelBar.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/LevelBar.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -21,10 +21,13 @@
public class LevelBar extends Component {
private float value;
+ private String text;
+ private int textColor;
public LevelBar() {
bgColor = ANSI.BLACK;
fgColor = ANSI.RED;
+ textColor = ANSI.WHITE;
}
public float getValue() {
@@ -36,6 +39,15 @@
}
protected void draw(ANSIContext context) throws IOException {
+ if (text == null) {
+ drawWithoutText(context);
+ }
+ else {
+ drawWithText(context);
+ }
+ }
+
+ private void drawWithoutText(ANSIContext context) throws IOException {
context.moveTo(sx, sy);
context.bgColor(fgColor);
int c = (int) (value * width);
@@ -43,4 +55,43 @@
context.bgColor(bgColor);
context.spaces(width - c);
}
+
+ private void drawWithText(ANSIContext context) throws IOException {
+ int textPos = (width - text.length()) / 2;
+ StringBuilder sb = new StringBuilder();
+ spaces(sb, textPos);
+ sb.append(text);
+ spaces(sb, width - textPos - text.length());
+ String s = sb.toString();
+
+ context.moveTo(sx, sy);
+ context.bgColor(fgColor);
+ context.fgColor(textColor);
+ int c = (int) (value * width);
+ context.text(s.substring(0, c));
+ context.bgColor(bgColor);
+ context.text(s.substring(c));
+ }
+
+ private void spaces(StringBuilder sb, int count) {
+ for(int i = 0; i < count; i++) {
+ sb.append(' ');
+ }
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public int getTextColor() {
+ return textColor;
+ }
+
+ public void setTextColor(int textColor) {
+ this.textColor = textColor;
+ }
}
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/LevelBars.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/LevelBars.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/ansi/tui/LevelBars.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -43,6 +43,10 @@
getBar(i).setValue((float) values[i] / range);
}
}
+
+ public void setText(int index, String text) {
+ getBar(index).setText(text);
+ }
private LevelBar getBar(int i) {
return (LevelBar) getComponents().get(i);
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/swing/GanttChart.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/swing/GanttChart.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/swing/GanttChart.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -63,8 +63,8 @@
private JTable table, header;
private HeaderModel hmodel;
private ChartModel cmodel;
- private List jobs;
- private Map jobmap;
+ private List<Job> jobs;
+ private Map<String, Job> jobmap;
private JScrollPane csp, hsp;
private JSpinner scalesp;
private long firstEvent;
@@ -74,8 +74,8 @@
public GanttChart() {
scale = 1.0 / SCALE;
- jobs = new ArrayList();
- jobmap = new HashMap();
+ jobs = new ArrayList<Job>();
+ jobmap = new HashMap<String, Job>();
header = new JTable() {
public Dimension getPreferredSize() {
@@ -127,38 +127,38 @@
repaint();
}
- public void itemUpdated(int updateType, StatefulItem item) {
+ public void itemUpdated(SystemStateListener.UpdateType updateType, StatefulItem item) {
if (firstEvent == 0) {
firstEvent = System.currentTimeMillis();
}
if (item.getItemClass().equals(StatefulItemClass.APPLICATION)) {
ApplicationItem ai = (ApplicationItem) item;
- if (updateType == ITEM_ADDED) {
+ if (updateType == SystemStateListener.UpdateType.ITEM_ADDED) {
addJob(ai);
}
- else if (updateType == ITEM_REMOVED) {
- Job j = (Job) jobmap.get(item.getID());
+ else if (updateType == SystemStateListener.UpdateType.ITEM_REMOVED) {
+ Job j = jobmap.get(item.getID());
j.end();
}
}
else if (item.getItemClass().equals(StatefulItemClass.TASK)) {
TaskItem ti = (TaskItem) item;
if (ti.getTask() != null && item.getParent() != null) {
- Job job = (Job) jobmap.get(item.getParent().getID());
+ Job job = jobmap.get(item.getParent().getID());
if (job == null) {
return;
}
Task task = ti.getTask();
if (task.getType() == Task.FILE_OPERATION) {
- if (updateType == ITEM_ADDED) {
+ if (updateType == SystemStateListener.UpdateType.ITEM_ADDED) {
job.addPretask();
}
- else if (updateType == ITEM_REMOVED) {
+ else if (updateType == SystemStateListener.UpdateType.ITEM_REMOVED) {
job.removePretask();
}
}
else if (task.getType() == Task.JOB_SUBMISSION) {
- if (updateType == ITEM_UPDATED) {
+ if (updateType == SystemStateListener.UpdateType.ITEM_UPDATED) {
job.setJobStatus(ti.getStatus());
hmodel.fireTableDataChanged();
}
@@ -190,7 +190,7 @@
}
- public Class getColumnClass(int columnIndex) {
+ public Class<?> getColumnClass(int columnIndex) {
return Job.class;
}
@@ -214,7 +214,7 @@
}
- public Class getColumnClass(int columnIndex) {
+ public Class<?> getColumnClass(int columnIndex) {
return Job.class;
}
@@ -275,11 +275,11 @@
private class Job {
private ApplicationItem ai;
- private List events;
+ private List<Event> events;
private int pretasks;
public Job(ApplicationItem ai) {
- events = new ArrayList();
+ events = new ArrayList<Event>();
this.ai = ai;
}
@@ -411,18 +411,18 @@
}
public void paint(Graphics g) {
- List events;
+ List<Event> events;
synchronized (job.events) {
- events = new ArrayList(job.events);
+ events = new ArrayList<Event>(job.events);
}
if (events.size() == 0) {
return;
}
int ox = 0, ex = 0;
boolean endcap = false;
- Iterator i = events.iterator();
+ Iterator<Event> i = events.iterator();
while (i.hasNext()) {
- Event e = (Event) i.next();
+ Event e = i.next();
if (e.type == StartEvent.TYPE) {
ox = e.time;
}
@@ -452,7 +452,7 @@
int lx = ox;
i = events.iterator();
while (i.hasNext()) {
- Event e = (Event) i.next();
+ Event e = i.next();
int x = (int) (e.time * scale);
// System.err.println(crt+", "+lx+", "+x);
if (crt != null) {
Modified: branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/swing/SwingMonitor.java
===================================================================
--- branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/swing/SwingMonitor.java 2013-03-19 00:24:44 UTC (rev 6397)
+++ branches/faster/src/org/griphyn/vdl/karajan/monitor/monitors/swing/SwingMonitor.java 2013-03-19 00:28:44 UTC (rev 6398)
@@ -30,6 +30,7 @@
import org.griphyn.vdl.karajan.monitor.StatefulItemClassSet;
import org.griphyn.vdl.karajan.monitor.SystemState;
+import org.griphyn.vdl.karajan.monitor.SystemStateListener;
import org.griphyn.vdl.karajan.monitor.items.ApplicationItem;
import org.griphyn.vdl.karajan.monitor.items.StatefulItem;
import org.griphyn.vdl.karajan.monitor.items.StatefulItemClass;
@@ -38,12 +39,12 @@
public class SwingMonitor extends AbstractMonitor {
private JFrame frame;
private Timer timer;
- private Map tablemap;
+ private Map<StatefulItemClass, ClassRenderer> tablemap;
private GanttChart gantt;
public SwingMonitor() {
createFrame();
- tablemap = new HashMap();
+ tablemap = new HashMap<StatefulItemClass, ClassRenderer>();
}
private void createFrame() {
@@ -82,8 +83,8 @@
tabs.add("Gantt Chart", gantt);
}
- public void itemUpdated(int updateType, StatefulItem item) {
- ClassRenderer table = (ClassRenderer) tablemap.get(item.getItemClass());
+ public void itemUpdated(SystemStateListener.UpdateType updateType, StatefulItem item) {
+ ClassRenderer table = tablemap.get(item.getItemClass());
if (table != null) {
table.dataChanged();
}
@@ -92,4 +93,8 @@
public void shutdown() {
}
+
+ @Override
+ public void setParams(String params) {
+ }
}
More information about the Swift-commit
mailing list