buildMethodTableFromCallTree function

ProfileMethodTable buildMethodTableFromCallTree(
  1. ProfileCallTree callTree
)

Builds a method table 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

ProfileMethodTable buildMethodTableFromCallTree(ProfileCallTree callTree) {
  if (callTree.view != ProfileCallTreeView.topDown) {
    throw ArgumentError.value(
      callTree.view,
      'callTree.view',
      'Expected topDown',
    );
  }
  final samplePeriodMicros = callTree.samplePeriodMicros;
  final sampleCount = callTree.sampleCount;

  final methodsById = <String, _MutableMethodEntry>{};
  final ancestorMethodIds = <String>{};
  for (final child in callTree.root.children) {
    _walkMethodTableOccurrences(
      node: child,
      methodsById: methodsById,
      ancestorMethodIds: ancestorMethodIds,
      parentEntry: null,
    );
  }

  final summaries =
      methodsById.values
          .map(
            (entry) => entry.freeze(
              totalSampleCount: sampleCount,
              samplePeriodMicros: samplePeriodMicros,
            ),
          )
          .toList()
        ..sort(_compareMethodSummaries);

  return ProfileMethodTable(
    sampleCount: sampleCount,
    samplePeriodMicros: samplePeriodMicros,
    methods: summaries,
  );
}