[flutter_tools] reland migrate FlutterViews to package:vm_service (#55797)
Move FlutterView and related RPCs to the package:vm_service implementation. Update some getIsolate calls with catchError to match previous behavior. - Updates tests that were previously mocking FlutterViews to use real views - Moves the FlutterView cache from VM to FlutterDevice - Catch SentinelException during Isolate.kill
This commit is contained in:
@@ -620,13 +620,12 @@ class FuchsiaDevice extends Device {
|
||||
// loopback (::1).
|
||||
final Uri uri = Uri.parse('http://[$_ipv6Loopback]:$port');
|
||||
final VMService vmService = await VMService.connect(uri);
|
||||
await vmService.getVMOld();
|
||||
await vmService.refreshViews();
|
||||
for (final FlutterView flutterView in vmService.vm.views) {
|
||||
final List<FlutterView> flutterViews = await vmService.getFlutterViews();
|
||||
for (final FlutterView flutterView in flutterViews) {
|
||||
if (flutterView.uiIsolate == null) {
|
||||
continue;
|
||||
}
|
||||
final Uri address = flutterView.owner.vmService.httpAddress;
|
||||
final Uri address = vmService.httpAddress;
|
||||
if (flutterView.uiIsolate.name.contains(isolateName)) {
|
||||
return address.port;
|
||||
}
|
||||
@@ -717,13 +716,12 @@ class FuchsiaIsolateDiscoveryProtocol {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
await service.getVMOld();
|
||||
await service.refreshViews();
|
||||
for (final FlutterView flutterView in service.vm.views) {
|
||||
final List<FlutterView> flutterViews = await service.getFlutterViews();
|
||||
for (final FlutterView flutterView in flutterViews) {
|
||||
if (flutterView.uiIsolate == null) {
|
||||
continue;
|
||||
}
|
||||
final Uri address = flutterView.owner.vmService.httpAddress;
|
||||
final Uri address = service.httpAddress;
|
||||
if (flutterView.uiIsolate.name.contains(_isolateName)) {
|
||||
_foundUri.complete(_device.ipv6
|
||||
? Uri.parse('http://[$_ipv6Loopback]:${address.port}/')
|
||||
|
||||
@@ -233,18 +233,25 @@ class FlutterDevice {
|
||||
if (vmService == null) {
|
||||
return;
|
||||
}
|
||||
await flutterDeprecatedVmService.vm.refreshViews(waitForViews: true);
|
||||
final List<FlutterView> updatedViews = await vmService.getFlutterViews();
|
||||
_views
|
||||
..clear()
|
||||
..addAll(updatedViews);
|
||||
}
|
||||
final List<FlutterView> _views = <FlutterView>[];
|
||||
|
||||
List<FlutterView> get views {
|
||||
if (vmService == null || flutterDeprecatedVmService.isClosed) {
|
||||
if (vmService == null) {
|
||||
return <FlutterView>[];
|
||||
}
|
||||
|
||||
|
||||
return (viewFilter != null
|
||||
? flutterDeprecatedVmService.vm.allViewsWithName(viewFilter)
|
||||
: flutterDeprecatedVmService.vm.views).toList();
|
||||
if (viewFilter != null) {
|
||||
return <FlutterView>[
|
||||
for (final FlutterView flutterView in _views)
|
||||
if (flutterView.uiIsolate.name.contains(viewFilter))
|
||||
flutterView
|
||||
];
|
||||
}
|
||||
return _views;
|
||||
}
|
||||
|
||||
Future<void> getVMs() => flutterDeprecatedVmService.getVMOld();
|
||||
@@ -254,35 +261,32 @@ class FlutterDevice {
|
||||
await device.stopApp(package);
|
||||
return;
|
||||
}
|
||||
final List<FlutterView> flutterViews = views;
|
||||
if (flutterViews == null || flutterViews.isEmpty) {
|
||||
await refreshViews();
|
||||
if (views == null || views.isEmpty) {
|
||||
return;
|
||||
}
|
||||
// If any of the flutter views are paused, we might not be able to
|
||||
// cleanly exit since the service extension may not have been registered.
|
||||
if (flutterViews.any((FlutterView view) {
|
||||
return view != null &&
|
||||
view.uiIsolate != null &&
|
||||
view.uiIsolate.pauseEvent != null &&
|
||||
view.uiIsolate.pauseEvent.isPauseEvent;
|
||||
for (final FlutterView flutterView in views) {
|
||||
final vm_service.Isolate isolate = await vmService
|
||||
.getIsolateOrNull(flutterView.uiIsolate.id);
|
||||
if (isolate == null) {
|
||||
continue;
|
||||
}
|
||||
if (isPauseEvent(isolate.pauseEvent.kind)) {
|
||||
await device.stopApp(package);
|
||||
return;
|
||||
}
|
||||
)) {
|
||||
await device.stopApp(package);
|
||||
return;
|
||||
}
|
||||
final List<Future<void>> futures = <Future<void>>[];
|
||||
for (final FlutterView view in flutterViews) {
|
||||
for (final FlutterView view in views) {
|
||||
if (view != null && view.uiIsolate != null) {
|
||||
assert(!view.uiIsolate.pauseEvent.isPauseEvent);
|
||||
futures.add(vmService.flutterExit(
|
||||
// If successful, there will be no response from flutterExit.
|
||||
unawaited(vmService.flutterExit(
|
||||
isolateId: view.uiIsolate.id,
|
||||
));
|
||||
}
|
||||
}
|
||||
// The flutterExit message only returns if it fails, so just wait a few
|
||||
// seconds then assume it worked.
|
||||
// TODO(ianh): We should make this return once the VM service disconnects.
|
||||
await Future.wait(futures).timeout(const Duration(seconds: 2), onTimeout: () => <void>[]);
|
||||
return vmService.onDone;
|
||||
}
|
||||
|
||||
Future<Uri> setupDevFS(
|
||||
|
||||
@@ -514,10 +514,8 @@ class HotRunner extends ResidentRunner {
|
||||
String reason,
|
||||
bool benchmarkMode = false,
|
||||
}) async {
|
||||
if (!_isPaused()) {
|
||||
globals.printTrace('Refreshing active FlutterViews before restarting.');
|
||||
await refreshViews();
|
||||
}
|
||||
globals.printTrace('Refreshing active FlutterViews before restarting.');
|
||||
await refreshViews();
|
||||
|
||||
final Stopwatch restartTimer = Stopwatch()..start();
|
||||
// TODO(aam): Add generator reset logic once we switch to using incremental
|
||||
@@ -542,31 +540,36 @@ class HotRunner extends ResidentRunner {
|
||||
// Check if the isolate is paused and resume it.
|
||||
final List<Future<void>> operations = <Future<void>>[];
|
||||
for (final FlutterDevice device in flutterDevices) {
|
||||
final Set<Isolate> uiIsolates = <Isolate>{};
|
||||
final Set<String> uiIsolatesIds = <String>{};
|
||||
for (final FlutterView view in device.views) {
|
||||
if (view.uiIsolate == null) {
|
||||
continue;
|
||||
}
|
||||
uiIsolates.add(view.uiIsolate);
|
||||
uiIsolatesIds.add(view.uiIsolate.id);
|
||||
// Reload the isolate.
|
||||
operations.add(view.uiIsolate.reload().then((ServiceObject _) {
|
||||
final ServiceEvent pauseEvent = view.uiIsolate.pauseEvent;
|
||||
if ((pauseEvent != null) && pauseEvent.isPauseEvent) {
|
||||
final Future<vm_service.Isolate> reloadIsolate = device.vmService
|
||||
.getIsolateOrNull(view.uiIsolate.id);
|
||||
operations.add(reloadIsolate.then((vm_service.Isolate isolate) async {
|
||||
if ((isolate != null) && isPauseEvent(isolate.pauseEvent.kind)) {
|
||||
// Resume the isolate so that it can be killed by the embedder.
|
||||
return device.vmService.resume(view.uiIsolate.id);
|
||||
await device.vmService.resume(view.uiIsolate.id);
|
||||
}
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
|
||||
// The engine handles killing and recreating isolates that it has spawned
|
||||
// ("uiIsolates"). The isolates that were spawned from these uiIsolates
|
||||
// will not be restared, and so they must be manually killed.
|
||||
for (final Isolate isolate in device?.flutterDeprecatedVmService?.vm?.isolates ?? <Isolate>[]) {
|
||||
if (!uiIsolates.contains(isolate)) {
|
||||
operations.add(isolate.invokeRpcRaw('kill', params: <String, dynamic>{
|
||||
'isolateId': isolate.id,
|
||||
}));
|
||||
final vm_service.VM vm = await device.vmService.getVM();
|
||||
for (final vm_service.IsolateRef isolateRef in vm.isolates) {
|
||||
if (uiIsolatesIds.contains(isolateRef.id)) {
|
||||
continue;
|
||||
}
|
||||
operations.add(device.vmService.kill(isolateRef.id)
|
||||
.catchError((dynamic error, StackTrace stackTrace) {
|
||||
// Do nothing on a SentinelException since it means the isolate
|
||||
// has already been killed.
|
||||
}, test: (dynamic error) => error is vm_service.SentinelException));
|
||||
}
|
||||
}
|
||||
await Future.wait(operations);
|
||||
@@ -589,13 +592,11 @@ class HotRunner extends ResidentRunner {
|
||||
} on vm_service.RPCError {
|
||||
// Do nothing, we're already subcribed.
|
||||
}
|
||||
for (final FlutterView view in device.views) {
|
||||
isolateNotifications.add(
|
||||
view.owner.vm.vmService.onIsolateEvent.firstWhere((vm_service.Event event) {
|
||||
return event.kind == vm_service.EventKind.kIsolateRunnable;
|
||||
}),
|
||||
);
|
||||
}
|
||||
isolateNotifications.add(
|
||||
device.vmService.onIsolateEvent.firstWhere((vm_service.Event event) {
|
||||
return event.kind == vm_service.EventKind.kIsolateRunnable;
|
||||
}),
|
||||
);
|
||||
}
|
||||
await Future.wait(isolateNotifications);
|
||||
}
|
||||
@@ -818,11 +819,9 @@ class HotRunner extends ResidentRunner {
|
||||
|
||||
final Stopwatch reloadTimer = Stopwatch()..start();
|
||||
|
||||
if (!_isPaused()) {
|
||||
globals.printTrace('Refreshing active FlutterViews before reloading.');
|
||||
await refreshVM();
|
||||
await refreshViews();
|
||||
}
|
||||
globals.printTrace('Refreshing active FlutterViews before reloading.');
|
||||
await refreshVM();
|
||||
await refreshViews();
|
||||
|
||||
final Stopwatch devFSTimer = Stopwatch()..start();
|
||||
final UpdateFSReport updatedDevFS = await _updateDevFS();
|
||||
@@ -914,27 +913,19 @@ class HotRunner extends ResidentRunner {
|
||||
// Record time it took for the VM to reload the sources.
|
||||
_addBenchmarkData('hotReloadVMReloadMilliseconds', vmReloadTimer.elapsed.inMilliseconds);
|
||||
final Stopwatch reassembleTimer = Stopwatch()..start();
|
||||
// Reload the isolate.
|
||||
final List<Future<void>> allDevices = <Future<void>>[];
|
||||
for (final FlutterDevice device in flutterDevices) {
|
||||
globals.printTrace('Sending reload events to ${device.device.name}');
|
||||
final List<Future<ServiceObject>> futuresViews = <Future<ServiceObject>>[];
|
||||
for (final FlutterView view in device.views) {
|
||||
globals.printTrace('Sending reload event to "${view.uiIsolate.name}"');
|
||||
futuresViews.add(view.uiIsolate.reload());
|
||||
}
|
||||
allDevices.add(Future.wait(futuresViews).whenComplete(() {
|
||||
return device.refreshViews();
|
||||
}));
|
||||
}
|
||||
await Future.wait(allDevices);
|
||||
|
||||
// Reload the isolate data.
|
||||
await Future.wait(<Future<void>>[
|
||||
for (final FlutterDevice device in flutterDevices)
|
||||
device.refreshViews()
|
||||
]);
|
||||
|
||||
globals.printTrace('Evicting dirty assets');
|
||||
await _evictDirtyAssets();
|
||||
|
||||
// Check if any isolates are paused and reassemble those
|
||||
// that aren't.
|
||||
final List<FlutterView> reassembleViews = <FlutterView>[];
|
||||
final Map<FlutterView, vm_service.VmService> reassembleViews = <FlutterView, vm_service.VmService>{};
|
||||
final List<Future<void>> reassembleFutures = <Future<void>>[];
|
||||
String serviceEventKind;
|
||||
int pausedIsolatesFound = 0;
|
||||
@@ -943,8 +934,12 @@ class HotRunner extends ResidentRunner {
|
||||
for (final FlutterView view in device.views) {
|
||||
// Check if the isolate is paused, and if so, don't reassemble. Ignore the
|
||||
// PostPauseEvent event - the client requesting the pause will resume the app.
|
||||
final ServiceEvent pauseEvent = view.uiIsolate.pauseEvent;
|
||||
if (pauseEvent != null && pauseEvent.isPauseEvent && pauseEvent.kind != ServiceEvent.kPausePostRequest) {
|
||||
final vm_service.Isolate isolate = await device.vmService
|
||||
.getIsolateOrNull(view.uiIsolate.id);
|
||||
final vm_service.Event pauseEvent = isolate?.pauseEvent;
|
||||
if (pauseEvent != null
|
||||
&& isPauseEvent(pauseEvent.kind)
|
||||
&& pauseEvent.kind != vm_service.EventKind.kPausePostRequest) {
|
||||
pausedIsolatesFound += 1;
|
||||
if (serviceEventKind == null) {
|
||||
serviceEventKind = pauseEvent.kind;
|
||||
@@ -952,7 +947,7 @@ class HotRunner extends ResidentRunner {
|
||||
serviceEventKind = ''; // many kinds
|
||||
}
|
||||
} else {
|
||||
reassembleViews.add(view);
|
||||
reassembleViews[view] = device.vmService;
|
||||
reassembleFutures.add(device.vmService.flutterReassemble(
|
||||
isolateId: view.uiIsolate.id,
|
||||
).catchError((dynamic error) {
|
||||
@@ -974,6 +969,7 @@ class HotRunner extends ResidentRunner {
|
||||
assert(reassembleViews.isNotEmpty);
|
||||
|
||||
globals.printTrace('Reassembling application');
|
||||
|
||||
final Future<void> reassembleFuture = Future.wait<void>(reassembleFutures);
|
||||
await reassembleFuture.timeout(
|
||||
const Duration(seconds: 2),
|
||||
@@ -986,14 +982,17 @@ class HotRunner extends ResidentRunner {
|
||||
globals.printTrace('This is taking a long time; will now check for paused isolates.');
|
||||
int postReloadPausedIsolatesFound = 0;
|
||||
String serviceEventKind;
|
||||
for (final FlutterView view in reassembleViews) {
|
||||
await view.uiIsolate.reload();
|
||||
final ServiceEvent pauseEvent = view.uiIsolate.pauseEvent;
|
||||
if (pauseEvent != null && pauseEvent.isPauseEvent) {
|
||||
for (final FlutterView view in reassembleViews.keys) {
|
||||
final vm_service.Isolate isolate = await reassembleViews[view]
|
||||
.getIsolateOrNull(view.uiIsolate.id);
|
||||
if (isolate == null) {
|
||||
continue;
|
||||
}
|
||||
if (isolate.pauseEvent != null && isPauseEvent(isolate.pauseEvent.kind)) {
|
||||
postReloadPausedIsolatesFound += 1;
|
||||
if (serviceEventKind == null) {
|
||||
serviceEventKind = pauseEvent.kind;
|
||||
} else if (serviceEventKind != pauseEvent.kind) {
|
||||
serviceEventKind = isolate.pauseEvent.kind;
|
||||
} else if (serviceEventKind != isolate.pauseEvent.kind) {
|
||||
serviceEventKind = ''; // many kinds
|
||||
}
|
||||
}
|
||||
@@ -1069,32 +1068,33 @@ class HotRunner extends ResidentRunner {
|
||||
}
|
||||
assert(serviceEventKind != null);
|
||||
switch (serviceEventKind) {
|
||||
case ServiceEvent.kPauseStart: message.write('paused (probably due to --start-paused)'); break;
|
||||
case ServiceEvent.kPauseExit: message.write('paused because ${ plural ? 'they have' : 'it has' } terminated'); break;
|
||||
case ServiceEvent.kPauseBreakpoint: message.write('paused in the debugger on a breakpoint'); break;
|
||||
case ServiceEvent.kPauseInterrupted: message.write('paused due in the debugger'); break;
|
||||
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:
|
||||
message.write('paused (probably due to --start-paused)');
|
||||
break;
|
||||
case vm_service.EventKind.kPauseExit:
|
||||
message.write('paused because ${ plural ? 'they have' : 'it has' } terminated');
|
||||
break;
|
||||
case vm_service.EventKind.kPauseBreakpoint:
|
||||
message.write('paused in the debugger on a breakpoint');
|
||||
break;
|
||||
case vm_service.EventKind.kPauseInterrupted:
|
||||
message.write('paused due in the debugger');
|
||||
break;
|
||||
case vm_service.EventKind.kPauseException:
|
||||
message.write('paused in the debugger after an exception was thrown');
|
||||
break;
|
||||
case vm_service.EventKind.kPausePostRequest:
|
||||
message.write('paused');
|
||||
break;
|
||||
case '':
|
||||
message.write('paused for various reasons');
|
||||
break;
|
||||
default:
|
||||
message.write('paused');
|
||||
}
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
bool _isPaused() {
|
||||
for (final FlutterDevice device in flutterDevices) {
|
||||
for (final FlutterView view in device.views) {
|
||||
if (view.uiIsolate != null) {
|
||||
final ServiceEvent pauseEvent = view.uiIsolate.pauseEvent;
|
||||
if (pauseEvent != null && pauseEvent.isPauseEvent) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
void printHelp({ @required bool details }) {
|
||||
@@ -1134,7 +1134,7 @@ class HotRunner extends ResidentRunner {
|
||||
}
|
||||
for (final String assetPath in device.devFS.assetPathsToEvict) {
|
||||
futures.add(
|
||||
device.views.first.uiIsolate.vmService
|
||||
device.vmService
|
||||
.flutterEvictAsset(
|
||||
assetPath,
|
||||
isolateId: device.views.first.uiIsolate.id,
|
||||
|
||||
@@ -53,8 +53,9 @@ class Tracing {
|
||||
}
|
||||
});
|
||||
bool done = false;
|
||||
for (final FlutterView view in vmService.vm.views) {
|
||||
if (await view.uiIsolate.vmService
|
||||
final List<FlutterView> views = await vmService.getFlutterViews();
|
||||
for (final FlutterView view in views) {
|
||||
if (await vmService
|
||||
.flutterAlreadyPaintedFirstUsefulFrame(
|
||||
isolateId: view.uiIsolate.id,
|
||||
)) {
|
||||
|
||||
@@ -19,6 +19,7 @@ const String kGetSkSLsMethod = '_flutter.getSkSLs';
|
||||
const String kSetAssetBundlePathMethod = '_flutter.setAssetBundlePath';
|
||||
const String kFlushUIThreadTasksMethod = '_flutter.flushUIThreadTasks';
|
||||
const String kRunInViewMethod = '_flutter.runInView';
|
||||
const String kListViewsMethod = '_flutter.listViews';
|
||||
|
||||
/// The error response code from an unrecoverable compilation failure.
|
||||
const int kIsolateReloadBarred = 1005;
|
||||
@@ -509,10 +510,10 @@ class VMService implements vm_service.VmService {
|
||||
// getFromMap creates the Isolate if necessary.
|
||||
final Isolate isolate = vm.getFromMap(eventIsolate) as Isolate;
|
||||
event = ServiceObject._fromMap(isolate, eventData) as ServiceEvent;
|
||||
if (event.kind == ServiceEvent.kIsolateExit) {
|
||||
if (event.kind == vm_service.EventKind.kIsolateExit) {
|
||||
vm._isolateCache.remove(isolate.id);
|
||||
vm._buildIsolateList();
|
||||
} else if (event.kind == ServiceEvent.kIsolateRunnable) {
|
||||
} else if (event.kind == vm_service.EventKind.kIsolateRunnable) {
|
||||
// Force reload once the isolate becomes runnable so that we
|
||||
// update the root library.
|
||||
isolate.reload();
|
||||
@@ -532,8 +533,6 @@ class VMService implements vm_service.VmService {
|
||||
/// Reloads the VM.
|
||||
Future<void> getVMOld() async => await vm.reload();
|
||||
|
||||
Future<void> refreshViews({ bool waitForViews = false }) => vm.refreshViews(waitForViews: waitForViews);
|
||||
|
||||
Future<void> close() async {
|
||||
_delegateService?.dispose();
|
||||
}
|
||||
@@ -555,6 +554,21 @@ class VMService implements vm_service.VmService {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<vm_service.Isolate> getIsolate(String isolateId) {
|
||||
return _delegateService.getIsolate(isolateId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<vm_service.Success> resume(String isolateId, {String step, int frameIndex}) {
|
||||
return _delegateService.resume(isolateId, step: step, frameIndex: frameIndex);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<vm_service.Success> kill(String isolateId) {
|
||||
return _delegateService.kill(isolateId);
|
||||
}
|
||||
|
||||
// To enable a gradual migration to package:vm_service
|
||||
@override
|
||||
dynamic noSuchMethod(Invocation invocation) {
|
||||
@@ -644,9 +658,6 @@ abstract class ServiceObject {
|
||||
case 'Event':
|
||||
serviceObject = ServiceEvent._empty(owner);
|
||||
break;
|
||||
case 'FlutterView':
|
||||
serviceObject = FlutterView._empty(owner.vm);
|
||||
break;
|
||||
case 'Isolate':
|
||||
serviceObject = Isolate._empty(owner.vm);
|
||||
break;
|
||||
@@ -790,34 +801,6 @@ class ServiceEvent extends ServiceObject {
|
||||
String _message;
|
||||
String get message => _message;
|
||||
|
||||
// The possible 'kind' values.
|
||||
static const String kVMUpdate = 'VMUpdate';
|
||||
static const String kIsolateStart = 'IsolateStart';
|
||||
static const String kIsolateRunnable = 'IsolateRunnable';
|
||||
static const String kIsolateExit = 'IsolateExit';
|
||||
static const String kIsolateUpdate = 'IsolateUpdate';
|
||||
static const String kIsolateReload = 'IsolateReload';
|
||||
static const String kIsolateSpawn = 'IsolateSpawn';
|
||||
static const String kServiceExtensionAdded = 'ServiceExtensionAdded';
|
||||
static const String kPauseStart = 'PauseStart';
|
||||
static const String kPauseExit = 'PauseExit';
|
||||
static const String kPauseBreakpoint = 'PauseBreakpoint';
|
||||
static const String kPauseInterrupted = 'PauseInterrupted';
|
||||
static const String kPauseException = 'PauseException';
|
||||
static const String kPausePostRequest = 'PausePostRequest';
|
||||
static const String kNone = 'None';
|
||||
static const String kResume = 'Resume';
|
||||
static const String kBreakpointAdded = 'BreakpointAdded';
|
||||
static const String kBreakpointResolved = 'BreakpointResolved';
|
||||
static const String kBreakpointRemoved = 'BreakpointRemoved';
|
||||
static const String kGraph = '_Graph';
|
||||
static const String kGC = 'GC';
|
||||
static const String kInspect = 'Inspect';
|
||||
static const String kDebuggerSettingsUpdate = '_DebuggerSettingsUpdate';
|
||||
static const String kConnectionClosed = 'ConnectionClosed';
|
||||
static const String kLogging = '_Logging';
|
||||
static const String kExtension = 'Extension';
|
||||
|
||||
@override
|
||||
void _update(Map<String, dynamic> map, bool mapIsRef) {
|
||||
_loaded = true;
|
||||
@@ -842,16 +825,6 @@ class ServiceEvent extends ServiceObject {
|
||||
_message = utf8.decode(base64.decode(base64Bytes)).trim();
|
||||
}
|
||||
}
|
||||
|
||||
bool get isPauseEvent {
|
||||
return kind == kPauseStart ||
|
||||
kind == kPauseExit ||
|
||||
kind == kPauseBreakpoint ||
|
||||
kind == kPauseInterrupted ||
|
||||
kind == kPauseException ||
|
||||
kind == kPausePostRequest ||
|
||||
kind == kNone;
|
||||
}
|
||||
}
|
||||
|
||||
/// A ServiceObjectOwner is either a [VM] or an [Isolate]. Owners can cache
|
||||
@@ -917,9 +890,6 @@ class VM extends ServiceObjectOwner {
|
||||
/// The list of live isolates, ordered by isolate start time.
|
||||
final List<Isolate> isolates = <Isolate>[];
|
||||
|
||||
/// The set of live views.
|
||||
final Map<String, FlutterView> _viewCache = <String, FlutterView>{};
|
||||
|
||||
/// The number of bytes allocated (e.g. by malloc) in the native heap.
|
||||
int _heapAllocatedMemoryUsage;
|
||||
int get heapAllocatedMemoryUsage => _heapAllocatedMemoryUsage ?? 0;
|
||||
@@ -1008,16 +978,6 @@ class VM extends ServiceObjectOwner {
|
||||
isolate.updateFromMap(map);
|
||||
}
|
||||
return isolate;
|
||||
case 'FlutterView':
|
||||
FlutterView view = _viewCache[mapId];
|
||||
if (view == null) {
|
||||
// Add new view to the cache.
|
||||
view = ServiceObject._fromMap(this, map) as FlutterView;
|
||||
_viewCache[mapId] = view;
|
||||
} else {
|
||||
view.updateFromMap(map);
|
||||
}
|
||||
return view;
|
||||
default:
|
||||
// If we don't have a model object for this service object type, as a
|
||||
// fallback return a ServiceMap object.
|
||||
@@ -1094,47 +1054,6 @@ class VM extends ServiceObjectOwner {
|
||||
Future<Map<String, dynamic>> getVMTimeline() {
|
||||
return invokeRpcRaw('getVMTimeline');
|
||||
}
|
||||
|
||||
Future<void> refreshViews({ bool waitForViews = false }) async {
|
||||
assert(waitForViews != null);
|
||||
assert(loaded);
|
||||
if (!isFlutterEngine) {
|
||||
return;
|
||||
}
|
||||
int failCount = 0;
|
||||
while (true) {
|
||||
_viewCache.clear();
|
||||
// When the future returned by invokeRpc() below returns,
|
||||
// the _viewCache will have been updated.
|
||||
// This message updates all the views of every isolate.
|
||||
await vmService.vm.invokeRpc<ServiceObject>(
|
||||
'_flutter.listViews', truncateLogs: false);
|
||||
if (_viewCache.values.isNotEmpty || !waitForViews) {
|
||||
return;
|
||||
}
|
||||
failCount += 1;
|
||||
if (failCount == 5) { // waited 200ms
|
||||
globals.printStatus('Flutter is taking longer than expected to report its views. Still trying...');
|
||||
}
|
||||
await Future<void>.delayed(const Duration(milliseconds: 50));
|
||||
await reload();
|
||||
}
|
||||
}
|
||||
|
||||
Iterable<FlutterView> get views => _viewCache.values;
|
||||
|
||||
FlutterView get firstView {
|
||||
return _viewCache.values.isEmpty ? null : _viewCache.values.first;
|
||||
}
|
||||
|
||||
List<FlutterView> allViewsWithName(String isolateFilter) {
|
||||
if (_viewCache.values.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
return _viewCache.values.where(
|
||||
(FlutterView v) => v.uiIsolate.name.contains(isolateFilter)
|
||||
).toList();
|
||||
}
|
||||
}
|
||||
|
||||
/// An isolate running inside the VM. Instances of the Isolate class are always
|
||||
@@ -1284,23 +1203,39 @@ class ServiceMap extends ServiceObject implements Map<String, dynamic> {
|
||||
}
|
||||
|
||||
/// Peered to an Android/iOS FlutterView widget on a device.
|
||||
class FlutterView extends ServiceObject {
|
||||
FlutterView._empty(ServiceObjectOwner owner) : super._empty(owner);
|
||||
class FlutterView {
|
||||
FlutterView({
|
||||
@required this.id,
|
||||
@required this.uiIsolate,
|
||||
});
|
||||
|
||||
Isolate _uiIsolate;
|
||||
Isolate get uiIsolate => _uiIsolate;
|
||||
|
||||
@override
|
||||
void _update(Map<String, dynamic> map, bool mapIsRef) {
|
||||
_loaded = !mapIsRef;
|
||||
_upgradeCollection(map, owner);
|
||||
_uiIsolate = map['isolate'] as Isolate;
|
||||
factory FlutterView.parse(Map<String, Object> json) {
|
||||
final Map<String, Object> rawIsolate = json['isolate'] as Map<String, Object>;
|
||||
vm_service.IsolateRef isolate;
|
||||
if (rawIsolate != null) {
|
||||
rawIsolate['number'] = rawIsolate['number']?.toString();
|
||||
isolate = vm_service.IsolateRef.parse(rawIsolate);
|
||||
}
|
||||
return FlutterView(
|
||||
id: json['id'] as String,
|
||||
uiIsolate: isolate,
|
||||
);
|
||||
}
|
||||
|
||||
bool get hasIsolate => _uiIsolate != null;
|
||||
final vm_service.IsolateRef uiIsolate;
|
||||
final String id;
|
||||
|
||||
bool get hasIsolate => uiIsolate != null;
|
||||
|
||||
@override
|
||||
String toString() => id;
|
||||
|
||||
Map<String, Object> toJson() {
|
||||
return <String, Object>{
|
||||
'id': id,
|
||||
'isolate': uiIsolate?.toJson(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// Flutter specific VM Service functionality.
|
||||
@@ -1532,13 +1467,15 @@ extension FlutterVmService on vm_service.VmService {
|
||||
///
|
||||
/// This method is only supported by certain embedders. This is
|
||||
/// described by [Device.supportsFlutterExit].
|
||||
Future<Map<String, dynamic>> flutterExit({
|
||||
Future<void> flutterExit({
|
||||
@required String isolateId,
|
||||
}) {
|
||||
return invokeFlutterExtensionRpcRaw(
|
||||
'ext.flutter.exit',
|
||||
isolateId: isolateId,
|
||||
);
|
||||
).catchError((dynamic error, StackTrace stackTrace) {
|
||||
// Do nothing on sentinel or exception, the isolate already exited.
|
||||
}, test: (dynamic error) => error is vm_service.SentinelException || error is vm_service.RPCError);
|
||||
}
|
||||
|
||||
/// Return the current platform override for the flutter view running with
|
||||
@@ -1588,4 +1525,37 @@ extension FlutterVmService on vm_service.VmService {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
/// List all [FlutterView]s attached to the current VM.
|
||||
Future<List<FlutterView>> getFlutterViews() async {
|
||||
final vm_service.Response response = await callMethod(
|
||||
kListViewsMethod,
|
||||
);
|
||||
final List<Object> rawViews = response.json['views'] as List<Object>;
|
||||
return <FlutterView>[
|
||||
for (final Object rawView in rawViews)
|
||||
FlutterView.parse(rawView as Map<String, Object>)
|
||||
];
|
||||
}
|
||||
|
||||
/// Attempt to retrieve the isolate with id [isolateId], or `null` if it has
|
||||
/// been collected.
|
||||
Future<vm_service.Isolate> getIsolateOrNull(String isolateId) {
|
||||
return getIsolate(isolateId)
|
||||
.catchError((dynamic error, StackTrace stackTrace) {
|
||||
return null;
|
||||
}, test: (dynamic error) => error is vm_service.SentinelException);
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the event attached to an [Isolate.pauseEvent] should be considered
|
||||
/// a "pause" event.
|
||||
bool isPauseEvent(String kind) {
|
||||
return kind == vm_service.EventKind.kPauseStart ||
|
||||
kind == vm_service.EventKind.kPauseExit ||
|
||||
kind == vm_service.EventKind.kPauseBreakpoint ||
|
||||
kind == vm_service.EventKind.kPauseInterrupted ||
|
||||
kind == vm_service.EventKind.kPauseException ||
|
||||
kind == vm_service.EventKind.kPausePostRequest ||
|
||||
kind == vm_service.EventKind.kNone;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user