diff --git a/tools/profview/profile-utils.js b/tools/profview/profile-utils.js index e1410550a7..69fed93c74 100644 --- a/tools/profview/profile-utils.js +++ b/tools/profview/profile-utils.js @@ -150,11 +150,7 @@ function findNextFrame(file, stack, stackPos, step, filter) { codeId = stack[stackPos]; code = codeId >= 0 ? file.code[codeId] : undefined; - if (filter) { - let type = code ? code.type : undefined; - let kind = code ? code.kind : undefined; - if (filter(type, kind)) return stackPos; - } + if (!filter || filter(code?.type, code?.kind)) return stackPos; stackPos += step; } return -1; @@ -399,8 +395,9 @@ class FunctionListTree { class CategorySampler { - constructor(file, bucketCount) { + constructor(file, bucketCount, filter) { this.bucketCount = bucketCount; + this.filter = filter; this.firstTime = file.ticks[0].tm; let lastTime = file.ticks[file.ticks.length - 1].tm; @@ -426,7 +423,8 @@ class CategorySampler { let bucket = this.buckets[i]; bucket.total++; - let codeId = (stack.length > 0) ? stack[0] : -1; + let stackPos = findNextFrame(file, stack, 0, 2, this.filter); + let codeId = stackPos >= 0 ? stack[stackPos] : -1; let code = codeId >= 0 ? file.code[codeId] : undefined; let kind = resolveCodeKindAndVmState(code, vmState); bucket[kind]++; diff --git a/tools/profview/profview.js b/tools/profview/profview.js index 4dd3fbf9d0..e98b0e5e65 100644 --- a/tools/profview/profview.js +++ b/tools/profview/profview.js @@ -908,6 +908,7 @@ class TimelineView { height === oldState.timelineSize.height && newState.file === oldState.file && newState.currentCodeId === oldState.currentCodeId && + newState.callTree.attribution === oldState.callTree.attribution && newState.start === oldState.start && newState.end === oldState.end) { // No change, nothing to do. @@ -945,11 +946,10 @@ class TimelineView { this.selectionStart = (start - firstTime) / (lastTime - firstTime) * width; this.selectionEnd = (end - firstTime) / (lastTime - firstTime) * width; - let stackProcessor = new CategorySampler(file, bucketCount); + let filter = filterFromFilterId(this.currentState.callTree.attribution); + let stackProcessor = new CategorySampler(file, bucketCount, filter); generateTree(file, 0, Infinity, stackProcessor); - let codeIdProcessor = new FunctionTimelineProcessor( - currentCodeId, - filterFromFilterId(this.currentState.callTree.attribution)); + let codeIdProcessor = new FunctionTimelineProcessor(currentCodeId, filter); generateTree(file, 0, Infinity, codeIdProcessor); let buffer = document.createElement("canvas");