Unverified Commit edd4c620 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

prevent stream notifications from interfering with reload (#29467)

parent 03900bc8
...@@ -215,7 +215,7 @@ class HotRunner extends ResidentRunner { ...@@ -215,7 +215,7 @@ class HotRunner extends ResidentRunner {
printStatus('Running in benchmark mode.'); printStatus('Running in benchmark mode.');
// Measure time to perform a hot restart. // Measure time to perform a hot restart.
printStatus('Benchmarking hot restart'); printStatus('Benchmarking hot restart');
await restart(fullRestart: true); await restart(fullRestart: true, benchmarkMode: true);
printStatus('Benchmarking hot reload'); printStatus('Benchmarking hot reload');
// Measure time to perform a hot reload. // Measure time to perform a hot reload.
await restart(fullRestart: false); await restart(fullRestart: false);
...@@ -402,7 +402,7 @@ class HotRunner extends ResidentRunner { ...@@ -402,7 +402,7 @@ class HotRunner extends ResidentRunner {
} }
Future<OperationResult> _restartFromSources({ String reason }) async { Future<OperationResult> _restartFromSources({ String reason, bool benchmarkMode = false }) async {
final Map<String, String> analyticsParameters = final Map<String, String> analyticsParameters =
reason == null reason == null
? null ? null
...@@ -465,6 +465,25 @@ class HotRunner extends ResidentRunner { ...@@ -465,6 +465,25 @@ class HotRunner extends ResidentRunner {
restartTimer.elapsed.inMilliseconds); restartTimer.elapsed.inMilliseconds);
flutterUsage.sendEvent('hot', 'restart', parameters: analyticsParameters); flutterUsage.sendEvent('hot', 'restart', parameters: analyticsParameters);
flutterUsage.sendTiming('hot', 'restart', restartTimer.elapsed); flutterUsage.sendTiming('hot', 'restart', restartTimer.elapsed);
// In benchmark mode, make sure all stream notifications have finished.
if (benchmarkMode) {
final List<Future<void>> isolateNotifications = <Future<void>>[];
for (FlutterDevice device in flutterDevices) {
for (FlutterView view in device.views) {
isolateNotifications.add(
view.owner.vm.vmService.onIsolateEvent.then((Stream<ServiceEvent> serviceEvents) async {
await for (ServiceEvent serviceEvent in serviceEvents) {
if (serviceEvent.owner.name.contains('_spawn') && serviceEvent.kind == ServiceEvent.kIsolateExit) {
return;
}
}
}),
);
}
}
await Future.wait(isolateNotifications);
}
return OperationResult.ok; return OperationResult.ok;
} }
...@@ -511,7 +530,7 @@ class HotRunner extends ResidentRunner { ...@@ -511,7 +530,7 @@ class HotRunner extends ResidentRunner {
bool get supportsRestart => true; bool get supportsRestart => true;
@override @override
Future<OperationResult> restart({ bool fullRestart = false, bool pauseAfterRestart = false, String reason }) async { Future<OperationResult> restart({ bool fullRestart = false, bool pauseAfterRestart = false, String reason, bool benchmarkMode = false }) async {
final Stopwatch timer = Stopwatch()..start(); final Stopwatch timer = Stopwatch()..start();
if (fullRestart) { if (fullRestart) {
if (!canHotRestart) { if (!canHotRestart) {
...@@ -525,7 +544,7 @@ class HotRunner extends ResidentRunner { ...@@ -525,7 +544,7 @@ class HotRunner extends ResidentRunner {
try { try {
if (!(await hotRunnerConfig.setupHotRestart())) if (!(await hotRunnerConfig.setupHotRestart()))
return OperationResult(1, 'setupHotRestart failed'); return OperationResult(1, 'setupHotRestart failed');
final OperationResult result = await _restartFromSources(reason: reason); final OperationResult result = await _restartFromSources(reason: reason, benchmarkMode: benchmarkMode,);
if (!result.isOk) if (!result.isOk)
return result; return result;
} finally { } finally {
...@@ -573,7 +592,7 @@ class HotRunner extends ResidentRunner { ...@@ -573,7 +592,7 @@ class HotRunner extends ResidentRunner {
} }
} }
Future<OperationResult> _reloadSources({ bool pause = false, String reason, void Function(String message) onSlow }) async { Future<OperationResult> _reloadSources({ bool pause = false, String reason, void Function(String message) onSlow, }) async {
final Map<String, String> analyticsParameters = <String, String>{}; final Map<String, String> analyticsParameters = <String, String>{};
if (reason != null) { if (reason != null) {
analyticsParameters[kEventReloadReasonParameterName] = reason; analyticsParameters[kEventReloadReasonParameterName] = reason;
......
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