Mercurial > hg > config
comparison chrome/report.js @ 196:dd0018bc27de
Copy the pageloader from CVS and into a bundle format (single chrome.manifest).
| author | Benjamin Smedberg <benjamin@smedbergs.us> |
|---|---|
| date | Wed, 21 Jul 2010 15:57:39 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 196:dd0018bc27de |
|---|---|
| 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | |
| 2 /* ***** BEGIN LICENSE BLOCK ***** | |
| 3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | |
| 4 * | |
| 5 * The contents of this file are subject to the Mozilla Public License Version | |
| 6 * 1.1 (the "License"); you may not use this file except in compliance with | |
| 7 * the License. You may obtain a copy of the License at | |
| 8 * http://www.mozilla.org/MPL/ | |
| 9 * | |
| 10 * Software distributed under the License is distributed on an "AS IS" basis, | |
| 11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
| 12 * for the specific language governing rights and limitations under the | |
| 13 * License. | |
| 14 * | |
| 15 * The Original Code is tp. | |
| 16 * | |
| 17 * The Initial Developer of the Original Code is | |
| 18 * Mozilla Corporation. | |
| 19 * Portions created by the Initial Developer are Copyright (C) 2007 | |
| 20 * the Initial Developer. All Rights Reserved. | |
| 21 * | |
| 22 * Contributor(s): | |
| 23 * Darin Fisher <darin@meer.net> | |
| 24 * Rob Helmer <rhelmer@mozilla.com> | |
| 25 * Vladimir Vukicevic <vladimir@mozilla.com> | |
| 26 * | |
| 27 * Alternatively, the contents of this file may be used under the terms of | |
| 28 * either the GNU General Public License Version 2 or later (the "GPL"), or | |
| 29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | |
| 30 * in which case the provisions of the GPL or the LGPL are applicable instead | |
| 31 * of those above. If you wish to allow use of your version of this file only | |
| 32 * under the terms of either the GPL or the LGPL, and not to allow others to | |
| 33 * use your version of this file under the terms of the MPL, indicate your | |
| 34 * decision by deleting the provisions above and replace them with the notice | |
| 35 * and other provisions required by the GPL or the LGPL. If you do not delete | |
| 36 * the provisions above, a recipient may use your version of this file under | |
| 37 * the terms of any one of the MPL, the GPL or the LGPL. | |
| 38 * | |
| 39 * ***** END LICENSE BLOCK ***** */ | |
| 40 | |
| 41 // Constructor | |
| 42 function Report(pages) { | |
| 43 this.pages = pages; | |
| 44 this.timeVals = new Array(pages.length); // matrix of times | |
| 45 for (var i = 0; i < this.timeVals.length; ++i) { | |
| 46 this.timeVals[i] = new Array(); | |
| 47 } | |
| 48 this.totalCCTime = 0; | |
| 49 this.showTotalCCTime = false; | |
| 50 } | |
| 51 | |
| 52 // given an array of strings, finds the longest common prefix | |
| 53 function findCommonPrefixLength(strs) { | |
| 54 if (strs.length < 2) | |
| 55 return 0; | |
| 56 | |
| 57 var len = 0; | |
| 58 do { | |
| 59 var newlen = len + 1; | |
| 60 var newprefix = null; | |
| 61 var failed = false; | |
| 62 for (var i = 0; i < strs.length; i++) { | |
| 63 if (newlen > strs[i].length) { | |
| 64 failed = true; | |
| 65 break; | |
| 66 } | |
| 67 | |
| 68 var s = strs[i].substr(0, newlen); | |
| 69 if (newprefix == null) { | |
| 70 newprefix = s; | |
| 71 } else if (newprefix != s) { | |
| 72 failed = true; | |
| 73 break; | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 if (failed) | |
| 78 break; | |
| 79 | |
| 80 len++; | |
| 81 } while (true); | |
| 82 return len; | |
| 83 } | |
| 84 | |
| 85 function compareNumbers(a, b) { | |
| 86 return a - b; | |
| 87 } | |
| 88 | |
| 89 // returns an object with the following properties: | |
| 90 // min : min value of array elements | |
| 91 // max : max value of array elements | |
| 92 // mean : mean value of array elements | |
| 93 // vari : variance computation | |
| 94 // stdd : standard deviation, sqrt(vari) | |
| 95 // indexOfMax : index of max element (the element that is | |
| 96 // removed from the mean computation) | |
| 97 function getArrayStats(ary) { | |
| 98 var r = {}; | |
| 99 r.min = ary[0]; | |
| 100 r.max = ary[0]; | |
| 101 r.indexOfMax = 0; | |
| 102 var sum = 0; | |
| 103 for (var i = 0; i < ary.length; ++i) { | |
| 104 if (ary[i] < r.min) { | |
| 105 r.min = ary[i]; | |
| 106 } else if (ary[i] > r.max) { | |
| 107 r.max = ary[i]; | |
| 108 r.indexOfMax = i; | |
| 109 } | |
| 110 sum = sum + ary[i]; | |
| 111 } | |
| 112 | |
| 113 // median | |
| 114 if (ary.length > 1) { | |
| 115 sorted_ary = ary.concat(); | |
| 116 sorted_ary.sort(compareNumbers); | |
| 117 // remove longest run | |
| 118 sorted_ary.pop(); | |
| 119 if (sorted_ary.length%2) { | |
| 120 r.median = sorted_ary[(sorted_ary.length-1)/2]; | |
| 121 }else{ | |
| 122 var n = Math.floor(sorted_ary.length / 2); | |
| 123 if (n >= sorted_ary.length) | |
| 124 r.median = sorted_ary[n]; | |
| 125 else | |
| 126 r.median = (sorted_ary[n-1] + sorted_ary[n]) / 2; | |
| 127 } | |
| 128 }else{ | |
| 129 r.median = ary[0]; | |
| 130 } | |
| 131 | |
| 132 // ignore max value when computing mean and stddev | |
| 133 if (ary.length > 1) | |
| 134 r.mean = (sum - r.max) / (ary.length - 1); | |
| 135 else | |
| 136 r.mean = ary[0]; | |
| 137 | |
| 138 r.vari = 0; | |
| 139 for (var i = 0; i < ary.length; ++i) { | |
| 140 if (i == r.indexOfMax) | |
| 141 continue; | |
| 142 var d = r.mean - ary[i]; | |
| 143 r.vari = r.vari + d * d; | |
| 144 } | |
| 145 | |
| 146 if (ary.length > 1) { | |
| 147 r.vari = r.vari / (ary.length - 1); | |
| 148 r.stdd = Math.sqrt(r.vari); | |
| 149 } else { | |
| 150 r.vari = 0.0; | |
| 151 r.stdd = 0.0; | |
| 152 } | |
| 153 return r; | |
| 154 } | |
| 155 | |
| 156 function strPad(o, len, left) { | |
| 157 var str = o.toString(); | |
| 158 if (!len) | |
| 159 len = 6; | |
| 160 if (left == null) | |
| 161 left = true; | |
| 162 | |
| 163 if (str.length < len) { | |
| 164 len -= str.length; | |
| 165 while (--len) { | |
| 166 if (left) | |
| 167 str = " " + str; | |
| 168 else | |
| 169 str += " "; | |
| 170 } | |
| 171 } | |
| 172 | |
| 173 str += " "; | |
| 174 return str; | |
| 175 } | |
| 176 | |
| 177 function strPadFixed(n, len, left) { | |
| 178 return strPad(n.toFixed(0), len, left); | |
| 179 } | |
| 180 | |
| 181 Report.prototype.getReport = function(format) { | |
| 182 // avg and avg median are cumulative for all the pages | |
| 183 var avgs = new Array(); | |
| 184 var medians = new Array(); | |
| 185 for (var i = 0; i < this.timeVals.length; ++i) { | |
| 186 avgs[i] = getArrayStats(this.timeVals[i]).mean; | |
| 187 medians[i] = getArrayStats(this.timeVals[i]).median; | |
| 188 } | |
| 189 var avg = getArrayStats(avgs).mean; | |
| 190 var avgmed = getArrayStats(medians).mean; | |
| 191 | |
| 192 var report; | |
| 193 | |
| 194 var prefixLen = findCommonPrefixLength(this.pages); | |
| 195 | |
| 196 if (format == "js") { | |
| 197 // output "simple" js format; | |
| 198 // array of { page: "str", value: 123.4, stddev: 23.3 } objects | |
| 199 report = "(["; | |
| 200 for (var i = 0; i < this.timeVals.length; i++) { | |
| 201 var stats = getArrayStats(this.timeVals[i]); | |
| 202 report += uneval({ page: this.pages[i].substr(prefixLen), value: stats.mean, stddev: stats.stdd}); | |
| 203 report += ","; | |
| 204 } | |
| 205 report += "])"; | |
| 206 } else if (format == "jsfull") { | |
| 207 // output "full" js format, with raw values | |
| 208 } else if (format == "text") { | |
| 209 // output text format suitable for dumping | |
| 210 report = "============================================================\n"; | |
| 211 report += " " + strPad("Page", 40, false) + strPad("mean") + strPad("stdd") + strPad("min") + strPad("max") + "raw" + "\n"; | |
| 212 for (var i = 0; i < this.timeVals.length; i++) { | |
| 213 var stats = getArrayStats(this.timeVals[i]); | |
| 214 report += | |
| 215 strPad(i, 4, true) + | |
| 216 strPad(this.pages[i].substr(prefixLen), 40, false) + | |
| 217 strPadFixed(stats.mean) + | |
| 218 strPadFixed(stats.stdd) + | |
| 219 strPadFixed(stats.min) + | |
| 220 strPadFixed(stats.max) + | |
| 221 this.timeVals[i] + | |
| 222 "\n"; | |
| 223 } | |
| 224 if (this.showTotalCCTime) { | |
| 225 report += "Cycle collection: " + this.totalCCTime + "\n" | |
| 226 } | |
| 227 report += "============================================================\n"; | |
| 228 } else if (format == "tinderbox") { | |
| 229 report = "__start_tp_report\n"; | |
| 230 report += "_x_x_mozilla_page_load,"+avgmed+",NaN,NaN\n"; // max and min are just 0, ignored | |
| 231 report += "_x_x_mozilla_page_load_details,avgmedian|"+avgmed+"|average|"+avg.toFixed(2)+"|minimum|NaN|maximum|NaN|stddev|NaN\n"; | |
| 232 report += "|i|pagename|median|mean|min|max|runs|\n"; | |
| 233 | |
| 234 for (var i = 0; i < this.timeVals.length; i++) { | |
| 235 var r = getArrayStats(this.timeVals[i]); | |
| 236 report += '|'+ | |
| 237 i + ';'+ | |
| 238 this.pages[i].substr(prefixLen) + ';'+ | |
| 239 r.median + ';'+ | |
| 240 r.mean + ';'+ | |
| 241 r.min + ';'+ | |
| 242 r.max + ';'+ | |
| 243 this.timeVals[i].join(";") + | |
| 244 "\n"; | |
| 245 } | |
| 246 report += "__end_tp_report\n"; | |
| 247 if (this.showTotalCCTime) { | |
| 248 report += "__start_cc_report\n"; | |
| 249 report += "_x_x_mozilla_cycle_collect," + this.totalCCTime + "\n"; | |
| 250 report += "__end_cc_report\n"; | |
| 251 } | |
| 252 var now = (new Date()).getTime(); | |
| 253 report += "__startTimestamp" + now + "__endTimestamp\n"; //timestamp for determning shutdown time, used by talos | |
| 254 } else { | |
| 255 report = "Unknown report format"; | |
| 256 } | |
| 257 | |
| 258 return report; | |
| 259 } | |
| 260 | |
| 261 Report.prototype.recordTime = function(pageIndex, ms) { | |
| 262 this.timeVals[pageIndex].push(ms); | |
| 263 } | |
| 264 | |
| 265 Report.prototype.recordCCTime = function(ms) { | |
| 266 this.totalCCTime += ms; | |
| 267 this.showTotalCCTime = true; | |
| 268 } |
