1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 /** Random constants. */
6 var MAX_BUILD_STATUS_LENGTH = 50;
7 var TICKS_BETWEEN_REFRESHES = 60;
8 var NUM_PREVIOUS_BUILDS_TO_SHOW = 3;
9 var MAX_MILLISECONDS_TO_WAIT = 5 * 60 * 1000;
11 /** Parsed JSON data. */
12 var gWaterfallData = [];
14 var gWaterfallDataIsDirty = true;
17 var gTicksUntilRefresh = TICKS_BETWEEN_REFRESHES;
20 var gNumRequestsInFlight = 0;
21 var gNumRequestsIgnored = 0;
22 var gNumRequestsRetried = 0;
23 var gStartTimestamp = 0;
25 /** Cut the status message down so it doesn't hog the whole screen. */
26 function truncateStatusText(text) {
27 if (text.length > MAX_BUILD_STATUS_LENGTH) {
28 return text.substr(0, MAX_BUILD_STATUS_LENGTH) + '...';
33 /** Queries all of the servers for their latest statuses. */
34 function queryServersForInfo() {
35 for (var index = 0; index < gWaterfallData.length; ++index) {
36 gWaterfallData[index].requestJson();
39 for (var index = 0; index < gStatusData.length; ++index) {
40 gStatusData[index].requestJson();
44 /** Updates the sidebar's contents. */
45 function updateSidebarHTML() {
46 // Update all of the project info.
47 var divElement = document.getElementById('sidebar-contents');
48 while (divElement.firstChild) {
49 divElement.removeChild(divElement.firstChild);
52 for (var i = 0; i < gStatusData.length; ++i) {
53 divElement.appendChild(gStatusData[i].createHtml());
57 document.getElementById('num-ticks-until-refresh').innerHTML =
59 document.getElementById('num-requests-in-flight').innerHTML =
61 document.getElementById('num-requests-ignored').innerHTML =
63 document.getElementById('num-requests-retried').innerHTML =
68 * Organizes all of the bots by category, then alphabetically within their
71 function sortBotNamesByCategory(botInfo) {
72 // Bucket all of the bots according to their category.
73 var allBotNames = Object.keys(botInfo);
74 var bucketedNames = {};
75 for (var i = 0; i < allBotNames.length; ++i) {
76 var botName = allBotNames[i];
77 var category = botInfo[botName].category;
79 if (!bucketedNames[category]) bucketedNames[category] = [];
80 bucketedNames[category].push(botName);
83 // Alphabetically sort bots within their buckets, then append them to the
85 var sortedBotNames = [];
86 var allCategories = Object.keys(bucketedNames);
88 for (var i = 0; i < allCategories.length; ++i) {
89 var category = allCategories[i];
90 var bucketBots = bucketedNames[category];
93 for (var j = 0; j < bucketBots.length; ++j) {
94 sortedBotNames.push(bucketBots[j]);
98 return sortedBotNames;
101 /** Update all the waterfall data. */
102 function updateStatusHTML() {
103 var table = document.getElementById('build-info');
104 while (table.rows.length > 0) {
108 for (var i = 0; i < gWaterfallData.length; ++i) {
109 gWaterfallData[i].updateWaterfallStatusHTML();
113 /** Marks the waterfall data as dirty due to updated filter. */
114 function filterUpdated() {
115 gWaterfallDataIsDirty = true;
118 /** Update the page content. */
119 function updateContent() {
120 if (--gTicksUntilRefresh <= 0) {
121 gTicksUntilRefresh = TICKS_BETWEEN_REFRESHES;
122 queryServersForInfo();
125 // Redraw the page content.
126 if (gWaterfallDataIsDirty) {
127 gWaterfallDataIsDirty = false;
130 if (document.getElementById('failure-info')) {
131 updateCorrelationsHTML();
137 /** Initialize all the things. */
138 function initialize() {
139 var gStartTimestamp = new Date().getTime();
141 // Initialize the waterfall pages.
142 for (var i = 0; i < kBuilderPages.length; ++i) {
143 gWaterfallData.push(new WaterfallInfo(kBuilderPages[i]));
146 // Initialize the status pages.
147 for (var i = 0; i < kStatusPages.length; ++i) {
148 gStatusData.push(new StatusPageInfo(kStatusPages[i][0],
149 kStatusPages[i][1]));
152 // Kick off the main loops.
153 queryServersForInfo();
155 setInterval('updateContent()', 1000);