Remove the diagnostic server from flutter_tools (#12771)
diff --git a/packages/flutter_tools/lib/src/android/android_device.dart b/packages/flutter_tools/lib/src/android/android_device.dart index 05b0db1..3e885e0 100644 --- a/packages/flutter_tools/lib/src/android/android_device.dart +++ b/packages/flutter_tools/lib/src/android/android_device.dart
@@ -378,15 +378,12 @@ printTrace('$this startApp'); ProtocolDiscovery observatoryDiscovery; - ProtocolDiscovery diagnosticDiscovery; if (debuggingOptions.debuggingEnabled) { // TODO(devoncarew): Remember the forwarding information (so we can later remove the // port forwarding or set it up again when adb fails on us). observatoryDiscovery = new ProtocolDiscovery.observatory( getLogReader(), portForwarder: portForwarder, hostPort: debuggingOptions.observatoryPort); - diagnosticDiscovery = new ProtocolDiscovery.diagnosticService( - getLogReader(), portForwarder: portForwarder, hostPort: debuggingOptions.diagnosticPort); } List<String> cmd; @@ -430,33 +427,20 @@ // device has printed "Observatory is listening on...". printTrace('Waiting for observatory port to be available...'); - // TODO(danrubel) Waiting for observatory and diagnostic services - // can be made common across all devices. + // TODO(danrubel) Waiting for observatory services can be made common across all devices. try { - Uri observatoryUri, diagnosticUri; + Uri observatoryUri; - if (debuggingOptions.buildInfo.isDebug) { - final List<Uri> deviceUris = await Future.wait( - <Future<Uri>>[observatoryDiscovery.uri, diagnosticDiscovery.uri] - ); - observatoryUri = deviceUris[0]; - diagnosticUri = deviceUris[1]; - } else if (debuggingOptions.buildInfo.isProfile) { + if (debuggingOptions.buildInfo.isDebug || debuggingOptions.buildInfo.isProfile) { observatoryUri = await observatoryDiscovery.uri; } - return new LaunchResult.succeeded( - observatoryUri: observatoryUri, - diagnosticUri: diagnosticUri, - ); + return new LaunchResult.succeeded(observatoryUri: observatoryUri); } catch (error) { printError('Error waiting for a debug connection: $error'); return new LaunchResult.failed(); } finally { - await waitGroup<Null>(<Future<Null>>[ - observatoryDiscovery.cancel(), - diagnosticDiscovery.cancel(), - ]); + await observatoryDiscovery.cancel(); } } @@ -519,7 +503,7 @@ final Match match = discoverExp.firstMatch(line); if (match != null) { final Map<String, dynamic> app = JSON.decode(match.group(1)); - result.add(new DiscoveredApp(app['id'], app['observatoryPort'], app['diagnosticPort'])); + result.add(new DiscoveredApp(app['id'], app['observatoryPort'])); } });
diff --git a/packages/flutter_tools/lib/src/base/common.dart b/packages/flutter_tools/lib/src/base/common.dart index db8c5d5..ea60c69 100644 --- a/packages/flutter_tools/lib/src/base/common.dart +++ b/packages/flutter_tools/lib/src/base/common.dart
@@ -6,7 +6,6 @@ import 'platform.dart'; const int kDefaultObservatoryPort = 8100; -const int kDefaultDiagnosticPort = 8101; /// Return the absolute path of the user's home directory String get homeDirPath {
diff --git a/packages/flutter_tools/lib/src/base/port_scanner.dart b/packages/flutter_tools/lib/src/base/port_scanner.dart index d3a0cb5..58af21d 100644 --- a/packages/flutter_tools/lib/src/base/port_scanner.dart +++ b/packages/flutter_tools/lib/src/base/port_scanner.dart
@@ -30,11 +30,11 @@ /// If [defaultPort] is available, this will return it. Otherwise, it will /// search for an avaiable port close to [defaultPort]. If it cannot find one, /// it will return any available port. - Future<int> findPreferredPort(int defaultPort, { int searchStep: 2 }) async { + Future<int> findPreferredPort(int defaultPort) async { int iterationCount = 0; while (iterationCount < _kMaxSearchIterations) { - final int port = defaultPort + iterationCount * searchStep; + final int port = defaultPort + iterationCount; if (await isPortAvailable(port)) return port; iterationCount++;
diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index aabb8bd..c477798 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.dart
@@ -508,7 +508,6 @@ return <String, dynamic>{ 'id': app.id, 'observatoryDevicePort': app.observatoryPort, - 'diagnosticDevicePort': app.diagnosticPort, }; }).toList(); }
diff --git a/packages/flutter_tools/lib/src/commands/drive.dart b/packages/flutter_tools/lib/src/commands/drive.dart index 53e0704..d0d67ad 100644 --- a/packages/flutter_tools/lib/src/commands/drive.dart +++ b/packages/flutter_tools/lib/src/commands/drive.dart
@@ -268,7 +268,6 @@ command.getBuildInfo(), startPaused: true, observatoryPort: command.observatoryPort, - diagnosticPort: command.diagnosticPort, ), platformArgs: platformArgs, usesTerminalUi: false,
diff --git a/packages/flutter_tools/lib/src/commands/run.dart b/packages/flutter_tools/lib/src/commands/run.dart index 9d2cf36..f297f3f 100644 --- a/packages/flutter_tools/lib/src/commands/run.dart +++ b/packages/flutter_tools/lib/src/commands/run.dart
@@ -44,11 +44,6 @@ 'Specifying port 0 will find a random free port.\n' 'Defaults to the first available port after $kDefaultObservatoryPort.' ); - argParser.addOption('diagnostic-port', - help: 'Listen to the given port for a diagnostic connection.\n' - 'Specifying port 0 will find a random free port.\n' - 'Defaults to the first available port after $kDefaultDiagnosticPort.' - ); } int get observatoryPort { @@ -61,17 +56,6 @@ } return null; } - - int get diagnosticPort { - if (argResults['diagnostic-port'] != null) { - try { - return int.parse(argResults['diagnostic-port']); - } catch (error) { - throwToolExit('Invalid port for `--diagnostic-port`: $error'); - } - } - return null; - } } class RunCommand extends RunCommandBase { @@ -244,7 +228,6 @@ enableSoftwareRendering: argResults['enable-software-rendering'], traceSkia: argResults['trace-skia'], observatoryPort: observatoryPort, - diagnosticPort: diagnosticPort, ); } }
diff --git a/packages/flutter_tools/lib/src/commands/screenshot.dart b/packages/flutter_tools/lib/src/commands/screenshot.dart index b24d5eb..1f7085a 100644 --- a/packages/flutter_tools/lib/src/commands/screenshot.dart +++ b/packages/flutter_tools/lib/src/commands/screenshot.dart
@@ -3,20 +3,18 @@ // found in the LICENSE file. import 'dart:async'; - -import 'package:http/http.dart' as http; +import 'dart:convert'; import '../base/common.dart'; import '../base/file_system.dart'; -import '../base/io.dart' hide IOSink; import '../base/utils.dart'; import '../device.dart'; import '../globals.dart'; import '../runner/flutter_command.dart'; +import '../vmservice.dart'; const String _kOut = 'out'; const String _kSkia = 'skia'; -const String _kSkiaServe = 'skiaserve'; class ScreenshotCommand extends FlutterCommand { ScreenshotCommand() { @@ -29,14 +27,9 @@ _kSkia, valueHelp: 'port', help: 'Retrieve the last frame rendered by a Flutter app as a Skia picture\n' - 'using the specified diagnostic server port.\n' - 'To find the diagnostic server port number, use "flutter run --verbose"\n' - 'and look for "Diagnostic server listening on" in the output.' - ); - argParser.addOption( - _kSkiaServe, - valueHelp: 'url', - help: 'Post the picture to a skiaserve debugger at this URL.', + 'using the specified observatory port.\n' + 'To find the observatory port number, use "flutter run --verbose"\n' + 'and look for "Forwarded host port ... for Observatory" in the output.' ); } @@ -53,18 +46,11 @@ @override Future<Null> verifyThenRunCommand() async { - if (argResults[_kSkia] != null) { - if (argResults[_kOut] != null && argResults[_kSkiaServe] != null) - throwToolExit('Cannot specify both --$_kOut and --$_kSkiaServe'); - } else { - if (argResults[_kSkiaServe] != null) - throwToolExit('Must specify --$_kSkia with --$_kSkiaServe'); - device = await findTargetDevice(); - if (device == null) - throwToolExit('Must specify --$_kSkia or have a connected device'); - if (!device.supportsScreenshot && argResults[_kSkia] == null) - throwToolExit('Screenshot not supported for ${device.name}.'); - } + device = await findTargetDevice(); + if (device == null) + throwToolExit('Must have a connected device'); + if (!device.supportsScreenshot && argResults[_kSkia] == null) + throwToolExit('Screenshot not supported for ${device.name}.'); return super.verifyThenRunCommand(); } @@ -92,47 +78,20 @@ } Future<Null> runSkia(File outputFile) async { - final Uri skpUri = new Uri(scheme: 'http', host: '127.0.0.1', - port: int.parse(argResults[_kSkia]), - path: '/skp'); + final Uri observatoryUri = new Uri(scheme: 'http', host: '127.0.0.1', + port: int.parse(argResults[_kSkia])); + final VMService vmService = VMService.connect(observatoryUri); + final Map<String, dynamic> skp = await vmService.vm.invokeRpcRaw('_flutter.screenshotSkp'); - const String errorHelpText = - 'Be sure the --$_kSkia= option specifies the diagnostic server port, not the observatory port.\n' - 'To find the diagnostic server port number, use "flutter run --verbose"\n' - 'and look for "Diagnostic server listening on" in the output.'; - - http.StreamedResponse skpResponse; - try { - skpResponse = await new http.Request('GET', skpUri).send(); - } on SocketException catch (e) { - throwToolExit('Skia screenshot failed: $skpUri\n$e\n\n$errorHelpText'); - } - if (skpResponse.statusCode != HttpStatus.OK) { - final String error = await skpResponse.stream.toStringStream().join(); - throwToolExit('Error: $error\n\n$errorHelpText'); - } - - if (argResults[_kSkiaServe] != null) { - final Uri skiaserveUri = Uri.parse(argResults[_kSkiaServe]); - final Uri postUri = new Uri.http(skiaserveUri.authority, '/new'); - final http.MultipartRequest postRequest = new http.MultipartRequest('POST', postUri); - postRequest.files.add(new http.MultipartFile( - 'file', skpResponse.stream, skpResponse.contentLength)); - - final http.StreamedResponse postResponse = await postRequest.send(); - if (postResponse.statusCode != HttpStatus.OK) - throwToolExit('Failed to post Skia picture to skiaserve.\n\n$errorHelpText'); - } else { - outputFile ??= getUniqueFile(fs.currentDirectory, 'flutter', 'skp'); - final IOSink sink = outputFile.openWrite(); - await sink.addStream(skpResponse.stream); - await sink.close(); - await showOutputFileInfo(outputFile); - if (await outputFile.length() < 1000) { - final String content = await outputFile.readAsString(); - if (content.startsWith('{"jsonrpc":"2.0", "error"')) - throwToolExit('\nIt appears the output file contains an error message, not valid skia output.\n\n$errorHelpText'); - } + outputFile ??= getUniqueFile(fs.currentDirectory, 'flutter', 'skp'); + final IOSink sink = outputFile.openWrite(); + sink.add(BASE64.decode(skp['skp'])); + await sink.close(); + await showOutputFileInfo(outputFile); + if (await outputFile.length() < 1000) { + final String content = await outputFile.readAsString(); + if (content.startsWith('{"jsonrpc":"2.0", "error"')) + throwToolExit('\nIt appears the output file contains an error message, not valid skia output.'); } }
diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart index ec7cbff..0d62b40 100644 --- a/packages/flutter_tools/lib/src/device.dart +++ b/packages/flutter_tools/lib/src/device.dart
@@ -320,7 +320,6 @@ this.traceSkia: false, this.useTestFonts: false, this.observatoryPort, - this.diagnosticPort }) : debuggingEnabled = true; DebuggingOptions.disabled(this.buildInfo) : @@ -329,8 +328,7 @@ startPaused = false, enableSoftwareRendering = false, traceSkia = false, - observatoryPort = null, - diagnosticPort = null; + observatoryPort = null; final bool debuggingEnabled; @@ -340,7 +338,6 @@ final bool traceSkia; final bool useTestFonts; final int observatoryPort; - final int diagnosticPort; bool get hasObservatoryPort => observatoryPort != null; @@ -351,35 +348,22 @@ return new Future<int>.value(observatoryPort); return portScanner.findPreferredPort(observatoryPort ?? kDefaultObservatoryPort); } - - bool get hasDiagnosticPort => diagnosticPort != null; - - /// Return the user specified diagnostic port. If that isn't available, - /// return [kDefaultDiagnosticPort], or a port close to that one. - Future<int> findBestDiagnosticPort() { - if (hasDiagnosticPort) - return new Future<int>.value(diagnosticPort); - return portScanner.findPreferredPort(diagnosticPort ?? kDefaultDiagnosticPort); - } } class LaunchResult { - LaunchResult.succeeded({ this.observatoryUri, this.diagnosticUri }) : started = true; - LaunchResult.failed() : started = false, observatoryUri = null, diagnosticUri = null; + LaunchResult.succeeded({ this.observatoryUri }) : started = true; + LaunchResult.failed() : started = false, observatoryUri = null; bool get hasObservatory => observatoryUri != null; final bool started; final Uri observatoryUri; - final Uri diagnosticUri; @override String toString() { final StringBuffer buf = new StringBuffer('started=$started'); if (observatoryUri != null) buf.write(', observatory=$observatoryUri'); - if (diagnosticUri != null) - buf.write(', diagnostic=$diagnosticUri'); return buf.toString(); } } @@ -427,8 +411,7 @@ /// Describes an app running on the device. class DiscoveredApp { - DiscoveredApp(this.id, this.observatoryPort, this.diagnosticPort); + DiscoveredApp(this.id, this.observatoryPort); final String id; final int observatoryPort; - final int diagnosticPort; }
diff --git a/packages/flutter_tools/lib/src/ios/devices.dart b/packages/flutter_tools/lib/src/ios/devices.dart index 693dc9c..0704749 100644 --- a/packages/flutter_tools/lib/src/ios/devices.dart +++ b/packages/flutter_tools/lib/src/ios/devices.dart
@@ -238,51 +238,37 @@ int installationResult = -1; Uri localObservatoryUri; - Uri localDiagnosticUri; if (!debuggingOptions.debuggingEnabled) { // If debugging is not enabled, just launch the application and continue. printTrace('Debugging is not enabled'); installationResult = await runCommandAndStreamOutput(launchCommand, trace: true); } else { - // Debugging is enabled, look for the observatory and diagnostic server - // ports post launch. - printTrace('Debugging is enabled, connecting to observatory and the diagnostic server'); + // Debugging is enabled, look for the observatory server port post launch. + printTrace('Debugging is enabled, connecting to observatory'); // TODO(danrubel): The Android device class does something similar to this code below. // The various Device subclasses should be refactored and common code moved into the superclass. final ProtocolDiscovery observatoryDiscovery = new ProtocolDiscovery.observatory( getLogReader(app: app), portForwarder: portForwarder, hostPort: debuggingOptions.observatoryPort); - final ProtocolDiscovery diagnosticDiscovery = new ProtocolDiscovery.diagnosticService( - getLogReader(app: app), portForwarder: portForwarder, hostPort: debuggingOptions.diagnosticPort); final Future<Uri> forwardObservatoryUri = observatoryDiscovery.uri; - Future<Uri> forwardDiagnosticUri; - if (debuggingOptions.buildInfo.isDebug) { - forwardDiagnosticUri = diagnosticDiscovery.uri; - } else { - forwardDiagnosticUri = new Future<Uri>.value(null); - } final Future<int> launch = runCommandAndStreamOutput(launchCommand, trace: true); - final List<Uri> uris = await launch.then<List<Uri>>((int result) async { + localObservatoryUri = await launch.then<Uri>((int result) async { installationResult = result; if (result != 0) { printTrace('Failed to launch the application on device.'); - return <Uri>[null, null]; + return null; } printTrace('Application launched on the device. Attempting to forward ports.'); - return await Future.wait(<Future<Uri>>[forwardObservatoryUri, forwardDiagnosticUri]); + return await forwardObservatoryUri; }).whenComplete(() { observatoryDiscovery.cancel(); - diagnosticDiscovery.cancel(); }); - - localObservatoryUri = uris[0]; - localDiagnosticUri = uris[1]; } if (installationResult != 0) { @@ -293,7 +279,7 @@ return new LaunchResult.failed(); } - return new LaunchResult.succeeded(observatoryUri: localObservatoryUri, diagnosticUri: localDiagnosticUri); + return new LaunchResult.succeeded(observatoryUri: localObservatoryUri); } @override
diff --git a/packages/flutter_tools/lib/src/ios/simulators.dart b/packages/flutter_tools/lib/src/ios/simulators.dart index 4581b22..347b8a6 100644 --- a/packages/flutter_tools/lib/src/ios/simulators.dart +++ b/packages/flutter_tools/lib/src/ios/simulators.dart
@@ -351,8 +351,6 @@ final int observatoryPort = await debuggingOptions.findBestObservatoryPort(); args.add('--observatory-port=$observatoryPort'); - final int diagnosticPort = await debuggingOptions.findBestDiagnosticPort(); - args.add('--diagnostic-port=$diagnosticPort'); } ProtocolDiscovery observatoryDiscovery;
diff --git a/packages/flutter_tools/lib/src/protocol_discovery.dart b/packages/flutter_tools/lib/src/protocol_discovery.dart index da45644..8a8b5cb 100644 --- a/packages/flutter_tools/lib/src/protocol_discovery.dart +++ b/packages/flutter_tools/lib/src/protocol_discovery.dart
@@ -38,20 +38,6 @@ ); } - factory ProtocolDiscovery.diagnosticService( - DeviceLogReader logReader, { - DevicePortForwarder portForwarder, - int hostPort, - }) { - const String kDiagnosticService = 'Diagnostic server'; - return new ProtocolDiscovery._( - logReader, kDiagnosticService, - portForwarder: portForwarder, - hostPort: hostPort, - defaultHostPort: kDefaultDiagnosticPort, - ); - } - final DeviceLogReader logReader; final String serviceName; final DevicePortForwarder portForwarder;
diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart index f59eeef..119f3bf 100644 --- a/packages/flutter_tools/lib/src/resident_runner.dart +++ b/packages/flutter_tools/lib/src/resident_runner.dart
@@ -217,8 +217,7 @@ if (_loggingSubscription != null) return; _loggingSubscription = device.getLogReader(app: package).logLines.listen((String line) { - if (!line.contains('Observatory listening on http') && - !line.contains('Diagnostic server listening on http')) + if (!line.contains('Observatory listening on http')) printStatus(line); }); }
diff --git a/packages/flutter_tools/lib/src/test/flutter_platform.dart b/packages/flutter_tools/lib/src/test/flutter_platform.dart index 2504d93..a9dc32e 100644 --- a/packages/flutter_tools/lib/src/test/flutter_platform.dart +++ b/packages/flutter_tools/lib/src/test/flutter_platform.dart
@@ -49,7 +49,7 @@ /// /// On systems where each [_FlutterPlatform] is only used to run one test suite /// (that is, one Dart file with a `*_test.dart` file name and a single `void -/// main()`), you can set an observatory port and a diagnostic port explicitly. +/// main()`), you can set an observatory port explicitly. void installHook({ @required String shellPath, TestWatcher watcher, @@ -57,10 +57,9 @@ bool machine: false, bool startPaused: false, int observatoryPort, - int diagnosticPort, InternetAddressType serverType: InternetAddressType.IP_V4, }) { - if (startPaused || observatoryPort != null || diagnosticPort != null) + if (startPaused || observatoryPort != null) assert(enableObservatory); hack.registerPlatformPlugin( <TestPlatform>[TestPlatform.vm], @@ -71,7 +70,6 @@ enableObservatory: enableObservatory, startPaused: startPaused, explicitObservatoryPort: observatoryPort, - explicitDiagnosticPort: diagnosticPort, host: _kHosts[serverType], ), ); @@ -89,7 +87,6 @@ this.machine, this.startPaused, this.explicitObservatoryPort, - this.explicitDiagnosticPort, this.host, }) { assert(shellPath != null); @@ -101,7 +98,6 @@ final bool machine; final bool startPaused; final int explicitObservatoryPort; - final int explicitDiagnosticPort; final InternetAddress host; // Each time loadChannel() is called, we spin up a local WebSocket server, @@ -116,9 +112,9 @@ @override StreamChannel<dynamic> loadChannel(String testPath, TestPlatform platform) { // Fail if there will be a port conflict. - if (explicitObservatoryPort != null || explicitDiagnosticPort != null) { + if (explicitObservatoryPort != null) { if (_testCount > 0) - throwToolExit('installHook() was called with an observatory port, a diagnostic port, both, or debugger mode enabled, but then more than one test suite was run.'); + throwToolExit('installHook() was called with an observatory port or debugger mode enabled, but then more than one test suite was run.'); } final int ourTestCount = _testCount; _testCount += 1; @@ -205,7 +201,6 @@ enableObservatory: enableObservatory, startPaused: startPaused, observatoryPort: explicitObservatoryPort, - diagnosticPort: explicitDiagnosticPort, ); subprocessActive = true; finalizers.add(() async { @@ -473,7 +468,6 @@ bool enableObservatory: false, bool startPaused: false, int observatoryPort, - int diagnosticPort, }) { assert(executable != null); // Please provide the path to the shell in the SKY_SHELL environment variable. assert(!startPaused || enableObservatory); @@ -490,12 +484,10 @@ // the obvious simplification to this code and remove this entire feature. if (observatoryPort != null) command.add('--observatory-port=$observatoryPort'); - if (diagnosticPort != null) - command.add('--diagnostic-port=$diagnosticPort'); if (startPaused) command.add('--start-paused'); } else { - command.addAll(<String>['--disable-observatory', '--disable-diagnostic']); + command.add('--disable-observatory'); } if (host.type == InternetAddressType.IP_V6) command.add('--ipv6'); @@ -521,7 +513,6 @@ void reportObservatoryUri(Uri uri), }) { final String observatoryString = 'Observatory listening on '; - final String diagnosticServerString = 'Diagnostic server listening on '; for (Stream<List<int>> stream in <Stream<List<int>>>[process.stderr, process.stdout]) { @@ -544,8 +535,6 @@ } catch (error) { printError('Could not parse shell observatory port message: $error'); } - } else if (line.startsWith(diagnosticServerString)) { - printTrace('Shell: $line'); } else if (line != null) { printStatus('Shell: $line'); }