Unverified Commit 1affb423 authored by Jason Simmons's avatar Jason Simmons Committed by GitHub

Remove the diagnostic server from flutter_tools (#12771)

parent 2e97ee40
......@@ -378,15 +378,12 @@ class AndroidDevice extends Device {
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 @@ class AndroidDevice extends Device {
// 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 @@ class AndroidDevice extends Device {
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']));
}
});
......
......@@ -6,7 +6,6 @@ import 'file_system.dart';
import 'platform.dart';
const int kDefaultObservatoryPort = 8100;
const int kDefaultDiagnosticPort = 8101;
/// Return the absolute path of the user's home directory
String get homeDirPath {
......
......@@ -30,11 +30,11 @@ abstract class PortScanner {
/// 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++;
......
......@@ -508,7 +508,6 @@ class AppDomain extends Domain {
return <String, dynamic>{
'id': app.id,
'observatoryDevicePort': app.observatoryPort,
'diagnosticDevicePort': app.diagnosticPort,
};
}).toList();
}
......
......@@ -268,7 +268,6 @@ Future<LaunchResult> _startApp(DriveCommand command) async {
command.getBuildInfo(),
startPaused: true,
observatoryPort: command.observatoryPort,
diagnosticPort: command.diagnosticPort,
),
platformArgs: platformArgs,
usesTerminalUi: false,
......
......@@ -44,11 +44,6 @@ abstract class RunCommandBase extends FlutterCommand {
'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 @@ abstract class RunCommandBase extends FlutterCommand {
}
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 @@ class RunCommand extends RunCommandBase {
enableSoftwareRendering: argResults['enable-software-rendering'],
traceSkia: argResults['trace-skia'],
observatoryPort: observatoryPort,
diagnosticPort: diagnosticPort,
);
}
}
......
......@@ -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 @@ class ScreenshotCommand extends FlutterCommand {
_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 @@ class ScreenshotCommand extends FlutterCommand {
@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 @@ class ScreenshotCommand extends FlutterCommand {
}
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');
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');
}
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');
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.');
}
}
......
......@@ -320,7 +320,6 @@ class DebuggingOptions {
this.traceSkia: false,
this.useTestFonts: false,
this.observatoryPort,
this.diagnosticPort
}) : debuggingEnabled = true;
DebuggingOptions.disabled(this.buildInfo) :
......@@ -329,8 +328,7 @@ class DebuggingOptions {
startPaused = false,
enableSoftwareRendering = false,
traceSkia = false,
observatoryPort = null,
diagnosticPort = null;
observatoryPort = null;
final bool debuggingEnabled;
......@@ -340,7 +338,6 @@ class DebuggingOptions {
final bool traceSkia;
final bool useTestFonts;
final int observatoryPort;
final int diagnosticPort;
bool get hasObservatoryPort => observatoryPort != null;
......@@ -351,35 +348,22 @@ class DebuggingOptions {
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 @@ abstract class DeviceLogReader {
/// 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;
}
......@@ -238,51 +238,37 @@ class IOSDevice extends Device {
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 @@ class IOSDevice extends Device {
return new LaunchResult.failed();
}
return new LaunchResult.succeeded(observatoryUri: localObservatoryUri, diagnosticUri: localDiagnosticUri);
return new LaunchResult.succeeded(observatoryUri: localObservatoryUri);
}
@override
......
......@@ -351,8 +351,6 @@ class IOSSimulator extends Device {
final int observatoryPort = await debuggingOptions.findBestObservatoryPort();
args.add('--observatory-port=$observatoryPort');
final int diagnosticPort = await debuggingOptions.findBestDiagnosticPort();
args.add('--diagnostic-port=$diagnosticPort');
}
ProtocolDiscovery observatoryDiscovery;
......
......@@ -38,20 +38,6 @@ class ProtocolDiscovery {
);
}
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;
......
......@@ -217,8 +217,7 @@ class FlutterDevice {
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);
});
}
......
......@@ -49,7 +49,7 @@ final Map<InternetAddressType, InternetAddress> _kHosts = <InternetAddressType,
///
/// 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 @@ void installHook({
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 @@ void installHook({
enableObservatory: enableObservatory,
startPaused: startPaused,
explicitObservatoryPort: observatoryPort,
explicitDiagnosticPort: diagnosticPort,
host: _kHosts[serverType],
),
);
......@@ -89,7 +87,6 @@ class _FlutterPlatform extends PlatformPlugin {
this.machine,
this.startPaused,
this.explicitObservatoryPort,
this.explicitDiagnosticPort,
this.host,
}) {
assert(shellPath != null);
......@@ -101,7 +98,6 @@ class _FlutterPlatform extends PlatformPlugin {
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 @@ class _FlutterPlatform extends PlatformPlugin {
@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 @@ class _FlutterPlatform extends PlatformPlugin {
enableObservatory: enableObservatory,
startPaused: startPaused,
observatoryPort: explicitObservatoryPort,
diagnosticPort: explicitDiagnosticPort,
);
subprocessActive = true;
finalizers.add(() async {
......@@ -473,7 +468,6 @@ void main() {
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 @@ void main() {
// 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 main() {
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 @@ void main() {
} 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');
}
......
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