3 function PerfTestResult(runs, result, associatedBuild) {
4 this.metric = function () { return runs.metric(); }
5 this.values = function () { return result.values ? result.values.map(function (value) { return runs.scalingFactor() * value; }) : undefined; }
6 this.mean = function () { return runs.scalingFactor() * result.mean; }
7 this.unscaledMean = function () { return result.mean; }
8 this.confidenceIntervalDelta = function () {
9 return runs.scalingFactor() * this.unscaledConfidenceIntervalDelta();
11 this.unscaledConfidenceIntervalDelta = function () {
12 return Statistics.confidenceIntervalDelta(0.95, result.iterationCount, result.sum, result.squareSum);
14 this.isBetterThan = function(other) { return runs.smallerIsBetter() == (this.mean() < other.mean()); }
15 this.relativeDifference = function(other) { return (other.mean() - this.mean()) / this.mean(); }
16 this.formattedRelativeDifference = function (other) { return Math.abs(this.relativeDifference(other) * 100).toFixed(2) + '%'; }
17 this.formattedProgressionOrRegression = function (previousResult) {
18 return previousResult.formattedRelativeDifference(this) + ' ' + (this.isBetterThan(previousResult) ? 'better' : 'worse');
20 this.isStatisticallySignificant = function (other) {
21 var diff = Math.abs(other.mean() - this.mean());
22 return diff > this.confidenceIntervalDelta() && diff > other.confidenceIntervalDelta();
24 this.build = function () { return associatedBuild; }
25 this.label = function (previousResult) {
26 var mean = this.mean();
27 var label = mean.toPrecision(4) + ' ' + runs.unit();
29 var delta = this.confidenceIntervalDelta();
31 var percentageStdev = delta * 100 / mean;
32 label += ' ± ' + percentageStdev.toFixed(2) + '%';
36 label += ' (' + this.formattedProgressionOrRegression(previousResult) + ')';
42 function TestBuild(repositories, builders, platform, rawRun) {
43 const revisions = rawRun.revisions;
45 var revisionCount = 0;
46 for (var repositoryName in revisions) {
47 maxTime = Math.max(maxTime, revisions[repositoryName][1]); // Revision is an pair (revision, time)
51 maxTime = rawRun.buildTime;
52 maxTime = TestBuild.UTCtoPST(maxTime);
53 var maxTimeString = new Date(maxTime).toISOString().replace('T', ' ').replace(/\.\d+Z$/, '');
54 var buildTime = TestBuild.UTCtoPST(rawRun.buildTime);
55 var buildTimeString = new Date(buildTime).toISOString().replace('T', ' ').replace(/\.\d+Z$/, '');
57 this.time = function () { return maxTime; }
58 this.formattedTime = function () { return maxTimeString; }
59 this.buildTime = function () { return buildTime; }
60 this.formattedBuildTime = function () { return buildTimeString; }
61 this.builder = function () { return builders[rawRun.builder].name; }
62 this.buildNumber = function () { return rawRun.buildNumber; }
63 this.buildUrl = function () {
64 var template = builders[rawRun.builder].buildUrl;
65 return template ? template.replace(/\$buildNumber/g, this.buildNumber()) : null;
67 this.platform = function () { return platform; }
68 this.revision = function(repositoryName) { return revisions[repositoryName][0]; }
69 this.formattedRevisions = function (previousBuild) {
71 for (var repositoryName in repositories) {
72 if (!revisions[repositoryName])
74 var previousRevision = previousBuild ? previousBuild.revision(repositoryName) : undefined;
75 var currentRevision = this.revision(repositoryName);
76 if (previousRevision === currentRevision)
77 previousRevision = undefined;
79 var revisionPrefix = '';
80 var revisionDelimitor = '-';
81 if (parseInt(currentRevision) == currentRevision) { // e.g. r12345.
84 previousRevision = (parseInt(previousRevision) + 1);
85 } else if (currentRevision.indexOf(' ') >= 0) // e.g. 10.9 13C64.
86 revisionDelimitor = ' - ';
88 var labelForThisRepository;
90 labelForThisRepository = revisionPrefix + previousRevision + revisionDelimitor + revisionPrefix + currentRevision;
92 labelForThisRepository = '@ ' + revisionPrefix + currentRevision;
95 var repository = repositories[repositoryName];
98 url = (repository['blameUrl'] || '').replace(/\$1/g, previousRevision).replace(/\$2/g, currentRevision);
100 url = (repository['url'] || '').replace(/\$1/g, currentRevision);
103 result[repositoryName] = {
104 'label': labelForThisRepository,
105 'currentRevision': currentRevision,
106 'previousRevision': previousRevision,
114 TestBuild.UTCtoPST = function (date) {
115 // Pretend that PST is UTC since vanilla flot doesn't support multiple timezones.
116 const PSTOffsetInMilliseconds = 8 * 3600 * 1000;
117 return date - PSTOffsetInMilliseconds;
119 TestBuild.now = function () { return this.UTCtoPST(Date.now()); }
121 // A sequence of test results for a specific test on a specific platform
122 function PerfTestRuns(metric, platform) {
124 var cachedUnit = null;
125 var cachedScalingFactor = null;
127 var unit = {'Combined': '', // Assume smaller is better for now.
134 'EndAllocations': 'B',
135 'MaxAllocations': 'B',
136 'MeanAllocations': 'B'}[metric.name];
138 // We can't do this in PerfTestResult because all results for each metric need to share the same unit and the same scaling factor.
139 function computeScalingFactorIfNeeded() {
140 // FIXME: We shouldn't be adjusting units on every test result.
141 // We can only do this on the first test.
142 if (!results.length || cachedUnit)
145 var mean = results[0].unscaledMean(); // FIXME: We should look at all values.
146 var kilo = unit == 'B' ? 1024 : 1000;
147 if (mean > 2 * kilo * kilo && unit != 'ms') {
148 cachedScalingFactor = 1 / kilo / kilo;
149 var unitFirstChar = unit.charAt(0);
150 cachedUnit = 'M' + (unitFirstChar.toUpperCase() == unitFirstChar ? '' : ' ') + unit;
151 } else if (mean > 2 * kilo) {
152 cachedScalingFactor = 1 / kilo;
153 cachedUnit = unit == 'ms' ? 's' : ('K ' + unit);
155 cachedScalingFactor = 1;
160 this.metric = function () { return metric; }
161 this.platform = function () { return platform; }
162 this.addResult = function (newResult) {
163 if (results.indexOf(newResult) >= 0)
165 results.push(newResult);
167 cachedScalingFactor = null;
169 this.lastResult = function () { return results[results.length - 1]; }
170 this.resultAt = function (i) { return results[i]; }
172 var unscaledMeansCache;
173 var unscaledMeansCacheMinTime;
174 function unscaledMeansForAllResults(minTime) {
175 if (unscaledMeansCacheMinTime == minTime && unscaledMeansCache)
176 return unscaledMeansCache;
177 unscaledMeansCache = results.filter(function (result) { return !minTime || result.build().time() >= minTime; })
178 .map(function (result) { return result.unscaledMean(); });
179 unscaledMeansCacheMinTime = minTime;
180 return unscaledMeansCache;
183 this.min = function (minTime) {
184 return this.scalingFactor() * unscaledMeansForAllResults(minTime)
185 .reduce(function (minSoFar, currentMean) { return Math.min(minSoFar, currentMean); }, Number.MAX_VALUE);
187 this.max = function (minTime, baselineName) {
188 return this.scalingFactor() * unscaledMeansForAllResults(minTime)
189 .reduce(function (maxSoFar, currentMean) { return Math.max(maxSoFar, currentMean); }, Number.MIN_VALUE);
191 this.sampleStandardDeviation = function (minTime) {
192 var unscaledMeans = unscaledMeansForAllResults(minTime);
193 return this.scalingFactor() * Statistics.sampleStandardDeviation(unscaledMeans.length, Statistics.sum(unscaledMeans), Statistics.squareSum(unscaledMeans));
195 this.exponentialMovingArithmeticMean = function (minTime, alpha) {
196 var unscaledMeans = unscaledMeansForAllResults(minTime);
197 if (!unscaledMeans.length)
199 return this.scalingFactor() * unscaledMeans.reduce(function (movingAverage, currentMean) { return alpha * movingAverage + (1 - alpha) * movingAverage; });
201 this.hasConfidenceInterval = function () { return !isNaN(this.lastResult().unscaledConfidenceIntervalDelta()); }
203 this.meanPlotData = function () {
205 meanPlotCache = results.map(function (result, index) { return [result.build().time(), result.mean()]; });
206 return meanPlotCache;
208 var upperConfidenceCache;
209 this.upperConfidencePlotData = function () {
210 if (!upperConfidenceCache) // FIXME: Use the actual confidence interval
211 upperConfidenceCache = results.map(function (result, index) { return [result.build().time(), result.mean() + result.confidenceIntervalDelta()]; });
212 return upperConfidenceCache;
214 var lowerConfidenceCache;
215 this.lowerConfidencePlotData = function () {
216 if (!lowerConfidenceCache) // FIXME: Use the actual confidence interval
217 lowerConfidenceCache = results.map(function (result, index) { return [result.build().time(), result.mean() - result.confidenceIntervalDelta()]; });
218 return lowerConfidenceCache;
220 this.scalingFactor = function() {
221 computeScalingFactorIfNeeded();
222 return cachedScalingFactor;
224 this.unit = function () {
225 computeScalingFactorIfNeeded();
228 this.smallerIsBetter = function() { return unit == 'ms' || unit == 'bytes' || unit == ''; }
231 var URLState = new (function () {
236 function parseIfNeeded() {
237 if (updateTimer || '#' + hash == location.hash)
239 hash = location.hash.substr(1).replace(/\/+$/, '');
241 hash.split(/[&;]/).forEach(function (token) {
242 var keyValue = token.split('=');
243 var key = decodeURIComponent(keyValue[0]);
245 parameters[key] = decodeURIComponent(keyValue.slice(1).join('='));
249 function updateHash() {
250 if (location.hash != hash)
251 location.hash = hash;
254 this.get = function (key, defaultValue) {
256 if (key in parameters)
257 return parameters[key];
262 function scheduleHashUpdate() {
264 for (key in parameters) {
267 newHash += encodeURIComponent(key) + '=' + encodeURIComponent(parameters[key]);
271 clearTimeout(updateTimer);
273 updateTimer = setTimeout(function () {
274 updateTimer = undefined;
279 this.set = function (key, value) {
281 parameters[key] = value;
282 scheduleHashUpdate();
285 this.remove = function (key) {
287 delete parameters[key];
288 scheduleHashUpdate();
291 var watchCallbacks = {};
292 function onhashchange() {
293 if ('#' + hash == location.hash)
296 // Race. If the hash had changed while we're waiting to update, ignore the change.
298 clearTimeout(updateTimer);
299 updateTimer = undefined;
302 // FIXME: Consider ignoring URLState.set/remove while notifying callbacks.
303 var oldParameters = parameters;
306 var changedStates = [];
307 for (var key in watchCallbacks) {
308 if (parameters[key] == oldParameters[key])
310 changedStates.push(key);
311 callbacks.push(watchCallbacks[key]);
314 for (var i = 0; i < callbacks.length; i++)
315 callbacks[i](changedStates);
317 $(window).bind('hashchange', onhashchange);
319 // FIXME: Support multiple callbacks on a single key.
320 this.watch = function (key, callback) {
322 watchCallbacks[key] = callback;
326 function Tooltip(containerParent, className) {
329 var hideTimer; // Use setTimeout(~, 0) to workaround the race condition that arises when moving mouse fast.
332 function ensureContainer() {
335 container = document.createElement('div');
336 $(containerParent).append(container);
337 container.className = className;
338 container.style.position = 'absolute';
342 this.show = function (x, y, content) {
344 clearTimeout(hideTimer);
345 hideTimer = undefined;
348 if (previousContent === content) {
352 previousContent = content;
355 container.innerHTML = content;
357 // FIXME: Style specific computation like this one shouldn't be in Tooltip class.
358 $(container).offset({left: x - $(container).outerWidth() / 2, top: y - $(container).outerHeight() - 15});
361 this.hide = function () {
366 clearTimeout(hideTimer);
367 hideTimer = setTimeout(function () {
368 $(container).fadeOut(100);
369 previousResult = undefined;
373 this.remove = function (immediately) {
378 clearTimeout(hideTimer);
380 $(container).remove();
381 container = undefined;
382 previousResult = undefined;
385 this.toggle = function () {
386 $(container).toggle();
387 document.body.appendChild(container); // Toggled tooltip should show up at the top.
390 this.bindClick = function (callback) {
392 $(container).bind('click', callback);
394 this.bindMouseEnter = function (callback) {
396 $(container).bind('mouseenter', callback);