-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create troubleshooting helpers. #89
Merged
Merged
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
4d69a14
-
polina-c adeb80a
Update end_to_end_test.dart
polina-c d7a0eec
-
polina-c c72d8ec
-
polina-c 8822711
-
polina-c 8344b10
Update _retaining_path.dart
polina-c c9562b8
-
polina-c ac68c5c
-
polina-c b4bf26e
Update _retaining_path_test.dart
polina-c 0f0765b
Update _retaining_path_test.dart
polina-c 9f3aa00
Update _retaining_path_test.dart
polina-c 713feec
-
polina-c b5a084d
Update _retaining_path_test.dart
polina-c f1b84b9
Update _retaining_path_test.dart
polina-c 18be89c
Update _retaining_path_test.dart
polina-c 0c49072
-
polina-c 9d5620f
-
polina-c 982a05e
-
polina-c f4fe7af
-
polina-c 224e572
Update TROUBLESHOOT.md
polina-c 37db89a
Update orchestration.dart
polina-c d2decee
Update TROUBLESHOOT.md
polina-c 735e53f
Update analyze.sh
polina-c File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,12 @@ | |
import 'dart:async'; | ||
import 'dart:developer'; | ||
|
||
import 'package:clock/clock.dart'; | ||
|
||
import '../shared/shared_model.dart'; | ||
import '_formatting.dart'; | ||
import '_gc_counter.dart'; | ||
import 'leak_tracker.dart'; | ||
import 'leak_tracker_model.dart'; | ||
import 'retaining_path/_retaining_path.dart'; | ||
|
||
/// Asynchronous callback. | ||
/// | ||
|
@@ -100,8 +100,8 @@ Future<Leaks> withLeakTracking( | |
await checkNonGCed(); | ||
} | ||
|
||
await _forceGC( | ||
gcCycles: gcCountBuffer, | ||
await forceGC( | ||
fullGcCycles: gcCountBuffer, | ||
timeout: timeoutForFinalGarbageCollection, | ||
); | ||
|
||
|
@@ -124,22 +124,57 @@ Future<Leaks> withLeakTracking( | |
} | ||
|
||
/// Forces garbage collection by aggressive memory allocation. | ||
Future<void> _forceGC({required int gcCycles, Duration? timeout}) async { | ||
final start = clock.now(); | ||
final barrier = reachabilityBarrier; | ||
/// | ||
/// Verifies that garbage collection happened using [reachabilityBarrier]. | ||
/// Does not work in web and in release mode. | ||
/// | ||
/// Use [timeout] to limit waitning time. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: waiting |
||
/// Use [fullGcCycles] to force multiple garbage collections. | ||
/// | ||
/// The methot is useable for testing in combination with [WeakReference] to ensure | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: "method is used" |
||
/// an object is not held by another object from garbage collection. | ||
/// | ||
/// For code example see | ||
/// https://github.com/dart-lang/leak_tracker/blob/main/doc/TROUBLESHOOT.md | ||
Future<void> forceGC({ | ||
Duration? timeout, | ||
int fullGcCycles = 1, | ||
}) async { | ||
final Stopwatch? stopwatch = timeout == null ? null : (Stopwatch()..start()); | ||
final int barrier = reachabilityBarrier; | ||
|
||
final storage = <List<DateTime>>[]; | ||
final List<List<DateTime>> storage = <List<DateTime>>[]; | ||
|
||
void allocateMemory() { | ||
storage.add(Iterable.generate(10000, (_) => DateTime.now()).toList()); | ||
if (storage.length > 100) storage.removeAt(0); | ||
storage.add( | ||
Iterable<DateTime>.generate(10000, (_) => DateTime.now()).toList(), | ||
); | ||
if (storage.length > 100) { | ||
storage.removeAt(0); | ||
} | ||
} | ||
|
||
while (reachabilityBarrier < barrier + gcCycles) { | ||
if (timeout != null && clock.now().difference(start) > timeout) { | ||
while (reachabilityBarrier < barrier + fullGcCycles) { | ||
if ((stopwatch?.elapsed ?? Duration.zero) > (timeout ?? Duration.zero)) { | ||
throw TimeoutException('forceGC timed out', timeout); | ||
} | ||
await Future.delayed(const Duration()); | ||
await Future<void>.delayed(Duration.zero); | ||
allocateMemory(); | ||
} | ||
} | ||
|
||
/// Returns nicely formatted retaining path for the [ref.target]. | ||
/// | ||
/// If the object is garbage collected or not retained, returns null. | ||
/// | ||
/// Does not work in web and in release mode. | ||
Future<String?> formattedRetainingPath(WeakReference ref) async { | ||
if (ref.target == null) return null; | ||
final path = await obtainRetainingPath( | ||
ref.target.runtimeType, | ||
identityHashCode(ref.target), | ||
); | ||
|
||
if (path == null) return null; | ||
return retainingPathToString(path); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ To run them locally: | |
``` | ||
dart test --debug test/dart_debug | ||
``` | ||
|
||
Or click 'Debug' near the test name in your IDE. |
15 changes: 15 additions & 0 deletions
15
pkgs/leak_tracker/test/debug/leak_tracking/orchestration_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// 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/leak_tracker.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
test('formattedRetainingPath returns path', () async { | ||
final Object myObject = <int>[1, 2, 3, 4, 5]; | ||
final path = await formattedRetainingPath(WeakReference(myObject)); | ||
|
||
print(path); | ||
}); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.