From a0aa0edfc5e7aabaee36676fcd246daac65346d8 Mon Sep 17 00:00:00 2001 From: Yegor Date: Tue, 9 Aug 2016 14:12:15 -0700 Subject: [PATCH] --trace-startup: non-zero exit code when fails; enable in iOS runtime (#5309) --- packages/flutter_tools/lib/src/commands/run.dart | 2 +- packages/flutter_tools/lib/src/commands/trace.dart | 12 +++++++----- packages/flutter_tools/lib/src/ios/devices.dart | 3 +++ packages/flutter_tools/lib/src/run.dart | 7 ++++++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/run.dart b/packages/flutter_tools/lib/src/commands/run.dart index 3565d7b3a4..c31c861475 100644 --- a/packages/flutter_tools/lib/src/commands/run.dart +++ b/packages/flutter_tools/lib/src/commands/run.dart @@ -275,7 +275,7 @@ Future startApp( Observatory observatory = await Observatory.connect(result.observatoryPort); await downloadStartupTrace(observatory); } catch (error) { - printError('Error connecting to observatory: $error'); + printError('Error downloading trace from observatory: $error'); return 1; } } diff --git a/packages/flutter_tools/lib/src/commands/trace.dart b/packages/flutter_tools/lib/src/commands/trace.dart index 7581795015..da920b61c0 100644 --- a/packages/flutter_tools/lib/src/commands/trace.dart +++ b/packages/flutter_tools/lib/src/commands/trace.dart @@ -154,6 +154,11 @@ class Tracing { /// Download the startup trace information from the given observatory client and /// store it to build/start_up_info.json. Future downloadStartupTrace(Observatory observatory) async { + File traceInfoFile = new File('build/start_up_info.json'); + + if (await traceInfoFile.exists()) + await traceInfoFile.delete(); + Tracing tracing = new Tracing(observatory); Map timeline = await tracing.stopTracingAndDownloadTimeline( @@ -173,16 +178,13 @@ Future downloadStartupTrace(Observatory observatory) async { int firstFrameTimestampMicros = extractInstantEventTimestamp(kFirstUsefulFrameEventName); if (engineEnterTimestampMicros == null) { - printError('Engine start event is missing in the timeline. Cannot compute startup time.'); - return null; + throw 'Engine start event is missing in the timeline. Cannot compute startup time.'; } if (firstFrameTimestampMicros == null) { - printError('First frame event is missing in the timeline. Cannot compute startup time.'); - return null; + throw 'First frame event is missing in the timeline. Cannot compute startup time.'; } - File traceInfoFile = new File('build/start_up_info.json'); int timeToFirstFrameMicros = firstFrameTimestampMicros - engineEnterTimestampMicros; Map traceInfo = { 'engineEnterTimestampMicros': engineEnterTimestampMicros, diff --git a/packages/flutter_tools/lib/src/ios/devices.dart b/packages/flutter_tools/lib/src/ios/devices.dart index 0d8108512f..64730d5991 100644 --- a/packages/flutter_tools/lib/src/ios/devices.dart +++ b/packages/flutter_tools/lib/src/ios/devices.dart @@ -216,6 +216,9 @@ class IOSDevice extends Device { // the port picked and scrape that later. } + if (platformArgs['trace-startup'] ?? false) + launchArguments.add('--trace-startup'); + List launchCommand = [ '/usr/bin/env', 'ios-deploy', diff --git a/packages/flutter_tools/lib/src/run.dart b/packages/flutter_tools/lib/src/run.dart index 1b4f2e8e17..ad1d3bff82 100644 --- a/packages/flutter_tools/lib/src/run.dart +++ b/packages/flutter_tools/lib/src/run.dart @@ -188,7 +188,12 @@ class RunAndStayResident extends ResidentRunner { if (serviceProtocol != null && traceStartup) { printStatus('Downloading startup trace info...'); - await downloadStartupTrace(serviceProtocol); + try { + await downloadStartupTrace(serviceProtocol); + } catch(error) { + printError(error); + return 2; + } appFinished(); } else { setupTerminal();