diff options
author | craigdh@chromium.org <craigdh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-20 00:35:24 +0000 |
---|---|---|
committer | craigdh@chromium.org <craigdh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-20 00:35:24 +0000 |
commit | 71aec4be75c2137d3d2701b6a5b38b48f1737f33 (patch) | |
tree | ac55557b585bffc619baaae94301914ae21370a3 /build | |
parent | d826a97b28c5fbd15fd4bef3b7fc440aa71e5308 (diff) | |
download | chromium_src-71aec4be75c2137d3d2701b6a5b38b48f1737f33.zip chromium_src-71aec4be75c2137d3d2701b6a5b38b48f1737f33.tar.gz chromium_src-71aec4be75c2137d3d2701b6a5b38b48f1737f33.tar.bz2 |
[Android] Refactor and reuse reraiser_thread thread stack dumping utility.
BUG=None
TEST=reraiser_thread_unittest.py
NOTRY=True
R=frankf@chromium.org
Review URL: https://codereview.chromium.org/76233005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236077 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build')
-rw-r--r-- | build/android/pylib/utils/reraiser_thread.py | 27 | ||||
-rwxr-xr-x | build/android/test_runner.py | 15 |
2 files changed, 21 insertions, 21 deletions
diff --git a/build/android/pylib/utils/reraiser_thread.py b/build/android/pylib/utils/reraiser_thread.py index f4fa577..d4ba781 100644 --- a/build/android/pylib/utils/reraiser_thread.py +++ b/build/android/pylib/utils/reraiser_thread.py @@ -18,6 +18,23 @@ class TimeoutError(Exception): pass +def LogThreadStack(thread): + """Log the stack for the given thread. + + Args: + thread: a threading.Thread instance. + """ + stack = sys._current_frames()[thread.ident] + logging.critical('*' * 80) + logging.critical('Stack dump for thread \'%s\'', thread.name) + logging.critical('*' * 80) + for filename, lineno, name, line in traceback.extract_stack(stack): + logging.critical('File: "%s", line %d, in %s', filename, lineno, name) + if line: + logging.critical(' %s', line.strip()) + logging.critical('*' * 80) + + class ReraiserThread(threading.Thread): """Thread class that can reraise exceptions.""" @@ -113,13 +130,5 @@ class ReraiserThreadGroup(object): self._JoinAll(watcher) except TimeoutError: for thread in (t for t in self._threads if t.isAlive()): - stack = sys._current_frames()[thread.ident] - logging.critical('*' * 80) - logging.critical('Stack dump for timed out thread \'%s\'', thread.name) - logging.critical('*' * 80) - for filename, lineno, name, line in traceback.extract_stack(stack): - logging.critical('File: "%s", line %d, in %s', filename, lineno, name) - if line: - logging.critical(' %s', line.strip()) - logging.critical('*' * 80) + LogThreadStack(thread) raise diff --git a/build/android/test_runner.py b/build/android/test_runner.py index ea6ef09..46fefe9 100755 --- a/build/android/test_runner.py +++ b/build/android/test_runner.py @@ -38,6 +38,7 @@ from pylib.uiautomator import setup as uiautomator_setup from pylib.uiautomator import test_options as uiautomator_test_options from pylib.utils import command_option_parser from pylib.utils import report_results +from pylib.utils import reraiser_thread from pylib.utils import run_tests_helper @@ -797,18 +798,8 @@ VALID_COMMANDS = { def DumpThreadStacks(signal, frame): - thread_names_map = dict( - [(thread.ident, thread.name) for thread in threading.enumerate()]) - lines = [] - for thread_id, stack in sys._current_frames().items(): - lines.append( - '\n# Thread: %s (%d)' % ( - thread_names_map.get(thread_id, ''), thread_id)) - for filename, lineno, name, line in traceback.extract_stack(stack): - lines.append('File: "%s", line %d, in %s' % (filename, lineno, name)) - if line: - lines.append(' %s' % (line.strip())) - print '\n'.join(lines) + for thread in threading.enumerate(): + reraiser_thread.LogThreadStack(thread) def main(argv): |