From 70d4002030070f4f699a53a7bc193803a0c5b1d4 Mon Sep 17 00:00:00 2001 From: Michael Bebenita Date: Wed, 17 Dec 2014 17:18:38 -0800 Subject: [PATCH] Add button to profile for 1 second. --- main.html | 1 + main.js | 19 ++++++++++++++++++- tests/asteroids/Field.java | 35 ++++++++++++++++++++--------------- tests/asteroids/Game.java | 2 -- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/main.html b/main.html index 9f5d7fbe7..09feaa4d7 100644 --- a/main.html +++ b/main.html @@ -90,6 +90,7 @@ +
diff --git a/main.js b/main.js index 204820bda..6e40e5a94 100644 --- a/main.js +++ b/main.js @@ -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(); diff --git a/tests/asteroids/Field.java b/tests/asteroids/Field.java index 945b3a602..a127a7571 100644 --- a/tests/asteroids/Field.java +++ b/tests/asteroids/Field.java @@ -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. @@ -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 @@ -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) { @@ -440,8 +440,8 @@ 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(); @@ -449,17 +449,22 @@ public void run() { // 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(); diff --git a/tests/asteroids/Game.java b/tests/asteroids/Game.java index d8563e4f9..31f0b1e1e 100644 --- a/tests/asteroids/Game.java +++ b/tests/asteroids/Game.java @@ -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