Remove unused features and reduce code duplications in PerfTestRunner
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Sep 2012 04:16:48 +0000 (04:16 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Sep 2012 04:16:48 +0000 (04:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=97852

Reviewed by Kentaro Hara.

Made the following refactoring changes:
- Remove PerfTestRunner.info since it's never used.
- Moved the js heap/malloc related functions up to where they belong.
- Moved the initialization of _callsPerIteration, _test, and -description into _start,
  and stopped initializing _runFunction and _doneFunction since both test times now
  use _test object.
- Made _measureTimeOnce and _measureRunsPerSecondOnce return the measured value
  instead of calling ignoreWarmUpAndLog and _runLoop to share the code; they're now
  called in _measureRunsPerSecondOnce.

* resources/runner.js:
(PerfTestRunner.storeHeapResults): Moved.
(PerfTestRunner.getUsedMallocHeap): Moved.
(PerfTestRunner.getUsedJSHeap): Moved.
(PerfTestRunner.getAndPrintMemoryStatistics): Moved.
(PerfTestRunner._scheduleNextMeasurementOrNotifyDone): Renamed from _runLoop. Calls
ignoreWarmUpAndLog and schedules the next call.
(PerfTestRunner._measureTimeOnce): Renamed from _runner.
(PerfTestRunner._start): Renamed from initAndStartLoop.
(PerfTestRunner.measureTime):
(PerfTestRunner.runPerSecond):
(PerfTestRunner._measureRunsPerSecondOnce): Renamed from _measureRunsPerSecondOnce.
(PerfTestRunner._perSecondRunnerIterator):

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

PerformanceTests/ChangeLog
PerformanceTests/resources/runner.js

index cf16ba5..7ef9d6f 100644 (file)
@@ -1,5 +1,36 @@
 2012-09-27  Ryosuke Niwa  <rniwa@webkit.org>
 
+        Remove unused features and reduce code duplications in PerfTestRunner
+        https://bugs.webkit.org/show_bug.cgi?id=97852
+
+        Reviewed by Kentaro Hara.
+
+        Made the following refactoring changes:
+        - Remove PerfTestRunner.info since it's never used.
+        - Moved the js heap/malloc related functions up to where they belong.
+        - Moved the initialization of _callsPerIteration, _test, and -description into _start,
+          and stopped initializing _runFunction and _doneFunction since both test times now
+          use _test object.
+        - Made _measureTimeOnce and _measureRunsPerSecondOnce return the measured value
+          instead of calling ignoreWarmUpAndLog and _runLoop to share the code; they're now
+          called in _measureRunsPerSecondOnce.
+
+        * resources/runner.js:
+        (PerfTestRunner.storeHeapResults): Moved.
+        (PerfTestRunner.getUsedMallocHeap): Moved.
+        (PerfTestRunner.getUsedJSHeap): Moved.
+        (PerfTestRunner.getAndPrintMemoryStatistics): Moved.
+        (PerfTestRunner._scheduleNextMeasurementOrNotifyDone): Renamed from _runLoop. Calls
+        ignoreWarmUpAndLog and schedules the next call.
+        (PerfTestRunner._measureTimeOnce): Renamed from _runner.
+        (PerfTestRunner._start): Renamed from initAndStartLoop.
+        (PerfTestRunner.measureTime):
+        (PerfTestRunner.runPerSecond):
+        (PerfTestRunner._measureRunsPerSecondOnce): Renamed from _measureRunsPerSecondOnce.
+        (PerfTestRunner._perSecondRunnerIterator):
+
+2012-09-27  Ryosuke Niwa  <rniwa@webkit.org>
+
         PerfTestRunner.run should take an object
         https://bugs.webkit.org/show_bug.cgi?id=97743
 
index 35ae045..bb4e52b 100755 (executable)
@@ -43,10 +43,6 @@ PerfTestRunner.log = function (text) {
     window.scrollTo(0, document.body.height);
 }
 
-PerfTestRunner.info = function (text) {
-    this.log("Info: " + text);
-}
-
 PerfTestRunner.logInfo = function (text) {
     if (!window.testRunner)
         this.log(text);
@@ -109,6 +105,32 @@ PerfTestRunner.printStatistics = function (statistics, title) {
     this.log("max " + statistics.max + " " + statistics.unit);
 }
 
+PerfTestRunner.storeHeapResults = function() {
+    if (!window.internals)
+        return;
+    this._jsHeapResults.push(this.getUsedJSHeap());
+    this._mallocHeapResults.push(this.getUsedMallocHeap());
+}
+
+PerfTestRunner.getUsedMallocHeap = function() {
+    var stats = window.internals.mallocStatistics();
+    return stats.committedVMBytes - stats.freeListBytes;
+}
+
+PerfTestRunner.getUsedJSHeap = function() {
+    return console.memory.usedJSHeapSize;
+}
+
+PerfTestRunner.getAndPrintMemoryStatistics = function() {
+    if (!window.internals)
+        return;
+    var jsMemoryStats = PerfTestRunner.computeStatistics([PerfTestRunner.getUsedJSHeap()], "bytes");
+    PerfTestRunner.printStatistics(jsMemoryStats, "JS Heap:");
+
+    var mallocMemoryStats = PerfTestRunner.computeStatistics([PerfTestRunner.getUsedMallocHeap()], "bytes");
+    PerfTestRunner.printStatistics(mallocMemoryStats, "Malloc:");
+}
+
 PerfTestRunner.gc = function () {
     if (window.GCController)
         window.GCController.collect();
@@ -125,10 +147,14 @@ PerfTestRunner.gc = function () {
     }
 }
 
-PerfTestRunner._runLoop = function () {
+PerfTestRunner._scheduleNextMeasurementOrNotifyDone = function () {
     if (this._completedRuns < this._runCount) {
         this.gc();
-        window.setTimeout(function () { PerfTestRunner._runner(); }, 0);
+        window.setTimeout(function () {
+            var measuredValue = PerfTestRunner._runner();
+            PerfTestRunner.ignoreWarmUpAndLog(measuredValue);
+            PerfTestRunner._scheduleNextMeasurementOrNotifyDone();
+        }, 0);
     } else {
         if (this._description)
             this.log("Description: " + this._description);
@@ -143,52 +169,25 @@ PerfTestRunner._runLoop = function () {
             var self = this;
             logLines.forEach(function(text) { self.log(text); });
         }
-        this._doneFunction();
+        if (this._test.done)
+            this._test.done();
         if (window.testRunner)
             testRunner.notifyDone();
     }
 }
 
-PerfTestRunner._runner = function () {
+PerfTestRunner._measureTimeOnce = function () {
     var start = this.now();
-    var returnValue = this._runFunction.call(window);
+    var returnValue = this._test.run.call(window);
     var end = this.now();
 
     if (returnValue - 0 === returnValue) {
         if (returnValue <= 0)
             this.log("runFunction returned a non-positive value: " + returnValue);
-        time = returnValue;
-    } else
-        time = end - start;
-
-    this.ignoreWarmUpAndLog(time);
-    this._runLoop();
-}
-
-PerfTestRunner.storeHeapResults = function() {
-    if (!window.internals)
-        return;
-    this._jsHeapResults.push(this.getUsedJSHeap());
-    this._mallocHeapResults.push(this.getUsedMallocHeap());
-}
-
-PerfTestRunner.getUsedMallocHeap = function() {
-    var stats = window.internals.mallocStatistics();
-    return stats.committedVMBytes - stats.freeListBytes;
-}
-
-PerfTestRunner.getUsedJSHeap = function() {
-    return console.memory.usedJSHeapSize;
-}
-
-PerfTestRunner.getAndPrintMemoryStatistics = function() {
-    if (!window.internals)
-        return;
-    var jsMemoryStats = PerfTestRunner.computeStatistics([PerfTestRunner.getUsedJSHeap()], "bytes");
-    PerfTestRunner.printStatistics(jsMemoryStats, "JS Heap:");
+        return returnValue;
+    }
 
-    var mallocMemoryStats = PerfTestRunner.computeStatistics([PerfTestRunner.getUsedMallocHeap()], "bytes");
-    PerfTestRunner.printStatistics(mallocMemoryStats, "Malloc:");
+    return end - start;
 }
 
 PerfTestRunner.ignoreWarmUpAndLog = function (result) {
@@ -204,42 +203,36 @@ PerfTestRunner.ignoreWarmUpAndLog = function (result) {
     }
 }
 
-PerfTestRunner.initAndStartLoop = function() {
+PerfTestRunner._start = function(test) {
+    this._description = test.description || "";
     this._completedRuns = -1;
-    this.customRunFunction = null;
+    this._callsPerIteration = 1;
+    this._test = test;
+
     this._results = [];
     this._jsHeapResults = [];
     this._mallocHeapResults = [];
+
     this._logLines = window.testRunner ? [] : null;
     this.log("Running " + this._runCount + " times");
-    this._runLoop();
+    this._scheduleNextMeasurementOrNotifyDone();
 }
 
 PerfTestRunner.measureTime = function (test) {
-    this._runFunction = test.run;
-    this._doneFunction = test.done || function () {};
-    this._description = test.description || "";
     this._runCount = test.runCount || 20;
-    this._callsPerIteration = 1;
     this.unit = 'ms';
-
-    this._test = test;
-    this.initAndStartLoop();
+    this._runner = this._measureTimeOnce;
+    this._start(test);
 }
 
 PerfTestRunner.runPerSecond = function (test) {
-    this._doneFunction = test.done || function () {};
-    this._description = test.description || "";
     this._runCount = 20;
-    this._callsPerIteration = 1;
     this.unit = 'runs/s';
-
-    this._test = test;
-    this._runner = this._perSecondRunner;
-    this.initAndStartLoop();
+    this._runner = this._measureRunsPerSecondOnce;
+    this._start(test);
 }
 
-PerfTestRunner._perSecondRunner = function () {
+PerfTestRunner._measureRunsPerSecondOnce = function () {
     var timeToRun = this._test.timeToRun || 750;
     var totalTime = 0;
     var i = 0;
@@ -256,14 +249,13 @@ PerfTestRunner._perSecondRunner = function () {
     }
     this._callsPerIteration = callsPerIteration;
 
-    this.ignoreWarmUpAndLog(i * 1000 / totalTime);
-    this._runLoop();
+    return i * 1000 / totalTime;
 }
 
 PerfTestRunner._perSecondRunnerIterator = function (callsPerIteration) {
     var startTime = this.now();
     for (var i = 0; i < callsPerIteration; i++)
-        this._test.run();
+        this._test.run.call(window);
     return this.now() - startTime;
 }