summaryrefslogtreecommitdiffstats
path: root/tools/page_cycler/database/head.js
diff options
context:
space:
mode:
authordumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-29 23:27:37 +0000
committerdumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-29 23:27:37 +0000
commit81545760b52a29fbcc7a594b5b81fd1d7cdcf8ec (patch)
tree3b750fc0c9508b4eff5b9729e7e0613bb4328cb1 /tools/page_cycler/database/head.js
parent35f2094cd0ac27018aff2646445f44c3f9ee8d36 (diff)
downloadchromium_src-81545760b52a29fbcc7a594b5b81fd1d7cdcf8ec.zip
chromium_src-81545760b52a29fbcc7a594b5b81fd1d7cdcf8ec.tar.gz
chromium_src-81545760b52a29fbcc7a594b5b81fd1d7cdcf8ec.tar.bz2
Adding the DB performance tests.
BUG=none TEST=none Review URL: http://codereview.chromium.org/465141 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35355 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/page_cycler/database/head.js')
-rw-r--r--tools/page_cycler/database/head.js120
1 files changed, 120 insertions, 0 deletions
diff --git a/tools/page_cycler/database/head.js b/tools/page_cycler/database/head.js
new file mode 100644
index 0000000..fedacec
--- /dev/null
+++ b/tools/page_cycler/database/head.js
@@ -0,0 +1,120 @@
+// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var totalTime;
+var fudgeTime;
+var elapsedTime;
+var endTime;
+var iterations;
+var cycle;
+var results = false;
+var TIMEOUT = 15;
+
+/**
+ * Returns the value of the given property stored in the cookie.
+ * @param {string} name The property name.
+ * @return {string} The value of the given property, or empty string
+ * if the property was not found.
+ */
+function getPropertyValue(name) {
+ var cookies = document.cookie.split('; ');
+ for (var i = 0; i < cookies.length; ++i) {
+ var t = cookies[i].split('=');
+ if ((t[0] == name) && t[1])
+ return t[1];
+ }
+ return '';
+}
+
+/**
+ * Returns the value of the '__pc_timings' property.
+ * @return {string} The list of all timings we got so far.
+ */
+function getTimings() {
+ return getPropertyValue('__pc_timings');
+}
+
+/**
+ * Sets the value of the '__pc_timings' property in the cookie.
+ * @param {string} timings A comma-separated list of timings.
+ */
+function setTimings(timings) {
+ document.cookie = '__pc_timings=' + timings + '; path=/';
+}
+
+/**
+ * Starts the next test cycle or redirects the browser to the results page.
+ */
+function nextCycleOrResults() {
+ // Call GC twice to cleanup JS heap before starting a new test.
+ if (window.gc) {
+ window.gc();
+ window.gc();
+ }
+
+ var tLag = Date.now() - endTime - TIMEOUT;
+ if (tLag > 0)
+ fudgeTime += tLag;
+
+ var doc;
+ if (cycle == iterations) {
+ document.cookie = '__pc_done=1; path=/';
+ doc = '../../common/report.html';
+ } else {
+ doc = 'index.html';
+ }
+
+ var timings = elapsedTime;
+ var oldTimings = getTimings();
+ if (oldTimings != '')
+ timings = oldTimings + ',' + timings;
+ setTimings(timings);
+
+ var url = doc + '?n=' + iterations + '&i=' + cycle +
+ '&td=' + totalTime + '&tf=' + fudgeTime;
+ document.location.href = url;
+}
+
+/**
+ * Computes various running times and updates the stats reported at the end.
+ * @param {!number} cycleTime The running time of the test cycle.
+ */
+function testComplete(cycleTime) {
+ if (results)
+ return;
+
+ var oldTotalTime = 0;
+ var cycleEndTime = Date.now();
+ var cycleFudgeTime = 0;
+
+ var s = document.location.search;
+ if (s) {
+ var params = s.substring(1).split('&');
+ for (var i = 0; i < params.length; i++) {
+ var f = params[i].split('=');
+ switch (f[0]) {
+ case 'skip':
+ return; // No calculation, just viewing
+ case 'n':
+ iterations = f[1];
+ break;
+ case 'i':
+ cycle = f[1] - 0 + 1;
+ break;
+ case 'td':
+ oldTotalTime = f[1] - 0;
+ break;
+ case 'tf':
+ cycleFudgeTime = f[1] - 0;
+ break;
+ }
+ }
+ }
+ elapsedTime = cycleTime;
+ totalTime = oldTotalTime + elapsedTime;
+ endTime = cycleEndTime;
+ fudgeTime = cycleFudgeTime;
+
+ setTimeout(nextCycleOrResults, TIMEOUT);
+}