Commit 83be3e59 authored by John McCutchan's avatar John McCutchan Committed by GitHub

Stop tracking time to first frame because it is unreliable. (#6800)

- [x] Stop tracking time to first frame because it is unreliable.
- [x] Track time to complete reassemble instead.
parent 74e31679
...@@ -79,42 +79,6 @@ class DartDependencySetBuilder { ...@@ -79,42 +79,6 @@ class DartDependencySetBuilder {
} }
} }
class FirstFrameTimer {
FirstFrameTimer(this.vmService);
void start() {
stopwatch.reset();
stopwatch.start();
_subscription = vmService.onExtensionEvent.listen(_onExtensionEvent);
}
/// Returns a Future which completes after the first frame event is received.
Future<Null> firstFrame() => _completer.future;
void _onExtensionEvent(ServiceEvent event) {
if (event.extensionKind == 'Flutter.FirstFrame')
_stop();
}
void _stop() {
_subscription?.cancel();
_subscription = null;
stopwatch.stop();
_completer.complete(null);
}
Duration get elapsed {
assert(!stopwatch.isRunning);
return stopwatch.elapsed;
}
final VMService vmService;
final Stopwatch stopwatch = new Stopwatch();
final Completer<Null> _completer = new Completer<Null>();
StreamSubscription<ServiceEvent> _subscription;
}
class HotRunner extends ResidentRunner { class HotRunner extends ResidentRunner {
HotRunner( HotRunner(
Device device, { Device device, {
...@@ -450,31 +414,21 @@ class HotRunner extends ResidentRunner { ...@@ -450,31 +414,21 @@ class HotRunner extends ResidentRunner {
} }
Future<OperationResult> _restartFromSources() async { Future<OperationResult> _restartFromSources() async {
FirstFrameTimer firstFrameTimer = new FirstFrameTimer(vmService); Stopwatch restartTimer = new Stopwatch();
firstFrameTimer.start(); restartTimer.start();
bool updatedDevFS = await _updateDevFS(); bool updatedDevFS = await _updateDevFS();
if (!updatedDevFS) if (!updatedDevFS)
return new OperationResult(1, 'Dart Source Error'); return new OperationResult(1, 'Dart Source Error');
await _launchFromDevFS(_package, _mainPath); await _launchFromDevFS(_package, _mainPath);
bool waitForFrame = restartTimer.stop();
await currentView.uiIsolate.flutterFrameworkPresent();
Status restartStatus =
logger.startProgress('Waiting for application to start...');
if (waitForFrame) {
// Wait for the first frame to be rendered.
await firstFrameTimer.firstFrame();
}
restartStatus.stop();
if (waitForFrame) {
printTrace('Restart performed in ' printTrace('Restart performed in '
'${getElapsedAsMilliseconds(firstFrameTimer.elapsed)}.'); '${getElapsedAsMilliseconds(restartTimer.elapsed)}.');
if (benchmarkMode) { if (benchmarkMode) {
benchmarkData['hotRestartMillisecondsToFrame'] = benchmarkData['hotRestartMillisecondsToFrame'] =
firstFrameTimer.elapsed.inMilliseconds; restartTimer.elapsed.inMilliseconds;
}
flutterUsage.sendTiming('hot', 'restart', firstFrameTimer.elapsed);
} }
flutterUsage.sendEvent('hot', 'restart'); flutterUsage.sendEvent('hot', 'restart');
flutterUsage.sendTiming('hot', 'restart', restartTimer.elapsed);
return OperationResult.ok; return OperationResult.ok;
} }
...@@ -520,13 +474,11 @@ class HotRunner extends ResidentRunner { ...@@ -520,13 +474,11 @@ class HotRunner extends ResidentRunner {
Future<OperationResult> _reloadSources({ bool pause: false }) async { Future<OperationResult> _reloadSources({ bool pause: false }) async {
if (currentView.uiIsolate == null) if (currentView.uiIsolate == null)
throw 'Application isolate not found'; throw 'Application isolate not found';
FirstFrameTimer firstFrameTimer = new FirstFrameTimer(vmService); Stopwatch reloadTimer = new Stopwatch();
firstFrameTimer.start(); reloadTimer.start();
if (_devFS != null) {
bool updatedDevFS = await _updateDevFS(); bool updatedDevFS = await _updateDevFS();
if (!updatedDevFS) if (!updatedDevFS)
return new OperationResult(1, 'Dart Source Error'); return new OperationResult(1, 'Dart Source Error');
}
String reloadMessage; String reloadMessage;
try { try {
Map<String, dynamic> reloadReport = Map<String, dynamic> reloadReport =
...@@ -566,9 +518,8 @@ class HotRunner extends ResidentRunner { ...@@ -566,9 +518,8 @@ class HotRunner extends ResidentRunner {
} }
await _evictDirtyAssets(); await _evictDirtyAssets();
printTrace('Reassembling application'); printTrace('Reassembling application');
bool waitForFrame = true;
try { try {
waitForFrame = (await currentView.uiIsolate.flutterReassemble() != null); await currentView.uiIsolate.flutterReassemble();
} catch (_) { } catch (_) {
printError('Reassembling application failed.'); printError('Reassembling application failed.');
return new OperationResult(1, 'error reassembling application'); return new OperationResult(1, 'error reassembling application');
...@@ -579,18 +530,14 @@ class HotRunner extends ResidentRunner { ...@@ -579,18 +530,14 @@ class HotRunner extends ResidentRunner {
} catch (_) { } catch (_) {
/* ignore any errors */ /* ignore any errors */
} }
if (waitForFrame) { reloadTimer.stop();
// When the framework is present, we can wait for the first frame
// event and measure reload time.
await firstFrameTimer.firstFrame();
printTrace('Hot reload performed in ' printTrace('Hot reload performed in '
'${getElapsedAsMilliseconds(firstFrameTimer.elapsed)}.'); '${getElapsedAsMilliseconds(reloadTimer.elapsed)}.');
if (benchmarkMode) { if (benchmarkMode) {
benchmarkData['hotReloadMillisecondsToFrame'] = benchmarkData['hotReloadMillisecondsToFrame'] =
firstFrameTimer.elapsed.inMilliseconds; reloadTimer.elapsed.inMilliseconds;
}
flutterUsage.sendTiming('hot', 'reload', firstFrameTimer.elapsed);
} }
flutterUsage.sendTiming('hot', 'reload', reloadTimer.elapsed);
return new OperationResult(OperationResult.ok.code, reloadMessage); return new OperationResult(OperationResult.ok.code, reloadMessage);
} }
......
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