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 (defaultValue) {
12 var delta = Statistics.confidenceIntervalDelta(0.95, result.iterationCount, result.sum, result.squareSum);
13 if (isNaN(delta) && defaultValue !== undefined)
17 this.isInUnscaledInterval = function (min, max) {
18 var mean = this.unscaledMean();
19 var delta = this.unscaledConfidenceIntervalDelta(0);
20 return min <= mean - delta && mean + delta <= max;
22 this.isBetterThan = function(other) { return runs.smallerIsBetter() == (this.mean() < other.mean()); }
23 this.relativeDifference = function(other) { return (other.mean() - this.mean()) / this.mean(); }
24 this.formattedRelativeDifference = function (other) { return Math.abs(this.relativeDifference(other) * 100).toFixed(2) + '%'; }
25 this.formattedProgressionOrRegression = function (previousResult) {
26 return previousResult.formattedRelativeDifference(this) + ' ' + (this.isBetterThan(previousResult) ? 'better' : 'worse');
28 this.isStatisticallySignificant = function (other) {
29 var diff = Math.abs(other.mean() - this.mean());
30 return diff > this.confidenceIntervalDelta() && diff > other.confidenceIntervalDelta();
32 this.build = function () { return associatedBuild; }
33 this.label = function (previousResult) {
34 var mean = this.mean();
35 var label = mean.toPrecision(4) + ' ' + runs.unit();
37 var delta = this.confidenceIntervalDelta();
39 var percentageStdev = delta * 100 / mean;
40 label += ' ± ' + percentageStdev.toFixed(2) + '%';
44 label += ' (' + this.formattedProgressionOrRegression(previousResult) + ')';
50 function TestBuild(repositories, builders, platform, rawRun) {
51 const revisions = rawRun.revisions;
53 var revisionCount = 0;
54 for (var repositoryId in revisions) {
55 maxTime = Math.max(maxTime, revisions[repositoryId][1]); // Revision is an pair (revision, time)
59 maxTime = rawRun.buildTime;
60 maxTime = TestBuild.UTCtoPST(maxTime);
62 var buildTime = TestBuild.UTCtoPST(rawRun.buildTime);
65 this.time = function () { return maxTime; }
66 this.formattedTime = function () {
68 maxTimeString = new Date(maxTime).toISOString().replace('T', ' ').replace(/\.\d+Z$/, '');
71 this.buildTime = function () { return buildTime; }
72 this.formattedBuildTime = function () {
74 buildTimeString = new Date(buildTime).toISOString().replace('T', ' ').replace(/\.\d+Z$/, '');
75 return buildTimeString;
77 this.builder = function () { return builders[rawRun.builder].name; }
78 this.buildNumber = function () { return rawRun.buildNumber; }
79 this.buildUrl = function () {
80 var builder = builders[rawRun.builder];
81 var template = builder.buildUrl;
84 return template.replace(/\$buildNumber/g, this.buildNumber()).replace(/\$builderName/g, builder.name);
86 this.platform = function () { return platform; }
87 this.revision = function(repositoryId) { return revisions[repositoryId][0]; }
88 this.formattedRevisions = function (previousBuild) {
90 for (var repositoryId in repositories) {
91 if (!revisions[repositoryId])
93 var previousRevision = previousBuild ? previousBuild.revision(repositoryId) : undefined;
94 var currentRevision = this.revision(repositoryId);
95 if (previousRevision === currentRevision)
96 previousRevision = undefined;
98 var revisionPrefix = '';
99 var revisionDelimiter = '-';
101 if (parseInt(currentRevision) == currentRevision) { // e.g. r12345.
102 revisionPrefix = 'r';
103 if (previousRevision)
104 previousRevision = (parseInt(previousRevision) + 1);
105 } else if (currentRevision.indexOf(' ') >= 0) // e.g. 10.9 13C64.
106 revisionDelimiter = ' - ';
107 else if (currentRevision.length == 40) // e.g. git hash
110 var labelForThisRepository;
112 formattedCurrentHash = currentRevision.substring(0, 8);
113 if (previousRevision)
114 labelForThisRepository = previousRevision.substring(0, 8) + '..' + formattedCurrentHash;
116 labelForThisRepository = '@ ' + formattedCurrentHash;
118 if (previousRevision)
119 labelForThisRepository = revisionPrefix + previousRevision + revisionDelimiter + revisionPrefix + currentRevision;
121 labelForThisRepository = '@ ' + revisionPrefix + currentRevision;
125 var repository = repositories[repositoryId];
127 if (previousRevision)
128 url = (repository['blameUrl'] || '').replace(/\$1/g, previousRevision).replace(/\$2/g, currentRevision);
130 url = (repository['url'] || '').replace(/\$1/g, currentRevision);
133 result[repository.name] = {
134 'label': labelForThisRepository,
135 'currentRevision': currentRevision,
136 'previousRevision': previousRevision,
144 TestBuild.UTCtoPST = function (date) {
145 // Pretend that PST is UTC since vanilla flot doesn't support multiple timezones.
146 const PSTOffsetInMilliseconds = 8 * 3600 * 1000;
147 return date - PSTOffsetInMilliseconds;
149 TestBuild.now = function () { return this.UTCtoPST(Date.now()); }
151 // A sequence of test results for a specific test on a specific platform
152 function PerfTestRuns(metric, platform) {
154 var cachedUnit = null;
155 var cachedScalingFactor = null;
157 var suffix = metric.name.match('([A-z][a-z]+|FrameRate)$')[0];
158 var unit = {'Combined': '', // Assume smaller is better for now.
166 'Score': 'pt'}[suffix];
168 // We can't do this in PerfTestResult because all results for each metric need to share the same unit and the same scaling factor.
169 function computeScalingFactorIfNeeded() {
170 // FIXME: We shouldn't be adjusting units on every test result.
171 // We can only do this on the first test.
172 if (!results.length || cachedUnit)
175 var mean = results[0].unscaledMean(); // FIXME: We should look at all values.
176 var kilo = unit == 'B' ? 1024 : 1000;
177 if (mean > 2 * kilo * kilo && unit != 'ms') {
178 cachedScalingFactor = 1 / kilo / kilo;
179 var unitFirstChar = unit.charAt(0);
180 cachedUnit = 'M' + (unitFirstChar.toUpperCase() == unitFirstChar ? '' : ' ') + unit;
181 } else if (mean > 2 * kilo) {
182 cachedScalingFactor = 1 / kilo;
183 cachedUnit = unit == 'ms' ? 's' : ('K ' + unit);
185 cachedScalingFactor = 1;
190 this.metric = function () { return metric; }
191 this.platform = function () { return platform; }
192 this.setResults = function (newResults) {
193 results = newResults;
195 cachedScalingFactor = null;
197 this.lastResult = function () { return results[results.length - 1]; }
198 this.resultAt = function (i) { return results[i]; }
200 var resultsFilterCache;
201 var resultsFilterCacheMinTime;
202 function filteredResults(minTime) {
205 if (resultsFilterCacheMinTime != minTime) {
206 resultsFilterCache = results.filter(function (result) { return !minTime || result.build().time() >= minTime; });
207 resultsFilterCacheMinTime = minTime;
209 return resultsFilterCache;
212 function unscaledMeansForAllResults(minTime) {
213 return filteredResults(minTime).map(function (result) { return result.unscaledMean(); });
216 this.min = function (minTime) {
217 return this.scalingFactor() * filteredResults(minTime)
218 .reduce(function (minSoFar, result) { return Math.min(minSoFar, result.unscaledMean() - result.unscaledConfidenceIntervalDelta(0)); }, Number.MAX_VALUE);
220 this.max = function (minTime, baselineName) {
221 return this.scalingFactor() * filteredResults(minTime)
222 .reduce(function (maxSoFar, result) { return Math.max(maxSoFar, result.unscaledMean() + result.unscaledConfidenceIntervalDelta(0)); }, Number.MIN_VALUE);
224 this.countResults = function (minTime) {
225 return unscaledMeansForAllResults(minTime).length;
227 this.countResultsInInterval = function (minTime, min, max) {
228 var unscaledMin = min / this.scalingFactor();
229 var unscaledMax = max / this.scalingFactor();
230 return filteredResults(minTime).reduce(function (count, currentResult) {
231 return count + (currentResult.isInUnscaledInterval(unscaledMin, unscaledMax) ? 1 : 0); }, 0);
233 this.sampleStandardDeviation = function (minTime) {
234 var unscaledMeans = unscaledMeansForAllResults(minTime);
235 return this.scalingFactor() * Statistics.sampleStandardDeviation(unscaledMeans.length, Statistics.sum(unscaledMeans), Statistics.squareSum(unscaledMeans));
237 this.exponentialMovingArithmeticMean = function (minTime, alpha) {
238 var unscaledMeans = unscaledMeansForAllResults(minTime);
239 if (!unscaledMeans.length)
241 return this.scalingFactor() * unscaledMeans.reduce(function (movingAverage, currentMean) { return alpha * currentMean + (1 - alpha) * movingAverage; });
243 this.hasConfidenceInterval = function () { return !isNaN(this.lastResult().unscaledConfidenceIntervalDelta()); }
245 this.meanPlotData = function () {
247 meanPlotCache = results.map(function (result, index) { return [result.build().time(), result.mean()]; });
248 return meanPlotCache;
250 var upperConfidenceCache;
251 this.upperConfidencePlotData = function () {
252 if (!upperConfidenceCache) // FIXME: Use the actual confidence interval
253 upperConfidenceCache = results.map(function (result, index) { return [result.build().time(), result.mean() + result.confidenceIntervalDelta()]; });
254 return upperConfidenceCache;
256 var lowerConfidenceCache;
257 this.lowerConfidencePlotData = function () {
258 if (!lowerConfidenceCache) // FIXME: Use the actual confidence interval
259 lowerConfidenceCache = results.map(function (result, index) { return [result.build().time(), result.mean() - result.confidenceIntervalDelta()]; });
260 return lowerConfidenceCache;
262 this.scalingFactor = function() {
263 computeScalingFactorIfNeeded();
264 return cachedScalingFactor;
266 this.unit = function () {
267 computeScalingFactorIfNeeded();
270 this.smallerIsBetter = function() { return unit == 'ms' || unit == 'B' || unit == ''; }
273 var URLState = new (function () {
278 function parseIfNeeded() {
279 if (updateTimer || '#' + hash == location.hash)
281 hash = location.hash.substr(1).replace(/\/+$/, '');
283 hash.split(/[&;]/).forEach(function (token) {
284 var keyValue = token.split('=');
285 var key = decodeURIComponent(keyValue[0]);
287 parameters[key] = decodeURIComponent(keyValue.slice(1).join('='));
291 function updateHash() {
292 if (location.hash != hash)
293 location.hash = hash;
296 this.get = function (key, defaultValue) {
298 if (key in parameters)
299 return parameters[key];
304 function scheduleHashUpdate() {
306 for (key in parameters) {
309 newHash += encodeURIComponent(key) + '=' + encodeURIComponent(parameters[key]);
313 clearTimeout(updateTimer);
315 updateTimer = setTimeout(function () {
316 updateTimer = undefined;
321 this.set = function (key, value) {
323 parameters[key] = value;
324 scheduleHashUpdate();
327 this.remove = function (key) {
329 delete parameters[key];
330 scheduleHashUpdate();
333 var watchCallbacks = {};
334 function onhashchange() {
335 if ('#' + hash == location.hash)
338 // Race. If the hash had changed while we're waiting to update, ignore the change.
340 clearTimeout(updateTimer);
341 updateTimer = undefined;
344 // FIXME: Consider ignoring URLState.set/remove while notifying callbacks.
345 var oldParameters = parameters;
348 var changedStates = [];
349 for (var key in watchCallbacks) {
350 if (parameters[key] == oldParameters[key])
352 changedStates.push(key);
353 callbacks.push(watchCallbacks[key]);
356 for (var i = 0; i < callbacks.length; i++)
357 callbacks[i](changedStates);
359 $(window).bind('hashchange', onhashchange);
361 // FIXME: Support multiple callbacks on a single key.
362 this.watch = function (key, callback) {
364 watchCallbacks[key] = callback;
368 function Tooltip(containerParent, className) {
371 var hideTimer; // Use setTimeout(~, 0) to workaround the race condition that arises when moving mouse fast.
374 function ensureContainer() {
377 container = document.createElement('div');
378 $(containerParent).append(container);
379 container.className = className;
380 container.style.position = 'absolute';
384 this.show = function (x, y, content) {
386 clearTimeout(hideTimer);
387 hideTimer = undefined;
390 if (previousContent === content) {
394 previousContent = content;
397 container.innerHTML = content;
399 // FIXME: Style specific computation like this one shouldn't be in Tooltip class.
400 var top = y - $(container).outerHeight() - 15;
402 $(container).addClass('inverted');
405 $(container).removeClass('inverted');
406 $(container).offset({left: x - $(container).outerWidth() / 2, top: top});
409 this.hide = function () {
414 clearTimeout(hideTimer);
415 hideTimer = setTimeout(function () {
416 $(container).fadeOut(100);
417 previousResult = undefined;
421 this.remove = function (immediately) {
426 clearTimeout(hideTimer);
428 $(container).remove();
429 container = undefined;
430 previousResult = undefined;
433 this.toggle = function () {
434 $(container).toggle();
435 document.body.appendChild(container); // Toggled tooltip should show up at the top.
438 this.bindClick = function (callback) {
440 $(container).bind('click', callback);
442 this.bindMouseEnter = function (callback) {
444 $(container).bind('mouseenter', callback);