diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-16 09:35:47 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-16 09:35:47 +0000 |
commit | e0fef03f9db2c3823fbddeecec83c88ce49af51a (patch) | |
tree | 370afa6395b0022ba95c28a79889a8f6c0118e1d /chrome | |
parent | d7f67360df8d684aab90c9a33e724c2ff1586de6 (diff) | |
download | chromium_src-e0fef03f9db2c3823fbddeecec83c88ce49af51a.zip chromium_src-e0fef03f9db2c3823fbddeecec83c88ce49af51a.tar.gz chromium_src-e0fef03f9db2c3823fbddeecec83c88ce49af51a.tar.bz2 |
Merge 34638 - Significant improvements to the benchmark extension:
enable multipage testing.
add totals.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/506021
TBR=mbelshe@google.com
Review URL: http://codereview.chromium.org/500064
git-svn-id: svn://svn.chromium.org/chrome/branches/249/src@34716 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/common/extensions/docs/examples/extensions/benchmark/background.html | 135 | ||||
-rw-r--r-- | chrome/common/extensions/docs/examples/extensions/benchmark/options.html | 67 |
2 files changed, 153 insertions, 49 deletions
diff --git a/chrome/common/extensions/docs/examples/extensions/benchmark/background.html b/chrome/common/extensions/docs/examples/extensions/benchmark/background.html index e31c17e..209ac5a 100644 --- a/chrome/common/extensions/docs/examples/extensions/benchmark/background.html +++ b/chrome/common/extensions/docs/examples/extensions/benchmark/background.html @@ -37,9 +37,56 @@ window.results.data = new Array(); window.testUrl = ""; window.windowId = 0; +// The list of currently running benchmarks +var benchmarks = new Array(); +var benchmarkIndex = 0; +var benchmarkWindow = 0; + +function addBenchmark(benchmark) { + benchmarks.push(benchmark); +} + +// Array Remove - By John Resig (MIT Licensed) +Array.prototype.remove = function(from, to) { + var rest = this.slice((to || from) + 1 || this.length); + this.length = from < 0 ? this.length + from : from; + return this.push.apply(this, rest); +}; + +function removeBenchmark(benchmark) { + var index; + for (var index = 0; index < benchmarks.length; ++index) { + if (benchmarks[index] == benchmark) { + break; + } + } + benchmarks.remove(index); + + // Preserve index ordering when removing from the list. + if (index <= benchmarkIndex) { + benchmarkIndex--; // Note: it is okay to drop to -1 here. + } +} + +function findBenchmark(url) { + for (var index = 0; index < benchmarks.length; ++index) { + if (benchmarks[index].url() == url) { + return benchmarks[index]; + } + } + return undefined; +} + +function nextBenchmark() { + benchmarkIndex = (benchmarkIndex + 1) % benchmarks.length; + return benchmarks[benchmarkIndex]; +} + function show_options() { chrome.tabs.getSelected(null, function(tab) { - window.testUrl = tab.url; + if (window.testUrl == "") { + window.testUrl = tab.url; + } var tabs = chrome.extension.getExtensionTabs(); if (tabs && tabs.length) { tabs[0].setUrl(testUrl); @@ -64,7 +111,6 @@ function Benchmark() { var runCount_ = 0; var count_; var totalTime_; - var lastWin_; var me_ = this; var current_; var initialReadBytes_; @@ -77,22 +123,23 @@ function Benchmark() { return; } - console.log("Starting test for url: " + url); + console.log("Benchmark testing url: " + url); + + // Add this benchmark to the list of benchmarks running. + addBenchmark(this); runCount_ = window.iterations; count_ = 0; totalTime_ = 0; - lastWin_ = 0; current_ = {}; current_.url = url; current_.docLoadResults = new Array(); // times to docload current_.paintResults = new Array(); // times to paint current_.totalResults = new Array(); // times to complete load - initialReadBytes = chrome.benchmarking.counter("tcp.read_bytes"); - initialWriteBytes = chrome.benchmarking.counter("tcp.write_bytes"); - - me_.runPage(); + current_.bytesRead = 0; + current_.bytesWritten = 0; + current_.totalTime = 0; } // Is the benchmark currently in progress. @@ -100,21 +147,23 @@ function Benchmark() { return runCount_ > 0; } + // The url which this benchmark is running. + this.url = function() { return current_.url; } + // Called when the test run completes. this.finish = function() { - chrome.tabs.remove(lastWin_.id); - lastWin_ = 0; - - // Record some more stats. - current_.bytesRead = chrome.benchmarking.counter("tcp.read_bytes") - - initialReadBytes; - current_.bytesWritten = chrome.benchmarking.counter("tcp.write_bytes") - - initialWriteBytes; - current_.totalTime = totalTime_; + removeBenchmark(this); - // push the result + // Push the result. window.results.data.push(current_); - current_ = 0; + + // If we're the last benchmark, close the window. + if (benchmarks.length == 0) { + chrome.tabs.remove(benchmarkWindow.id); + benchmarkWindow = 0; + + show_options(); + } } // Update the UI after a test run. @@ -143,15 +192,21 @@ function Benchmark() { if (window.clearCache) { chrome.benchmarking.clearCache(); } + if (window.clearConnections) { chrome.benchmarking.closeConnections(); } - if (lastWin_) { - chrome.tabs.update(lastWin_.id, {"url": current_.url}); + initialReadBytes = chrome.benchmarking.counter("tcp.read_bytes"); + initialWriteBytes = chrome.benchmarking.counter("tcp.write_bytes"); + + + if (benchmarkWindow) { + var benchmark = nextBenchmark(); + chrome.tabs.update(benchmarkWindow.id, {"url": benchmark.url() }); } else { - chrome.tabs.create({"url": current_.url}, - function(tab) { lastWin_ = tab; }); + chrome.tabs.create({"url": current_.url }, + function(tab) { benchmarkWindow = tab; }); } } @@ -164,32 +219,46 @@ function Benchmark() { var totalTime = Math.round((csi.finishLoadTime - csi.startLoadTime) * 1000.0); + if (paintTime < 0) { + // If the user navigates away from the test while it is running, + // paint may not occur. + alert("No paint detected. Did you navigate while the test was running?"); + paintTime = totalTime; // approximate. + } + + // For our toolbar counters + totalTime_ += totalTime; + count_++; + // Record the result current_.docLoadResults.push(docLoadTime); current_.paintResults.push(paintTime); current_.totalResults.push(totalTime); + current_.bytesRead += chrome.benchmarking.counter("tcp.read_bytes") - + initialReadBytes; + current_.bytesWritten += chrome.benchmarking.counter("tcp.write_bytes") - + initialWriteBytes; + current_.totalTime += totalTime; - // For our toolbar counters - totalTime_ += totalTime; - count_++; + if (--runCount_ == 0) { + me_.finish(); + } - if (--runCount_ > 0) { + // If there are more tests, schedule them + if (runCount_ > 0 || benchmarks.length > 0) { setTimeout(me_.runPage, 100); - } else { - me_.finish(); } // Update the UI me_.displayResults(); + } } -var benchmarks = new Array(); - chrome.extension.onConnect.addListener(function(port) { port.onMessage.addListener(function(data) { if (data.message == "load") { - var benchmark = benchmarks[data.url]; + var benchmark = findBenchmark(data.url); if (benchmark != undefined && benchmark.isRunning()) { benchmark.pageFinished(data.values); } @@ -201,9 +270,9 @@ function run() { var urls = testUrl.split(","); for (var i = 0; i < urls.length; i++) { var benchmark = new Benchmark(); - benchmarks[urls[i]] = benchmark; benchmark.start(urls[i]); // XXXMB - move to constructor } + benchmarks[0].runPage(); } // Run at startup diff --git a/chrome/common/extensions/docs/examples/extensions/benchmark/options.html b/chrome/common/extensions/docs/examples/extensions/benchmark/options.html index 99a7dcd..4df1db3 100644 --- a/chrome/common/extensions/docs/examples/extensions/benchmark/options.html +++ b/chrome/common/extensions/docs/examples/extensions/benchmark/options.html @@ -118,7 +118,7 @@ Array.avg = function(array) { sum = sum - min - max; count -= 2; } - return (sum / count).toFixed(1); + return sum / count; } // Compute the standard deviation of an array @@ -134,21 +134,41 @@ Array.stddev = function(array) { return Math.sqrt(variance).toFixed(2); } +// Object to summarize everything +var totals = {}; + // Computes min/max/mean/stddev, etc all up front. function computeResults(data) { - for (var i = 0; i < data.data.length; i++) { + totals = {}; + totals.mean = 0; + totals.paintMean = 0; + totals.docLoadMean = 0; + + var count = data.data.length; + for (var i = 0; i < count; i++) { var obj = data.data[i]; var resultList = obj.totalResults; obj.mean = Array.avg(resultList); obj.stddev = Array.stddev(resultList); obj.min = Array.min(resultList); obj.max = Array.max(resultList); - obj.readbps = (obj.bytesRead * 8 / obj.totalTime).toFixed(2); - obj.writebps = (obj.bytesWritten * 8 / obj.totalTime).toFixed(2); - obj.readKB = (obj.bytesRead / 1024).toFixed(0); - obj.writeKB = (obj.bytesWritten / 1024).toFixed(0); + obj.readbps = obj.bytesRead * 8 / obj.totalTime; + obj.writebps = obj.bytesWritten * 8 / obj.totalTime; + obj.readKB = obj.bytesRead / 1024; + obj.writeKB = obj.bytesWritten / 1024; obj.paintMean = Array.avg(obj.paintResults); obj.docLoadMean = Array.avg(obj.docLoadResults); + + totals.mean += obj.mean; + totals.paintMean += obj.paintMean; + totals.docLoadMean += obj.docLoadMean; + } + + totals.url = "(" + count + " urls)"; + if (count > 0) { + totals.mean /= count; + totals.paintMean /= count; + totals.docLoadMean /= count; } // Find the biggest sample for our bar graph. @@ -258,18 +278,33 @@ Clear Cache?<input id="clearcache" type="checkbox"> <th samples</th> </tr> + <tr id="t.total" jsselect="totals"> + <td class="url">TOTALS <span jscontent="url"></span></td> + <td class="avg"><span jseval="val = docLoadMean.toFixed(1)" jscontent="val"></span></td> + <td class="avg"><span jseval="val = paintMean.toFixed(1)" jscontent="val"></span></td> + <td class="avg"><span jseval="val = mean.toFixed(1)" jscontent="val"></span></td> + <td class="avg" jseval="1"></td> + <td class="avg" jseval="1"></td> + <td class="avg" jseval="1"></td> + <td class="avg" jseval="1"></td> + <td class="avg" jseval="1"></td> + <td class="avg" jseval="1"></td> + <td class="avg" jseval="1"></td> + <td class="data"></td> + </tr> + <tr jsselect="data"> <td class="url" jseval="$width = getWidth($this.mean, 600)"><div jsvalues=".style.width:$width" class="bggraph"><a jsvalues="href:$this.url" jscontent="url"></a></div></td> - <td class="avg" jscontent="docLoadMean"></td> - <td class="avg" jscontent="paintMean"></td> - <td class="avg" jscontent="mean"></td> - <td class="avg" jscontent="stddev"></td> - <td class="avg" jscontent="min"></td> - <td class="avg" jscontent="max"></td> - <td class="avg" jscontent="readKB"></td> - <td class="avg" jscontent="writeKB"></td> - <td class="avg" jscontent="readbps"></td> - <td class="avg" jscontent="writebps"></td> + <td class="avg" jseval="val = docLoadMean.toFixed(1)" jscontent="val"></td> + <td class="avg" jseval="val = paintMean.toFixed(1)" jscontent="val"></td> + <td class="avg" jseval="val = mean.toFixed(1)" jscontent="val"></td> + <td class="avg" jseval="val = stddev.toFixed(1)" jscontent="val"></td> + <td class="avg" jseval="val = min.toFixed(1)" jscontent="val"></td> + <td class="avg" jseval="val = max.toFixed(1)" jscontent="val"></td> + <td class="avg" jseval="val = readKB.toFixed(1)" jscontent="val"></td> + <td class="avg" jseval="val = writeKB.toFixed(1)" jscontent="val"></td> + <td class="avg" jseval="val = readbps.toFixed(1)" jscontent="val"></td> + <td class="avg" jseval="val = writebps.toFixed(1)" jscontent="val"></td> <td class="data"><span jsselect="totalResults"><span jscontent="$this"></span>,</span> </td> </tr> <tr jsdisplay="data.length == 0"> |