I was doing some performance tests in the simulator, and I ran into a Watchdog exception because my code ran for too long. It makes no difference where I test this code (e.g. in the onStart or onShow methods for an application).
This got me wondering:
A) what the code execution timeout is for any given piece of code?
B) if there is more than 1 execution timeout, depending on where the code is being called? For instance, I could imagine the timeout in an onStart or onStop method being shorter than in an onHide method.
When I hit the timeout, it also seems that exception handling isn't working, and that the execution time (in milliseconds) doesn't get calculated.
In the output you can see that the exception doesn't get caught, and that the timers always show 0 milliseconds.
Can anyone confirm that they see the same behaviour, or is it my code/pc/setup?
This is the test code:
function onStart() {
var appStart, appStop, appDelta;
try {
appStart = Sys.getTimer();
// ObjectStore tests
//setupShop();
// Math performance tests
// Random numbers
var i = 100;
while(i<=10000) {
System.println("");
System.println("Trying to generate " + i + " random numbers.");
rndPerformance(i);
i += i < 1000 ? 100 : 1000;
}
}
catch( ex ) {
appStop = Sys.getTimer();
appDelta = appStop - appStart;
System.println("EXCEPTION occurred: " + ex);
System.println("onStart ran for " + appDelta + " milliseconds before hitting a timeout.");
}
}
function rndPerformance(iterations)
{
var timeStart, timeStop, timeDelta;
var countEven = 0;
var countOdd = 0;
timeStart = Sys.getTimer();
for(var i = 0; i < iterations; i ++)
{
var rn = Math.rand();
if(rn%2==0) {
countEven++;
} else {
countOdd++;
}
}
timeStop = Sys.getTimer();
timeDelta = timeStop - timeStart;
System.println("For " + iterations + " iterations of Math.random, we got " + countEven + " even numbers, and " + countOdd + " odd numbers.");
System.println("Calculation took " + timeDelta + " milliseconds.");
}
And this is the output:
Connecting to device...
Device Version 0.1.0
Device id 1 name "A garmin device"
Shell Version 0.1.0
Trying to generate 100 random numbers.
For 100 iterations of Math.random, we got 53 even numbers, and 47 odd numbers.
Calculation took 0 milliseconds.
Trying to generate 200 random numbers.
For 200 iterations of Math.random, we got 105 even numbers, and 95 odd numbers.
Calculation took 0 milliseconds.
Trying to generate 300 random numbers.
For 300 iterations of Math.random, we got 159 even numbers, and 141 odd numbers.
Calculation took 0 milliseconds.
Trying to generate 400 random numbers.
For 400 iterations of Math.random, we got 214 even numbers, and 186 odd numbers.
Calculation took 0 milliseconds.
Trying to generate 500 random numbers.
For 500 iterations of Math.random, we got 235 even numbers, and 265 odd numbers.
Calculation took 0 milliseconds.
Trying to generate 600 random numbers.
For 600 iterations of Math.random, we got 323 even numbers, and 277 odd numbers.
Calculation took 0 milliseconds.
Trying to generate 700 random numbers.
For 700 iterations of Math.random, we got 346 even numbers, and 354 odd numbers.
Calculation took 0 milliseconds.
Trying to generate 800 random numbers.
Failed invoking <symbol>
Watchdog Tripped Error - Code Executed Too Long
in rndPerformance (D:\workspaces\connectiq\IQTest\source\IQTestApp.mc:56)
in onStart (D:\workspaces\connectiq\IQTest\source\IQTestApp.mc:26)
Watchdog Tripped Error - Code Executed Too Long
Complete
Connection Finished
Closing shell and port