-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: analysis total time sum unique stacks
Collect the stacks and only sum the unique entries e.g If we have an analysis like this methodA: 5s methodB: 3s methodC: 2s Sibling Methods The three methods are at the same level directly called from EXECUTION_STARTED. All 3 should be summed as they are in different stacks. Total: 10s Child Methods methodB is a child of methodA and methodC is a sibling of methodA. we first add methodA to the total but the total for methodB has already been accounted by including methodA so we skip it and any other children of methodA. methodC is in a unique stack and needs to be added to the total. Total: 7s
- Loading branch information
1 parent
512b3a0
commit f979a81
Showing
2 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
log-viewer/modules/components/analysis-view/column-calcs/CallStackSum.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { LogLine, TimedNode } from '../../../parsers/ApexLogParser'; | ||
import { type Metric } from '../../AnalysisView.js'; | ||
|
||
export function callStackSum(values: number[], data: Metric[], _calcParams: unknown) { | ||
// All filtered debug logs nodes | ||
const includedNodes = new Set<TimedNode>(); | ||
data.forEach((row) => { | ||
row.nodes.forEach((node) => { | ||
includedNodes.add(node); | ||
}); | ||
}); | ||
|
||
let total = 0; | ||
data.forEach((row, i) => { | ||
// All the parents (to root) of the log nodes for this row. | ||
const parents = _getParentNodes(row.nodes); | ||
// If any of these parent are else where in the (filtered) stacks do not include in the sum. | ||
// This value will be included when the parent is summed e.g m1 -> m2 -> m3 (no need to include m2 + m3) | ||
if (!_containsAny(parents, includedNodes)) { | ||
total += values[i] ?? 0; | ||
} | ||
}); | ||
|
||
return total; | ||
} | ||
|
||
const _getParentNodes = (nodes: TimedNode[]) => { | ||
const parents = new Set<LogLine>(); | ||
nodes.forEach((node) => { | ||
let parent = node.parent; | ||
while (parent && !parents.has(parent)) { | ||
parents.add(parent); | ||
parent = parent.parent; | ||
} | ||
}); | ||
return parents; | ||
}; | ||
|
||
const _containsAny = (target: Set<LogLine>, toCheck: Set<LogLine>) => { | ||
for (const t of target) { | ||
if (toCheck.has(t)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; |