diff options
author | hans@chromium.org <hans@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-23 10:50:51 +0000 |
---|---|---|
committer | hans@chromium.org <hans@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-23 10:50:51 +0000 |
commit | 8b2c331d637d153edbd630f6b5fdfbd2ba519a53 (patch) | |
tree | c4d7e344b911a92ad5e467f2eca70ee94be4c078 /tools/page_cycler | |
parent | 6c751e787fac3664b2d099d91db6863bbe2bdc26 (diff) | |
download | chromium_src-8b2c331d637d153edbd630f6b5fdfbd2ba519a53.zip chromium_src-8b2c331d637d153edbd630f6b5fdfbd2ba519a53.tar.gz chromium_src-8b2c331d637d153edbd630f6b5fdfbd2ba519a53.tar.bz2 |
IndexedDB: Set up a page cycler.
Set up a page cycler to track Indexed DB performance. Start off with a basic
insertion test.
BUG=61428
TEST=page_cycler_tests --gtest_filter="PageCyclerIndexedDatabase*"
Review URL: http://codereview.chromium.org/5096003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67079 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/page_cycler')
-rw-r--r-- | tools/page_cycler/indexed_db/basic_insert/index.html | 73 | ||||
-rw-r--r-- | tools/page_cycler/indexed_db/basic_insert/start.html | 9 | ||||
-rw-r--r-- | tools/page_cycler/indexed_db/common.js | 26 | ||||
-rw-r--r-- | tools/page_cycler/indexed_db/head.js | 120 | ||||
-rw-r--r-- | tools/page_cycler/indexed_db/start.js | 58 |
5 files changed, 286 insertions, 0 deletions
diff --git a/tools/page_cycler/indexed_db/basic_insert/index.html b/tools/page_cycler/indexed_db/basic_insert/index.html new file mode 100644 index 0000000..5110556 --- /dev/null +++ b/tools/page_cycler/indexed_db/basic_insert/index.html @@ -0,0 +1,73 @@ +<!DOCTYPE HTML> +<html> +<title>Basic Insert</title> +<script src="../head.js"></script> +<script src="../common.js"></script> +<script> + var RECORDS = 3000; + + var failed = false; + function error(event) { + log('Error ' + event.code + ': ' + event.message); + + if (!failed) + testComplete(TEST_FAILED); + failed = true; + } + + function start() { + if (!setup()) + testComplete(SETUP_FAILED); + + var request = indexedDB.open('idb_basic_insert', ''); + request.onsuccess = onOpen; + request.onerror = error; + } + + function onOpen() { + window.db = event.result; + + var request = db.setVersion('1'); + request.onerror = error; + request.onsuccess = onSetVersion; + } + + function onSetVersion() { + var transaction = event.result; + transaction.onerror = error; + transaction.oncomplete = storeCreated; + + while (db.objectStores.length) + db.removeObjectStore(db.objectStores[0]); + + db.createObjectStore('store'); + } + + function storeCreated() { + var transaction = db.transaction([], IDBTransaction.READ_WRITE, 0); + transaction.oncomplete = insertsDone; + transaction.onabort = error; + + var objectStore = transaction.objectStore('store'); + log('Inserting ' + RECORDS + ' records with explicit key.'); + startTime = new Date(); + for (var i = 0; i < RECORDS; i++) { + var x = Math.floor(Math.random() * 1000000); + objectStore.put(x, x).onerror = error; + } + } + + function insertsDone() { + var now = Date.now(); + var diff = now - startTime; + log('Inserted ' + RECORDS + ' records in ' + diff + ' ms (' + diff / + RECORDS + ' ms per record)'); + + if (!failed) + testComplete(now - startTime); + } +</script> + +<body onLoad="start()"> +</body> +</html> diff --git a/tools/page_cycler/indexed_db/basic_insert/start.html b/tools/page_cycler/indexed_db/basic_insert/start.html new file mode 100644 index 0000000..ecdc393 --- /dev/null +++ b/tools/page_cycler/indexed_db/basic_insert/start.html @@ -0,0 +1,9 @@ +<!DOCTYPE HTML> +<html> +<body> +<h3>Note: You must have started chrome with <tt>--enable-file-cookies</tt> for + this test to work manually.</h3> +<script>document.cookie = "__pc_pages=basic_insert; path=/";</script> +<script src="../start.js"></script> +</body> +</html> diff --git a/tools/page_cycler/indexed_db/common.js b/tools/page_cycler/indexed_db/common.js new file mode 100644 index 0000000..d1b4f72 --- /dev/null +++ b/tools/page_cycler/indexed_db/common.js @@ -0,0 +1,26 @@ +// Copyright (c) 2010 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 CANNOT_OPEN_DB = -1; +var SETUP_FAILED = -2; +var TEST_FAILED = -3; + +function setup() { + if ('webkitIndexedDB' in window) { + indexedDB = webkitIndexedDB; + IDBCursor = webkitIDBCursor; + IDBKeyRange = webkitIDBKeyRange; + IDBTransaction = webkitIDBTransaction; + return true; + } + + if ('indexedDB' in window) + return true; + + return false; +} + +function log(msg) { + document.write(msg + '<br>'); +} diff --git a/tools/page_cycler/indexed_db/head.js b/tools/page_cycler/indexed_db/head.js new file mode 100644 index 0000000..a1b3149 --- /dev/null +++ b/tools/page_cycler/indexed_db/head.js @@ -0,0 +1,120 @@ +// Copyright (c) 2010 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); +} diff --git a/tools/page_cycler/indexed_db/start.js b/tools/page_cycler/indexed_db/start.js new file mode 100644 index 0000000..1163ea0 --- /dev/null +++ b/tools/page_cycler/indexed_db/start.js @@ -0,0 +1,58 @@ +// Copyright (c) 2010 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. + +document.title = 'page cycler'; + +document.cookie = '__pc_done=0; path=/'; +document.cookie = '__pc_timings=; path=/'; + +var options = location.search.substring(1).split('&'); + +function getOption(name) { + var r = new RegExp('^' + name + '='); + for (var i = 0; i < options.length; i++) { + if (options[i].match(r)) { + return options[i].substring(name.length + 1); + } + } + return null; +} + +function start() { + var iterations = document.getElementById('iterations').value; + window.resizeTo(800, 800); + var url = 'index.html?n=' + iterations + '&i=0&td=0'; + window.location = url; +} + +function renderForm() { + var form = document.createElement('form'); + form.onsubmit = function(e) { + start(); + e.preventDefault(); + }; + + var label = document.createTextNode('Iterations: '); + form.appendChild(label); + + var input = document.createElement('input'); + input.id = 'iterations'; + input.type = 'number'; + var iterations = getOption('iterations'); + input.value = iterations ? iterations : '5'; + form.appendChild(input); + + input = document.createElement('input'); + input.type = 'submit'; + input.value = 'Start'; + form.appendChild(input); + + document.body.appendChild(form); +} + +renderForm(); + +// should we start automatically? +if (location.search.match('auto=1')) + start(); |