Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <style> | 1 <style> |
| 2 #options { | 2 #options { |
| 3 position: absolute; | 3 position: absolute; |
| 4 background-color: #FFFFCC; | 4 background-color: #FFFFCC; |
| 5 display: none; | 5 display: none; |
| 6 font-family: "Courier New"; | 6 font-family: "Courier New"; |
| 7 font-size: 9pt; | 7 font-size: 9pt; |
| 8 padding: 5px; | 8 padding: 5px; |
| 9 border: 1px solid #CCCC88; | 9 border: 1px solid #CCCC88; |
| 10 z-index: 3; | 10 z-index: 3; |
| 11 } | 11 } |
| 12 </style> | 12 </style> |
| 13 | 13 |
| 14 <script> | 14 <script> |
| 15 var optionsForm; | |
| 16 function show_options() { | |
| 17 optionsForm = window.open("options.html", "optionswindow"); | |
| 18 } | |
| 19 | |
| 20 // Round a number to the 1's place. | 15 // Round a number to the 1's place. |
| 21 function formatNumber(str) { | 16 function formatNumber(str) { |
| 22 str += ''; | 17 str += ''; |
| 23 if (str == '0') { | 18 if (str == '0') { |
| 24 return 'N/A '; | 19 return 'N/A '; |
| 25 } | 20 } |
| 26 var x = str.split('.'); | 21 var x = str.split('.'); |
| 27 var x1 = x[0]; | 22 var x1 = x[0]; |
| 28 var x2 = x.length > 1 ? '.' + x[1] : ''; | 23 var x2 = x.length > 1 ? '.' + x[1] : ''; |
| 29 var regex = /(\d+)(\d{3})/; | 24 var regex = /(\d+)(\d{3})/; |
| 30 while (regex.test(x1)) { | 25 while (regex.test(x1)) { |
| 31 x1 = x1.replace(regex, '$1' + ',' + '$2'); | 26 x1 = x1.replace(regex, '$1' + ',' + '$2'); |
| 32 } | 27 } |
| 33 return x1; | 28 return x1; |
| 34 } | 29 } |
| 35 | 30 |
| 36 // Configuration and results are stored globally. | 31 // Configuration and results are stored globally. |
| 37 window.iterations = 10; | 32 window.iterations = 10; |
| 38 window.clearConnections = true; | 33 window.clearConnections = true; |
| 39 window.clearCache = true; | 34 window.clearCache = true; |
| 40 window.results = {}; | 35 window.results = {}; |
| 41 window.results.data = new Array(); | 36 window.results.data = new Array(); |
| 37 window.testUrl = ""; | |
| 38 window.windowId = 0; | |
| 39 | |
| 40 var optionsForm = 0; | |
| 41 function show_options() { | |
| 42 // This functionality is a bit racey, probably due to the extension API. | |
|
Erik does not do reviews
2009/07/17 17:15:52
Is this still racey the way you've implemented it?
| |
| 43 // If we open the window from within the getSelected() callback, then the | |
| 44 // window opens in a new window rather than a new tab (is that a bug?). | |
| 45 // If thwe open the window before we call getSelected(), then the selected | |
|
Erik does not do reviews
2009/07/17 17:15:52
thwe -> we
| |
| 46 // tab URL will be NULL, because the page won't have loaded yet, but it will | |
| 47 // be the selected tab. So, we do this weird thing where we first call | |
| 48 // get selected, knowing that it is asynchronous. Then we open the window, | |
| 49 // and finally when the callback occurs for getSelected, the window will | |
| 50 // be created and we can use it. | |
| 51 chrome.tabs.getSelected(windowId, function(tab) { | |
|
Erik does not do reviews
2009/07/17 17:15:52
windowId is an optional parameter. If you don't p
| |
| 52 window.testUrl = tab.url; | |
| 53 optionsForm.setUrl(window.testUrl); | |
| 54 }); | |
| 55 optionsForm = window.open("options.html", "optionswindow"); | |
| 56 } | |
| 42 | 57 |
| 43 function Benchmark() { | 58 function Benchmark() { |
| 44 var runCount_ = 0; | 59 var runCount_ = 0; |
| 45 var count_; | 60 var count_; |
| 46 var totalTime_; | 61 var totalTime_; |
| 47 var lastWin_; | 62 var lastWin_; |
| 48 var me_ = this; | 63 var me_ = this; |
| 49 var current_; | 64 var current_; |
| 65 var initialReadBytes_; | |
| 66 var initialWriteBytes_; | |
| 50 | 67 |
| 51 // Start a test run | 68 // Start a test run |
| 52 this.start = function(url) { | 69 this.start = function(url) { |
| 53 // Check if a run is already in progress. | 70 // Check if a run is already in progress. |
| 54 if (me_.isRunning()) { | 71 if (me_.isRunning()) { |
| 55 return; | 72 return; |
| 56 } | 73 } |
| 57 | 74 |
| 75 console.log("Starting test for url: " + url); | |
| 76 | |
| 58 runCount_ = window.iterations; | 77 runCount_ = window.iterations; |
| 59 count_ = 0; | 78 count_ = 0; |
| 60 totalTime_ = 0; | 79 totalTime_ = 0; |
| 61 lastWin_ = 0; | 80 lastWin_ = 0; |
| 62 | 81 |
| 63 current_ = {}; | 82 current_ = {}; |
| 64 current_.url = url; | 83 current_.url = url; |
| 65 current_.results = new Array(); | 84 current_.docLoadResults = new Array(); // times to docload |
| 85 current_.paintResults = new Array(); // times to paint | |
| 86 current_.totalResults = new Array(); // times to complete load | |
| 87 initialReadBytes = chromium.benchmarking.counter("tcp.read_bytes"); | |
| 88 initialWriteBytes = chromium.benchmarking.counter("tcp.write_bytes"); | |
| 66 | 89 |
| 67 me_.runPage(); | 90 me_.runPage(); |
| 68 } | 91 } |
| 69 | 92 |
| 70 // Is the benchmark currently in progress. | 93 // Is the benchmark currently in progress. |
| 71 this.isRunning = function() { | 94 this.isRunning = function() { |
| 72 return runCount_ > 0; | 95 return runCount_ > 0; |
| 73 } | 96 } |
| 74 | 97 |
| 75 // Called when the test run completes. | 98 // Called when the test run completes. |
| 76 this.finish = function() { | 99 this.finish = function() { |
| 77 lastWin_.close(); | 100 lastWin_.close(); |
| 78 lastWin_ = 0; | 101 lastWin_ = 0; |
| 79 | 102 |
| 103 // Record some more stats. | |
| 104 current_.bytesRead = chromium.benchmarking.counter("tcp.read_bytes") - | |
| 105 initialReadBytes; | |
| 106 current_.bytesWritten = chromium.benchmarking.counter("tcp.write_bytes") - | |
| 107 initialWriteBytes; | |
| 108 current_.totalTime = totalTime_; | |
| 109 | |
| 80 // push the result | 110 // push the result |
| 81 window.results.data.push(current_); | 111 window.results.data.push(current_); |
| 82 current_ = 0; | 112 current_ = 0; |
| 83 | 113 |
| 84 // show the latest | 114 // show the latest |
| 85 show_options(); | 115 show_options(); |
| 86 } | 116 } |
| 87 | 117 |
| 88 // Update the UI after a test run. | 118 // Update the UI after a test run. |
| 89 this.displayResults = function() { | 119 this.displayResults = function() { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 106 | 136 |
| 107 if (lastWin_) { | 137 if (lastWin_) { |
| 108 lastWin_.location = current_.url; | 138 lastWin_.location = current_.url; |
| 109 } else { | 139 } else { |
| 110 lastWin_ = window.open(current_.url); | 140 lastWin_ = window.open(current_.url); |
| 111 } | 141 } |
| 112 } | 142 } |
| 113 | 143 |
| 114 // Called when a page finishes loading. | 144 // Called when a page finishes loading. |
| 115 this.pageFinished = function(csi) { | 145 this.pageFinished = function(csi) { |
| 116 var t = Math.round((csi.finishLoadTime - csi.startLoadTime) * 1000.0); | 146 var docLoadTime = |
| 147 Math.round((csi.finishDocumentLoadTime - csi.startLoadTime) * 1000.0); | |
| 148 var paintTime = | |
| 149 Math.round((csi.firstPaintTime - csi.startLoadTime) * 1000.0); | |
| 150 var totalTime = | |
| 151 Math.round((csi.finishLoadTime - csi.startLoadTime) * 1000.0); | |
| 117 | 152 |
| 118 // Record the result | 153 // Record the result |
| 119 current_.results.push(t); | 154 current_.docLoadResults.push(docLoadTime); |
| 155 current_.paintResults.push(paintTime); | |
| 156 current_.totalResults.push(totalTime); | |
| 120 | 157 |
| 121 // For our toolbar counters | 158 // For our toolbar counters |
| 122 totalTime_ += t; | 159 totalTime_ += totalTime; |
| 123 count_++; | 160 count_++; |
| 124 | 161 |
| 125 if (--runCount_ > 0) { | 162 if (--runCount_ > 0) { |
| 126 setTimeout(me_.runPage, 100); | 163 setTimeout(me_.runPage, 100); |
| 127 } else { | 164 } else { |
| 128 me_.finish(); | 165 me_.finish(); |
| 129 } | 166 } |
| 130 | 167 |
| 131 // Update the UI | 168 // Update the UI |
| 132 me_.displayResults(); | 169 me_.displayResults(); |
| 133 } | 170 } |
| 134 } | 171 } |
| 135 | 172 |
| 136 var benchmarks = new Array(); | 173 var benchmarks = new Array(); |
| 137 | 174 |
| 138 chrome.self.onConnect.addListener(function(port) { | 175 chrome.self.onConnect.addListener(function(port) { |
| 139 port.onMessage.addListener(function(data) { | 176 port.onMessage.addListener(function(data) { |
| 140 if (data.message == "load") { | 177 if (data.message == "load") { |
| 141 var benchmark = benchmarks[data.url]; | 178 var benchmark = benchmarks[data.url]; |
| 142 if (benchmark != undefined && benchmark.isRunning()) { | 179 if (benchmark != undefined && benchmark.isRunning()) { |
| 143 benchmark.pageFinished(data.values); | 180 benchmark.pageFinished(data.values); |
| 144 } | 181 } |
| 145 } | 182 } |
| 146 }); | 183 }); |
| 147 }); | 184 }); |
| 148 | 185 |
| 149 function run() { | 186 function run() { |
| 150 show_options(); | 187 show_options(); |
| 151 var urls = document.getElementById("url").value.split(","); | 188 var urls = testUrl.split(","); |
| 152 for (var i = 0; i < urls.length; i++) { | 189 for (var i = 0; i < urls.length; i++) { |
| 153 var benchmark = new Benchmark(); | 190 var benchmark = new Benchmark(); |
| 154 benchmarks[urls[i]] = benchmark; | 191 benchmarks[urls[i]] = benchmark; |
| 155 benchmark.start(urls[i]); // XXXMB - move to constructor | 192 benchmark.start(urls[i]); // XXXMB - move to constructor |
| 156 } | 193 } |
| 157 } | 194 } |
| 195 | |
| 196 // Run at startup | |
| 197 chrome.windows.getCurrent(function(currentWindow) { | |
|
Erik does not do reviews
2009/07/17 17:15:52
so you don't need this...
| |
| 198 window.windowId = currentWindow.id; | |
| 199 }); | |
| 158 </script> | 200 </script> |
| 159 | 201 |
| 160 <style> | 202 <style> |
| 161 #result { | 203 #result { |
| 162 color: green; | 204 color: green; |
| 163 text-align: center; | 205 text-align: center; |
| 164 vertical-align: center; | 206 vertical-align: center; |
| 165 } | 207 } |
| 166 </style> | 208 </style> |
| 167 | 209 |
| 168 <div id="bench"> | 210 <div id="bench"> |
| 169 <img src="stopwatch.jpg" height="25" width="25" align=top onclick="show_options( )"> | 211 <img src="stopwatch.jpg" height="25" width="25" align=top onclick="show_options( )"> |
| 170 <input type="text" id="url" value="http://www.google.com/"></input> | 212 <span id="result"></span> |
| 171 <div class="toolstrip-button"> | |
| 172 <span id="run" class="open" onclick="run()">Go</span> | |
| 173 </div> | |
| 174 <span id="result"></span> | |
| 175 </div> | 213 </div> |
| OLD | NEW |