summarizeMemoryProfile function
ProfileMemoryResult
summarizeMemoryProfile({
- required HeapSample start,
- required HeapSample end,
- required Iterable<
ClassHeapStats> startClasses, - required Iterable<
ClassHeapStats> endClasses, - required String rawProfilePath,
- int topClassCount = 10,
- ProfileMemoryClassPredicate? includeClass,
Builds a ProfileMemoryResult from start and end allocation snapshots.
Implementation
ProfileMemoryResult summarizeMemoryProfile({
required HeapSample start,
required HeapSample end,
required Iterable<ClassHeapStats> startClasses,
required Iterable<ClassHeapStats> endClasses,
required String rawProfilePath,
int topClassCount = 10,
ProfileMemoryClassPredicate? includeClass,
}) {
final startStats = _aggregateClassStats(startClasses);
final endStats = _aggregateClassStats(endClasses);
final summaries = <ProfileMemoryClassSummary>[];
for (final key in {...startStats.keys, ...endStats.keys}) {
final startStat = startStats[key];
final endStat = endStats[key];
final summary = ProfileMemoryClassSummary(
className: endStat?.className ?? startStat?.className ?? 'unknown',
libraryUri: endStat?.libraryUri ?? startStat?.libraryUri,
allocationBytesDelta:
(endStat?.accumulatedBytes ?? 0) - (startStat?.accumulatedBytes ?? 0),
allocationInstancesDelta:
(endStat?.accumulatedInstances ?? 0) -
(startStat?.accumulatedInstances ?? 0),
liveBytes: endStat?.liveBytes ?? 0,
liveBytesDelta: (endStat?.liveBytes ?? 0) - (startStat?.liveBytes ?? 0),
liveInstances: endStat?.liveInstances ?? 0,
liveInstancesDelta:
(endStat?.liveInstances ?? 0) - (startStat?.liveInstances ?? 0),
);
if (includeClass != null && !includeClass(summary)) {
continue;
}
summaries.add(summary);
}
summaries.sort(_compareMemoryClassSummary);
if (topClassCount > 0 && summaries.length > topClassCount) {
summaries.removeRange(topClassCount, summaries.length);
}
return ProfileMemoryResult(
start: start,
end: end,
deltaHeapBytes: end.used - start.used,
deltaExternalBytes: end.external - start.external,
deltaCapacityBytes: end.capacity - start.capacity,
classCount: {...startStats.keys, ...endStats.keys}.length,
topClasses: summaries,
rawProfilePath: rawProfilePath,
);
}