some logviewer improvement to help debug call signalling

This commit is contained in:
Bruno Windels 2022-04-06 18:11:06 +02:00
parent 42b470b06b
commit 1ad5db73a9

View file

@ -22,6 +22,7 @@ const main = document.querySelector("main");
let selectedItemNode; let selectedItemNode;
let rootItem; let rootItem;
let itemByRef; let itemByRef;
let itemsRefFrom;
const logLevels = [undefined, "All", "Debug", "Detail", "Info", "Warn", "Error", "Fatal", "Off"]; const logLevels = [undefined, "All", "Debug", "Detail", "Info", "Warn", "Error", "Fatal", "Off"];
@ -49,6 +50,7 @@ window.addEventListener("hashchange", () => {
const id = window.location.hash.substr(1); const id = window.location.hash.substr(1);
const itemNode = document.getElementById(id); const itemNode = document.getElementById(id);
if (itemNode && itemNode.closest("main")) { if (itemNode && itemNode.closest("main")) {
ensureParentsExpanded(itemNode);
selectNode(itemNode); selectNode(itemNode);
itemNode.scrollIntoView({behavior: "smooth", block: "nearest"}); itemNode.scrollIntoView({behavior: "smooth", block: "nearest"});
} }
@ -70,6 +72,14 @@ function selectNode(itemNode) {
showItemDetails(item, parent, selectedItemNode); showItemDetails(item, parent, selectedItemNode);
} }
function ensureParentsExpanded(itemNode) {
let li = itemNode.parentElement.parentElement;
while (li.tagName === "LI") {
li.classList.add("expanded");
li = li.parentElement.parentElement;
}
}
function stringifyItemValue(value) { function stringifyItemValue(value) {
if (typeof value === "object" && value !== null) { if (typeof value === "object" && value !== null) {
return JSON.stringify(value, undefined, 2); return JSON.stringify(value, undefined, 2);
@ -102,6 +112,11 @@ function showItemDetails(item, parent, itemNode) {
} else { } else {
valueNode = `unknown ref ${value}`; valueNode = `unknown ref ${value}`;
} }
} else if (key === "refId") {
const refSources = itemsRefFrom.get(value) ?? [];
valueNode = t.div([t.p([`${value}`, t.br(),`Found these references:`]),t.ul(refSources.map(item => {
return t.li(t.a({href: `#${item.id}`}, itemCaption(item)));
}))]);
} else { } else {
valueNode = stringifyItemValue(value); valueNode = stringifyItemValue(value);
} }
@ -153,7 +168,8 @@ async function loadFile() {
logs.items.sort((a, b) => itemStart(a) - itemStart(b)); logs.items.sort((a, b) => itemStart(a) - itemStart(b));
rootItem = {c: logs.items}; rootItem = {c: logs.items};
itemByRef = new Map(); itemByRef = new Map();
preprocessRecursively(rootItem, null, itemByRef, []); itemsRefFrom = new Map();
preprocessRecursively(rootItem, null, itemByRef, itemsRefFrom, []);
const fragment = logs.items.reduce((fragment, item, i, items) => { const fragment = logs.items.reduce((fragment, item, i, items) => {
const prevItem = i === 0 ? null : items[i - 1]; const prevItem = i === 0 ? null : items[i - 1];
@ -167,18 +183,26 @@ async function loadFile() {
} }
// TODO: make this use processRecursively // TODO: make this use processRecursively
function preprocessRecursively(item, parentElement, refsMap, path) { function preprocessRecursively(item, parentElement, refsMap, refsFromMap, path) {
item.s = (parentElement?.s || 0) + item.s; item.s = (parentElement?.s || 0) + item.s;
if (itemRefSource(item)) { if (itemRefSource(item)) {
refsMap.set(itemRefSource(item), item); refsMap.set(itemRefSource(item), item);
} }
if (itemRef(item)) {
let refs = refsFromMap.get(itemRef(item));
if (!refs) {
refs = [];
refsFromMap.set(itemRef(item), refs);
}
refs.push(item);
}
if (itemChildren(item)) { if (itemChildren(item)) {
for (let i = 0; i < itemChildren(item).length; i += 1) { for (let i = 0; i < itemChildren(item).length; i += 1) {
// do it in advance for a child as we don't want to do it for the rootItem // do it in advance for a child as we don't want to do it for the rootItem
const child = itemChildren(item)[i]; const child = itemChildren(item)[i];
const childPath = path.concat(i); const childPath = path.concat(i);
child.id = childPath.join("/"); child.id = childPath.join("/");
preprocessRecursively(child, item, refsMap, childPath); preprocessRecursively(child, item, refsMap, refsFromMap, childPath);
} }
} }
} }