-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[flutter_tools] migrate FlutterView to new vm_service #55341
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
[flutter_tools] migrate FlutterView to new vm_service #55341
Conversation
for (final FlutterView flutterView in views) { | ||
final vm_service.Isolate isolate = await vmService | ||
.getIsolate(flutterView.uiIsolate.id) | ||
.catchError((dynamic error, StackTrace stackTrace) { |
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.
I added a catchError field to all of these because it seems like that is what we were doing before:
https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/vmservice.dart#L1035
Though before we might have been re-using invalid isolates, which is probably worse
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.
Would a trace message here be useful?
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.
Also, this pattern is repeated several times, so creating a new method somewhere for this could be a good cleanup.
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.
The previous trace was not useful, since we don't seem to hit this case often.
Updated to an extension method on VmService
} | ||
final List<FlutterView> _views = <FlutterView>[]; | ||
|
||
List<FlutterView> get views { |
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.
Moved the filtering here instead of on VM
String reason, | ||
bool benchmarkMode = false, | ||
}) async { | ||
if (!_isPaused()) { |
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.
I could not find a good justification for keeping the pause check
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.
#9733 fixed flutter/flutter-intellij#969, make sure removing this check doesn't regress that.
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.
Sorry, should have been more clear here:
We have a hot reload test in integration.shard that performs a hot restart while paused and that still passes with this removed. I've also verified locally that this listViews RPC returns successfully while paused:
An Observatory debugger and profiler on Pixel 4 is available at: http://127.0.0.1:50743/Nb1i5jI30FQ=/
Performing hot reload...
The application is paused due in the debugger; interface might not update.
Reloaded 0 of 660 libraries in 107ms.
Performing hot reload...
The application is paused due in the debugger; interface might not update.
Reloaded 0 of 660 libraries in 100ms.
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.
This was most likely a bug in the implementation of listVews. I can do some more research to try and figure out when it was fixed, but for now we should have good coverage
case ServiceEvent.kPauseException: message.write('paused in the debugger after an exception was thrown'); break; | ||
case ServiceEvent.kPausePostRequest: message.write('paused'); break; | ||
case '': message.write('paused for various reasons'); break; | ||
case vm_service.EventKind.kPauseStart: |
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.
Moved statements to different lines, updated constants to point to vm_service
for (final FlutterView flutterView in views) { | ||
final vm_service.Isolate isolate = await vmService | ||
.getIsolate(flutterView.uiIsolate.id) | ||
.catchError((dynamic error, StackTrace stackTrace) { |
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.
Would a trace message here be useful?
for (final FlutterView flutterView in views) { | ||
final vm_service.Isolate isolate = await vmService | ||
.getIsolate(flutterView.uiIsolate.id) | ||
.catchError((dynamic error, StackTrace stackTrace) { |
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.
Also, this pattern is repeated several times, so creating a new method somewhere for this could be a good cleanup.
assert(!view.uiIsolate.pauseEvent.isPauseEvent); | ||
futures.add(vmService.flutterExit( | ||
isolateId: view.uiIsolate.id, | ||
)); |
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.
Regarding the comment below on 282, what would go wrong if we don't wait for flutterExit
to fail?
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.
Its not if it fails its that when it succeeds the engine goes down so there is no signal. I could re-arrange this to instead listen to the vm_service done
signal, that would remove the need for the timeout
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.
Updated the logic to be a bit simpler, and catch any SentinelException (would be thrown if we exited after the app crashed, for example)
})); | ||
final vm_service.VM vm = await device.vmService.getVM(); | ||
for (final vm_service.IsolateRef isolateRef in vm.isolates) { | ||
if (!uiIsolatesIds.contains(isolateRef.id)) { |
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.
Consider flipping the sense of the if
with a continue
under it, and unindenting the rest of the loop body.
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.
Done
// Reload the isolate data. | ||
await Future.wait(<Future<void>>[ | ||
for (final FlutterDevice device in flutterDevices) | ||
device.refreshViews() |
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.
Is device.refreshViews()
now also doing the uiIsolate.reload()
?
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.
Yeah, we only need the isolateRef data so reloading the full isolate isn't necessary (and we do this as needed anyway below)
kind == vm_service.EventKind.kPauseException || | ||
kind == vm_service.EventKind.kPausePostRequest || | ||
kind == vm_service.EventKind.kNone; | ||
} |
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.
MIssing newline at EOF
final Completer<void> sawDebuggerPausedMessage = Completer<void>(); | ||
final StreamSubscription<String> subscription = _flutter.stdout.listen( | ||
(String line) { | ||
print('LOG: $line'); |
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.
stray print?
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.
Fixed
return; | ||
} | ||
await flutterDeprecatedVmService.vm.refreshViews(waitForViews: true); | ||
final List<FlutterView> newViews = await vmService.getFlutterViews(); |
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.
How are they new? Isn't this all of them?
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.
Updated to reflect this is an update of the view list
String reason, | ||
bool benchmarkMode = false, | ||
}) async { | ||
if (!_isPaused()) { |
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.
#9733 fixed flutter/flutter-intellij#969, make sure removing this check doesn't regress that.
|
||
final Stopwatch reloadTimer = Stopwatch()..start(); | ||
|
||
if (!_isPaused()) { |
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.
Same here re: #9733
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.
lgtm
/// been collected. | ||
Future<vm_service.Isolate> getIsolateOrNull(String isolateId) { | ||
return getIsolate(isolateId) | ||
.catchError((dynamic error, StackTrace stackTrace) { |
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.
nit: 2 space indent on a continued line.
This reverts commit 2e50fd7.
Description
Move FlutterView and related RPCs to the package:vm_service implementation. Update some getIsolate calls with catchError to match previous behavior.
VM
toFlutterDevice
#52179
Maybe #55552