Cleanup leak_tracker. (#195)

diff --git a/pkgs/leak_tracker/CHANGELOG.md b/pkgs/leak_tracker/CHANGELOG.md
index e3d9386..2748c38 100644
--- a/pkgs/leak_tracker/CHANGELOG.md
+++ b/pkgs/leak_tracker/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 10.0.0
+
+* Remove `memory_usage`, as it is moved to https://github.com/dart-lang/leak_tracker/tree/main/pkgs/memory_usage.
+
 ## 9.0.18
 
 * Update `vm_service` dependency to `>=11.0.0 <15.0.0`.
diff --git a/pkgs/leak_tracker/lib/leak_tracker.dart b/pkgs/leak_tracker/lib/leak_tracker.dart
index 1ba1375..9fa6ac9 100644
--- a/pkgs/leak_tracker/lib/leak_tracker.dart
+++ b/pkgs/leak_tracker/lib/leak_tracker.dart
@@ -6,5 +6,3 @@
 export 'src/leak_tracking/leak_tracking.dart';
 export 'src/leak_tracking/primitives/model.dart';
 export 'src/shared/shared_model.dart';
-export 'src/usage_tracking/model.dart';
-export 'src/usage_tracking/usage_tracking.dart';
diff --git a/pkgs/leak_tracker/lib/src/usage_tracking/DEPENDENCIES.md b/pkgs/leak_tracker/lib/src/usage_tracking/DEPENDENCIES.md
deleted file mode 100644
index 44157f0..0000000
--- a/pkgs/leak_tracker/lib/src/usage_tracking/DEPENDENCIES.md
+++ /dev/null
@@ -1,14 +0,0 @@
-<!---
-Generated by https://github.com/polina-c/layerlens
-Dependencies that create loop are markes with `!`.
--->
-
-```mermaid
-flowchart TD;
-_snapshot.dart-->model.dart;
-_usage_event.dart-->model.dart;
-usage_tracking.dart-->_snapshot.dart;
-usage_tracking.dart-->_usage_event.dart;
-usage_tracking.dart-->model.dart;
-```
-
diff --git a/pkgs/leak_tracker/lib/src/usage_tracking/_snapshot.dart b/pkgs/leak_tracker/lib/src/usage_tracking/_snapshot.dart
deleted file mode 100644
index 1b9b4fd..0000000
--- a/pkgs/leak_tracker/lib/src/usage_tracking/_snapshot.dart
+++ /dev/null
@@ -1,108 +0,0 @@
-// Copyright (c) 2023, the Dart project authors.  Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-import 'dart:developer';
-import 'dart:io';
-
-import 'package:path/path.dart' as path;
-
-import '../shared/_util.dart';
-import 'model.dart';
-
-class AutoSnapshotter {
-  AutoSnapshotter(this.config);
-
-  final AutoSnapshottingConfig config;
-
-  bool _snapshottingIsInProgress = false;
-  SnapshotEvent? _previousSnapshot;
-  bool _noSnapshotsAnyMore = false;
-
-  Future<void> autoSnapshot() async {
-    if (_noSnapshotsAnyMore || _snapshottingIsInProgress) return;
-    _snapshottingIsInProgress = true;
-    await _maybeTakeSnapshot();
-    _snapshottingIsInProgress = false;
-  }
-
-  Future<void> _maybeTakeSnapshot() async {
-    final rss = ProcessInfo.currentRss;
-    if (rss < config.thresholdMb.mbToBytes) {
-      return;
-    }
-
-    // Directory size validation is heavier than rss check, so we do it after.
-    // We do not stop monitoring, in case user will free some space.
-    if (_isDirectoryOversized()) return;
-
-    final stepMb = config.increaseMb;
-
-    if (_previousSnapshot == null) {
-      _takeSnapshot(rss: rss);
-      if (stepMb == null) _noSnapshotsAnyMore = true;
-      return;
-    }
-
-    final previous = _previousSnapshot!;
-
-    if (stepMb == null) {
-      throw StateError(
-        'Autosnapshotting should be off if step is null and there is a snapshot already taken',
-      );
-    }
-
-    final nextAllowedSnapshotTime =
-        previous.timestamp.add(config.minDelayBetweenSnapshots);
-    if (nextAllowedSnapshotTime.isAfter(DateTime.now())) {
-      return;
-    }
-
-    final nextThreshold = previous.rss + stepMb.mbToBytes;
-    if (rss >= nextThreshold) {
-      _takeSnapshot(rss: rss);
-    }
-  }
-
-  void _takeSnapshot({required int rss}) {
-    final snapshotNumber = (_previousSnapshot?.snapshotNumber ?? 0) + 1;
-
-    final snapshot = saveSnapshot(
-      config.directory,
-      rss: rss,
-      snapshotNumber: snapshotNumber,
-    );
-    _previousSnapshot = snapshot;
-    config.onSnapshot?.call(snapshot);
-  }
-
-  bool _isDirectoryOversized() {
-    final directorySize = Directory(config.directory)
-        .listSync(recursive: true)
-        .whereType<File>()
-        .map((f) => f.lengthSync())
-        .fold<int>(0, (a, b) => a + b);
-    return directorySize >= config.directorySizeLimitMb.mbToBytes;
-  }
-}
-
-/// Saves a memory heap snapshot of the current process, to the [directory].
-///
-/// Returns the name of the file where the snapshot was saved.
-///
-/// The file name contains process id, snapshot number and current RSS.
-SnapshotEvent saveSnapshot(
-  String directory, {
-  required int rss,
-  required int snapshotNumber,
-  void Function(String fileName) snapshotter =
-      NativeRuntime.writeHeapSnapshotToFile,
-}) {
-  final fileName = path.absolute(
-    path.join(directory, 'snapshot-$pid-$snapshotNumber-rss$rss.json'),
-  );
-
-  snapshotter(fileName);
-
-  return SnapshotEvent(fileName, snapshotNumber: snapshotNumber, rss: rss);
-}
diff --git a/pkgs/leak_tracker/lib/src/usage_tracking/_usage_event.dart b/pkgs/leak_tracker/lib/src/usage_tracking/_usage_event.dart
deleted file mode 100644
index 7c84a1d..0000000
--- a/pkgs/leak_tracker/lib/src/usage_tracking/_usage_event.dart
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright (c) 2023, the Dart project authors.  Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-import 'dart:io';
-
-import '../shared/_util.dart';
-import 'model.dart';
-
-class UsageEventCreator {
-  UsageEventCreator(this.config);
-
-  final UsageEventsConfig config;
-
-  late MemoryUsageEvent _previousEvent;
-
-  void createFirstUsageEvent() => _triggerEvent(
-        MemoryUsageEvent(
-          delta: null,
-          previousEventTime: null,
-          rss: ProcessInfo.currentRss,
-        ),
-      );
-
-  void mayBeCreateUsageEvent() {
-    final rss = ProcessInfo.currentRss;
-    final delta = (rss - _previousEvent.rss).abs();
-
-    if (delta < config.deltaMb.mbToBytes) return;
-
-    _triggerEvent(
-      MemoryUsageEvent(
-        delta: delta,
-        previousEventTime: _previousEvent.timestamp,
-        rss: ProcessInfo.currentRss,
-      ),
-    );
-  }
-
-  void _triggerEvent(MemoryUsageEvent event) {
-    _previousEvent = event;
-    config.onUsageEvent(event);
-  }
-}
diff --git a/pkgs/leak_tracker/lib/src/usage_tracking/model.dart b/pkgs/leak_tracker/lib/src/usage_tracking/model.dart
deleted file mode 100644
index 62ba9e8..0000000
--- a/pkgs/leak_tracker/lib/src/usage_tracking/model.dart
+++ /dev/null
@@ -1,170 +0,0 @@
-// Copyright (c) 2023, the Dart project authors.  Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-import 'package:path/path.dart' as path;
-
-/// A record of a taken snapshot.
-class SnapshotEvent {
-  SnapshotEvent(
-    this.fileName, {
-    required this.snapshotNumber,
-    required this.rss,
-    DateTime? timestamp,
-  }) : timestamp = timestamp ?? DateTime.now();
-
-  final String fileName;
-  final int snapshotNumber;
-  final int rss;
-  final DateTime timestamp;
-}
-
-/// A callback that is called when a snapshot is taken.
-typedef SnapshotCallback = void Function(SnapshotEvent event);
-
-/// A record of a memory usage event.
-class MemoryUsageEvent {
-  MemoryUsageEvent({
-    required this.delta,
-    required DateTime? previousEventTime,
-    required this.rss,
-    DateTime? timestamp,
-  }) : timestamp = timestamp ?? DateTime.now() {
-    if (previousEventTime == null) {
-      period = null;
-    } else {
-      period = this.timestamp.difference(previousEventTime);
-    }
-  }
-
-  /// Difference with previous rss value.
-  ///
-  /// Equals to `null` for first event.
-  final int? delta;
-
-  /// Time since previous event.
-  ///
-  /// Equals to `null` for first event.
-  late Duration? period;
-
-  /// RSS memory usage.
-  final int rss;
-
-  ///
-  final DateTime timestamp;
-}
-
-/// A callback that is called for memory usage event.
-typedef UsageCallback = void Function(MemoryUsageEvent event);
-
-/// Configures memory usage tracking.
-///
-/// Set [interval] to customize how often to verify memory usage.
-class UsageTrackingConfig {
-  const UsageTrackingConfig({
-    this.usageEventsConfig,
-    this.autoSnapshottingConfig,
-    this.interval = const Duration(seconds: 1),
-  });
-
-  /// Configuration for snapshotting.
-  final AutoSnapshottingConfig? autoSnapshottingConfig;
-
-  /// Configuration for usage events.
-  final UsageEventsConfig? usageEventsConfig;
-
-  /// How often to verify memory usage.
-  final Duration interval;
-
-  bool get isNoOp =>
-      autoSnapshottingConfig == null && usageEventsConfig == null;
-
-  @override
-  String toString() {
-    return 'interval: $interval\n'
-        '$usageEventsConfig\n'
-        '$autoSnapshottingConfig';
-  }
-}
-
-/// Configures memory usage tracking.
-///
-/// [onUsageEvent] will be triggered when rss value changes
-/// more then by [deltaMb] since previous [onUsageEvent].
-/// First [onUsageEvent] will be triggered immediately.
-class UsageEventsConfig {
-  const UsageEventsConfig(
-    this.onUsageEvent, {
-    this.deltaMb = 128,
-  });
-
-  /// A callback that is called when a snapshot is taken.
-  final UsageCallback onUsageEvent;
-
-  /// Change in memory usage to trigger [onUsageEvent].
-  final int deltaMb;
-}
-
-/// Configures auto-snapshotting, based on the value of `ProcessInfo.currentRss` (dart:io).
-///
-/// Automatic snapshots will begin to be taken when the rss value exceeds [thresholdMb].
-/// The snapshots will be saved to [directory].
-///
-/// The snapshots will be re-taken when the value
-/// increases more than by [increaseMb] since previous snapshot,
-/// until the size of [directory] exceeds
-/// [directorySizeLimitMb].
-///
-/// The [onSnapshot] callback is called when a snapshot is taken.
-///
-/// Set [minDelayBetweenSnapshots] to make sure snapshots do not trigger each other.
-class AutoSnapshottingConfig {
-  AutoSnapshottingConfig({
-    this.thresholdMb = 1024, // 1Gb
-    this.increaseMb = 512, // 0.5Gb
-    this.directory = 'dart_memory_snapshots',
-    this.directorySizeLimitMb = 10240, // 10Gb
-    this.minDelayBetweenSnapshots = const Duration(seconds: 10),
-    this.onSnapshot,
-  }) {
-    if (minDelayBetweenSnapshots <= Duration.zero) {
-      throw ArgumentError.value(
-        minDelayBetweenSnapshots,
-        'minDelayBetweenSnapshots',
-        'must be positive',
-      );
-    }
-  }
-
-  /// The rss value in Mb that will trigger the first snapshot.
-  final int thresholdMb;
-
-  /// The value by which the rss value should increase, since
-  /// previous snapshot, to take another snapshot.
-  ///
-  /// If [increaseMb] is null, only one snapshot will be taken.
-  final int? increaseMb;
-
-  /// The directory where snapshots will be saved.
-  ///
-  /// If the directory does not exist, it will be created.
-  ///
-  /// If the path is relative, it will be relative to the current working directory.
-  final String directory;
-
-  /// The size limit for the [directory] in Mb.
-  ///
-  /// The directory size will be checked before a snapshot is taken and saved,
-  /// so the directory may exceed the size specified by [directorySizeLimitMb]
-  /// depending on the size of the snapshot.
-  final int directorySizeLimitMb;
-
-  /// How long to wait after taking a snapshot before taking another one.
-  final Duration minDelayBetweenSnapshots;
-
-  /// A callback that is called when a snapshot is taken.
-  final SnapshotCallback? onSnapshot;
-
-  /// The absolute path to the [directory].
-  String get directoryAbsolute => path.absolute(directory);
-}
diff --git a/pkgs/leak_tracker/lib/src/usage_tracking/usage_tracking.dart b/pkgs/leak_tracker/lib/src/usage_tracking/usage_tracking.dart
deleted file mode 100644
index c9b4bd8..0000000
--- a/pkgs/leak_tracker/lib/src/usage_tracking/usage_tracking.dart
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright (c) 2023, the Dart project authors.  Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-import 'dart:async';
-import 'dart:io';
-
-import '_snapshot.dart';
-import '_usage_event.dart';
-import 'model.dart';
-
-Timer? timer;
-AutoSnapshotter? autoSnapshotter;
-UsageEventCreator? usageEventCreator;
-
-/// 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.
-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();
-  });
-}
-
-/// Stops memory usage tracking if it is started by [trackMemoryUsage].
-void stopMemoryUsageTracking() {
-  timer?.cancel();
-  timer = null;
-
-  autoSnapshotter = null;
-  usageEventCreator = null;
-}
diff --git a/pkgs/leak_tracker/test/tests/usage_tracking/_snapshot_test.dart b/pkgs/leak_tracker/test/tests/usage_tracking/_snapshot_test.dart
deleted file mode 100644
index b795bef..0000000
--- a/pkgs/leak_tracker/test/tests/usage_tracking/_snapshot_test.dart
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright (c) 2023, the Dart project authors.  Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-import 'dart:io';
-
-import 'package:leak_tracker/src/usage_tracking/_snapshot.dart';
-import 'package:test/test.dart';
-
-void main() {
-  test('saveSnapshot invokes snapshotter', () {
-    late String actualFileName;
-
-    final returnedFileName = saveSnapshot(
-      'directory',
-      rss: ProcessInfo.currentRss,
-      snapshotNumber: 1,
-      snapshotter: (fileName) => actualFileName = fileName,
-    ).fileName;
-
-    expect(returnedFileName, actualFileName);
-    expect(returnedFileName, contains('/snapshot-'));
-    expect(returnedFileName, endsWith('.json'));
-  });
-}
diff --git a/pkgs/leak_tracker/test/tests/usage_tracking/model_test.dart b/pkgs/leak_tracker/test/tests/usage_tracking/model_test.dart
deleted file mode 100644
index 96bcd9e..0000000
--- a/pkgs/leak_tracker/test/tests/usage_tracking/model_test.dart
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (c) 2023, the Dart project authors.  Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-import 'package:leak_tracker/src/usage_tracking/model.dart';
-import 'package:test/test.dart';
-
-void main() {
-  test('$MemoryUsageEvent initial', () {
-    final event =
-        MemoryUsageEvent(rss: 100, delta: null, previousEventTime: null);
-
-    expect(event.delta, null);
-    expect(event.period, null);
-    expect(event.rss, 100);
-  });
-
-  test('$MemoryUsageEvent delta', () {
-    final event = MemoryUsageEvent(
-      rss: 200,
-      delta: 100,
-      previousEventTime: DateTime(2022),
-      timestamp: DateTime(2023),
-    );
-
-    expect(event.delta, 100);
-    expect(event.period, const Duration(days: 365));
-    expect(event.rss, 200);
-  });
-}
diff --git a/pkgs/leak_tracker_flutter_testing/pubspec.yaml b/pkgs/leak_tracker_flutter_testing/pubspec.yaml
index 9c681a4..2fe47f1 100644
--- a/pkgs/leak_tracker_flutter_testing/pubspec.yaml
+++ b/pkgs/leak_tracker_flutter_testing/pubspec.yaml
@@ -9,8 +9,8 @@
 dependencies:
   flutter:
     sdk: flutter
-  leak_tracker: ^9.0.10
-  leak_tracker_testing: ^1.0.5
+  leak_tracker: '>=9.0.0 <11.0.0'
+  leak_tracker_testing: '>=1.0.5 <3.0.0'
   matcher: ^0.12.16
   meta: ^1.8.0
 
diff --git a/pkgs/leak_tracker_testing/CHANGELOG.md b/pkgs/leak_tracker_testing/CHANGELOG.md
index 9ce6acf..d68a333 100644
--- a/pkgs/leak_tracker_testing/CHANGELOG.md
+++ b/pkgs/leak_tracker_testing/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 2.0.0
+
+* Remove fields `failOnLeaksCollected` and `onLeaks` from `LeakTesting`.
+
 ## 1.0.6
 
 * Updated to use `package:lints/recommended.yaml` for analysis.
diff --git a/pkgs/leak_tracker_testing/lib/src/leak_testing.dart b/pkgs/leak_tracker_testing/lib/src/leak_testing.dart
index f19ce33..ee29348 100644
--- a/pkgs/leak_tracker_testing/lib/src/leak_testing.dart
+++ b/pkgs/leak_tracker_testing/lib/src/leak_testing.dart
@@ -8,8 +8,6 @@
 
 import 'matchers.dart';
 
-void _emptyLeakHandler(Leaks leaks) {}
-
 /// Leak tracker settings for tests.
 ///
 /// Set [LeakTesting.settings], to
@@ -39,8 +37,6 @@
     this.ignore = true,
     this.ignoredLeaks = const IgnoredLeaks(),
     this.leakDiagnosticConfig = const LeakDiagnosticConfig(),
-    this.failOnLeaksCollected = true,
-    this.onLeaks = _emptyLeakHandler,
     this.baselining = const MemoryBaselining.none(),
   });
 
@@ -178,16 +174,12 @@
   LeakTesting copyWith({
     IgnoredLeaks? ignoredLeaks,
     LeakDiagnosticConfig? leakDiagnosticConfig,
-    bool? failOnLeaksCollected,
-    LeaksCallback? onLeaks,
     bool? ignore,
     MemoryBaselining? baselining,
   }) {
     return LeakTesting._(
       ignoredLeaks: ignoredLeaks ?? this.ignoredLeaks,
       leakDiagnosticConfig: leakDiagnosticConfig ?? this.leakDiagnosticConfig,
-      failOnLeaksCollected: failOnLeaksCollected ?? this.failOnLeaksCollected,
-      onLeaks: onLeaks ?? this.onLeaks,
       ignore: ignore ?? this.ignore,
       baselining: baselining ?? this.baselining,
     );
@@ -196,14 +188,6 @@
   /// If true, leak tracking is paused.
   final bool ignore;
 
-  /// If true, tests will fail on leaks.
-  ///
-  /// Set to true to test that tests collect expected leaks.
-  final bool failOnLeaksCollected;
-
-  /// Callback to invoke before the test fails when [failOnLeaksCollected] is true and if leaks were found.
-  final LeaksCallback onLeaks;
-
   /// Leaks to ignore.
   final IgnoredLeaks ignoredLeaks;
 
@@ -228,8 +212,6 @@
     }
     return other is LeakTesting &&
         other.ignore == ignore &&
-        other.failOnLeaksCollected == failOnLeaksCollected &&
-        other.onLeaks == onLeaks &&
         other.ignoredLeaks == ignoredLeaks &&
         other.baselining == baselining &&
         other.leakDiagnosticConfig == leakDiagnosticConfig;
@@ -238,8 +220,6 @@
   @override
   int get hashCode => Object.hash(
         ignore,
-        failOnLeaksCollected,
-        onLeaks,
         ignoredLeaks,
         baselining,
         leakDiagnosticConfig,
diff --git a/pkgs/leak_tracker_testing/pubspec.yaml b/pkgs/leak_tracker_testing/pubspec.yaml
index 7c7adc1..a2df827 100644
--- a/pkgs/leak_tracker_testing/pubspec.yaml
+++ b/pkgs/leak_tracker_testing/pubspec.yaml
@@ -1,5 +1,5 @@
 name: leak_tracker_testing
-version: 1.0.6
+version: 2.0.0
 description: Leak tracking code intended for usage in tests.
 repository: https://github.com/dart-lang/leak_tracker/tree/main/pkgs/leak_tracker_testing
 
diff --git a/pkgs/leak_tracker_testing/test/leak_testing_test.dart b/pkgs/leak_tracker_testing/test/leak_testing_test.dart
index 2470432..0d4441a 100644
--- a/pkgs/leak_tracker_testing/test/leak_testing_test.dart
+++ b/pkgs/leak_tracker_testing/test/leak_testing_test.dart
@@ -102,15 +102,11 @@
       });
 
       test('customized equal', () {
-        void onLeaks(_) {}
-
         final settings1 = LeakTesting.settings.copyWith(
-          onLeaks: onLeaks,
           leakDiagnosticConfig: const LeakDiagnosticConfig(),
           ignoredLeaks: const IgnoredLeaks(),
         );
         final settings2 = LeakTesting.settings.copyWith(
-          onLeaks: onLeaks,
           leakDiagnosticConfig: const LeakDiagnosticConfig(),
           ignoredLeaks: const IgnoredLeaks(),
         );