Skip to content
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

Enhance scripting. #199

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
# Configuration for .github/workflows/pull_request_label.yml.

'type-infra':
- changed-files:
- any-glob-to-any-file: '.github/**'
- '.github/**'

'package:leak_tracker':
- changed-files:
- any-glob-to-any-file: 'pkgs/leak_tracker/**'
- 'pkgs/leak_tracker/**'

'package:leak_tracker_flutter_testing':
- changed-files:
- any-glob-to-any-file: 'pkgs/leak_tracker_flutter_testing/**'
- 'pkgs/leak_tracker_flutter_testing/**'

'package:leak_tracker_testing':
- changed-files:
- any-glob-to-any-file: 'pkgs/leak_tracker_testing/**'
- 'pkgs/leak_tracker_testing/**'

'package:memory_usage':
- changed-files:
- any-glob-to-any-file: 'pkgs/memory_usage/**'
- 'pkgs/memory_usage/**'
4 changes: 0 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ jobs:
run: dart test
working-directory: pkgs/leak_tracker

- name: dart test
run: dart test
working-directory: pkgs/leak_tracker_testing

- name: flutter test
run: flutter test --enable-vmservice
working-directory: pkgs/leak_tracker_flutter_testing
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull_request_label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9
- uses: actions/labeler@ac9175f8a1f3625fd0d4fb234536d26811351594
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
sync-labels: true
3 changes: 1 addition & 2 deletions examples/leak_tracking/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import 'package:leak_tracker/leak_tracker.dart';

void main() {
LeakTracking.start();
// Dispatch memory events from the Flutter engine to LeakTracking.
FlutterMemoryAllocations.instance.addListener(
MemoryAllocations.instance.addListener(
(ObjectEvent event) => LeakTracking.dispatchObjectEvent(event.toMap()),
);

Expand Down
4 changes: 0 additions & 4 deletions pkgs/leak_tracker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# 10.0.1

* Allow to ignore objects created by test helpers.

## 10.0.0

* Remove `memory_usage`, as it is moved to https://github.com/dart-lang/leak_tracker/tree/main/pkgs/memory_usage.
Expand Down
3 changes: 0 additions & 3 deletions pkgs/leak_tracker/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,3 @@ analyzer:
linter:
rules:
- avoid_print
- comment_references
- only_throw_errors
- unawaited_futures
16 changes: 2 additions & 14 deletions pkgs/leak_tracker/lib/src/leak_tracking/_object_tracker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import 'primitives/_finalizer.dart';
import 'primitives/_gc_counter.dart';
import 'primitives/_retaining_path/_connection.dart';
import 'primitives/_retaining_path/_retaining_path.dart';
import 'primitives/_test_helper_detector.dart';
import 'primitives/model.dart';

/// Keeps collection of object records until
Expand Down Expand Up @@ -63,22 +62,11 @@ class ObjectTracker implements LeakProvider {
throwIfDisposed();
if (phase.ignoreLeaks) return;

StackTrace? stackTrace;

if (phase.ignoredLeaks.createdByTestHelpers) {
stackTrace = StackTrace.current;
if (isCreatedByTestHelper(
stackTrace.toString(),
phase.ignoredLeaks.testHelperExceptions,
)) return;
}

final record =
_objects.notGCed.putIfAbsent(object, context, phase, trackedClass);

if (phase.leakDiagnosticConfig.collectStackTraceOnStart) {
stackTrace ??= StackTrace.current;
record.setContext(ContextKeys.startCallstack, stackTrace);
record.setContext(ContextKeys.startCallstack, StackTrace.current);
}

_finalizer.attach(object, record);
Expand All @@ -101,7 +89,7 @@ class ObjectTracker implements LeakProvider {
void _declareNotDisposedLeak(ObjectRecord record) {
if (record.isGCedLateLeak(disposalTime, numberOfGcCycles)) {
_objects.gcedLateLeaks.add(record);
} else if (!record.isDisposed) {
} else if (record.isNotDisposedLeak) {
_objects.gcedNotDisposedLeaks.add(record);
}

Expand Down

This file was deleted.

30 changes: 2 additions & 28 deletions pkgs/leak_tracker/lib/src/leak_tracking/primitives/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class IgnoredLeaksSet {

const IgnoredLeaksSet.ignore() : this(ignoreAll: true, byClass: const {});

const IgnoredLeaksSet.byClass(Map<String, int?> byClass)
: this(byClass: byClass);
const IgnoredLeaksSet.byClass(this.byClass) : ignoreAll = false;

/// Classes to ignore during leak tracking.
///
Expand Down Expand Up @@ -128,8 +127,6 @@ class IgnoredLeaks {
const IgnoredLeaks({
this.notGCed = const IgnoredLeaksSet(),
this.notDisposed = const IgnoredLeaksSet(),
this.createdByTestHelpers = false,
this.testHelperExceptions = const [],
});

/// Ignore list for notGCed leaks.
Expand All @@ -138,22 +135,6 @@ class IgnoredLeaks {
/// Ignore list for notDisposed leaks.
final IgnoredLeaksSet notDisposed;

/// If true, leaking objects created by test helpers will be ignored.
///
/// An object counts as created by a test helper if the stack trace of
/// start of leak tracking contains a frame, located after the test body
/// frame, that points to the folder `test` or the package `flutter_test`,
/// except:
/// * methods intended to be called from test body like `runAsunc` or `pump`
/// * frames that match [testHelperExceptions]
final bool createdByTestHelpers;

/// Stack frames that match this pattern will not be treated as test helpers.
///
/// Is used to test functionality of
/// the leak tracker.
final List<RegExp> testHelperExceptions;

/// Returns true if the class is ignored.
///
/// If [leakType] is null, returns true if the class is ignored for all
Expand All @@ -180,20 +161,13 @@ class IgnoredLeaks {
}
return other is IgnoredLeaks &&
other.notGCed == notGCed &&
other.notDisposed == notDisposed &&
other.createdByTestHelpers == createdByTestHelpers &&
const DeepCollectionEquality().equals(
other.testHelperExceptions,
testHelperExceptions,
);
other.notDisposed == notDisposed;
}

@override
int get hashCode => Object.hash(
notGCed,
notDisposed,
createdByTestHelpers,
testHelperExceptions,
);
}

Expand Down
17 changes: 0 additions & 17 deletions pkgs/leak_tracker/lib/src/shared/shared_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ class LeakSummary {
class Leaks {
Leaks(this.byType);

Leaks.empty() : this({});

factory Leaks.fromJson(Map<String, dynamic> json) => Leaks(
json.map(
(key, value) => MapEntry(
Expand All @@ -118,21 +116,6 @@ class Leaks {

int get total => byType.values.map((e) => e.length).sum;

late final Map<String?, Leaks> byPhase = () {
final leaks = <String?, Map<LeakType, List<LeakReport>>>{};
for (final entry in byType.entries) {
for (final leak in entry.value) {
leaks
.putIfAbsent(leak.phase, () => {})
.putIfAbsent(entry.key, () => <LeakReport>[])
.add(leak);
}
}
return {
for (final entry in leaks.entries) entry.key: Leaks(entry.value),
};
}();

String toYaml({required bool phasesAreTests}) {
if (total == 0) return '';
final leaks = LeakType.values
Expand Down
2 changes: 1 addition & 1 deletion pkgs/leak_tracker/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: leak_tracker
version: 10.0.1
version: 10.0.0
description: A framework for memory leak tracking for Dart and Flutter applications.
repository: https://github.com/dart-lang/leak_tracker/tree/main/pkgs/leak_tracker

Expand Down
Loading
Loading