diff options
author | craigdh@chromium.org <craigdh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-10 00:43:10 +0000 |
---|---|---|
committer | craigdh@chromium.org <craigdh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-10 00:43:10 +0000 |
commit | de70560e673eafe0733ba407770806130bb7781f (patch) | |
tree | a6ee3862b0b475207961cdb5584213c0ec96d607 /build | |
parent | 81fdd5c14a8e462fa157407767e024ccd8fb604a (diff) | |
download | chromium_src-de70560e673eafe0733ba407770806130bb7781f.zip chromium_src-de70560e673eafe0733ba407770806130bb7781f.tar.gz chromium_src-de70560e673eafe0733ba407770806130bb7781f.tar.bz2 |
[Android] Thread names reflect the device serial number they are associated with.
BUG=160320
TEST=Ran the tests and unittests
Review URL: https://codereview.chromium.org/13820024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193274 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build')
-rw-r--r-- | build/android/pylib/base/shard.py | 12 | ||||
-rw-r--r-- | build/android/pylib/utils/reraiser_thread.py | 19 | ||||
-rw-r--r-- | build/android/pylib/utils/run_tests_helper.py | 6 |
3 files changed, 24 insertions, 13 deletions
diff --git a/build/android/pylib/base/shard.py b/build/android/pylib/base/shard.py index aaa3975..c9fc838 100644 --- a/build/android/pylib/base/shard.py +++ b/build/android/pylib/base/shard.py @@ -205,7 +205,8 @@ def _RunAllTests(runners, tests, timeout=None): watcher = watchdog_timer.WatchdogTimer(timeout) workers = reraiser_thread.ReraiserThreadGroup( [reraiser_thread.ReraiserThread(_RunTestsFromQueue, - [r, tests_collection, results, watcher]) + [r, tests_collection, results, watcher], + name=r.device[-4:]) for r in runners]) workers.StartAll() workers.JoinAll(watcher) @@ -234,8 +235,9 @@ def _CreateRunners(runner_factory, devices, timeout=None): runners = [] counter = _ThreadSafeCounter() threads = reraiser_thread.ReraiserThreadGroup( - [reraiser_thread.ReraiserThread(_SetUp, [runner_factory, d, runners, - counter]) + [reraiser_thread.ReraiserThread(_SetUp, + [runner_factory, d, runners, counter], + name=d[-4:]) for d in devices]) threads.StartAll() threads.JoinAll(watchdog_timer.WatchdogTimer(timeout)) @@ -249,8 +251,8 @@ def _TearDownRunners(runners, timeout=None): timeout: watchdog timeout in seconds, defaults to the default timeout. """ threads = reraiser_thread.ReraiserThreadGroup( - [reraiser_thread.ReraiserThread(runner.TearDown) - for runner in runners]) + [reraiser_thread.ReraiserThread(r.TearDown, name=r.device[-4:]) + for r in runners]) threads.StartAll() threads.JoinAll(watchdog_timer.WatchdogTimer(timeout)) diff --git a/build/android/pylib/utils/reraiser_thread.py b/build/android/pylib/utils/reraiser_thread.py index bde162c..f4fa577 100644 --- a/build/android/pylib/utils/reraiser_thread.py +++ b/build/android/pylib/utils/reraiser_thread.py @@ -21,8 +21,16 @@ class TimeoutError(Exception): class ReraiserThread(threading.Thread): """Thread class that can reraise exceptions.""" - def __init__(self, func, args=[], kwargs={}): - super(ReraiserThread, self).__init__() + def __init__(self, func, args=[], kwargs={}, name=None): + """Initialize thread. + + Args: + func: callable to call on a new thread. + args: list of positional arguments for callable, defaults to empty. + kwargs: dictionary of keyword arguments for callable, defaults to empty. + name: thread name, defaults to Thread-N. + """ + super(ReraiserThread, self).__init__(name=name) self.daemon = True self._func = func self._args = args @@ -104,11 +112,10 @@ class ReraiserThreadGroup(object): try: self._JoinAll(watcher) except TimeoutError: - alive_thread_ids = (t.ident for t in self._threads if t.isAlive()) - for thread_id in alive_thread_ids: - stack = sys._current_frames()[thread_id] + 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 ThreadId = %s', thread_id) + 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) diff --git a/build/android/pylib/utils/run_tests_helper.py b/build/android/pylib/utils/run_tests_helper.py index b5730b6..3227597 100644 --- a/build/android/pylib/utils/run_tests_helper.py +++ b/build/android/pylib/utils/run_tests_helper.py @@ -13,7 +13,7 @@ class CustomFormatter(logging.Formatter): """Custom log formatter.""" #override - def __init__(self, fmt=''): + def __init__(self, fmt='%(threadName)-4s %(message)s'): # Can't use super() because in older Python versions logging.Formatter does # not inherit from object. logging.Formatter.__init__(self, fmt=fmt) @@ -24,8 +24,10 @@ class CustomFormatter(logging.Formatter): # Can't use super() because in older Python versions logging.Formatter does # not inherit from object. msg = logging.Formatter.format(self, record) + if 'MainThread' in msg[:19]: + msg = msg.replace('MainThread', 'Main', 1) timediff = str(int(time.time() - self._creation_time)) - return '%s %ss %s' % (record.levelname[0], timediff.rjust(4), msg) + return '%s %ss %s' % (record.levelname[0], timediff.rjust(4), msg) def GetExpectations(file_name): |