Add flags for disabling the diagnostic server or setting its port (flutter/engine#3352)

Fixes https://github.com/flutter/flutter/issues/7557
This commit is contained in:
Jason Simmons
2017-01-20 15:18:13 -08:00
committed by GitHub
parent 26fe5e1b12
commit 4c92ea1506
6 changed files with 43 additions and 14 deletions

View File

@@ -17,6 +17,8 @@ struct Settings {
// Port on target will be auto selected by the OS. A message will be printed
// on the target with the port after it has been selected.
uint32_t observatory_port = 0;
bool enable_diagnostic = false;
uint32_t diagnostic_port = 0;
bool start_paused = false;
bool trace_startup = false;
bool endless_trace_buffer = false;

View File

@@ -31,6 +31,7 @@ using tonic::DartLibraryNatives;
using blink::EmbedderResources;
using tonic::DartInvokeField;
using tonic::LogIfError;
using tonic::ToDart;
namespace {
@@ -60,7 +61,7 @@ void SendNull(Dart_Port port_id) {
DART_NATIVE_CALLBACK_STATIC(DiagnosticServer, HandleSkiaPictureRequest);
void DiagnosticServer::Start() {
void DiagnosticServer::Start(uint32_t port) {
if (!g_natives) {
g_natives = new DartLibraryNatives();
g_natives->Register({
@@ -91,7 +92,7 @@ void DiagnosticServer::Start() {
FTL_CHECK(!LogIfError(Dart_FinalizeLoading(false)));
DartInvokeField(Dart_RootLibrary(), "diagnosticServerStart", {});
DartInvokeField(Dart_RootLibrary(), "diagnosticServerStart", {ToDart(port)});
}
void DiagnosticServer::HandleSkiaPictureRequest(Dart_Handle send_port) {

View File

@@ -11,8 +11,8 @@ import 'dart:typed_data';
void handleSkiaPictureRequest(SendPort sendPort)
native 'DiagnosticServer_HandleSkiaPictureRequest';
void diagnosticServerStart() {
HttpServer.bind('127.0.0.1', 0).then((HttpServer server) {
void diagnosticServerStart(int port) {
HttpServer.bind('127.0.0.1', port).then((HttpServer server) {
server.listen(dispatchRequest, cancelOnError: true);
String ip = server.address.address.toString();

View File

@@ -11,7 +11,7 @@ namespace shell {
class DiagnosticServer {
public:
static void Start();
static void Start(uint32_t port);
static void HandleSkiaPictureRequest(Dart_Handle send_port);
private:

View File

@@ -42,6 +42,18 @@ bool IsViewInvalid(const ftl::WeakPtr<PlatformView>& platform_view) {
return !platform_view;
}
template <typename T> bool GetSwitchValue(const base::CommandLine& command_line,
Switch sw, T* result) {
auto port_string = command_line.GetSwitchValueASCII(FlagForSwitch(sw));
std::stringstream stream(port_string);
T value = 0;
if (stream >> value) {
*result = value;
return true;
}
return false;
}
class NonDiscardableMemory : public base::DiscardableMemory {
public:
explicit NonDiscardableMemory(size_t size) : data_(new uint8_t[size]) {}
@@ -66,8 +78,8 @@ base::LazyInstance<NonDiscardableMemoryAllocator> g_discardable;
void ServiceIsolateHook(bool running_precompiled) {
if (!running_precompiled) {
const blink::Settings& settings = blink::Settings::Get();
if (settings.enable_observatory)
DiagnosticServer::Start();
if (settings.enable_diagnostic)
DiagnosticServer::Start(settings.diagnostic_port);
}
}
@@ -135,19 +147,26 @@ void Shell::InitStandalone(std::string icu_data_path,
// Set Observatory Port
if (command_line.HasSwitch(FlagForSwitch(Switch::DeviceObservatoryPort))) {
auto port_string = command_line.GetSwitchValueASCII(
FlagForSwitch(Switch::DeviceObservatoryPort));
std::stringstream stream(port_string);
uint32_t port = 0;
if (stream >> port) {
settings.observatory_port = port;
} else {
if (!GetSwitchValue(command_line, Switch::DeviceObservatoryPort,
&settings.observatory_port)) {
FTL_LOG(INFO)
<< "Observatory port specified was malformed. Will default to "
<< settings.observatory_port;
}
}
settings.enable_diagnostic =
!command_line.HasSwitch(FlagForSwitch(Switch::DisableDiagnostic));
if (command_line.HasSwitch(FlagForSwitch(Switch::DeviceDiagnosticPort))) {
if (!GetSwitchValue(command_line, Switch::DeviceDiagnosticPort,
&settings.diagnostic_port)) {
FTL_LOG(INFO)
<< "Diagnostic port specified was malformed. Will default to "
<< settings.diagnostic_port;
}
}
settings.start_paused =
command_line.HasSwitch(FlagForSwitch(Switch::StartPaused));

View File

@@ -43,6 +43,13 @@ DEF_SWITCH(DisableObservatory,
"disable-observatory",
"Disable the Dart Observatory. The observatory is never available "
"in release mode.")
DEF_SWITCH(DeviceDiagnosticPort,
"diagnostic-port",
"A custom diagnostic server port.")
DEF_SWITCH(DisableDiagnostic,
"disable-diagnostic",
"Disable the diagnostic server. The diagnostic server is never "
"available in release mode.")
DEF_SWITCH(EnableDartProfiling,
"enable-dart-profiling",
"Enable Dart profiling. Profiling information can be viewed from "