serialize child items with parent start offset subtracted

for compactness
This commit is contained in:
Bruno Windels 2021-02-24 10:37:20 +01:00
parent 23b8ba7e54
commit ee8886f7c2
2 changed files with 7 additions and 6 deletions

View file

@ -147,7 +147,7 @@ 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, itemByRef, []); preprocessRecursively(rootItem, null, itemByRef, []);
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];
@ -160,7 +160,8 @@ async function loadFile() {
main.replaceChildren(fragment); main.replaceChildren(fragment);
} }
function preprocessRecursively(item, refsMap, path) { function preprocessRecursively(item, parentElement, refsMap, path) {
item.s = (parentElement?.s || 0) + item.s;
if (itemRefSource(item)) { if (itemRefSource(item)) {
refsMap.set(itemRefSource(item), item); refsMap.set(itemRefSource(item), item);
} }
@ -170,7 +171,7 @@ function preprocessRecursively(item, refsMap, path) {
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, refsMap, childPath); preprocessRecursively(child, item, refsMap, childPath);
} }
} }
} }

View file

@ -100,7 +100,7 @@ export class LogItem {
} }
} }
serialize(filter) { serialize(filter, parentStartTime = null) {
if (this._filterCreator) { if (this._filterCreator) {
try { try {
filter = this._filterCreator(new LogFilter(filter), this); filter = this._filterCreator(new LogFilter(filter), this);
@ -111,7 +111,7 @@ export class LogItem {
let children; let children;
if (this._children !== null) { if (this._children !== null) {
children = this._children.reduce((array, c) => { children = this._children.reduce((array, c) => {
const s = c.serialize(filter); const s = c.serialize(filter, this._start);
if (s) { if (s) {
if (array === null) { if (array === null) {
array = []; array = [];
@ -127,7 +127,7 @@ export class LogItem {
// in (v)alues, (l)abel and (t)ype are also reserved. // in (v)alues, (l)abel and (t)ype are also reserved.
const item = { const item = {
// (s)tart // (s)tart
s: this._start, s: parentStartTime === null ? this._start : this._start - parentStartTime,
// (d)uration // (d)uration
d: this.duration, d: this.duration,
// (v)alues // (v)alues