Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!-- This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | - License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> |
michael@0 | 4 | |
michael@0 | 5 | <html> |
michael@0 | 6 | <script> |
michael@0 | 7 | var pages = [ |
michael@0 | 8 | "bugzilla.mozilla.org/", |
michael@0 | 9 | "lxr.mozilla.org/", |
michael@0 | 10 | "vanilla-page/" |
michael@0 | 11 | ]; |
michael@0 | 12 | var pages_i18n = []; |
michael@0 | 13 | |
michael@0 | 14 | var NUM_PAGES; |
michael@0 | 15 | var NUM_CYCLES; |
michael@0 | 16 | |
michael@0 | 17 | function parseParams() { |
michael@0 | 18 | var s = document.location.search.substring(1); |
michael@0 | 19 | var params = s.split('&'); |
michael@0 | 20 | for (var i = 0; i < params.length; ++i) { |
michael@0 | 21 | var fields = params[i].split('='); |
michael@0 | 22 | switch (fields[0]) { |
michael@0 | 23 | case 'cycles': |
michael@0 | 24 | NUM_CYCLES = (fields[1] - 0); |
michael@0 | 25 | break; |
michael@0 | 26 | case 'pages': |
michael@0 | 27 | NUM_PAGES = (fields[1] - 0); |
michael@0 | 28 | break; |
michael@0 | 29 | case 'i18n': |
michael@0 | 30 | if (fields[1] == '1') { |
michael@0 | 31 | pages = pages.concat(pages_i18n); |
michael@0 | 32 | } |
michael@0 | 33 | break; |
michael@0 | 34 | } |
michael@0 | 35 | } |
michael@0 | 36 | if (!NUM_PAGES) |
michael@0 | 37 | NUM_PAGES = pages.length; |
michael@0 | 38 | if (!NUM_CYCLES) |
michael@0 | 39 | NUM_CYCLES = 5; |
michael@0 | 40 | } |
michael@0 | 41 | parseParams(); |
michael@0 | 42 | |
michael@0 | 43 | var timeVals = new Array(NUM_PAGES); // matrix of times |
michael@0 | 44 | for (var i = 0; i < timeVals.length; ++i) { |
michael@0 | 45 | timeVals[i] = new Array; |
michael@0 | 46 | } |
michael@0 | 47 | var tstart; |
michael@0 | 48 | var index = 0; |
michael@0 | 49 | var cycle = 0; |
michael@0 | 50 | |
michael@0 | 51 | // returns an object with the following properties: |
michael@0 | 52 | // min : min value of array elements |
michael@0 | 53 | // max : max value of array elements |
michael@0 | 54 | // mean : mean value of array elements |
michael@0 | 55 | // vari : variance computation |
michael@0 | 56 | // stdd : standard deviation, sqrt(vari) |
michael@0 | 57 | // indexOfMax : index of max element (the element that is |
michael@0 | 58 | // removed from the mean computation) |
michael@0 | 59 | function getArrayStats(ary) { |
michael@0 | 60 | var r = {}; |
michael@0 | 61 | r.min = ary[0]; |
michael@0 | 62 | r.max = ary[0]; |
michael@0 | 63 | r.indexOfMax = 0; |
michael@0 | 64 | var sum = 0; |
michael@0 | 65 | for (var i = 0; i < ary.length; ++i) { |
michael@0 | 66 | if (ary[i] < r.min) { |
michael@0 | 67 | r.min = ary[i]; |
michael@0 | 68 | } else if (ary[i] > r.max) { |
michael@0 | 69 | r.max = ary[i]; |
michael@0 | 70 | r.indexOfMax = i; |
michael@0 | 71 | } |
michael@0 | 72 | sum = sum + ary[i]; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | // median |
michael@0 | 76 | sorted_ary = ary.concat(); |
michael@0 | 77 | sorted_ary.sort(); |
michael@0 | 78 | // remove longest run |
michael@0 | 79 | sorted_ary.pop(); |
michael@0 | 80 | if (sorted_ary.length%2) { |
michael@0 | 81 | r.median = sorted_ary[(sorted_ary.length-1)/2]; |
michael@0 | 82 | }else{ |
michael@0 | 83 | var n = Math.floor(sorted_ary.length / 2); |
michael@0 | 84 | r.median = (sorted_ary[n] + sorted_ary[n + 1]) / 2; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | // ignore max value when computing mean and stddev |
michael@0 | 88 | r.mean = (sum - r.max) / (ary.length - 1); |
michael@0 | 89 | |
michael@0 | 90 | r.vari = 0; |
michael@0 | 91 | for (var i = 0; i < ary.length; ++i) { |
michael@0 | 92 | if (i == r.indexOfMax) |
michael@0 | 93 | continue; |
michael@0 | 94 | var d = r.mean - ary[i]; |
michael@0 | 95 | r.vari = r.vari + d * d; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | r.vari = r.vari / (ary.length - 1); |
michael@0 | 99 | r.stdd = Math.sqrt(r.vari); |
michael@0 | 100 | return r; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | function appendTableCol(tr, text) { |
michael@0 | 104 | var doc = tr.ownerDocument; |
michael@0 | 105 | var td = doc.createElement("TD"); |
michael@0 | 106 | td.appendChild(doc.createTextNode(text)); |
michael@0 | 107 | tr.appendChild(td); |
michael@0 | 108 | return td; |
michael@0 | 109 | } |
michael@0 | 110 | |
michael@0 | 111 | function dumpReport() { |
michael@0 | 112 | var all = new Array(); |
michael@0 | 113 | var counter = 0; |
michael@0 | 114 | |
michael@0 | 115 | for (var i = 0; i < timeVals.length; ++i) { |
michael@0 | 116 | for (var j = 0; j < timeVals[i].length; ++j) { |
michael@0 | 117 | all[counter] = timeVals[i][j]; |
michael@0 | 118 | ++counter; |
michael@0 | 119 | } |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | // avg and avg median are cumulative for all the pages |
michael@0 | 123 | var avgs = new Array(); |
michael@0 | 124 | var medians = new Array(); |
michael@0 | 125 | for (var i = 0; i < timeVals.length; ++i) { |
michael@0 | 126 | avgs[i] = getArrayStats(timeVals[i]).mean; |
michael@0 | 127 | medians[i] = getArrayStats(timeVals[i]).median; |
michael@0 | 128 | } |
michael@0 | 129 | var avg = getArrayStats(avgs).mean; |
michael@0 | 130 | var avgmed = getArrayStats(medians).mean; |
michael@0 | 131 | |
michael@0 | 132 | var r = getArrayStats(all); |
michael@0 | 133 | dump( |
michael@0 | 134 | "(tinderbox dropping follows)\n"+ |
michael@0 | 135 | "_x_x_mozilla_page_load,"+avgmed+","+r.max+","+r.min+"\n"+ |
michael@0 | 136 | "_x_x_mozilla_page_load_details,avgmedian|"+avgmed+"|average|"+avg.toFixed(2)+"|minimum|"+r.min+"|maximum|"+r.max+"|stddev|"+r.stdd.toFixed(2)+":" |
michael@0 | 137 | ); |
michael@0 | 138 | |
michael@0 | 139 | for (var i = 0; i < timeVals.length; ++i) { |
michael@0 | 140 | r = getArrayStats(timeVals[i]); |
michael@0 | 141 | dump( |
michael@0 | 142 | '|'+ |
michael@0 | 143 | i+';'+ |
michael@0 | 144 | pages[i]+';'+ |
michael@0 | 145 | r.median+';'+ |
michael@0 | 146 | r.mean+';'+ |
michael@0 | 147 | r.min+';'+ |
michael@0 | 148 | r.max |
michael@0 | 149 | ); |
michael@0 | 150 | for (var j = 0; j < timeVals[i].length; ++j) { |
michael@0 | 151 | dump( |
michael@0 | 152 | ';'+timeVals[i][j] |
michael@0 | 153 | ); |
michael@0 | 154 | } |
michael@0 | 155 | } |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | function showReport() { |
michael@0 | 159 | var doc = frames["content"].document; |
michael@0 | 160 | var tbody = doc.getElementById("tbody"); |
michael@0 | 161 | for (var i = 0; i < timeVals.length; ++i) { |
michael@0 | 162 | var tr = doc.createElement("TR"); |
michael@0 | 163 | |
michael@0 | 164 | appendTableCol(tr, pages[i]); |
michael@0 | 165 | |
michael@0 | 166 | var r = getArrayStats(timeVals[i]); |
michael@0 | 167 | appendTableCol(tr, r.min.toFixed(2)); |
michael@0 | 168 | appendTableCol(tr, r.max.toFixed(2)); |
michael@0 | 169 | appendTableCol(tr, r.mean.toFixed(2)); |
michael@0 | 170 | appendTableCol(tr, r.stdd.toFixed(2)); |
michael@0 | 171 | appendTableCol(tr, r.median.toFixed(2)); |
michael@0 | 172 | |
michael@0 | 173 | for (var j = 0; j < timeVals[i].length; ++j) { |
michael@0 | 174 | var tv = timeVals[i][j]; |
michael@0 | 175 | var td = appendTableCol(tr, tv); |
michael@0 | 176 | if (j == r.indexOfMax) |
michael@0 | 177 | td.setAttribute("class", "discarded"); |
michael@0 | 178 | } |
michael@0 | 179 | |
michael@0 | 180 | tbody.appendChild(tr); |
michael@0 | 181 | } |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | function loadPage(i) { |
michael@0 | 185 | tstart = new Date(); |
michael@0 | 186 | frames["content"].document.location = "base/" + pages[i] + "index.html"; |
michael@0 | 187 | } |
michael@0 | 188 | |
michael@0 | 189 | function frameLoad() { |
michael@0 | 190 | if (cycle == NUM_CYCLES) { |
michael@0 | 191 | showReport(); |
michael@0 | 192 | dumpReport(); |
michael@0 | 193 | window.close(); |
michael@0 | 194 | return; |
michael@0 | 195 | } |
michael@0 | 196 | |
michael@0 | 197 | var tend = new Date(); |
michael@0 | 198 | var href = frames["content"].document.location.href; |
michael@0 | 199 | if (href == "about:blank") |
michael@0 | 200 | return; |
michael@0 | 201 | var tdelta = tend - tstart; |
michael@0 | 202 | timeVals[index].push(tdelta); |
michael@0 | 203 | var fields = href.split('/'); |
michael@0 | 204 | |
michael@0 | 205 | var text = (cycle + 1) + ', ' + (index + 1) + ', ' + fields[fields.length - 2] + ", " + tdelta; |
michael@0 | 206 | |
michael@0 | 207 | var doc = frames["header"].document; |
michael@0 | 208 | var body = doc.body; |
michael@0 | 209 | while (body.firstChild) |
michael@0 | 210 | body.removeChild(body.firstChild); |
michael@0 | 211 | body.appendChild(doc.createTextNode(text)); |
michael@0 | 212 | |
michael@0 | 213 | if (++index == NUM_PAGES) { |
michael@0 | 214 | index = 0; |
michael@0 | 215 | if (++cycle == NUM_CYCLES) { |
michael@0 | 216 | // display summary |
michael@0 | 217 | frames["content"].document.location = "report.html"; |
michael@0 | 218 | return; |
michael@0 | 219 | } |
michael@0 | 220 | } |
michael@0 | 221 | |
michael@0 | 222 | window.setTimeout("loadPage(" + index + ")", 500); |
michael@0 | 223 | } |
michael@0 | 224 | |
michael@0 | 225 | function init() { |
michael@0 | 226 | window.resizeTo(800, 800); |
michael@0 | 227 | window.setTimeout("loadPage(" + index + ")", 500); |
michael@0 | 228 | } |
michael@0 | 229 | </script> |
michael@0 | 230 | <frameset rows="40,*" onload="init()"> |
michael@0 | 231 | <frame name="header" src="header.html"> |
michael@0 | 232 | <frame name="content" src="" onload="frameLoad()"> |
michael@0 | 233 | </frameset> |
michael@0 | 234 | </html> |