Performance test should support asynchronous tests
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Oct 2012 20:57:46 +0000 (20:57 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Oct 2012 20:57:46 +0000 (20:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=95668

Reviewed by Dirk Pranke.

Added PerfTestRunner.prepareToMeasureValuesAsync and PerfTestRunner.measureValueAsync,
and deployed it in Animation/balls.

* Animation/balls.html:
* resources/runner.js:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@131638 268f45cc-cd09-0410-ab3c-d52691b4dbfc

PerformanceTests/Animation/balls.html
PerformanceTests/ChangeLog
PerformanceTests/resources/runner.js

index e56c9f4..ffc93d6 100644 (file)
@@ -90,8 +90,6 @@
     <script type="text/javascript">
 
     var FRAMES_PER_TIMER_READING = 10;
-    var MAX_ITERATIONS = 110;
-    var MAX_RUNS = 1;
     var MAX_PARTICLES = 2500;
     var MAX_VELOCITY = 50;
     var PARTICLE_RADIUS = 6;
     var frameRates = [];
     var particles = [];
 
-    window.onload = init;
-
-    function init()
-    {
-        PerfTestRunner.resetRandomSeed();
-
-        var location = window.location.href;
-        frameRates = [];
-        frameTimes = [];
-        iteration = 0;
-        animateIntervalId = 0;
-        particles = [];
+    window.onload = function () {
+        PerfTestRunner.prepareToMeasureValuesAsync({runCount: 10, done: onCompletedRun, unit: 'fps'});
 
         // Create the particles
         for (var i = 0; i < MAX_PARTICLES; i++)
 
     function animate()
     {
-        var currTime = new Date().getTime();
+        var currTime = PerfTestRunner.now();
         var timeDelta = currTime - frameTimes[frameTimes.length - 1];
 
         if (isNaN(timeDelta))
             var frameRate = document.getElementById("frameRate");
             var frameRateVal = FRAMES_PER_TIMER_READING * 1000 / ((currTime - frameTimes[0]) / (frameTimes.length - 1));
 
-            if (!isNaN(frameRateVal)) {
-                frameRates.push(frameRateVal);
-                var frameRateText = frameRateVal + "";
-                frameRateText = frameRateText.replace(/(^[^.]+\...).*/, "$1");
-                frameRateText += " fps";
-                frameRate.innerHTML = frameRateText;
-            }
-        }
-
-        if (iteration > MAX_ITERATIONS) {
-            clearInterval(animateIntervalId);
-            onCompletedRun();
+            if (!isNaN(frameRateVal))
+                PerfTestRunner.measureValueAync(frameRateVal);
         }
     }
 
     }
 
     function onCompletedRun() {
+        clearInterval(animateIntervalId);
+
         for (var particle in particles) {
             var p = particles[particle];
             particles[particle] = 0;
         particles = [];
 
         frameRate.innerHTML = "";
-
-        for (var rate in frameRates)
-            PerfTestRunner.log(frameRates[rate].toFixed(2) + " fps");
-
-        var stats = PerfTestRunner.computeStatistics(frameRates, "fps");
-        statistics.push(stats);
-
-        PerfTestRunner.printStatistics(stats, "Time:");
-        PerfTestRunner.getAndPrintMemoryStatistics();
-
-        if (++run < MAX_RUNS) {
-            PerfTestRunner.log("<br>===================================================<br>");
-            init();
-        }
-        else if (window.testRunner)
-            testRunner.notifyDone();
     }
     </script>
     <script src="../resources/runner.js"></script>
index 67c124e..4f237f0 100644 (file)
@@ -1,3 +1,16 @@
+2012-10-17  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Performance test should support asynchronous tests
+        https://bugs.webkit.org/show_bug.cgi?id=95668
+
+        Reviewed by Dirk Pranke.
+
+        Added PerfTestRunner.prepareToMeasureValuesAsync and PerfTestRunner.measureValueAsync,
+        and deployed it in Animation/balls.
+
+        * Animation/balls.html:
+        * resources/runner.js:
+
 2012-10-16  Elliott Sprehn  <esprehn@chromium.org>
 
         html5-full-render.html test uses substring but meant substr
index 7ced9f0..6b5ba19 100755 (executable)
@@ -170,7 +170,8 @@ if (window.testRunner) {
         runCount = test.runCount || 20;
         logLines = window.testRunner ? [] : null;
         PerfTestRunner.log("Running " + runCount + " times");
-        scheduleNextRun(runner);
+        if (runner)
+            scheduleNextRun(runner);
     }
 
     function scheduleNextRun(runner) {
@@ -234,6 +235,25 @@ if (window.testRunner) {
             testRunner.notifyDone();
     }
 
+    PerfTestRunner.prepareToMeasureValuesAsync = function (test) {
+        PerfTestRunner.unit = test.unit;
+        start(test);
+    }
+
+    PerfTestRunner.measureValueAync = function (measuredValue) {
+        completedRuns++;
+
+        try {
+            ignoreWarmUpAndLog(measuredValue);
+        } catch (exception) {
+            logFatalError("Got an exception while logging the result with name=" + exception.name + ", message=" + exception.message);
+            return;
+        }
+
+        if (completedRuns >= runCount)
+            finish();
+    }
+
     PerfTestRunner.measureTime = function (test) {
         PerfTestRunner.unit = "ms";
         start(test, measureTimeOnce);