trackMemoryUsage function
Enables memory usage tracking, based on the value of ProcessInfo.currentRss (dart:io).
If tracking is already enabled, resets it. See UsageTrackingConfig for details. Use stopMemoryUsageTracking to stop auto-snapshotting. Snapshotting operation may cause a delay in the main thread.
Implementation
void trackMemoryUsage(UsageTrackingConfig config) {
stopMemoryUsageTracking();
if (config.isNoOp) return;
final autosnapshotting = config.autoSnapshottingConfig;
if (autosnapshotting != null) {
final dir = Directory(autosnapshotting.directory);
if (!dir.existsSync()) {
dir.createSync(recursive: true);
}
autoSnapshotter = AutoSnapshotter(autosnapshotting);
}
if (config.usageEventsConfig != null) {
usageEventCreator = UsageEventCreator(config.usageEventsConfig!);
usageEventCreator!.createFirstUsageEvent();
}
timer = Timer.periodic(config.interval, (_) async {
usageEventCreator?.mayBeCreateUsageEvent();
await autoSnapshotter?.autoSnapshot();
});
}