Initialize the graphics benchmark's Kalman filter with estimated 60 FPS
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Nov 2015 17:55:08 +0000 (17:55 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Nov 2015 17:55:08 +0000 (17:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150965

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2015-11-06
Reviewed by Darin Adler.

This should give the benchmark more accurate reading at warmup time. And
hence we can safely reduce the test running time to be 10 seconds.

* Animometer/runner/animometer.html:
Add "defer" back when loading resources/animometer.js since this script
depends on many other scripts and we need to wait till the page is parsed.
Also change the default test interval to be 10 seconds.

* Animometer/runner/resources/graph.js:
(graph): Make the test results curves smoother.

* Animometer/tests/resources/main.js:
(Animator): Initialize the Kalman filter with 60 FPS which should be true
if the test page is empty.

(Animator.prototype.animate):
* Animometer/tests/resources/math.js:
(KalmanEstimator): Fix the initial value of _vecX_est.
    _vecX_est[0] = current FPS (= 60FPS when the test page is empty)
    _vecX_est[1] = first time derivative of FPS (=0; FPS has been constant).
    _vecX_est[2] = second time derivative of FPS (=0; since _vecX_est[1]=0).
(KalmanEstimator.prototype.estimate): Add some comments.

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

PerformanceTests/Animometer/runner/animometer.html
PerformanceTests/Animometer/runner/resources/graph.js
PerformanceTests/Animometer/tests/resources/main.js
PerformanceTests/Animometer/tests/resources/math.js
PerformanceTests/ChangeLog

index ea36a69..fe4fc6b 100644 (file)
@@ -7,7 +7,7 @@
     <script src="../resources/extensions.js"></script>
     <script src="resources/tests.js"></script>
     <script src="resources/benchmark-runner.js"></script>
     <script src="../resources/extensions.js"></script>
     <script src="resources/tests.js"></script>
     <script src="resources/benchmark-runner.js"></script>
-    <script src="resources/animometer.js"></script>
+    <script src="resources/animometer.js" defer></script>
     <script src="resources/d3.min.js"></script>
     <script src="resources/graph.js"></script>
 </head>
     <script src="resources/d3.min.js"></script>
     <script src="resources/graph.js"></script>
 </head>
@@ -27,7 +27,7 @@
             </suites>
             <options>
                 <h2>Options:</h2>
             </suites>
             <options>
                 <h2>Options:</h2>
-                <label>Test interval: <input id="test-interval" type="number" value="30"> seconds</label><br>
+                <label>Test interval: <input id="test-interval" type="number" value="10"> seconds</label><br>
                 <label>Frame rate: <input id="frame-rate" type="number" value="50"> fps</label><br>
                 <label><input id="estimated-frame-rate" type="checkbox" checked> Estimated Frame Rate</label><br>
                 <label><input id="fix-test-complexity" type="checkbox"> Fix test complexity after warmup</label><br>
                 <label>Frame rate: <input id="frame-rate" type="number" value="50"> fps</label><br>
                 <label><input id="estimated-frame-rate" type="checkbox" checked> Estimated Frame Rate</label><br>
                 <label><input id="fix-test-complexity" type="checkbox"> Fix test complexity after warmup</label><br>
index 021f5f5..f976d7c 100644 (file)
@@ -30,10 +30,12 @@ function graph(selector, margins, axes, samples, samplingTimeOffset)
             .orient("right");
 
     var lineLeft = d3.svg.line()
             .orient("right");
 
     var lineLeft = d3.svg.line()
+            .interpolate("basis")
             .x(function(d) { return x(d.timeOffset); })
             .y(function(d) { return yLeft(d.values[0]); });
 
     var lineRight = d3.svg.line()
             .x(function(d) { return x(d.timeOffset); })
             .y(function(d) { return yLeft(d.values[0]); });
 
     var lineRight = d3.svg.line()
+            .interpolate("basis")
             .x(function(d) { return x(d.timeOffset); })
             .y(function(d) { return yRight(d.values[1]); });
 
             .x(function(d) { return x(d.timeOffset); })
             .y(function(d) { return yRight(d.values[1]); });
 
index aa92e81..7687334 100644 (file)
@@ -67,7 +67,7 @@ function Animator(benchmark)
     this._measureFrameCount = 3; 
     this._referenceTime = 0;
     this._currentTimeOffset = 0;
     this._measureFrameCount = 3; 
     this._referenceTime = 0;
     this._currentTimeOffset = 0;
-    this._estimator = new KalmanEstimator();
+    this._estimator = new KalmanEstimator(60);
 }
 
 Animator.prototype =
 }
 
 Animator.prototype =
@@ -110,7 +110,7 @@ Animator.prototype =
          
         // Use Kalman filter to get a more non-fluctuating frame rate.
         if (this._benchmark.options["estimated-frame-rate"])
          
         // Use Kalman filter to get a more non-fluctuating frame rate.
         if (this._benchmark.options["estimated-frame-rate"])
-            currentFrameRate = this._estimator.estimate(measureTimeDelta, currentFrameRate);
+            currentFrameRate = this._estimator.estimate(currentFrameRate);
         
         // Adjust the test to reach the desired FPS.
         var result = this._benchmark.update(this._currentTimeOffset, this.timeDelta(), currentFrameRate);
         
         // Adjust the test to reach the desired FPS.
         var result = this._benchmark.update(this._currentTimeOffset, this.timeDelta(), currentFrameRate);
index c13833b..f26f186 100644 (file)
@@ -233,42 +233,55 @@ PIDController.prototype =
     }
 }
 
     }
 }
 
-function KalmanEstimator()
+function KalmanEstimator(initX)
 {
 {
+    // Initialize state transition matrix
     this._matA = Matrix3.identity();
     this._matA = Matrix3.identity();
+    this._matA[Matrix3.pos(0, 2)] = 1;
     
     
+    // Initialize measurement matrix
     this._vecH = Vector3.zeros();
     this._vecH[0] = 1;
     
     this._matQ = Matrix3.identity();
     this._R = 1000;
     
     this._vecH = Vector3.zeros();
     this._vecH[0] = 1;
     
     this._matQ = Matrix3.identity();
     this._R = 1000;
     
-    this._vecX_est = Vector3.ones();
+    // Initial state conditions
+    this._vecX_est = Vector3.zeros();
+    this._vecX_est[0] = initX;
     this._matP_est = Matrix3.zeros();
 }
 
 KalmanEstimator.prototype =
 {
     this._matP_est = Matrix3.zeros();
 }
 
 KalmanEstimator.prototype =
 {
-    estimate: function(timeDelta, current)
+    estimate: function(current)
     {
     {
-        // Update the transition matrix.
-        this._matA[Matrix3.pos(0, 2)] = 1;
-
-        // Predicted state and covariance.
+        // Project the state ahead
+        //  X_prd(k) = A * X_est(k-1)
         var vecX_prd = Matrix3.multiplyVector3(this._matA, this._vecX_est);
         var vecX_prd = Matrix3.multiplyVector3(this._matA, this._vecX_est);
+        
+        // Project the error covariance ahead
+        //  P_prd(k) = A * P_est(k-1) * A' + Q
         var matP_prd = Matrix3.add(Matrix3.multiplyMatrix3(Matrix3.multiplyMatrix3(this._matA, this._matP_est), Matrix3.transpose(this._matA)), this._matQ);
 
         var matP_prd = Matrix3.add(Matrix3.multiplyMatrix3(Matrix3.multiplyMatrix3(this._matA, this._matP_est), Matrix3.transpose(this._matA)), this._matQ);
 
-        // Estimation.
+        // Compute Kalman gain
+        //  B = H * P_prd(k)';
+        //  S = B * H' + R;
+        //  K(k) = (S \ B)';
         var vecB = Vector3.multiplyMatrix3(this._vecH, Matrix3.transpose(matP_prd));
         var S = Vector3.multiplyVector3(vecB, this._vecH) + this._R;
         var vecB = Vector3.multiplyMatrix3(this._vecH, Matrix3.transpose(matP_prd));
         var S = Vector3.multiplyVector3(vecB, this._vecH) + this._R;
-
         var vecGain = Vector3.scale(1/S, vecB);
         
         var vecGain = Vector3.scale(1/S, vecB);
         
-        // Estimated state and covariance.
+        // Update the estimate via z(k)
+        //  X_est(k) = x_prd + K(k) * (z(k) - H * X_prd(k));
         this._vecX_est = Vector3.add(vecX_prd, Vector3.scale(current - Vector3.multiplyVector3(this._vecH, vecX_prd), vecGain));
         this._vecX_est = Vector3.add(vecX_prd, Vector3.scale(current - Vector3.multiplyVector3(this._vecH, vecX_prd), vecGain));
+        
+        // Update the error covariance
+        //  P_est(k) = P_prd(k) - K(k) * H * P_prd(k);
         this._matP_est = Matrix3.subtract(matP_prd, Matrix3.scale(Vector3.multiplyVector3(vecGain, this._vecH), matP_prd));
 
         // Compute the estimated measurement.
         this._matP_est = Matrix3.subtract(matP_prd, Matrix3.scale(Vector3.multiplyVector3(vecGain, this._vecH), matP_prd));
 
         // Compute the estimated measurement.
+        //  y = H * X_est(k);
         return Vector3.multiplyVector3(this._vecH,  this._vecX_est);
     }
 }
         return Vector3.multiplyVector3(this._vecH,  this._vecX_est);
     }
 }
index 34f2343..2ea4ad2 100644 (file)
@@ -1,3 +1,33 @@
+2015-11-06  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+        Initialize the graphics benchmark's Kalman filter with estimated 60 FPS
+        https://bugs.webkit.org/show_bug.cgi?id=150965
+
+        Reviewed by Darin Adler.
+
+        This should give the benchmark more accurate reading at warmup time. And
+        hence we can safely reduce the test running time to be 10 seconds.
+
+        * Animometer/runner/animometer.html:
+        Add "defer" back when loading resources/animometer.js since this script
+        depends on many other scripts and we need to wait till the page is parsed.
+        Also change the default test interval to be 10 seconds.
+        
+        * Animometer/runner/resources/graph.js:
+        (graph): Make the test results curves smoother.
+        
+        * Animometer/tests/resources/main.js:
+        (Animator): Initialize the Kalman filter with 60 FPS which should be true
+        if the test page is empty.
+        
+        (Animator.prototype.animate):
+        * Animometer/tests/resources/math.js:
+        (KalmanEstimator): Fix the initial value of _vecX_est.
+            _vecX_est[0] = current FPS (= 60FPS when the test page is empty)
+            _vecX_est[1] = first time derivative of FPS (=0; FPS has been constant).
+            _vecX_est[2] = second time derivative of FPS (=0; since _vecX_est[1]=0).
+        (KalmanEstimator.prototype.estimate): Add some comments.
+
 2015-11-04  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         Remove "defer" from the scripts' references in the graphics benchmark home page 
 2015-11-04  Said Abou-Hallawa  <sabouhallawa@apple.com>
 
         Remove "defer" from the scripts' references in the graphics benchmark home page