Chromium Code Reviews| Index: tools/findit/crash_utils.py |
| diff --git a/tools/findit/crash_utils.py b/tools/findit/crash_utils.py |
| index da3c081e79e534b5fdbfb372a90701e6aaf9854d..d408970b691e84943c2ff11fbe1fda4cb5a8108c 100644 |
| --- a/tools/findit/crash_utils.py |
| +++ b/tools/findit/crash_utils.py |
| @@ -6,6 +6,8 @@ import cgi |
| import ConfigParser |
| import json |
| import os |
| +import Queue |
| +import threading |
| import time |
| from common import utils |
| @@ -14,6 +16,60 @@ from result import Result |
| INFINITY = float('inf') |
| +THREAD_NUMBER = 5 |
|
aarya
2014/08/28 01:55:12
s/THREAD_NUMBER/MAX_THREADS or something like that
stgao
2014/08/28 04:24:38
Done.
|
| +TASK_QUEUE = None |
| + |
| + |
| +def Worker(): |
| + global TASK_QUEUE |
| + while True: |
| + task_id, function, args, kwargs, result_semaphore = TASK_QUEUE.get() |
| + print threading.current_thread().name, ' is running task ', task_id |
|
aarya
2014/08/28 01:55:12
Why print ? Won't this show up in findit results w
stgao
2014/08/28 04:24:37
Removed.
Sorry. That's for debugging.
|
| + try: |
| + function(*args, **kwargs) |
| + except: |
| + pass |
| + finally: |
| + # Signal one task is done in case of exception. |
| + result_semaphore.release() |
| + |
| + |
| +def RunTasks(tasks): |
| + """Run given tasks. Not thread-safe: no concurrent calls of this function. |
| + |
| + Return after all tasks were completed. A task is a dict as below: |
| + { |
| + 'function': the function to call, |
| + 'args': the positional argument to pass to the function, |
| + 'kwargs': the key-value arguments to pass to the function, |
| + } |
| + """ |
| + if not tasks: |
| + return |
| + |
| + global TASK_QUEUE |
| + if not TASK_QUEUE: |
| + TASK_QUEUE = Queue.Queue() |
| + for index in range(THREAD_NUMBER): |
| + thread = threading.Thread(target=Worker, name='worker_%s' % index) |
| + # Set as daemon, so no join is needed. |
| + thread.daemon = True |
| + thread.start() |
| + print thread.name, 'is started' |
|
aarya
2014/08/28 01:55:12
probably need to remove print to prevent from not
stgao
2014/08/28 04:24:38
Removed.
|
| + |
| + result_semaphore = threading.Semaphore(0) |
| + |
| + # Push task to task queue for execution. |
| + task_id = 0 |
| + for task in tasks: |
| + task_id += 1 |
|
aarya
2014/08/28 01:55:12
task_id is not needed. even in debugging, you can
|
| + TASK_QUEUE.put( |
| + (task_id, task['function'], task.get('args', []), |
| + task.get('kwargs', {}), result_semaphore)) |
| + |
| + # Wait until all tasks to be executed. |
| + for task in tasks: |
|
aarya
2014/08/28 01:55:12
probably for _ in tasks:
stgao
2014/08/28 04:24:37
Done.
|
| + result_semaphore.acquire() |
| def GetRepositoryType(revision_number): |
| """Returns the repository type of this revision number. |
| @@ -231,7 +287,7 @@ def GetDataFromURL(url, retries=10, sleep_time=0.1, timeout=5): |
| # Retrieves data from URL. |
| try: |
| status_code, data = utils.GetHttpClient().Get(url, timeout=timeout) |
| - except IOError: |
| + except IOError as e: |
| status_code = -1 |
| data = None |
| @@ -370,7 +426,7 @@ def PrettifyFrameInfo(frame_indices, functions): |
| """Return a string to represent the frames with functions.""" |
| frames = [] |
| for frame_index, function in zip(frame_indices, functions): |
| - frames.append('frame #%s, function "%s"' % (frame_index, function)) |
| + frames.append('frame #%s, "%s"' % (frame_index, function.split('(')[0])) |
| return '; '.join(frames) |