Skip to content

Commit

Permalink
Add button to profile for 1 second.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbebenita committed Dec 18, 2014
1 parent ca0056f commit 70d4002
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
1 change: 1 addition & 0 deletions main.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<button id="profile">Profile: OFF</button>
<button id="clearCounters">Clear Counters</button>
<button id="dumpCounters">Dump Counters</button>
<button id="dumpCountersTime">Dump Counters Time</button>
</section>
</div>
<div id="display"><canvas id="canvas"></canvas></div>
Expand Down
19 changes: 18 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,25 @@ window.onload = function() {
J2ME.interpreterCounter.clear();
};
document.getElementById("dumpCounters").onclick = function() {
J2ME.interpreterCounter.traceSorted(new J2ME.IndentingWriter());
if (J2ME.interpreterCounter) {
J2ME.interpreterCounter.traceSorted(new J2ME.IndentingWriter());
}
if (nativeCounter) {
nativeCounter.traceSorted(new J2ME.IndentingWriter());
}
};
document.getElementById("dumpCountersTime").onclick = function() {
J2ME.interpreterCounter && J2ME.interpreterCounter.clear();
nativeCounter && nativeCounter.clear();
setTimeout(function () {
if (J2ME.interpreterCounter) {
J2ME.interpreterCounter.traceSorted(new J2ME.IndentingWriter());
}
if (nativeCounter) {
nativeCounter.traceSorted(new J2ME.IndentingWriter());
}
}, 1000);
};
document.getElementById("profile").onclick = function() {
if (getIsOff(this)) {
Instrument.startProfile();
Expand Down
35 changes: 20 additions & 15 deletions tests/asteroids/Field.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ public class Field extends Canvas implements Runnable {
/**
* Time spent moving objects and computing collisions.
*/
//public static long computeavg;
public static long computeavg;

/**
* Time spent painting screens.
*/
//public static long paintavg;
public static long paintavg;

/**
* Number of game frames since beginning.
*/
//public static long frames;
public static long frames;

private byte _state; // The current game state
private Slideshow _nextSlide; // A TimeTask used to trigger the transition to the next state.
Expand All @@ -109,9 +109,9 @@ public class Field extends Canvas implements Runnable {
private boolean _isRepeatedKey; // True if _lastKeyPressed was obtained through keyRepeated().

public Field() {
//computeavg = 0;
//paintavg = 0;
//frames = 0;
computeavg = 0;
paintavg = 0;
frames = 0;

// Determine the dimensions of the Canvas.
// The game has been developed using the j2mewtk's
Expand Down Expand Up @@ -377,7 +377,7 @@ public void run() {
try {
while (!_paused) {
long time1 = System.currentTimeMillis();
//long time2;
long time2;
long time3;
long ellapsed = 0;
if (!_frozen) {
Expand Down Expand Up @@ -440,26 +440,31 @@ public void run() {
}

// Determine the time spent to compute the frame.
//time2 = System.currentTimeMillis();
//computeavg += (time2 - time1);
time2 = System.currentTimeMillis();
computeavg += (time2 - time1);

// Force a screen refresh.
repaint();
serviceRepaints();

// Determine the time spent to draw the frame.
time3 = System.currentTimeMillis();
//paintavg += (time3 - time2);
//frames++;
paintavg += (time3 - time2);
frames++;

// Determine the total time for the frame.
ellapsed = time3 - time1;
}
// Sleep for a while (at least 20ms)
try {
Thread.currentThread().sleep(Math.max(50 - ellapsed, 20));
} catch(java.lang.InterruptedException e) {
}
// try {
// Thread.currentThread().sleep(Math.max(50 - ellapsed, 20));
Thread.yield();
// } catch(java.lang.InterruptedException e) {
// }
if (frames % 60 == 0) {
System.out.println("computeavg = " + (Field.computeavg / Field.frames));
System.out.println("paintavg = " + (Field.paintavg / Field.frames));
}
}
} catch (Exception e) {
e.printStackTrace();
Expand Down
2 changes: 0 additions & 2 deletions tests/asteroids/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ protected void destroyApp(boolean unconditional) throws MIDletStateChangeExcepti
licenseForm = null;
_scoreField = null;
_currentDisplayable = null;
//System.out.println("computeavg = " + (Field.computeavg / Field.frames));
//System.out.println("paintavg = " + (Field.paintavg / Field.frames));
}

// Implementation of the CommandListener interface
Expand Down

0 comments on commit 70d4002

Please sign in to comment.