Bug 972518 - Log qemu output to prevent stdout pipe from filling up, r=jgriffin

This commit is contained in:
Andrew Halberstadt 2014-02-20 09:28:22 -05:00
Родитель b39fe91b20
Коммит 034a3313aa
1 изменённых файлов: 28 добавлений и 12 удалений

Просмотреть файл

@ -23,16 +23,22 @@ from emulator_geo import EmulatorGeo
from emulator_screen import EmulatorScreen
class LogcatProc(ProcessHandlerMixin):
"""Process handler for logcat which saves all output to a logfile.
class LogOutputProc(ProcessHandlerMixin):
"""
Process handler for processes which save all output to a logfile.
If no logfile is specified, output will still be consumed to prevent
the output pipe's from overflowing.
"""
def __init__(self, logfile, cmd, **kwargs):
def __init__(self, cmd, logfile=None, **kwargs):
self.logfile = logfile
kwargs.setdefault('processOutputLine', []).append(self.log_output)
ProcessHandlerMixin.__init__(self, cmd, **kwargs)
def log_output(self, line):
if not self.logfile:
return
f = open(self.logfile, 'a')
f.write(line + "\n")
f.flush()
@ -210,8 +216,7 @@ class Emulator(object):
def close(self):
if self.is_running and self._emulator_launched:
self.proc.terminate()
self.proc.wait()
self.proc.kill()
if self._adb_started:
self._run_adb(['kill-server'])
self._adb_started = False
@ -317,9 +322,14 @@ waitFor(
original_online, original_offline = self._get_adb_devices()
self.proc = subprocess.Popen(qemu_args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
filename = None
if self.logcat_dir:
filename = os.path.join(self.logcat_dir, 'qemu.log')
if os.path.isfile(filename):
self.rotate_log(filename)
self.proc = LogOutputProc(qemu_args, filename)
self.proc.run()
online, offline = self._get_adb_devices()
now = datetime.datetime.now()
@ -463,8 +473,14 @@ window.addEventListener('mozbrowserloadend', function loaded(aEvent) {
""" Rotate a logfile, by recursively rotating logs further in the sequence,
deleting the last file if necessary.
"""
destlog = os.path.join(self.logcat_dir, 'emulator-%d.%d.log' % (self.port, index))
if os.access(destlog, os.F_OK):
basename = os.path.basename(srclog)
basename = basename[:-len('.log')]
if index > 1:
basename = basename[:-len('.1')]
basename = '%s.%d.log' % (basename, index)
destlog = os.path.join(self.logcat_dir, basename)
if os.path.isfile(destlog):
if index == 3:
os.remove(destlog)
else:
@ -475,11 +491,11 @@ window.addEventListener('mozbrowserloadend', function loaded(aEvent) {
""" Save the output of logcat to a file.
"""
filename = os.path.join(self.logcat_dir, "emulator-%d.log" % self.port)
if os.access(filename, os.F_OK):
if os.path.isfile(filename):
self.rotate_log(filename)
cmd = [self.adb, '-s', 'emulator-%d' % self.port, 'logcat', '-v', 'threadtime']
self.logcat_proc = LogcatProc(filename, cmd)
self.logcat_proc = LogOutputProc(cmd, filename)
self.logcat_proc.run()
def setup_port_forwarding(self, remote_port):