optimized some loops for increased performance and added runprof for profiling
This commit is contained in:
parent
221742559d
commit
f6e0702b3b
5 changed files with 59 additions and 24 deletions
|
@ -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: 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;
|
package se.sics.cooja.mspmote;
|
||||||
|
@ -262,6 +262,8 @@ public abstract class MspMote implements Mote {
|
||||||
protected abstract boolean initEmulator(File ELFFile);
|
protected abstract boolean initEmulator(File ELFFile);
|
||||||
|
|
||||||
private int currentSimTime = -1;
|
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) {
|
public boolean tick(int simTime) {
|
||||||
if (stopNextInstruction) {
|
if (stopNextInstruction) {
|
||||||
stopNextInstruction = false;
|
stopNextInstruction = false;
|
||||||
|
@ -281,12 +283,16 @@ public abstract class MspMote implements Mote {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
myMoteInterfaceHandler.doActiveActionsBeforeTick();
|
|
||||||
|
|
||||||
// Leave control to emulated CPU
|
// Leave control to emulated CPU
|
||||||
cycleCounter += 1;
|
cycleCounter += 1;
|
||||||
|
|
||||||
MSP430 cpu = getCPU();
|
MSP430 cpu = getCPU();
|
||||||
|
if (cpu.cycles > cycleCounter) {
|
||||||
|
/* CPU already ticked too far - just wait it out */
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
myMoteInterfaceHandler.doActiveActionsBeforeTick();
|
||||||
|
|
||||||
cpu.step(cycleCounter);
|
cpu.step(cycleCounter);
|
||||||
|
|
||||||
/* Check if radio has pending incoming bytes */
|
/* Check if radio has pending incoming bytes */
|
||||||
|
|
|
@ -71,6 +71,19 @@ The COOJA Simulator
|
||||||
</java>
|
</java>
|
||||||
</target>
|
</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">
|
<target name="run_bigmem" depends="init, compile, copy configs">
|
||||||
<java fork="yes" dir="${build}" classname="se.sics.cooja.GUI" maxmemory="512m">
|
<java fork="yes" dir="${build}" classname="se.sics.cooja.GUI" maxmemory="512m">
|
||||||
<arg line="${args}"/>
|
<arg line="${args}"/>
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* 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;
|
package se.sics.cooja;
|
||||||
|
@ -74,7 +74,8 @@ public class MoteInterfaceHandler {
|
||||||
private Radio myRadio;
|
private Radio myRadio;
|
||||||
|
|
||||||
private Vector<MoteInterface> myActiveInterfaces = new Vector<MoteInterface>();
|
private Vector<MoteInterface> myActiveInterfaces = new Vector<MoteInterface>();
|
||||||
|
private MoteInterface[] activeCache = null;
|
||||||
|
|
||||||
private Vector<MoteInterface> myPassiveInterfaces = new Vector<MoteInterface>();
|
private Vector<MoteInterface> myPassiveInterfaces = new Vector<MoteInterface>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -283,8 +284,15 @@ public class MoteInterfaceHandler {
|
||||||
* tick before the mote software is executed.
|
* tick before the mote software is executed.
|
||||||
*/
|
*/
|
||||||
public void doActiveActionsBeforeTick() {
|
public void doActiveActionsBeforeTick() {
|
||||||
for (int i = 0; i < myActiveInterfaces.size(); i++)
|
// Assuming only one caller!!!
|
||||||
myActiveInterfaces.get(i).doActionsBeforeTick();
|
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) {
|
public void addActiveInterface(MoteInterface newInterface) {
|
||||||
myActiveInterfaces.add(newInterface);
|
myActiveInterfaces.add(newInterface);
|
||||||
|
activeCache = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* 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;
|
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) {
|
while (isRunning) {
|
||||||
try {
|
|
||||||
|
|
||||||
/* Tick MSP motes */
|
/* Tick MSP motes */
|
||||||
try {
|
// try {
|
||||||
boolean wantMoreTicks = true;
|
boolean wantMoreTicks = true;
|
||||||
while (wantMoreTicks) {
|
while (wantMoreTicks) {
|
||||||
/* Tick all MSP motes until none need more ticks */
|
/* Tick all MSP motes until none need more ticks */
|
||||||
wantMoreTicks = false;
|
wantMoreTicks = false;
|
||||||
for (Mote moteToTick : mspMotes) {
|
for (int i = 0, n = mspArray.length; i < n; i++) {
|
||||||
if (moteToTick.tick(currentSimulationTime)) {
|
if (mspArray[i].tick(currentSimulationTime)) {
|
||||||
wantMoreTicks = true;
|
wantMoreTicks = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
// } catch (RuntimeException e) {
|
||||||
isRunning = false;
|
// isRunning = false;
|
||||||
thread = null;
|
// thread = null;
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Tick current mote subset
|
// Tick current mote subset
|
||||||
for (Mote moteToTick : allLists[currentTickListIndex]) {
|
for (Mote moteToTick : allLists[currentTickListIndex]) {
|
||||||
|
@ -212,23 +213,23 @@ public class Simulation extends Observable implements Runnable {
|
||||||
thread = null;
|
thread = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
thread = null;
|
thread = null;
|
||||||
break;
|
// break;
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
logger.warn("llegalArgumentException:" + e);
|
logger.warn("llegalArgumentException:" + e);
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
thread = null;
|
thread = null;
|
||||||
break;
|
// break;
|
||||||
} catch (IllegalMonitorStateException e) {
|
} catch (IllegalMonitorStateException e) {
|
||||||
logger.warn("IllegalMonitorStateException:" + e);
|
logger.warn("IllegalMonitorStateException:" + e);
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
thread = null;
|
thread = null;
|
||||||
break;
|
// break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
thread = null;
|
thread = null;
|
||||||
stopSimulation = false;
|
stopSimulation = false;
|
||||||
|
|
|
@ -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: 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;
|
package se.sics.cooja.plugins;
|
||||||
|
@ -65,6 +65,8 @@ public class LogScriptEngine {
|
||||||
|
|
||||||
private String scriptCode;
|
private String scriptCode;
|
||||||
|
|
||||||
|
private ScriptMote scriptMote;
|
||||||
|
|
||||||
private interface ScriptLog {
|
private interface ScriptLog {
|
||||||
public void log(String log);
|
public void log(String log);
|
||||||
}
|
}
|
||||||
|
@ -180,6 +182,7 @@ public class LogScriptEngine {
|
||||||
" mote = obj;" +
|
" mote = obj;" +
|
||||||
" id = mote.getInterfaces().getMoteID().getMoteID();" +
|
" id = mote.getInterfaces().getMoteID().getMoteID();" +
|
||||||
" msg = mote.getInterfaces().getLog().getLastLogMessages();" +
|
" msg = mote.getInterfaces().getLog().getLastLogMessages();" +
|
||||||
|
" node.setMoteMsg(mote, msg);" +
|
||||||
"} else {" +
|
"} else {" +
|
||||||
" return;" +
|
" return;" +
|
||||||
"} " +
|
"} " +
|
||||||
|
@ -201,6 +204,9 @@ public class LogScriptEngine {
|
||||||
Hashtable<Object, Object> hash = new Hashtable<Object, Object>();
|
Hashtable<Object, Object> hash = new Hashtable<Object, Object>();
|
||||||
engine.put("global", hash);
|
engine.put("global", hash);
|
||||||
|
|
||||||
|
scriptMote = new ScriptMote();
|
||||||
|
engine.put("node", scriptMote);
|
||||||
|
|
||||||
/* TODO Test script */
|
/* TODO Test script */
|
||||||
logObserver.update(null, null);
|
logObserver.update(null, null);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue