2023-05-20 15:41:41 -06:00
|
|
|
|
|
|
|
function createRow(table, cellName, items) {
|
|
|
|
var tr = document.createElement('tr');
|
|
|
|
var res = [];
|
|
|
|
|
2023-06-01 01:01:42 -06:00
|
|
|
items.forEach(function(x, i) {
|
|
|
|
if (x === undefined) {
|
|
|
|
res.push(null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-05-20 15:41:41 -06:00
|
|
|
var td = document.createElement(cellName);
|
|
|
|
td.textContent = x;
|
|
|
|
tr.appendChild(td);
|
|
|
|
res.push(td);
|
2023-06-01 01:01:42 -06:00
|
|
|
|
|
|
|
var colspan = 1;
|
|
|
|
for (var n = i + 1; n < items.length; n++) {
|
|
|
|
if (items[n] !== undefined) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
colspan += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (colspan > 1) {
|
|
|
|
td.colSpan = colspan;
|
|
|
|
}
|
2023-05-20 15:41:41 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
table.appendChild(tr);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2023-06-01 01:01:42 -06:00
|
|
|
function showProfile(path, cutoff = 0.05) {
|
2023-05-20 15:41:41 -06:00
|
|
|
requestGet(path, {}, function(data) {
|
|
|
|
var table = document.createElement('table');
|
|
|
|
table.className = 'popup-table';
|
|
|
|
|
|
|
|
data.records['total'] = data.total;
|
|
|
|
var keys = Object.keys(data.records).sort(function(a, b) {
|
|
|
|
return data.records[b] - data.records[a];
|
|
|
|
});
|
|
|
|
var items = keys.map(function(x) {
|
|
|
|
return {key: x, parts: x.split('/'), time: data.records[x]};
|
|
|
|
});
|
|
|
|
var maxLength = items.reduce(function(a, b) {
|
|
|
|
return Math.max(a, b.parts.length);
|
|
|
|
}, 0);
|
|
|
|
|
|
|
|
var cols = createRow(table, 'th', ['record', 'seconds']);
|
|
|
|
cols[0].colSpan = maxLength;
|
|
|
|
|
|
|
|
function arraysEqual(a, b) {
|
|
|
|
return !(a < b || b < a);
|
|
|
|
}
|
|
|
|
|
2023-06-01 01:01:42 -06:00
|
|
|
var addLevel = function(level, parent, hide) {
|
2023-05-20 15:41:41 -06:00
|
|
|
var matching = items.filter(function(x) {
|
|
|
|
return x.parts[level] && !x.parts[level + 1] && arraysEqual(x.parts.slice(0, level), parent);
|
|
|
|
});
|
|
|
|
var sorted = matching.sort(function(a, b) {
|
|
|
|
return b.time - a.time;
|
|
|
|
});
|
|
|
|
var othersTime = 0;
|
|
|
|
var othersList = [];
|
2023-06-01 01:01:42 -06:00
|
|
|
var othersRows = [];
|
|
|
|
var childrenRows = [];
|
2023-05-20 15:41:41 -06:00
|
|
|
sorted.forEach(function(x) {
|
2023-06-01 01:01:42 -06:00
|
|
|
var visible = x.time >= cutoff && !hide;
|
2023-05-20 15:41:41 -06:00
|
|
|
|
|
|
|
var cells = [];
|
|
|
|
for (var i = 0; i < maxLength; i++) {
|
|
|
|
cells.push(x.parts[i]);
|
|
|
|
}
|
|
|
|
cells.push(x.time.toFixed(3));
|
|
|
|
var cols = createRow(table, 'td', cells);
|
|
|
|
for (i = 0; i < level; i++) {
|
|
|
|
cols[i].className = 'muted';
|
|
|
|
}
|
|
|
|
|
2023-06-01 01:01:42 -06:00
|
|
|
var tr = cols[0].parentNode;
|
|
|
|
if (!visible) {
|
|
|
|
tr.classList.add("hidden");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x.time >= cutoff) {
|
|
|
|
childrenRows.push(tr);
|
|
|
|
} else {
|
|
|
|
othersTime += x.time;
|
|
|
|
othersList.push(x.parts[level]);
|
|
|
|
othersRows.push(tr);
|
|
|
|
}
|
|
|
|
|
|
|
|
var children = addLevel(level + 1, parent.concat([x.parts[level]]), true);
|
|
|
|
if (children.length > 0) {
|
|
|
|
var cell = cols[level];
|
|
|
|
var onclick = function() {
|
|
|
|
cell.classList.remove("link");
|
|
|
|
cell.removeEventListener("click", onclick);
|
|
|
|
children.forEach(function(x) {
|
|
|
|
x.classList.remove("hidden");
|
|
|
|
});
|
|
|
|
};
|
|
|
|
cell.classList.add("link");
|
|
|
|
cell.addEventListener("click", onclick);
|
|
|
|
}
|
2023-05-20 15:41:41 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
if (othersTime > 0) {
|
|
|
|
var cells = [];
|
|
|
|
for (var i = 0; i < maxLength; i++) {
|
|
|
|
cells.push(parent[i]);
|
|
|
|
}
|
|
|
|
cells.push(othersTime.toFixed(3));
|
2023-06-01 01:01:42 -06:00
|
|
|
cells[level] = 'others';
|
2023-05-20 15:41:41 -06:00
|
|
|
var cols = createRow(table, 'td', cells);
|
|
|
|
for (i = 0; i < level; i++) {
|
|
|
|
cols[i].className = 'muted';
|
|
|
|
}
|
|
|
|
|
2023-06-01 01:01:42 -06:00
|
|
|
var cell = cols[level];
|
|
|
|
var tr = cell.parentNode;
|
|
|
|
var onclick = function() {
|
|
|
|
tr.classList.add("hidden");
|
|
|
|
cell.classList.remove("link");
|
|
|
|
cell.removeEventListener("click", onclick);
|
|
|
|
othersRows.forEach(function(x) {
|
|
|
|
x.classList.remove("hidden");
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
cell.title = othersList.join(", ");
|
|
|
|
cell.classList.add("link");
|
|
|
|
cell.addEventListener("click", onclick);
|
|
|
|
|
|
|
|
if (hide) {
|
|
|
|
tr.classList.add("hidden");
|
|
|
|
}
|
|
|
|
|
|
|
|
childrenRows.push(tr);
|
2023-05-20 15:41:41 -06:00
|
|
|
}
|
2023-06-01 01:01:42 -06:00
|
|
|
|
|
|
|
return childrenRows;
|
2023-05-20 15:41:41 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
addLevel(0, []);
|
|
|
|
|
|
|
|
popup(table);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|