1 function newTaskState() {
2 return {"complete_count": 0,
9 function addToLogViewer(logViewer, lines, taskState) {
10 var re = /((\d\d\d\d)-(\d\d)-(\d\d))_((\d\d):(\d\d):(\d\d)) ([a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}) (\d+) (\d+)? (.*)/;
13 var count = logViewer.items.length;
14 for (var a in lines) {
15 var v = lines[a].match(re);
18 var ts = new Date(Date.UTC(v[2], v[3]-1, v[4], v[6], v[7], v[8]));
21 if (typeof v[11] === 'undefined') {
32 if (!taskState.hasOwnProperty(v11)) {
34 taskState.task_count += 1;
37 if (/^stderr /.test(message)) {
38 message = message.substr(7);
39 if (/^crunchstat: /.test(message)) {
41 message = message.substr(12);
42 } else if (/^srun: /.test(message) || /^slurmd/.test(message)) {
43 type = "task-dispatch";
49 if (m = /^success in (\d+) second/.exec(message)) {
50 taskState[v11].outcome = "success";
51 taskState[v11].runtime = Number(m[1]);
52 taskState.complete_count += 1;
54 else if (m = /^failure \(\#\d+, (temporary|permanent)\) after (\d+) second/.exec(message)) {
55 taskState[v11].outcome = "failure";
56 taskState[v11].runtime = Number(m[2]);
57 taskState.failure_count += 1;
58 if (m[1] == "permanent") {
59 taskState.incomplete_count += 1;
62 else if (m = /^child \d+ started on ([^.]*)\.(\d+)/.exec(message)) {
63 taskState[v11].node = m[1];
64 taskState[v11].slot = m[2];
65 if (taskState.nodes.indexOf(m[1], 0) == -1) {
66 taskState.nodes.push(m[1]);
68 for (var i in items) {
70 if (items[i].taskid === v11) {
77 type = "task-dispatch";
79 node = taskState[v11].node;
80 slot = taskState[v11].slot;
88 timestamp: ts.toLocaleDateString() + " " + ts.toLocaleTimeString(),
92 message: message.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'),
97 console.log("Did not parse line " + a + ": " + lines[a]);
100 logViewer.add(items);
103 function sortById(a, b, opt) {
107 if (a["id"] > b["id"]) {
110 if (a["id"] < b["id"]) {
116 function sortByTask(a, b, opt) {
120 if (aa["taskid"] === "" && bb["taskid"] !== "") {
123 if (aa["taskid"] !== "" && bb["taskid"] === "") {
127 if (aa["taskid"] !== "" && bb["taskid"] !== "") {
128 if (aa["taskid"] > bb["taskid"]) {
131 if (aa["taskid"] < bb["taskid"]) {
136 return sortById(a, b, opt);
139 function sortByNode(a, b, opt) {
143 if (aa["node"] === "" && bb["node"] !== "") {
146 if (aa["node"] !== "" && bb["node"] === "") {
150 if (aa["node"] !== "" && bb["node"] !== "") {
151 if (aa["node"] > bb["node"]) {
154 if (aa["node"] < bb["node"]) {
159 if (aa["slot"] !== "" && bb["slot"] !== "") {
160 if (aa["slot"] > bb["slot"]) {
163 if (aa["slot"] < bb["slot"]) {
168 return sortById(a, b, opt);
172 function dumbPluralize(n, s, p) {
173 if (typeof p === 'undefined') {
176 if (n == 0 || n > 1) {
177 return n + " " + (s + p);
183 function generateJobOverview(id, logViewer, taskState) {
186 if (logViewer.items.length > 2) {
187 var first = logViewer.items[1];
188 var last = logViewer.items[logViewer.items.length-1];
189 var duration = (last.values().ts.getTime() - first.values().ts.getTime()) / 1000;
195 if (duration >= 3600) {
196 hours = Math.floor(duration / 3600);
197 duration -= (hours * 3600);
199 if (duration >= 60) {
200 minutes = Math.floor(duration / 60);
201 duration -= (minutes * 60);
205 var tcount = taskState.task_count;
208 html += "Started at " + first.values().timestamp + ". ";
209 html += "Ran " + dumbPluralize(tcount, " task") + " over ";
211 html += dumbPluralize(hours, " hour");
214 html += " " + dumbPluralize(minutes, " minute");
217 html += " " + dumbPluralize(seconds, " second");
220 html += " using " + dumbPluralize(taskState.nodes.length, " node");
222 html += ". " + dumbPluralize(taskState.complete_count, "task") + " completed";
223 html += ", " + dumbPluralize(taskState.incomplete_count, "task") + " incomplete";
224 html += " (" + dumbPluralize(taskState.failure_count, " failure") + ")";
226 html += ". Finished at " + last.values().timestamp + ".";
229 html = "<p>Job log is empty or failed to load.</p>";
235 function gotoPage(n, logViewer, page, id) {
236 if (n < 0) { return; }
237 if (n*page > logViewer.matchingItems.length) { return; }
238 logViewer.page_offset = n;
239 logViewer.show(n*page, page);
242 function updatePaging(id, logViewer, page) {
244 var i = logViewer.matchingItems.length;
246 for (n = 0; (n*page) < i; n += 1) {
247 if (n == logViewer.page_offset) {
248 p += "<span class='log-viewer-page-num'>" + (n+1) + "</span> ";
250 p += "<a href=\"#\" class='log-viewer-page-num log-viewer-page-" + n + "'>" + (n+1) + "</a> ";
254 for (n = 0; (n*page) < i; n += 1) {
256 $(".log-viewer-page-" + n).on("click", function() {
257 gotoPage(n, logViewer, page, id);
263 if (logViewer.page_offset == 0) {
264 $(".log-viewer-page-up").addClass("text-muted");
266 $(".log-viewer-page-up").removeClass("text-muted");
269 if (logViewer.page_offset == (n-1)) {
270 $(".log-viewer-page-down").addClass("text-muted");
272 $(".log-viewer-page-down").removeClass("text-muted");
276 function nextPage(logViewer, page, id) {
277 gotoPage(logViewer.page_offset+1, logViewer, page, id);
280 function prevPage(logViewer, page, id) {
281 gotoPage(logViewer.page_offset-1, logViewer, page, id);