From 8be2c7c1683e65d23de753a8e2c0826aa7a76e42 Mon Sep 17 00:00:00 2001 From: Eric Seidel Date: Wed, 21 Jan 2015 15:53:17 -0800 Subject: [PATCH] Always use mojo_shell in over-http mode --origin tells mojo_shell to map all mojo: urls to to a new base-url instead of the build directory. This makes skydb's mojo_shell *always* use the network loading path, which is what Android mojo_shell does and is more like how mojo_shell will eventually be used. I also fixed the disk-space leak in the dynamic_application_loader's NetworkLoader path by having it immediately unlink the /tmp copy of the library after dlopen. In order to keep pprof working I had to teach the dynamic_application_loader to write out a map of /tmp/file -> url mappings so that we can fix the pprof file afterwords. This will "break" skydb --gdb on linux in exactly as much as it is already broken on Android, but I'm working on a build-id based solution for both so that gdb knows how to find symbols for non-existant randomly named /tmp libraries. R=abarth@chromium.org, viettrungluu@chromium.org BUG=450696 Review URL: https://codereview.chromium.org/829183005 --- .../flutter/tools/debugger/prompt/prompt.cc | 18 +++++- engine/src/flutter/tools/skydb | 63 +++++++++++++++---- 2 files changed, 68 insertions(+), 13 deletions(-) diff --git a/engine/src/flutter/tools/debugger/prompt/prompt.cc b/engine/src/flutter/tools/debugger/prompt/prompt.cc index 23f1c5dfb8..f5340c4521 100644 --- a/engine/src/flutter/tools/debugger/prompt/prompt.cc +++ b/engine/src/flutter/tools/debugger/prompt/prompt.cc @@ -102,12 +102,16 @@ class Prompt : public mojo::ApplicationDelegate, void OnWebSocketRequest( int connection_id, const net::HttpServerRequestInfo& info) override { - web_server_->Send500(connection_id, "http only"); + Error(connection_id, "OnWebSocketRequest not implemented"); } void OnWebSocketMessage( int connection_id, const std::string& data) override { - web_server_->Send500(connection_id, "http only"); + Error(connection_id, "OnWebSocketMessage not implemented"); + } + + void Error(int connection_id, std::string message) { + web_server_->Send500(connection_id, message); } void Respond(int connection_id, std::string response) { @@ -177,11 +181,21 @@ class Prompt : public mojo::ApplicationDelegate, } void StartProfiling(int connection_id) { +#if !defined(NDEBUG) || !defined(ENABLE_PROFILING) + Error(connection_id, + "Profiling requires is_debug=false and enable_profiling=true"); + return; +#else base::debug::StartProfiling("sky_viewer.pprof"); Respond(connection_id, "Starting profiling (stop with 'stop_profiling')"); +#endif } void StopProfiling(int connection_id) { + if (!base::debug::BeingProfiled()) { + Error(connection_id, "Profiling not started"); + return; + } base::debug::StopProfiling(); Respond(connection_id, "Stopped profiling"); } diff --git a/engine/src/flutter/tools/skydb b/engine/src/flutter/tools/skydb index 39763468a5..eb13caab5e 100755 --- a/engine/src/flutter/tools/skydb +++ b/engine/src/flutter/tools/skydb @@ -79,12 +79,6 @@ class SkyDebugger(object): return os.environ.get('CHROME_REMOTE_DESKTOP_SESSION', False) def _wrap_for_android(self, shell_args): - build_dir_url = SkyServer.url_for_path( - self.pids['remote_sky_server_port'], - self.pids['sky_server_root'], - self.pids['build_dir']) - shell_args += ['--origin=%s' % build_dir_url] - # am shell --esa: (someone shoot me now) # [--esa [,\S+\.mojo)') + MOJO_NAME_RE = re.compile(r'(?P\w+)\.mojo') + + with open("sky_viewer.pprof", "rb+") as profile_file: + # ISO-8859-1 can represent arbitrary binary while still keeping + # ASCII characters in the ASCII range (allowing us to regexp). + # http://en.wikipedia.org/wiki/ISO/IEC_8859-1 + as_string = profile_file.read().decode('iso-8859-1') + # Using the mojo_shell.PID.maps file tmp paths to build_dir paths. + as_string = MOJO_PATH_RE.sub(map_to_local_paths, as_string) + # In release foo.mojo is stripped but libfoo_library.so isn't. + as_string = MOJO_NAME_RE.sub(r'lib\1_library.so', as_string) profile_file.seek(0) - profile_file.write(re.sub(r'(\w+)\.mojo', r'lib\1_library.so', data)) + profile_file.write(as_string.encode('iso-8859-1')) profile_file.truncate() def _command_base_url(self): @@ -487,6 +521,9 @@ class SkyDebugger(object): logcat.wait() stack.wait() + def pids_command(self, args): + print json.dumps(self.pids, indent=1) + def main(self): logging.basicConfig(level=logging.WARNING) logging.getLogger("requests").setLevel(logging.WARNING) @@ -514,6 +551,10 @@ class SkyDebugger(object): help=('stop sky (as listed in %s)' % PID_FILE_PATH)) stop_parser.set_defaults(func=self.stop_command) + pids_parser = subparsers.add_parser('pids', + help='dump the current skydb pids file') + pids_parser.set_defaults(func=self.pids_command) + logcat_parser = subparsers.add_parser('logcat', help=('dump sky-related logs from device')) logcat_parser.set_defaults(func=self.logcat_command)