Dashboard should show performance bots.
[WebKit-https.git] / Tools / BuildSlaveSupport / build.webkit.org-config / public_html / dashboard / Scripts / BuildbotPerformanceQueueView.js
1 /*
2  * Copyright (C) 2013, 2014 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 BuildbotPerformanceQueueView = function(queues)
27 {
28     BuildbotQueueView.call(this, [], queues);
29     this.update();
30 };
31
32 BaseObject.addConstructorFunctions(BuildbotPerformanceQueueView);
33
34 BuildbotPerformanceQueueView.prototype = {
35     constructor: BuildbotPerformanceQueueView,
36     __proto__: BuildbotQueueView.prototype,
37
38     update: function()
39     {
40         QueueView.prototype.update.call(this);
41
42         this.element.removeChildren();
43
44         function appendPerformanceQueueStatus(queue)
45         {
46             var appendedStatus = false;
47
48             var limit = 2;
49             for (var i = 0; i < queue.iterations.length && limit > 0; ++i) {
50                 var iteration = queue.iterations[i];
51                 if (!iteration.loaded || !iteration.finished)
52                     continue;
53
54                 --limit;
55
56                 var willHaveAnotherStatusLine = i + 1 < queue.iterations.length && limit > 0 && !iteration.successful; // This is not 100% correct, as the remaining iterations may not be finished or loaded yet, but close enough.
57                 var messageElement = this.revisionContentForIteration(iteration, (iteration.productive && willHaveAnotherStatusLine) ? iteration.previousProductiveIteration : null);
58
59                 if (iteration.successful) {
60                     var status = new StatusLineView(messageElement, StatusLineView.Status.Good, "all tests passed");
61                     limit = 0;
62                 } else if (!iteration.productive) {
63                     var url = iteration.queue.buildbot.buildPageURLForIteration(iteration);
64                     var status = new StatusLineView(messageElement, StatusLineView.Status.Danger, iteration.text, null, url);
65                 } else if (iteration.failed) {
66                     var url = iteration.queue.buildbot.buildPageURLForIteration(iteration);
67                     var status = new StatusLineView(messageElement, StatusLineView.Status.Bad, iteration.text, null, url);
68                 } else {
69                     var url = iteration.queue.buildbot.buildPageURLForIteration(iteration);
70                     var status = new StatusLineView(messageElement, StatusLineView.Status.Danger, iteration.text, null, url);
71                 }
72
73                 this.element.appendChild(status.element);
74                 appendedStatus = true;
75             }
76
77             if (!appendedStatus) {
78                 var status = new StatusLineView("unknown", StatusLineView.Status.Neutral, "last passing build");
79                 this.element.appendChild(status.element);
80             }
81
82             new PopoverTracker(status.statusBubbleElement, this._presentPopoverForPerformanceQueue.bind(this), queue);
83         }
84
85         function appendBuild(queues, label)
86         {
87             queues.forEach(function(queue) {
88                 var releaseLabel = document.createElement("a");
89                 releaseLabel.classList.add("queueLabel");
90                 releaseLabel.textContent = queue.performanceTestName ? queue.performanceTestName : label;
91                 releaseLabel.href = queue.overviewURL;
92                 releaseLabel.target = "_blank";
93                 this.element.appendChild(releaseLabel);
94
95                 appendPerformanceQueueStatus.call(this, queue);
96             }.bind(this));
97         }
98
99         appendBuild.call(this, this.releaseQueues, 'Release');
100     },
101
102     addLinkToRow: function(rowElement, className, text, url)
103     {
104         var linkElement = document.createElement("a");
105         linkElement.className = className;
106         linkElement.textContent = text;
107         linkElement.href = url;
108         linkElement.target = "_blank";
109         rowElement.appendChild(linkElement);
110     },
111
112     _popoverContentForPerformanceQueue: function(queue)
113     {
114         var content = document.createElement("div");
115         content.className = "performance-popover";
116
117         var row = document.createElement("div");
118         this.addLinkToRow(row, "dashboard-link", "Performance Dashboard", queue.buildbot.performanceDashboardURL);
119
120         content.appendChild(row);
121
122         return content;
123     },
124
125     _presentPopoverForPerformanceQueue: function(element, popover, queue)
126     {
127         var content = this._popoverContentForPerformanceQueue(queue);
128
129         var rect = Dashboard.Rect.rectFromClientRect(element.getBoundingClientRect());
130         popover.content = content;
131         popover.present(rect, [Dashboard.RectEdge.MIN_Y, Dashboard.RectEdge.MAX_Y, Dashboard.RectEdge.MAX_X, Dashboard.RectEdge.MIN_X]);
132         return true;
133     }
134 };