|
| 1 | +function populate_data(data) { |
| 2 | + let state_div = document.querySelector("#benchmark-state"); |
| 3 | + if (data.last_commit) { |
| 4 | + let element = document.createElement("p"); |
| 5 | + element.innerHTML = `SHA: ${data.last_commit.sha}, date: ${data.last_commit.date}`; |
| 6 | + state_div.appendChild(element); |
| 7 | + } |
| 8 | + for (let benchmark of data.benchmarks) { |
| 9 | + let element = document.createElement("div"); |
| 10 | + element.innerHTML = `<details open> |
| 11 | + <summary>${benchmark.name} - error</summary> |
| 12 | + <pre class="benchmark-error"></pre> |
| 13 | + </details>`; |
| 14 | + element.querySelector(".benchmark-error").innerText = benchmark.error; |
| 15 | + state_div.appendChild(element); |
| 16 | + } |
| 17 | + let missing_div = document.querySelector("#data-insert-js"); |
| 18 | + if (data.current !== null) { |
| 19 | + let table = document.createElement("table"); |
| 20 | + let tr = document.createElement("tr"); |
| 21 | + let th = document.createElement("th"); |
| 22 | + th.innerText = "Step"; |
| 23 | + tr.appendChild(th); |
| 24 | + th = document.createElement("th"); |
| 25 | + tr.appendChild(th); |
| 26 | + th = document.createElement("th"); |
| 27 | + th.innerText = "Took"; |
| 28 | + tr.appendChild(th); |
| 29 | + th = document.createElement("th"); |
| 30 | + th.innerText = "Expected"; |
| 31 | + tr.appendChild(th); |
| 32 | + table.appendChild(tr); |
| 33 | + |
| 34 | + let left = 0; |
| 35 | + for (let step of data.current.progress) { |
| 36 | + let tr = document.createElement("tr"); |
| 37 | + let td = document.createElement("td"); |
| 38 | + td.innerText = step.step; |
| 39 | + tr.appendChild(td); |
| 40 | + td = document.createElement("td"); |
| 41 | + let progress = document.createElement("progress"); |
| 42 | + progress.setAttribute("max", step.expected_duration); |
| 43 | + progress.setAttribute("value", step.is_done ? |
| 44 | + step.expected_duration : step.current_progress); |
| 45 | + td.appendChild(progress); |
| 46 | + tr.appendChild(td); |
| 47 | + td = document.createElement("td"); |
| 48 | + td.innerHTML = step.current_progress == 0 ? "" : |
| 49 | + format_duration(step.current_progress); |
| 50 | + td.style.textAlign = "right"; |
| 51 | + tr.appendChild(td); |
| 52 | + td = document.createElement("td"); |
| 53 | + td.innerHTML = format_duration(step.expected_duration); |
| 54 | + td.style.textAlign = "right"; |
| 55 | + tr.appendChild(td); |
| 56 | + if (!step.is_done) { |
| 57 | + left += step.expected_duration - step.current_progress; |
| 58 | + } |
| 59 | + table.appendChild(tr); |
| 60 | + } |
| 61 | + let element = document.createElement("p"); |
| 62 | + let artifact_desc = ""; |
| 63 | + if (data.current.artifact.Commit) { |
| 64 | + artifact_desc = commit_url(data.current.artifact.Commit); |
| 65 | + } else { |
| 66 | + artifact_desc = data.current.artifact.Tag; |
| 67 | + } |
| 68 | + element.innerHTML = `Currently benchmarking: ${artifact_desc}. |
| 69 | + <br>Time left: ${format_duration(left)}`; |
| 70 | + missing_div.appendChild(element); |
| 71 | + missing_div.appendChild(table); |
| 72 | + } else { |
| 73 | + let element = document.createElement("p"); |
| 74 | + if (data.most_recent_end) { |
| 75 | + let end = new Date(data.most_recent_end * 1000); |
| 76 | + element.innerHTML = `No current collection in progress. Last one |
| 77 | + finished at ${end.toLocaleString()} local time, |
| 78 | + ${format_duration(Math.trunc((new Date() - end) / 1000))} ago.`; |
| 79 | + } else { |
| 80 | + element.innerHTML = "No current collection in progress."; |
| 81 | + } |
| 82 | + missing_div.appendChild(element); |
| 83 | + } |
| 84 | + { |
| 85 | + let element = document.createElement("p"); |
| 86 | + element.innerHTML = `Queue (${data.missing.length} total):<br> Times are local.`; |
| 87 | + missing_div.appendChild(element); |
| 88 | + } |
| 89 | + let table = document.createElement("table"); |
| 90 | + table.id = "missing-commits"; |
| 91 | + { |
| 92 | + let row = document.createElement("tr"); |
| 93 | + row.innerHTML = `<th>Commit Date</th><th>SHA</th><th>Reason</th>`; |
| 94 | + table.appendChild(row); |
| 95 | + } |
| 96 | + for (let [commit, reason] of data.missing) { |
| 97 | + let row = document.createElement("tr"); |
| 98 | + { |
| 99 | + let date = new Date(commit.date); |
| 100 | + let element = document.createElement("td"); |
| 101 | + if (date.getUTCFullYear() == 2001) { |
| 102 | + element.innerHTML = "try commit"; |
| 103 | + element.style.textAlign = "center"; |
| 104 | + } else { |
| 105 | + element.innerHTML = new Date(commit.date).toLocaleString(); |
| 106 | + } |
| 107 | + row.appendChild(element); |
| 108 | + } |
| 109 | + { |
| 110 | + let element = document.createElement("td"); |
| 111 | + element.innerHTML = commit_url(commit); |
| 112 | + row.appendChild(element); |
| 113 | + } |
| 114 | + { |
| 115 | + let element = document.createElement("td"); |
| 116 | + element.innerHTML = reason_to_string(reason); |
| 117 | + row.appendChild(element); |
| 118 | + } |
| 119 | + table.appendChild(row); |
| 120 | + } |
| 121 | + missing_div.appendChild(table); |
| 122 | +} |
| 123 | + |
| 124 | +function reason_to_string(reason) { |
| 125 | + if (typeof reason == 'string') { |
| 126 | + return reason; |
| 127 | + } else if (reason.InProgress) { |
| 128 | + return `${reason_to_string(reason.InProgress)} - in progress`; |
| 129 | + } else if (reason["Master"] != undefined && reason.Master.pr) { |
| 130 | + return `<a href="https://github.com/rust-lang/rust/pull/${reason["Master"].pr}"> |
| 131 | + #${reason["Master"].pr}</a>${reason.Master.is_try_parent ? " - Try commit parent" : "" |
| 132 | + }`; |
| 133 | + } else if (reason["Master"] != undefined && reason.Master.pr == 0) { |
| 134 | + return "Master"; |
| 135 | + } else if (reason["Try"] != undefined && reason.Try.pr) { |
| 136 | + return ` |
| 137 | + Try for |
| 138 | + <a href="https://github.com/rust-lang/rust/pull/${reason["Try"].pr}"> |
| 139 | + #${reason["Try"].pr} |
| 140 | + </a>`; |
| 141 | + } else { |
| 142 | + // Should never happen, but a good fallback |
| 143 | + return JSON.stringify(reason); |
| 144 | + } |
| 145 | +} |
| 146 | + |
| 147 | +function commit_url(commit) { |
| 148 | + return `<a href="https://github.com/rust-lang/rust/commit/${commit.sha}">${commit.sha.substr(0, 13)}</a>`; |
| 149 | +} |
| 150 | + |
| 151 | +function format_duration(seconds) { |
| 152 | + let secs = seconds % 60; |
| 153 | + let mins = Math.trunc(seconds / 60); |
| 154 | + let hours = Math.trunc(mins / 60); |
| 155 | + mins -= hours * 60; |
| 156 | + |
| 157 | + let s = ""; |
| 158 | + if (hours > 0) { |
| 159 | + s = `${hours}h${mins < 10 ? "0" + mins : mins}m${secs < 10 ? "0" + secs : secs}s`; |
| 160 | + } else { |
| 161 | + s = `${mins < 10 ? " " + mins : mins}m${secs < 10 ? "0" + secs : secs}s`; |
| 162 | + } |
| 163 | + return s; |
| 164 | +} |
| 165 | + |
| 166 | +function addHours(date, hours) { |
| 167 | + let ret = new Date(date); |
| 168 | + ret.setTime(ret.getTime() + (hours * 60 * 60 * 1000)); |
| 169 | + return ret; |
| 170 | +} |
| 171 | + |
| 172 | +function make_data() { |
| 173 | + fetch(BASE_URL + "/status_page", {}).then(function (response) { |
| 174 | + response.json().then(data => populate_data(data)); |
| 175 | + }); |
| 176 | +} |
| 177 | + |
| 178 | +make_data(); |
0 commit comments