-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize leak tracker for better performance. (#106)
- Loading branch information
Showing
40 changed files
with
906 additions
and
719 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// 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.s | ||
|
||
import '../shared/shared_model.dart'; | ||
import '_object_record.dart'; | ||
import '_primitives/model.dart'; | ||
|
||
/// Decides which leaks to report based on allow lists of the phase. | ||
class LeakFilter { | ||
final Map<PhaseSettings, _PhaseLeakFilter> _phases = {}; | ||
|
||
bool shouldReport(LeakType leakType, ObjectRecord record) { | ||
final filter = _phases.putIfAbsent( | ||
record.phase, | ||
() => _PhaseLeakFilter(record.phase), | ||
); | ||
return filter.shouldReport(leakType, record); | ||
} | ||
} | ||
|
||
class _PhaseLeakFilter { | ||
_PhaseLeakFilter(this.phase); | ||
|
||
/// Number of leaks by (object type, leak type) for limited allowlists. | ||
final _count = <(String, LeakType), int>{}; | ||
|
||
final PhaseSettings phase; | ||
|
||
bool shouldReport(LeakType leakType, ObjectRecord record) { | ||
switch (leakType) { | ||
case LeakType.notDisposed: | ||
return _shouldReport( | ||
leakType, | ||
record, | ||
phase.allowAllNotDisposed, | ||
phase.notDisposedAllowList, | ||
); | ||
case LeakType.notGCed: | ||
case LeakType.gcedLate: | ||
return _shouldReport( | ||
leakType, | ||
record, | ||
phase.allowAllNotGCed, | ||
phase.notGCedAllowList, | ||
); | ||
} | ||
} | ||
|
||
bool _shouldReport( | ||
LeakType leakType, | ||
ObjectRecord record, | ||
bool allAllowed, | ||
Map<String, int?> allowList, | ||
) { | ||
assert(record.phase == phase); | ||
if (allAllowed) return false; | ||
final objectType = record.type.toString(); | ||
if (!allowList.containsKey(objectType)) return true; | ||
final allowedCount = allowList[objectType]; | ||
if (allowedCount == null) return false; | ||
|
||
final actualCount = _count.update( | ||
(objectType, leakType), | ||
(value) => value + 1, | ||
ifAbsent: () => 1, | ||
); | ||
|
||
return actualCount > allowedCount; | ||
} | ||
} |
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
2 changes: 2 additions & 0 deletions
2
pkgs/leak_tracker/lib/src/leak_tracking/_primitives/README.md
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,2 @@ | ||
Items (folders or libraries) in this folder do not depend on each other | ||
and on other libraries in `leak_tracking`. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.