mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
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.
This commit is contained in:
parent
74e31679fb
commit
83be3e599f
@ -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 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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();
|
printTrace('Restart performed in '
|
||||||
Status restartStatus =
|
'${getElapsedAsMilliseconds(restartTimer.elapsed)}.');
|
||||||
logger.startProgress('Waiting for application to start...');
|
if (benchmarkMode) {
|
||||||
if (waitForFrame) {
|
benchmarkData['hotRestartMillisecondsToFrame'] =
|
||||||
// Wait for the first frame to be rendered.
|
restartTimer.elapsed.inMilliseconds;
|
||||||
await firstFrameTimer.firstFrame();
|
|
||||||
}
|
|
||||||
restartStatus.stop();
|
|
||||||
if (waitForFrame) {
|
|
||||||
printTrace('Restart performed in '
|
|
||||||
'${getElapsedAsMilliseconds(firstFrameTimer.elapsed)}.');
|
|
||||||
if (benchmarkMode) {
|
|
||||||
benchmarkData['hotRestartMillisecondsToFrame'] =
|
|
||||||
firstFrameTimer.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 {
|
|||||||
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 {
|
|||||||
}
|
}
|
||||||
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 {
|
|||||||
} catch (_) {
|
} catch (_) {
|
||||||
/* ignore any errors */
|
/* ignore any errors */
|
||||||
}
|
}
|
||||||
if (waitForFrame) {
|
reloadTimer.stop();
|
||||||
// When the framework is present, we can wait for the first frame
|
printTrace('Hot reload performed in '
|
||||||
// event and measure reload time.
|
'${getElapsedAsMilliseconds(reloadTimer.elapsed)}.');
|
||||||
await firstFrameTimer.firstFrame();
|
if (benchmarkMode) {
|
||||||
printTrace('Hot reload performed in '
|
benchmarkData['hotReloadMillisecondsToFrame'] =
|
||||||
'${getElapsedAsMilliseconds(firstFrameTimer.elapsed)}.');
|
reloadTimer.elapsed.inMilliseconds;
|
||||||
if (benchmarkMode) {
|
|
||||||
benchmarkData['hotReloadMillisecondsToFrame'] =
|
|
||||||
firstFrameTimer.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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user