buildBottomUpTreeFromCallTree function

ProfileCallTree buildBottomUpTreeFromCallTree(
  1. ProfileCallTree callTree
)

Builds a bottom-up view from an untruncated top-down callTree.

Reuses resolved, filtered paths when multiple views of one profile are needed. Apply presentation limits only after deriving all views. Throws ArgumentError if callTree is not a top-down view.

Implementation

ProfileCallTree buildBottomUpTreeFromCallTree(ProfileCallTree callTree) {
  if (callTree.view != ProfileCallTreeView.topDown) {
    throw ArgumentError.value(
      callTree.view,
      'callTree.view',
      'Expected topDown',
    );
  }
  final bottomUpRoots = <_MutableBottomUpNode>[];

  for (final rootChild in callTree.root.children) {
    _generateBottomUpRoots(
      node: rootChild,
      parent: null,
      bottomUpRoots: bottomUpRoots,
    );
  }

  final mergedRoots = _mergeBottomUpNodes(bottomUpRoots);
  final syntheticRoot = _MutableBottomUpNode.root(
    sampleCount: callTree.sampleCount,
  )..children.addAll(mergedRoots);

  return ProfileCallTree(
    sampleCount: callTree.sampleCount,
    samplePeriodMicros: callTree.samplePeriodMicros,
    view: ProfileCallTreeView.bottomUp,
    root: syntheticRoot.freeze(
      totalSampleCount: callTree.sampleCount,
      samplePeriodMicros: callTree.samplePeriodMicros,
    ),
  );
}