optimized some loops for increased performance and added runprof for profiling

This commit is contained in:
joxe 2008-09-22 16:18:22 +00:00
parent 221742559d
commit f6e0702b3b
5 changed files with 59 additions and 24 deletions

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: MspMote.java,v 1.11 2008/09/22 09:32:13 joxe Exp $
* $Id: MspMote.java,v 1.12 2008/09/22 16:18:48 joxe Exp $
*/
package se.sics.cooja.mspmote;
@ -262,6 +262,8 @@ public abstract class MspMote implements Mote {
protected abstract boolean initEmulator(File ELFFile);
private int currentSimTime = -1;
/* return false when done - e.g. true means more work to do before finished with this tick */
public boolean tick(int simTime) {
if (stopNextInstruction) {
stopNextInstruction = false;
@ -281,12 +283,16 @@ public abstract class MspMote implements Mote {
return false;
}
myMoteInterfaceHandler.doActiveActionsBeforeTick();
// Leave control to emulated CPU
cycleCounter += 1;
MSP430 cpu = getCPU();
if (cpu.cycles > cycleCounter) {
/* CPU already ticked too far - just wait it out */
return true;
}
myMoteInterfaceHandler.doActiveActionsBeforeTick();
cpu.step(cycleCounter);
/* Check if radio has pending incoming bytes */

View File

@ -71,6 +71,19 @@ The COOJA Simulator
</java>
</target>
<target name="runprof" depends="init, compile, jar, copy configs">
<java fork="yes" dir="${build}" classname="se.sics.cooja.GUI">
<arg line="${args}"/>
<env key="LD_LIBRARY_PATH" value="."/>
<jvmarg line="-agentlib:yjpagent"/>
<classpath>
<pathelement path="${build}"/>
<pathelement location="lib/jdom.jar"/>
<pathelement location="lib/log4j.jar"/>
</classpath>
</java>
</target>
<target name="run_bigmem" depends="init, compile, copy configs">
<java fork="yes" dir="${build}" classname="se.sics.cooja.GUI" maxmemory="512m">
<arg line="${args}"/>

View File

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: MoteInterfaceHandler.java,v 1.2 2007/01/10 14:57:42 fros4943 Exp $
* $Id: MoteInterfaceHandler.java,v 1.3 2008/09/22 16:18:22 joxe Exp $
*/
package se.sics.cooja;
@ -74,7 +74,8 @@ public class MoteInterfaceHandler {
private Radio myRadio;
private Vector<MoteInterface> myActiveInterfaces = new Vector<MoteInterface>();
private MoteInterface[] activeCache = null;
private Vector<MoteInterface> myPassiveInterfaces = new Vector<MoteInterface>();
/**
@ -283,8 +284,15 @@ public class MoteInterfaceHandler {
* tick before the mote software is executed.
*/
public void doActiveActionsBeforeTick() {
for (int i = 0; i < myActiveInterfaces.size(); i++)
myActiveInterfaces.get(i).doActionsBeforeTick();
// Assuming only one caller!!!
if (activeCache == null) {
activeCache = (MoteInterface[]) myActiveInterfaces.toArray(new MoteInterface[myActiveInterfaces.size()]);
}
// for (int i = 0; i < myActiveInterfaces.size(); i++)
// myActiveInterfaces.get(i).doActionsBeforeTick();
for (int i = 0, n = activeCache.length; i < n; i++) {
activeCache[i].doActionsBeforeTick();
}
}
/**
@ -352,6 +360,7 @@ public class MoteInterfaceHandler {
*/
public void addActiveInterface(MoteInterface newInterface) {
myActiveInterfaces.add(newInterface);
activeCache = null;
}
/**

View File

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: Simulation.java,v 1.22 2008/04/01 08:12:16 fros4943 Exp $
* $Id: Simulation.java,v 1.23 2008/09/22 16:18:22 joxe Exp $
*/
package se.sics.cooja;
@ -162,26 +162,27 @@ public class Simulation extends Observable implements Runnable {
}
}
Mote[] mspArray = mspMotes.toArray(new Mote[mspMotes.size()]);
try {
while (isRunning) {
try {
/* Tick MSP motes */
try {
// try {
boolean wantMoreTicks = true;
while (wantMoreTicks) {
/* Tick all MSP motes until none need more ticks */
wantMoreTicks = false;
for (Mote moteToTick : mspMotes) {
if (moteToTick.tick(currentSimulationTime)) {
for (int i = 0, n = mspArray.length; i < n; i++) {
if (mspArray[i].tick(currentSimulationTime)) {
wantMoreTicks = true;
}
}
}
} catch (RuntimeException e) {
isRunning = false;
thread = null;
break;
}
// } catch (RuntimeException e) {
// isRunning = false;
// thread = null;
// break;
// }
// Tick current mote subset
for (Mote moteToTick : allLists[currentTickListIndex]) {
@ -212,23 +213,23 @@ public class Simulation extends Observable implements Runnable {
thread = null;
}
} catch (InterruptedException e) {
}
} catch (InterruptedException e) {
isRunning = false;
thread = null;
break;
// break;
} catch (IllegalArgumentException e) {
logger.warn("llegalArgumentException:" + e);
isRunning = false;
thread = null;
break;
// break;
} catch (IllegalMonitorStateException e) {
logger.warn("IllegalMonitorStateException:" + e);
isRunning = false;
thread = null;
break;
// break;
}
}
isRunning = false;
thread = null;
stopSimulation = false;

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: LogScriptEngine.java,v 1.2 2008/09/17 16:30:57 fros4943 Exp $
* $Id: LogScriptEngine.java,v 1.3 2008/09/22 16:18:22 joxe Exp $
*/
package se.sics.cooja.plugins;
@ -65,6 +65,8 @@ public class LogScriptEngine {
private String scriptCode;
private ScriptMote scriptMote;
private interface ScriptLog {
public void log(String log);
}
@ -180,6 +182,7 @@ public class LogScriptEngine {
" mote = obj;" +
" id = mote.getInterfaces().getMoteID().getMoteID();" +
" msg = mote.getInterfaces().getLog().getLastLogMessages();" +
" node.setMoteMsg(mote, msg);" +
"} else {" +
" return;" +
"} " +
@ -201,6 +204,9 @@ public class LogScriptEngine {
Hashtable<Object, Object> hash = new Hashtable<Object, Object>();
engine.put("global", hash);
scriptMote = new ScriptMote();
engine.put("node", scriptMote);
/* TODO Test script */
logObserver.update(null, null);
}