Unverified Commit 39ebae2b authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[fuchsia] Fix isolate filter (#30458)

parent 9fe6be8a
...@@ -128,24 +128,18 @@ class DartVm { ...@@ -128,24 +128,18 @@ class DartVm {
/// Returns a [List] of [IsolateRef] objects whose name matches `pattern`. /// Returns a [List] of [IsolateRef] objects whose name matches `pattern`.
/// ///
/// This is not limited to Isolates running Flutter, but to any Isolate on the /// This is not limited to Isolates running Flutter, but to any Isolate on the
/// VM. /// VM. Therefore, the [pattern] argument should be written to exclude
/// /// matching unintended isolates.
/// `includeNonFlutterIsolates` makes sure to add non-flutter Dart isolates,
/// and defaults to `false`.
Future<List<IsolateRef>> getMainIsolatesByPattern( Future<List<IsolateRef>> getMainIsolatesByPattern(
Pattern pattern, { Pattern pattern, {
Duration timeout = _kRpcTimeout, Duration timeout = _kRpcTimeout,
bool includeNonFlutterIsolates = false,
}) async { }) async {
final Map<String, dynamic> jsonVmRef = final Map<String, dynamic> jsonVmRef =
await invokeRpc('getVM', timeout: timeout); await invokeRpc('getVM', timeout: timeout);
final List<IsolateRef> result = <IsolateRef>[]; final List<IsolateRef> result = <IsolateRef>[];
for (Map<String, dynamic> jsonIsolate in jsonVmRef['isolates']) { for (Map<String, dynamic> jsonIsolate in jsonVmRef['isolates']) {
final String name = jsonIsolate['name']; final String name = jsonIsolate['name'];
// `:main()` is included at the end of a flutter isolate, whereas the if (pattern.matchAsPrefix(name) != null) {
// name of a dart Isolate is concluded as if the name were a function.
if (name.contains(pattern) &&
(includeNonFlutterIsolates || name.contains(RegExp(r':main\(\)')))) {
_log.fine('Found Isolate matching "$pattern": "$name"'); _log.fine('Found Isolate matching "$pattern": "$name"');
result.add(IsolateRef._fromJson(jsonIsolate, this)); result.add(IsolateRef._fromJson(jsonIsolate, this));
} }
......
...@@ -289,14 +289,10 @@ class FuchsiaRemoteConnection { ...@@ -289,14 +289,10 @@ class FuchsiaRemoteConnection {
/// If there are no live Dart VM's or the Isolate cannot be found, waits until /// If there are no live Dart VM's or the Isolate cannot be found, waits until
/// either `timeout` is reached, or a Dart VM starts up with a name that /// either `timeout` is reached, or a Dart VM starts up with a name that
/// matches `pattern`. /// matches `pattern`.
///
/// `includeNonFlutterIsolates` can be set to true to include all isolates
/// found instead of just Flutter Isolates.
Future<List<IsolateRef>> getMainIsolatesByPattern( Future<List<IsolateRef>> getMainIsolatesByPattern(
Pattern pattern, { Pattern pattern, {
Duration timeout = _kIsolateFindTimeout, Duration timeout = _kIsolateFindTimeout,
Duration vmConnectionTimeout = _kDartVmConnectionTimeout, Duration vmConnectionTimeout = _kDartVmConnectionTimeout,
bool includeNonFlutterIsolates = false,
}) async { }) async {
// If for some reason there are no Dart VM's that are alive, wait for one to // If for some reason there are no Dart VM's that are alive, wait for one to
// start with the Isolate in question. // start with the Isolate in question.
...@@ -315,10 +311,7 @@ class FuchsiaRemoteConnection { ...@@ -315,10 +311,7 @@ class FuchsiaRemoteConnection {
if (vmService == null) { if (vmService == null) {
continue; continue;
} }
isolates.add(vmService.getMainIsolatesByPattern( isolates.add(vmService.getMainIsolatesByPattern(pattern));
pattern,
includeNonFlutterIsolates: includeNonFlutterIsolates,
));
} }
final List<IsolateRef> result = final List<IsolateRef> result =
await Future.wait<List<IsolateRef>>(isolates) await Future.wait<List<IsolateRef>>(isolates)
......
...@@ -241,7 +241,7 @@ void main() { ...@@ -241,7 +241,7 @@ void main() {
'type': '@Isolate', 'type': '@Isolate',
'fixedId': 'true', 'fixedId': 'true',
'id': 'isolates/3', 'id': 'isolates/3',
'name': 'file://flutterBinary2:main()', 'name': 'flutterBinary.cmx',
'number': '3', 'number': '3',
}, },
<String, dynamic>{ <String, dynamic>{
...@@ -268,13 +268,9 @@ void main() { ...@@ -268,13 +268,9 @@ void main() {
await DartVm.connect(Uri.parse('http://whatever.com/ws')); await DartVm.connect(Uri.parse('http://whatever.com/ws'));
expect(vm, isNot(null)); expect(vm, isNot(null));
final List<IsolateRef> matchingFlutterIsolates = final List<IsolateRef> matchingFlutterIsolates =
await vm.getMainIsolatesByPattern('flutterBinary'); await vm.getMainIsolatesByPattern('flutterBinary.cmx');
expect(matchingFlutterIsolates.length, 1); expect(matchingFlutterIsolates.length, 1);
final List<IsolateRef> allFlutterIsolates = final List<IsolateRef> allIsolates = await vm.getMainIsolatesByPattern('');
await vm.getMainIsolatesByPattern('');
expect(allFlutterIsolates.length, 2);
final List<IsolateRef> allIsolates = await vm.getMainIsolatesByPattern('',
includeNonFlutterIsolates: true);
expect(allIsolates.length, 4); expect(allIsolates.length, 4);
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment