Test freshness page should expose revision information for latest build on tooltip.
[WebKit.git] / Websites / perf.webkit.org / public / v3 / pages / test-freshness-page.js
1
2 class TestFreshnessPage extends PageWithHeading {
3     constructor(summaryPageConfiguration, testAgeToleranceInHours)
4     {
5         super('test-freshness', null);
6         this._testAgeTolerance = (testAgeToleranceInHours || 24) * 3600 * 1000;
7         this._timeDuration = this._testAgeTolerance * 2;
8         this._excludedConfigurations = {};
9         this._lastDataPointByConfiguration = null;
10         this._indicatorByConfiguration = null;
11         this._renderTableLazily = new LazilyEvaluatedFunction(this._renderTable.bind(this));
12         this._currentlyHighlightedIndicator = null;
13         this._hoveringTooltip = false;
14         this._builderByIndicator = null;
15         this._renderTooltipLazily = new LazilyEvaluatedFunction(this._renderTooltip.bind(this));
16
17         this._loadConfig(summaryPageConfiguration);
18     }
19
20     didConstructShadowTree()
21     {
22         const tooltipTable = this.content('tooltip-table');
23         tooltipTable.addEventListener('mouseenter', () => {
24             this._hoveringTooltip = true;
25             this.enqueueToRender();
26         });
27         tooltipTable.addEventListener('mouseleave', () => {
28             this._hoveringTooltip = false;
29             this.enqueueToRender();
30         });
31     }
32
33     name() { return 'Test-Freshness'; }
34
35     _loadConfig(summaryPageConfiguration)
36     {
37         const platformIdSet = new Set;
38         const metricIdSet = new Set;
39
40         for (const config of summaryPageConfiguration) {
41             for (const platformGroup of config.platformGroups) {
42                 for (const platformId of platformGroup.platforms)
43                     platformIdSet.add(platformId);
44             }
45
46             for (const metricGroup of config.metricGroups) {
47                 for (const subgroup of metricGroup.subgroups) {
48                     for (const metricId of subgroup.metrics)
49                         metricIdSet.add(metricId);
50                 }
51             }
52
53             const excludedConfigs = config.excludedConfigurations;
54             for (const platform in excludedConfigs) {
55                 if (platform in this._excludedConfigurations)
56                     this._excludedConfigurations[platform] = this._excludedConfigurations[platform].concat(excludedConfigs[platform]);
57                 else
58                     this._excludedConfigurations[platform] = excludedConfigs[platform];
59             }
60         }
61         this._platforms = [...platformIdSet].map((platformId) => Platform.findById(platformId));
62         this._metrics = [...metricIdSet].map((metricId) => Metric.findById(metricId));
63     }
64
65     open(state)
66     {
67         this._fetchTestResults();
68         super.open(state);
69     }
70
71     _fetchTestResults()
72     {
73         this._measurementSetFetchTime = Date.now();
74         this._lastDataPointByConfiguration = new Map;
75         this._builderByIndicator = new Map;
76
77         const startTime = this._measurementSetFetchTime - this._timeDuration;
78
79         for (const platform of this._platforms) {
80             const lastDataPointByMetric = new Map;
81             this._lastDataPointByConfiguration.set(platform, lastDataPointByMetric);
82
83             for (const metric of this._metrics) {
84                 if (!this._isValidPlatformMetricCombination(platform, metric, this._excludedConfigurations))
85                     continue;
86
87                 const measurementSet = MeasurementSet.findSet(platform.id(), metric.id(), platform.lastModified(metric));
88                 measurementSet.fetchBetween(startTime, this._measurementSetFetchTime).then(() => {
89                     const currentTimeSeries = measurementSet.fetchedTimeSeries('current', false, false);
90
91                     let timeForLatestBuild = startTime;
92                     let lastBuild = null;
93                     let builder = null;
94                     let commitSetOfLastPoint = null;
95                     const lastPoint = currentTimeSeries.lastPoint();
96                     if (lastPoint) {
97                         timeForLatestBuild = lastPoint.build().buildTime().getTime();
98                         const view = currentTimeSeries.viewBetweenPoints(currentTimeSeries.firstPoint(), lastPoint);
99                         for (const point of view) {
100                             const build = point.build();
101                             if (!build)
102                                 continue;
103                             if (build.buildTime().getTime() >= timeForLatestBuild) {
104                                 timeForLatestBuild = build.buildTime().getTime();
105                                 lastBuild = build;
106                                 builder = build.builder();
107                             }
108                         }
109                         commitSetOfLastPoint = lastPoint.commitSet();
110                     }
111
112                     lastDataPointByMetric.set(metric, {time: timeForLatestBuild, hasCurrentDataPoint: !!lastPoint,
113                         lastBuild, builder, commitSetOfLastPoint});
114                     this.enqueueToRender();
115                 });
116             }
117         }
118     }
119
120     render()
121     {
122         super.render();
123
124         this._renderTableLazily.evaluate(this._platforms, this._metrics);
125
126         let buildSummaryForCurrentlyHighlightedIndicator = null;
127         let buildForCurrentlyHighlightedIndicator = null;
128         let commitSetForCurrentHighlightedIndicator = null;
129         const builderForCurrentlyHighlightedIndicator = this._currentlyHighlightedIndicator ? this._builderByIndicator.get(this._currentlyHighlightedIndicator) : null;
130         for (const [platform, lastDataPointByMetric] of this._lastDataPointByConfiguration.entries()) {
131             for (const [metric, lastDataPoint] of lastDataPointByMetric.entries()) {
132                 const timeDuration = this._measurementSetFetchTime - lastDataPoint.time;
133                 const timeDurationSummaryPrefix = lastDataPoint.hasCurrentDataPoint ? '' : 'More than ';
134                 const timeDurationSummary = BuildRequest.formatTimeInterval(timeDuration);
135                 const summary = `${timeDurationSummaryPrefix}${timeDurationSummary} since latest data point.`;
136                 const url = this._router.url('charts', ChartsPage.createStateForDashboardItem(platform.id(), metric.id(),
137                     this._measurementSetFetchTime - this._timeDuration));
138
139                 const indicator = this._indicatorByConfiguration.get(platform).get(metric);
140                 if (this._currentlyHighlightedIndicator && this._currentlyHighlightedIndicator === indicator) {
141                     buildSummaryForCurrentlyHighlightedIndicator = summary;
142                     buildForCurrentlyHighlightedIndicator = lastDataPoint.lastBuild;
143                     commitSetForCurrentHighlightedIndicator = lastDataPoint.commitSetOfLastPoint;
144                 }
145                 this._builderByIndicator.set(indicator, lastDataPoint.builder);
146                 indicator.update(timeDuration, this._testAgeTolerance, url, builderForCurrentlyHighlightedIndicator && builderForCurrentlyHighlightedIndicator === lastDataPoint.builder);
147             }
148         }
149         this._renderTooltipLazily.evaluate(this._currentlyHighlightedIndicator, this._hoveringTooltip, buildSummaryForCurrentlyHighlightedIndicator, buildForCurrentlyHighlightedIndicator, commitSetForCurrentHighlightedIndicator);
150     }
151
152     _renderTooltip(indicator, hoveringTooltip, buildSummary, build, commitSet)
153     {
154         if (!indicator || !buildSummary) {
155             this.content('tooltip-table').style.display = hoveringTooltip ? null : 'none';
156             return;
157         }
158         const element = ComponentBase.createElement;
159         const link = ComponentBase.createLink;
160
161         const rect = indicator.element().getBoundingClientRect();
162         const tooltipTable = this.content('tooltip-table');
163         tooltipTable.style.display = null;
164
165         const tooltipContainerComputedStyle = getComputedStyle(tooltipTable);
166         const containerMarginTop = parseFloat(tooltipContainerComputedStyle.paddingTop);
167         const containerMarginLeft = parseFloat(tooltipContainerComputedStyle.marginLeft);
168
169         tooltipTable.style.position = 'absolute';
170         tooltipTable.style.top = rect.top - (tooltipTable.offsetHeight + containerMarginTop)  + 'px';
171         tooltipTable.style.left = rect.left + rect.width / 2 - tooltipTable.offsetWidth / 2 + containerMarginLeft + 'px';
172
173         let tableContent = [element('tr', element('td', {colspan: 2}, buildSummary))];
174         if (commitSet.repositories().length)
175             tableContent.push(element('tr', element('th', {colspan: 2}, 'Latest build information')));
176
177         tableContent.push(Repository.sortByNamePreferringOnesWithURL(commitSet.repositories()).map((repository) => {
178             const commit = commitSet.commitForRepository(repository);
179             return element('tr', [
180                 element('td', repository.name()),
181                 element('td', commit.url() ? link(commit.label(), commit.label(), commit.url(), true) : commit.label())
182             ]);
183         }));
184
185         if (build) {
186             const url = build.url();
187             const buildNumber = build.buildNumber();
188             tableContent.push(element('tr', [
189                 element('td', 'Build'),
190                 element('td', {colspan: 2}, [
191                     url ? link(buildNumber, build.label(), url, true) : buildNumber
192                 ]),
193             ]));
194         }
195
196         this.renderReplace(tooltipTable,  tableContent);
197     }
198
199     _renderTable(platforms, metrics)
200     {
201         const element = ComponentBase.createElement;
202         const tableBodyElement = [];
203         const tableHeadElements = [element('th',  {class: 'table-corner row-head'}, 'Platform \\ Test')];
204
205         for (const metric of metrics)
206             tableHeadElements.push(element('th', {class: 'diagonal-head'}, element('div', metric.test().fullName())));
207
208         this._indicatorByConfiguration = new Map;
209         for (const platform of platforms) {
210             const indicatorByMetric = new Map;
211             this._indicatorByConfiguration.set(platform, indicatorByMetric);
212             tableBodyElement.push(element('tr',
213                 [element('th', {class: 'row-head'}, platform.label()), ...metrics.map((metric) => this._constructTableCell(platform, metric, indicatorByMetric))]));
214         }
215
216         this.renderReplace(this.content('test-health'), [element('thead', tableHeadElements), element('tbody', tableBodyElement)]);
217     }
218
219     _isValidPlatformMetricCombination(platform, metric)
220     {
221         return !(this._excludedConfigurations && this._excludedConfigurations[platform.id()]
222             && this._excludedConfigurations[platform.id()].some((metricId) => metricId == metric.id()))
223             && platform.hasMetric(metric);
224     }
225
226     _constructTableCell(platform, metric, indicatorByMetric)
227     {
228         const element = ComponentBase.createElement;
229
230         if (!this._isValidPlatformMetricCombination(platform, metric))
231             return element('td', {class: 'blank-cell'}, element('div'));
232
233         const indicator = new FreshnessIndicator;
234         indicator.listenToAction('select', (originator) => {
235             this._currentlyHighlightedIndicator = originator;
236             this.enqueueToRender();
237         });
238         indicator.listenToAction('unselect', () => {
239             this._currentlyHighlightedIndicator = null;
240             this.enqueueToRender();
241         });
242         indicatorByMetric.set(metric, indicator);
243         return element('td', {class: 'status-cell'}, indicator);
244     }
245
246     static htmlTemplate()
247     {
248         return `<section class="page-with-heading"><table id="tooltip-table"></table><table id="test-health"></table></section>`;
249     }
250
251     static cssTemplate()
252     {
253         return `
254             .page-with-heading {
255                 display: flex;
256                 justify-content: center;
257             }
258             #test-health {
259                 font-size: 1rem;
260             }
261             #test-health thead {
262                 display: block;
263                 align: right;
264             }
265             #test-health th.table-corner {
266                 text-align: right;
267                 vertical-align: bottom;
268             }
269             #test-health .row-head {
270                 min-width: 15.5rem;
271             }
272             #test-health th {
273                 text-align: left;
274                 border-bottom: 0.1rem solid #ccc;
275                 font-weight: normal;
276             }
277             #test-health th.diagonal-head {
278                 white-space: nowrap;
279                 height: 16rem;
280                 border-bottom: 0rem;
281             }
282             #test-health th.diagonal-head > div {
283                 transform: translate(1rem, 7rem) rotate(315deg);
284                 width: 2rem;
285                 border: 0rem;
286             }
287             #test-health tbody {
288                 display: block;
289                 overflow: auto;
290                 height: calc(100vh - 24rem);
291             }
292             #test-health td.status-cell {
293                 margin: 0;
294                 padding: 0;
295                 max-width: 2.2rem;
296                 max-height: 2.2rem;
297                 min-width: 2.2rem;
298                 min-height: 2.2rem;
299             }
300             #test-health td.blank-cell {
301                 margin: 0;
302                 padding: 0;
303                 max-width: 2.2rem;
304                 max-height: 2.2rem;
305                 min-width: 2.2rem;
306                 min-height: 2.2rem;
307             }
308             #test-health td.blank-cell > div  {
309                 background-color: #F9F9F9;
310                 height: 1.6rem;
311                 width: 1.6rem;
312                 margin: 0.1rem;
313                 padding: 0;
314                 position: relative;
315                 overflow: hidden;
316             }
317             #test-health td.blank-cell > div::before {
318                 content: "";
319                 position: absolute;
320                 top: -1px;
321                 left: -1px;
322                 display: block;
323                 width: 0px;
324                 height: 0px;
325                 border-right: calc(1.6rem + 1px) solid #ddd;
326                 border-top: calc(1.6rem + 1px) solid transparent;
327             }
328             #test-health td.blank-cell > div::after {
329                 content: "";
330                 display: block;
331                 position: absolute;
332                 top: 1px;
333                 left: 1px;
334                 width: 0px;
335                 height: 0px;
336                 border-right: calc(1.6rem - 1px) solid #F9F9F9;
337                 border-top: calc(1.6rem - 1px) solid transparent;
338             }
339             #tooltip-table {
340                 width: 22rem;
341                 background-color: #34495E;
342                 opacity: 0.9;
343                 margin: 0.3rem;
344                 padding: 0.3rem;
345                 border-radius: 0.4rem;
346                 z-index: 1;
347                 text-align: center;
348                 display: inline-table;
349                 color: white;
350             }
351             #tooltip-table td {
352                 overflow: hidden;
353                 max-width: 22rem;
354                 text-overflow: ellipsis;
355             }
356             #tooltip-table::after {
357                 content: " ";
358                 position: absolute;
359                 top: 100%;
360                 left: 50%;
361                 margin-left: -1rem;
362                 border-width: 0.2rem;
363                 border-style: solid;
364                 border-color: #34495E transparent transparent transparent;
365             }
366             #tooltip-table a {
367                 color: #B03A2E;
368                 font-weight: bold;
369             }
370         `;
371     }
372
373     routeName() { return 'test-freshness'; }
374 }