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

Separate web implementation for retaining path. #183

Merged
merged 2 commits into from
Nov 13, 2023
Merged
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
4 changes: 4 additions & 0 deletions pkgs/leak_tracker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 9.0.16

* Stub web implementation for retaining path to serve G3.

## 9.0.15

* Fix: debug information should not wipe other settings.
Expand Down
1 change: 1 addition & 0 deletions pkgs/leak_tracker/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ analyzer:
linter:
rules:
- avoid_catching_errors
- avoid_print
- comment_references
- only_throw_errors
2 changes: 2 additions & 0 deletions pkgs/leak_tracker/lib/src/leak_tracking/_baseliner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// 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.

// ignore_for_file: avoid_print

import 'dart:io';

import 'primitives/_print_bytes.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,15 @@ class ObjectTracker implements LeakProvider {
}

@override
Future<void> checkNonGCed() async {
Future<void> checkNotGCed() async {
throwIfDisposed();
await _checkForNewNotGCedLeaks();
}

@override
Future<Leaks> collectLeaks() async {
throwIfDisposed();

await _checkForNewNotGCedLeaks();

final result = Leaks({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ abstract class LeakTracking {
Future<void>? result;

assert(() {
result = _leakTracker?.objectTracker.checkNonGCed();
result = _leakTracker?.objectTracker.checkNotGCed();
return true;
}());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
// 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:developer';
import 'dart:isolate';
import 'package:vm_service/vm_service.dart';

import 'package:vm_service/vm_service.dart' hide Isolate;
import '_retaining_path_web.dart'
if (dart.library.isolate) '_retaining_path_isolate.dart';

/// Returns retaining path for an object, if it can be detected.
///
Expand All @@ -16,28 +15,5 @@ Future<RetainingPath?> retainingPath(
VmService service,
Object? object,
) async {
if (object == null) return null;

final objRef = Service.getObjectId(object);

if (objRef == null) return null;

try {
// ignore: sdk_version_since
final isolateId = Service.getIsolateId(Isolate.current);

if (isolateId == null) {
return null;
}

final result = await service.getRetainingPath(
isolateId,
objRef,
100000,
);

return result;
} on SentinelException {
return null;
}
return retainingPathImpl(service, object);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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:developer';
import 'dart:isolate';

import 'package:vm_service/vm_service.dart' hide Isolate;

/// Returns retaining path for an object, if it can be detected.
///
/// If [object] is null or object reference cannot be obtained or isolate cannot be obtained,
/// returns null.
Future<RetainingPath?> retainingPathImpl(
VmService service,
Object? object,
) async {
if (object == null) return null;

final objRef = Service.getObjectId(object);

if (objRef == null) return null;

try {
// ignore: sdk_version_since
final isolateId = Service.getIsolateId(Isolate.current);

if (isolateId == null) {
return null;
}

final result = await service.getRetainingPath(
isolateId,
objRef,
100000,
);

return result;
} on SentinelException {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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 'package:vm_service/vm_service.dart';

/// Returns retaining path for an object, if it can be detected.
///
/// If [object] is null or object reference cannot be obtained or isolate cannot be obtained,
/// returns null.
Future<RetainingPath?> retainingPathImpl(
VmService service,
Object? object,
) async {
return null;
}
2 changes: 1 addition & 1 deletion pkgs/leak_tracker/lib/src/shared/shared_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class _JsonFields {
abstract class LeakProvider {
Future<LeakSummary> leaksSummary();
Future<Leaks> collectLeaks();
Future<void> checkNonGCed();
Future<void> checkNotGCed();
}

/// Statistical information about found leaks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,5 @@ class _MockLeakProvider implements LeakProvider {
Future<Leaks> collectLeaks() async => throw UnimplementedError();

@override
Future<void> checkNonGCed() => throw UnimplementedError();
Future<void> checkNotGCed() => throw UnimplementedError();
}
1 change: 1 addition & 0 deletions pkgs/leak_tracker_flutter_testing/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ analyzer:
linter:
rules:
- avoid_catching_errors
- avoid_print
- comment_references
- only_throw_errors
1 change: 1 addition & 0 deletions pkgs/leak_tracker_testing/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ analyzer:
linter:
rules:
- avoid_catching_errors
- avoid_print
- comment_references
- only_throw_errors