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
This commit is contained in:
parent
5c827f59c0
commit
8be2c7c168
@ -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");
|
||||
}
|
||||
|
@ -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 <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
|
||||
# (to embed a comma into a string escape it using "\,")
|
||||
@ -106,6 +100,7 @@ class SkyDebugger(object):
|
||||
for mime_type in SUPPORTED_MIME_TYPES]
|
||||
|
||||
remote_command_port = self.pids.get('remote_sky_command_port', self.pids['sky_command_port'])
|
||||
remote_server_port = self.pids.get('remote_sky_server_port', self.pids['sky_server_port'])
|
||||
|
||||
shell_args = [
|
||||
'--v=1',
|
||||
@ -115,6 +110,13 @@ class SkyDebugger(object):
|
||||
'mojo:window_manager',
|
||||
]
|
||||
|
||||
# Map all mojo: urls to http: urls using the --origin command.
|
||||
build_dir_url = SkyServer.url_for_path(
|
||||
remote_server_port,
|
||||
self.pids['sky_server_root'],
|
||||
self.pids['build_dir'])
|
||||
shell_args += ['--origin=%s' % build_dir_url]
|
||||
|
||||
# Desktop-only work-around for mojo crashing under chromoting.
|
||||
if not is_android and args.use_osmesa:
|
||||
shell_args.append(
|
||||
@ -322,14 +324,46 @@ class SkyDebugger(object):
|
||||
url = args.url_or_path
|
||||
self._send_command_to_sky('/load', url)
|
||||
|
||||
def _read_mojo_map(self):
|
||||
# TODO(eseidel): Does not work for android.
|
||||
mojo_map_path = "/tmp/mojo_shell.%d.maps" % self.pids['mojo_shell_pid']
|
||||
with open(mojo_map_path, 'r') as maps_file:
|
||||
lines = maps_file.read().strip().split('\n')
|
||||
return dict(map(lambda line: line.split(' '), lines))
|
||||
|
||||
def stop_profiling_command(self, args):
|
||||
self._send_command_to_sky('/stop_profiling')
|
||||
# We need to munge the profile to replace foo.mojo with libfoo.so so
|
||||
# that pprof knows this represents an SO.
|
||||
with open("sky_viewer.pprof", "r+") as profile_file:
|
||||
data = profile_file.read()
|
||||
mojo_map = self._read_mojo_map()
|
||||
|
||||
# TODO(eseidel): We should have a helper for resolving urls, etc.
|
||||
remote_server_port = self.pids.get('remote_sky_server_port', self.pids['sky_server_port'])
|
||||
build_dir_url = SkyServer.url_for_path(
|
||||
remote_server_port,
|
||||
self.pids['sky_server_root'],
|
||||
self.pids['build_dir'])
|
||||
|
||||
# Map /tmp cache paths to urls and then to local build_dir paths.
|
||||
def map_to_local_paths(match):
|
||||
path = match.group('mojo_path')
|
||||
url = mojo_map.get(path)
|
||||
if url and url.startswith(build_dir_url):
|
||||
return url.replace(build_dir_url, self.pids['build_dir'])
|
||||
return match.group(0)
|
||||
|
||||
MOJO_PATH_RE = re.compile(r'(?P<mojo_path>\S+\.mojo)')
|
||||
MOJO_NAME_RE = re.compile(r'(?P<mojo_name>\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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user