From ee8886f7c214885023516aed1a257ac81abbbc81 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 24 Feb 2021 10:37:20 +0100 Subject: [PATCH] serialize child items with parent start offset subtracted for compactness --- scripts/logviewer/main.js | 7 ++++--- src/logging/LogItem.js | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/logviewer/main.js b/scripts/logviewer/main.js index af5f562c..56d7024e 100644 --- a/scripts/logviewer/main.js +++ b/scripts/logviewer/main.js @@ -147,7 +147,7 @@ async function loadFile() { logs.items.sort((a, b) => itemStart(a) - itemStart(b)); rootItem = {c: logs.items}; itemByRef = new Map(); - preprocessRecursively(rootItem, itemByRef, []); + preprocessRecursively(rootItem, null, itemByRef, []); const fragment = logs.items.reduce((fragment, item, i, items) => { const prevItem = i === 0 ? null : items[i - 1]; @@ -160,7 +160,8 @@ async function loadFile() { main.replaceChildren(fragment); } -function preprocessRecursively(item, refsMap, path) { +function preprocessRecursively(item, parentElement, refsMap, path) { + item.s = (parentElement?.s || 0) + item.s; if (itemRefSource(item)) { refsMap.set(itemRefSource(item), item); } @@ -170,7 +171,7 @@ function preprocessRecursively(item, refsMap, path) { const child = itemChildren(item)[i]; const childPath = path.concat(i); child.id = childPath.join("/"); - preprocessRecursively(child, refsMap, childPath); + preprocessRecursively(child, item, refsMap, childPath); } } } diff --git a/src/logging/LogItem.js b/src/logging/LogItem.js index e699a4ac..cddcfecf 100644 --- a/src/logging/LogItem.js +++ b/src/logging/LogItem.js @@ -100,7 +100,7 @@ export class LogItem { } } - serialize(filter) { + serialize(filter, parentStartTime = null) { if (this._filterCreator) { try { filter = this._filterCreator(new LogFilter(filter), this); @@ -111,7 +111,7 @@ export class LogItem { let children; if (this._children !== null) { children = this._children.reduce((array, c) => { - const s = c.serialize(filter); + const s = c.serialize(filter, this._start); if (s) { if (array === null) { array = []; @@ -127,7 +127,7 @@ export class LogItem { // in (v)alues, (l)abel and (t)ype are also reserved. const item = { // (s)tart - s: this._start, + s: parentStartTime === null ? this._start : this._start - parentStartTime, // (d)uration d: this.duration, // (v)alues