minor fixes: better statistics output, added zoom level, popup menu labels

This commit is contained in:
fros4943 2010-03-02 13:33:10 +00:00
parent 4c9112a176
commit 024d8ff2b5
1 changed files with 129 additions and 100 deletions

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: TimeLine.java,v 1.23 2010/01/15 10:51:20 fros4943 Exp $ * $Id: TimeLine.java,v 1.24 2010/03/02 13:33:10 fros4943 Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
@ -114,7 +114,7 @@ public class TimeLine extends VisPlugin {
private static long currentPixelDivisor = 200; private static long currentPixelDivisor = 200;
private static final long[] ZOOM_LEVELS = { 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000 }; private static final long[] ZOOM_LEVELS = { 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000 };
private int zoomLevel = 9; private int zoomLevel = 9;
@ -323,7 +323,7 @@ public class TimeLine extends VisPlugin {
} }
}; };
private Action zoomInAction = new AbstractAction("Zoom in") { private Action zoomInAction = new AbstractAction("Zoom in (Ctrl+)") {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Rectangle r = timeline.getVisibleRect(); Rectangle r = timeline.getVisibleRect();
int pixelX = r.x + r.width/2; int pixelX = r.x + r.width/2;
@ -364,7 +364,7 @@ public class TimeLine extends VisPlugin {
} }
}; };
private Action zoomOutAction = new AbstractAction("Zoom out") { private Action zoomOutAction = new AbstractAction("Zoom out (Ctrl-)") {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Rectangle r = timeline.getVisibleRect(); Rectangle r = timeline.getVisibleRect();
int pixelX = r.x + r.width/2; int pixelX = r.x + r.width/2;
@ -526,16 +526,29 @@ public class TimeLine extends VisPlugin {
long onTimeRX = 0, onTimeTX = 0, onTimeInterfered = 0; long onTimeRX = 0, onTimeTX = 0, onTimeInterfered = 0;
public String toString() { public String toString() {
return return toString(true, true, true, true);
"Mote: " + (mote!=null?mote:"ALL") + "\n" + }
"LED red ontime:\t" + onTimeRedLED + "us = " + 100.0*((double)onTimeRedLED/simulation.getSimulationTime()) + "%\n" + public String toString(boolean logs, boolean leds, boolean radioHW, boolean radioRXTX) {
"LED green ontime:\t" + onTimeGreenLED + "us = " + 100.0*((double)onTimeGreenLED/simulation.getSimulationTime()) + "%\n" + long duration = simulation.getSimulationTime(); /* XXX */
"LED blue ontime:\t" + onTimeBlueLED + "us = " + 100.0*((double)onTimeBlueLED/simulation.getSimulationTime()) + "%\n" + StringBuilder sb = new StringBuilder();
"Log messages: " + nrLogs + "\n" + String moteDesc = (mote!=null?"" + mote.getID():"AVERAGE") + " ";
"Radio ontime:\t" + radioOn + "us = " + 100.0*((double)radioOn/simulation.getSimulationTime()) + "%\n" + if (logs) {
"Radio RX time:\t" + onTimeRX + "us = " + 100.0*((double)onTimeRX/simulation.getSimulationTime()) + "%\n" + sb.append(moteDesc + "nr_logs " + nrLogs + "\n");
"Radio TX time:\t" + onTimeTX + "us = " + 100.0*((double)onTimeTX/simulation.getSimulationTime()) + "%\n" + }
"Radio interfered time:\t" + onTimeInterfered + "us = " + 100.0*((double)onTimeInterfered/simulation.getSimulationTime()) + "%\n"; if (leds) {
sb.append(moteDesc + "led_red " + onTimeRedLED + " us " + 100.0*((double)onTimeRedLED/duration) + " %\n");
sb.append(moteDesc + "led_green " + onTimeGreenLED + " us " + 100.0*((double)onTimeGreenLED/duration) + " %\n");
sb.append(moteDesc + "led_blue " + onTimeBlueLED + " us " + 100.0*((double)onTimeBlueLED/duration) + " %\n");
}
if (radioHW) {
sb.append(moteDesc + "radio_on " + radioOn + " us " + 100.0*((double)radioOn/duration) + " %\n");
}
if (radioRXTX) {
sb.append(moteDesc + "radio_tx " + onTimeTX + " us " + 100.0*((double)onTimeTX/duration) + " %\n");
sb.append(moteDesc + "radio_rx " + onTimeRX + " us " + 100.0*((double)onTimeRX/duration) + " %\n");
sb.append(moteDesc + "radio_int " + onTimeInterfered + " us " + 100.0*((double)onTimeInterfered/duration) + " %\n");
}
return sb.toString();
} }
} }
private Action statisticsAction = new AbstractAction("Print statistics to console") { private Action statisticsAction = new AbstractAction("Print statistics to console") {
@ -547,7 +560,11 @@ public class TimeLine extends VisPlugin {
} }
}; };
public synchronized String extractStatistics() { public String extractStatistics() {
return extractStatistics(true, true, true, true);
}
public synchronized String extractStatistics(
boolean logs, boolean leds, boolean radioHW, boolean radioRXTX) {
StringBuilder output = new StringBuilder(); StringBuilder output = new StringBuilder();
/* Process all events (per mote basis) */ /* Process all events (per mote basis) */
@ -557,115 +574,126 @@ public class TimeLine extends VisPlugin {
allStats.add(stats); allStats.add(stats);
stats.mote = moteEvents.mote; stats.mote = moteEvents.mote;
for (MoteEvent ev: moteEvents.ledEvents) { if (leds) {
if (!(ev instanceof LEDEvent)) continue; for (MoteEvent ev: moteEvents.ledEvents) {
LEDEvent ledEvent = (LEDEvent) ev; if (!(ev instanceof LEDEvent)) continue;
LEDEvent ledEvent = (LEDEvent) ev;
/* Red */ /* Red */
if (ledEvent.red) { if (ledEvent.red) {
/* LED is on, add time interval */ /* LED is on, add time interval */
if (ledEvent.next == null) { if (ledEvent.next == null) {
stats.onTimeRedLED += (simulation.getSimulationTime() - ledEvent.time); stats.onTimeRedLED += (simulation.getSimulationTime() - ledEvent.time);
} else { } else {
stats.onTimeRedLED += (ledEvent.next.time - ledEvent.time); stats.onTimeRedLED += (ledEvent.next.time - ledEvent.time);
}
} }
}
/* Green */ /* Green */
if (ledEvent.green) { if (ledEvent.green) {
/* LED is on, add time interval */ /* LED is on, add time interval */
if (ledEvent.next == null) { if (ledEvent.next == null) {
stats.onTimeGreenLED += (simulation.getSimulationTime() - ledEvent.time); stats.onTimeGreenLED += (simulation.getSimulationTime() - ledEvent.time);
} else { } else {
stats.onTimeGreenLED += (ledEvent.next.time - ledEvent.time); stats.onTimeGreenLED += (ledEvent.next.time - ledEvent.time);
}
} }
}
/* Blue */ /* Blue */
if (ledEvent.blue) { if (ledEvent.blue) {
/* LED is on, add time interval */ /* LED is on, add time interval */
if (ledEvent.next == null) { if (ledEvent.next == null) {
stats.onTimeBlueLED += (simulation.getSimulationTime() - ledEvent.time); stats.onTimeBlueLED += (simulation.getSimulationTime() - ledEvent.time);
} else { } else {
stats.onTimeBlueLED += (ledEvent.next.time - ledEvent.time); stats.onTimeBlueLED += (ledEvent.next.time - ledEvent.time);
}
} }
} }
} }
for (MoteEvent ev: moteEvents.logEvents) { if (logs) {
if (!(ev instanceof LogEvent)) continue; for (MoteEvent ev: moteEvents.logEvents) {
stats.nrLogs++; if (!(ev instanceof LogEvent)) continue;
stats.nrLogs++;
}
} }
/* TODO Radio channels */ /* TODO Radio channels */
for (MoteEvent ev: moteEvents.radioHWEvents) { if (radioHW) {
if (!(ev instanceof RadioHWEvent)) continue; for (MoteEvent ev: moteEvents.radioHWEvents) {
RadioHWEvent hwEvent = (RadioHWEvent) ev; if (!(ev instanceof RadioHWEvent)) continue;
if (hwEvent.on) { RadioHWEvent hwEvent = (RadioHWEvent) ev;
/* HW is on */ if (hwEvent.on) {
if (hwEvent.next == null) { /* HW is on */
stats.radioOn += (simulation.getSimulationTime() - hwEvent.time); if (hwEvent.next == null) {
} else { stats.radioOn += (simulation.getSimulationTime() - hwEvent.time);
stats.radioOn += (hwEvent.next.time - hwEvent.time); } else {
stats.radioOn += (hwEvent.next.time - hwEvent.time);
}
} }
} }
} }
for (MoteEvent ev: moteEvents.radioRXTXEvents) { if (radioRXTX) {
if (!(ev instanceof RadioRXTXEvent)) continue; for (MoteEvent ev: moteEvents.radioRXTXEvents) {
RadioRXTXEvent rxtxEvent = (RadioRXTXEvent) ev; if (!(ev instanceof RadioRXTXEvent)) continue;
if (rxtxEvent.state == RXTXRadioEvent.IDLE) { RadioRXTXEvent rxtxEvent = (RadioRXTXEvent) ev;
continue; if (rxtxEvent.state == RXTXRadioEvent.IDLE) {
} continue;
}
long diff; long diff;
if (rxtxEvent.next == null) { if (rxtxEvent.next == null) {
diff = (simulation.getSimulationTime() - rxtxEvent.time); diff = (simulation.getSimulationTime() - rxtxEvent.time);
} else { } else {
diff = (rxtxEvent.next.time - rxtxEvent.time); diff = (rxtxEvent.next.time - rxtxEvent.time);
} }
if (rxtxEvent.state == RXTXRadioEvent.TRANSMITTING) { if (rxtxEvent.state == RXTXRadioEvent.TRANSMITTING) {
stats.onTimeTX += diff; stats.onTimeTX += diff;
continue; continue;
} }
if (rxtxEvent.state == RXTXRadioEvent.INTERFERED) { if (rxtxEvent.state == RXTXRadioEvent.INTERFERED) {
stats.onTimeInterfered += diff; stats.onTimeInterfered += diff;
continue; continue;
} }
if (rxtxEvent.state == RXTXRadioEvent.RECEIVING) { if (rxtxEvent.state == RXTXRadioEvent.RECEIVING) {
stats.onTimeRX += diff; stats.onTimeRX += diff;
continue; continue;
}
} }
} }
/* TODO Watchpoints */ /* TODO Watchpoints */
output.append(stats.toString()); output.append(stats.toString(logs, leds, radioHW, radioRXTX));
} }
/* Summary */ if (allStats.size() == 0) {
MoteStatistics all = new MoteStatistics(); return output.toString();
}
/* Average */
MoteStatistics average = new MoteStatistics();
for (MoteStatistics stats: allStats) { for (MoteStatistics stats: allStats) {
all.onTimeRedLED += stats.onTimeRedLED; average.onTimeRedLED += stats.onTimeRedLED;
all.onTimeGreenLED += stats.onTimeGreenLED; average.onTimeGreenLED += stats.onTimeGreenLED;
all.onTimeBlueLED += stats.onTimeBlueLED; average.onTimeBlueLED += stats.onTimeBlueLED;
all.radioOn += stats.radioOn; average.radioOn += stats.radioOn;
all.onTimeRX += stats.onTimeRX; average.onTimeRX += stats.onTimeRX;
all.onTimeTX += stats.onTimeTX; average.onTimeTX += stats.onTimeTX;
all.onTimeInterfered += stats.onTimeInterfered; average.onTimeInterfered += stats.onTimeInterfered;
} }
all.onTimeBlueLED /= allStats.size(); average.onTimeBlueLED /= allStats.size();
all.onTimeGreenLED /= allStats.size(); average.onTimeGreenLED /= allStats.size();
all.onTimeBlueLED /= allStats.size(); average.onTimeBlueLED /= allStats.size();
all.radioOn /= allStats.size(); average.radioOn /= allStats.size();
all.onTimeRX /= allStats.size(); average.onTimeRX /= allStats.size();
all.onTimeTX /= allStats.size(); average.onTimeTX /= allStats.size();
all.onTimeInterfered /= allStats.size(); average.onTimeInterfered /= allStats.size();
output.append("SIMULATION AVERAGE:"); output.append(average.toString(logs, leds, radioHW, radioRXTX));
output.append(all.toString());
return output.toString(); return output.toString();
} }
@ -675,6 +703,7 @@ public class TimeLine extends VisPlugin {
/* Visible rectangle */ /* Visible rectangle */
int newX = (int) (time / currentPixelDivisor); int newX = (int) (time / currentPixelDivisor);
int w = timeline.getVisibleRect().width; int w = timeline.getVisibleRect().width;
w = 50;
Rectangle r = new Rectangle( Rectangle r = new Rectangle(
newX - w/2, 0, newX - w/2, 0,
w, 1 w, 1