mirror of
https://github.com/ARM-software/devlib.git
synced 2025-02-12 07:58:07 +00:00
Merge pull request #168 from valschneider/logcat-tweaks
utils/android: LogcatMonitor fixes and improvements
This commit is contained in:
commit
ee153210c6
@ -32,6 +32,7 @@ from collections import defaultdict
|
|||||||
from devlib.exception import TargetError, HostError, DevlibError
|
from devlib.exception import TargetError, HostError, DevlibError
|
||||||
from devlib.utils.misc import check_output, which, memoized, ABI_MAP
|
from devlib.utils.misc import check_output, which, memoized, ABI_MAP
|
||||||
from devlib.utils.misc import escape_single_quotes, escape_double_quotes
|
from devlib.utils.misc import escape_single_quotes, escape_double_quotes
|
||||||
|
from devlib import host
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger('android')
|
logger = logging.getLogger('android')
|
||||||
@ -555,18 +556,21 @@ class LogcatMonitor(threading.Thread):
|
|||||||
regexp = '{}'.format('|'.join(self._regexps))
|
regexp = '{}'.format('|'.join(self._regexps))
|
||||||
if len(self._regexps) > 1:
|
if len(self._regexps) > 1:
|
||||||
regexp = '({})'.format(regexp)
|
regexp = '({})'.format(regexp)
|
||||||
logcat_cmd = '{} -e {}'.format(logcat_cmd, regexp)
|
logcat_cmd = '{} -e "{}"'.format(logcat_cmd, regexp)
|
||||||
|
|
||||||
logger.debug('logcat command ="{}"'.format(logcat_cmd))
|
logger.debug('logcat command ="{}"'.format(logcat_cmd))
|
||||||
self._logcat = self.target.background(logcat_cmd)
|
self._logcat = self.target.background(logcat_cmd)
|
||||||
|
|
||||||
while not self._stopped.is_set():
|
while not self._stopped.is_set():
|
||||||
line = self._logcat.stdout.readline(1024)
|
line = self._logcat.stdout.readline(1024)
|
||||||
self._add_line(line)
|
if line:
|
||||||
|
self._add_line(line)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
# Popen can be stuck on readline() so send it a SIGKILL
|
# Kill the underlying logcat process
|
||||||
self._logcat.terminate()
|
# This will unblock self._logcat.stdout.readline()
|
||||||
|
host.kill_children(self._logcat.pid)
|
||||||
|
self._logcat.kill()
|
||||||
|
|
||||||
self._stopped.set()
|
self._stopped.set()
|
||||||
self.join()
|
self.join()
|
||||||
@ -609,9 +613,10 @@ class LogcatMonitor(threading.Thread):
|
|||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def search(self, regexp, timeout=30):
|
def search(self, regexp):
|
||||||
"""
|
"""
|
||||||
Search a line that matches a regexp in the logcat log
|
Search a line that matches a regexp in the logcat log
|
||||||
|
Return immediatly
|
||||||
"""
|
"""
|
||||||
res = []
|
res = []
|
||||||
|
|
||||||
@ -623,8 +628,18 @@ class LogcatMonitor(threading.Thread):
|
|||||||
if re.match(regexp, line):
|
if re.match(regexp, line):
|
||||||
res.append(line)
|
res.append(line)
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
|
def wait_for(self, regexp, timeout=30):
|
||||||
|
"""
|
||||||
|
Search a line that matches a regexp in the logcat log
|
||||||
|
Wait for it to appear if it's not found
|
||||||
|
"""
|
||||||
|
res = self.search(regexp)
|
||||||
|
|
||||||
# Found some matches, return them
|
# Found some matches, return them
|
||||||
if len(res) > 0:
|
# Also return if thread not running
|
||||||
|
if len(res) > 0 or not self.is_alive():
|
||||||
return res
|
return res
|
||||||
|
|
||||||
# Did not find any match, wait for one to pop up
|
# Did not find any match, wait for one to pop up
|
||||||
|
Loading…
x
Reference in New Issue
Block a user