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 {
}
}
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 {
HotRunner(
Device device, {
......@@ -450,31 +414,21 @@ class HotRunner extends ResidentRunner {
}
Future<OperationResult> _restartFromSources() async {
FirstFrameTimer firstFrameTimer = new FirstFrameTimer(vmService);
firstFrameTimer.start();
Stopwatch restartTimer = new Stopwatch();
restartTimer.start();
bool updatedDevFS = await _updateDevFS();
if (!updatedDevFS)
return new OperationResult(1, 'Dart Source Error');
await _launchFromDevFS(_package, _mainPath);
bool waitForFrame =
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) {
restartTimer.stop();
printTrace('Restart performed in '
'${getElapsedAsMilliseconds(firstFrameTimer.elapsed)}.');
'${getElapsedAsMilliseconds(restartTimer.elapsed)}.');
if (benchmarkMode) {
benchmarkData['hotRestartMillisecondsToFrame'] =
firstFrameTimer.elapsed.inMilliseconds;
}
flutterUsage.sendTiming('hot', 'restart', firstFrameTimer.elapsed);
restartTimer.elapsed.inMilliseconds;
}
flutterUsage.sendEvent('hot', 'restart');
flutterUsage.sendTiming('hot', 'restart', restartTimer.elapsed);
return OperationResult.ok;
}
......@@ -520,13 +474,11 @@ class HotRunner extends ResidentRunner {
Future<OperationResult> _reloadSources({ bool pause: false }) async {
if (currentView.uiIsolate == null)
throw 'Application isolate not found';
FirstFrameTimer firstFrameTimer = new FirstFrameTimer(vmService);
firstFrameTimer.start();
if (_devFS != null) {
Stopwatch reloadTimer = new Stopwatch();
reloadTimer.start();
bool updatedDevFS = await _updateDevFS();
if (!updatedDevFS)
return new OperationResult(1, 'Dart Source Error');
}
String reloadMessage;
try {
Map<String, dynamic> reloadReport =
......@@ -566,9 +518,8 @@ class HotRunner extends ResidentRunner {
}
await _evictDirtyAssets();
printTrace('Reassembling application');
bool waitForFrame = true;
try {
waitForFrame = (await currentView.uiIsolate.flutterReassemble() != null);
await currentView.uiIsolate.flutterReassemble();
} catch (_) {
printError('Reassembling application failed.');
return new OperationResult(1, 'error reassembling application');
......@@ -579,18 +530,14 @@ class HotRunner extends ResidentRunner {
} catch (_) {
/* ignore any errors */
}
if (waitForFrame) {
// When the framework is present, we can wait for the first frame
// event and measure reload time.
await firstFrameTimer.firstFrame();
reloadTimer.stop();
printTrace('Hot reload performed in '
'${getElapsedAsMilliseconds(firstFrameTimer.elapsed)}.');
'${getElapsedAsMilliseconds(reloadTimer.elapsed)}.');
if (benchmarkMode) {
benchmarkData['hotReloadMillisecondsToFrame'] =
firstFrameTimer.elapsed.inMilliseconds;
}
flutterUsage.sendTiming('hot', 'reload', firstFrameTimer.elapsed);
reloadTimer.elapsed.inMilliseconds;
}
flutterUsage.sendTiming('hot', 'reload', reloadTimer.elapsed);
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