Commit ca7d8748 authored by Haiyang Pan's avatar Haiyang Pan Committed by Commit Bot

emulator: Add option "--debug-tags" for avd start

Also enable snapshot debugging when "snapshot" option is set for avd create.
Plus some minor fixes for root_ini and logging for emulator start

Bug: 922145
Change-Id: I6aaebc099ce25e9180efb6a66c097f885b804db2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2145957Reviewed-by: default avatarBen Pastene <bpastene@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Auto-Submit: Haiyang Pan <hypan@google.com>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758862}
parent ca9659f2
...@@ -236,8 +236,9 @@ class AvdConfig(object): ...@@ -236,8 +236,9 @@ class AvdConfig(object):
avd_dir = os.path.join(android_avd_home, '%s.avd' % self._config.avd_name) avd_dir = os.path.join(android_avd_home, '%s.avd' % self._config.avd_name)
config_ini = os.path.join(avd_dir, 'config.ini') config_ini = os.path.join(avd_dir, 'config.ini')
with open(root_ini, 'a') as root_ini_file: if os.path.exists(root_ini):
root_ini_file.write('path.rel=avd/%s.avd\n' % self._config.avd_name) with open(root_ini, 'a') as root_ini_file:
root_ini_file.write('path.rel=avd/%s.avd\n' % self._config.avd_name)
if os.path.exists(config_ini): if os.path.exists(config_ini):
with open(config_ini) as config_ini_file: with open(config_ini) as config_ini_file:
...@@ -263,7 +264,10 @@ class AvdConfig(object): ...@@ -263,7 +264,10 @@ class AvdConfig(object):
self._Initialize() self._Initialize()
instance = _AvdInstance(self._emulator_path, self._emulator_home, instance = _AvdInstance(self._emulator_path, self._emulator_home,
self._config) self._config)
instance.Start(read_only=False, snapshot_save=snapshot) # Enable debug for snapshot when it is set to True
debug_tags = 'snapshot' if snapshot else None
instance.Start(
read_only=False, snapshot_save=snapshot, debug_tags=debug_tags)
device_utils.DeviceUtils(instance.serial).WaitUntilFullyBooted( device_utils.DeviceUtils(instance.serial).WaitUntilFullyBooted(
timeout=180, retries=0) timeout=180, retries=0)
instance.Stop() instance.Stop()
...@@ -496,7 +500,8 @@ class _AvdInstance(object): ...@@ -496,7 +500,8 @@ class _AvdInstance(object):
read_only=True, read_only=True,
snapshot_save=False, snapshot_save=False,
window=False, window=False,
writable_system=False): writable_system=False,
debug_tags=None):
"""Starts the emulator running an instance of the given AVD.""" """Starts the emulator running an instance of the given AVD."""
with tempfile_ext.TemporaryFileName() as socket_path, (contextlib.closing( with tempfile_ext.TemporaryFileName() as socket_path, (contextlib.closing(
...@@ -517,6 +522,8 @@ class _AvdInstance(object): ...@@ -517,6 +522,8 @@ class _AvdInstance(object):
emulator_cmd.append('-no-snapshot-save') emulator_cmd.append('-no-snapshot-save')
if writable_system: if writable_system:
emulator_cmd.append('-writable-system') emulator_cmd.append('-writable-system')
if debug_tags:
emulator_cmd.extend(['-debug', debug_tags])
emulator_env = {} emulator_env = {}
if self._emulator_home: if self._emulator_home:
...@@ -531,11 +538,14 @@ class _AvdInstance(object): ...@@ -531,11 +538,14 @@ class _AvdInstance(object):
sock.listen(1) sock.listen(1)
logging.info('Starting emulator.') logging.info('Starting emulator with commands: %s',
' '.join(emulator_cmd))
# TODO(jbudorick): Add support for logging emulator stdout & stderr at # TODO(jbudorick): Add support for logging emulator stdout & stderr at
# higher logging levels. # higher logging levels.
self._sink = open('/dev/null', 'w') # Enable the emulator log when debug_tags is set.
if not debug_tags:
self._sink = open('/dev/null', 'w')
self._emulator_proc = cmd_helper.Popen( self._emulator_proc = cmd_helper.Popen(
emulator_cmd, stdout=self._sink, stderr=self._sink, env=emulator_env) emulator_cmd, stdout=self._sink, stderr=self._sink, env=emulator_env)
......
...@@ -99,6 +99,12 @@ def main(raw_args): ...@@ -99,6 +99,12 @@ def main(raw_args):
action='store_true', action='store_true',
default=False, default=False,
help='Enable graphical window display on the emulator.') help='Enable graphical window display on the emulator.')
start_parser.add_argument(
'--debug-tags',
help='Comma-separated list of debug tags. This can be used to enable or '
'disable debug messages from specific parts of the emulator, e.g. '
'init, snapshot. See "emulator -help-debug-tags" '
'for a full list of tags.')
add_common_arguments(start_parser) add_common_arguments(start_parser)
def start_cmd(args): def start_cmd(args):
...@@ -106,7 +112,8 @@ def main(raw_args): ...@@ -106,7 +112,8 @@ def main(raw_args):
inst.Start( inst.Start(
read_only=args.read_only, read_only=args.read_only,
snapshot_save=not args.read_only, snapshot_save=not args.read_only,
window=args.emulator_window) window=args.emulator_window,
debug_tags=args.debug_tags)
print('%s started (pid: %d)' % (str(inst), inst._emulator_proc.pid)) print('%s started (pid: %d)' % (str(inst), inst._emulator_proc.pid))
return 0 return 0
......
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