Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: tools/findit/crash_utils.py

Issue 510163002: [Findit] Fix blame for GIT and uptake bug fix. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reuse threads in a pool. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/findit/blame.py ('k') | tools/findit/findit_for_crash.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import cgi 5 import cgi
6 import ConfigParser 6 import ConfigParser
7 import json 7 import json
8 import os 8 import os
9 import Queue
10 import threading
9 import time 11 import time
10 12
11 from common import utils 13 from common import utils
12 from result import Result 14 from result import Result
13 15
14 16
15 INFINITY = float('inf') 17 INFINITY = float('inf')
16 18
19 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.
20 TASK_QUEUE = None
21
22
23 def Worker():
24 global TASK_QUEUE
25 while True:
26 task_id, function, args, kwargs, result_semaphore = TASK_QUEUE.get()
27 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.
28 try:
29 function(*args, **kwargs)
30 except:
31 pass
32 finally:
33 # Signal one task is done in case of exception.
34 result_semaphore.release()
35
36
37 def RunTasks(tasks):
38 """Run given tasks. Not thread-safe: no concurrent calls of this function.
39
40 Return after all tasks were completed. A task is a dict as below:
41 {
42 'function': the function to call,
43 'args': the positional argument to pass to the function,
44 'kwargs': the key-value arguments to pass to the function,
45 }
46 """
47 if not tasks:
48 return
49
50 global TASK_QUEUE
51 if not TASK_QUEUE:
52 TASK_QUEUE = Queue.Queue()
53 for index in range(THREAD_NUMBER):
54 thread = threading.Thread(target=Worker, name='worker_%s' % index)
55 # Set as daemon, so no join is needed.
56 thread.daemon = True
57 thread.start()
58 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.
59
60 result_semaphore = threading.Semaphore(0)
61
62 # Push task to task queue for execution.
63 task_id = 0
64 for task in tasks:
65 task_id += 1
aarya 2014/08/28 01:55:12 task_id is not needed. even in debugging, you can
66 TASK_QUEUE.put(
67 (task_id, task['function'], task.get('args', []),
68 task.get('kwargs', {}), result_semaphore))
69
70 # Wait until all tasks to be executed.
71 for task in tasks:
aarya 2014/08/28 01:55:12 probably for _ in tasks:
stgao 2014/08/28 04:24:37 Done.
72 result_semaphore.acquire()
17 73
18 def GetRepositoryType(revision_number): 74 def GetRepositoryType(revision_number):
19 """Returns the repository type of this revision number. 75 """Returns the repository type of this revision number.
20 76
21 Args: 77 Args:
22 revision_number: A revision number or git hash. 78 revision_number: A revision number or git hash.
23 79
24 Returns: 80 Returns:
25 'git' or 'svn', depending on the revision_number. 81 'git' or 'svn', depending on the revision_number.
26 """ 82 """
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 280
225 Returns: 281 Returns:
226 None if the data retrieval fails, or the raw data. 282 None if the data retrieval fails, or the raw data.
227 """ 283 """
228 count = 0 284 count = 0
229 while True: 285 while True:
230 count += 1 286 count += 1
231 # Retrieves data from URL. 287 # Retrieves data from URL.
232 try: 288 try:
233 status_code, data = utils.GetHttpClient().Get(url, timeout=timeout) 289 status_code, data = utils.GetHttpClient().Get(url, timeout=timeout)
234 except IOError: 290 except IOError as e:
235 status_code = -1 291 status_code = -1
236 data = None 292 data = None
237 293
238 if status_code == 200: 294 if status_code == 200:
239 return data 295 return data
240 296
241 if count < retries: 297 if count < retries:
242 # If retrieval fails, try after sleep_time second. 298 # If retrieval fails, try after sleep_time second.
243 time.sleep(sleep_time) 299 time.sleep(sleep_time)
244 else: 300 else:
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 Returns: 419 Returns:
364 A string representation of the list. 420 A string representation of the list.
365 """ 421 """
366 return ', '.join(map(str, items)) 422 return ', '.join(map(str, items))
367 423
368 424
369 def PrettifyFrameInfo(frame_indices, functions): 425 def PrettifyFrameInfo(frame_indices, functions):
370 """Return a string to represent the frames with functions.""" 426 """Return a string to represent the frames with functions."""
371 frames = [] 427 frames = []
372 for frame_index, function in zip(frame_indices, functions): 428 for frame_index, function in zip(frame_indices, functions):
373 frames.append('frame #%s, function "%s"' % (frame_index, function)) 429 frames.append('frame #%s, "%s"' % (frame_index, function.split('(')[0]))
374 return '; '.join(frames) 430 return '; '.join(frames)
375 431
376 432
377 def PrettifyFiles(file_list): 433 def PrettifyFiles(file_list):
378 """Returns a string representation of a list of file names. 434 """Returns a string representation of a list of file names.
379 435
380 Args: 436 Args:
381 file_list: A list of tuple, (file_name, file_url). 437 file_list: A list of tuple, (file_name, file_url).
382 Returns: 438 Returns:
383 A string representation of file names with their urls. 439 A string representation of file names with their urls.
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 review_url = None 558 review_url = None
503 reviewers = None 559 reviewers = None
504 line_content = blame.line_content 560 line_content = blame.line_content
505 message = blame.message 561 message = blame.message
506 562
507 result = Result(suspected_cl, revision_url, component_name, author, reason, 563 result = Result(suspected_cl, revision_url, component_name, author, reason,
508 review_url, reviewers, line_content, message) 564 review_url, reviewers, line_content, message)
509 result_list.append(result) 565 result_list.append(result)
510 566
511 return result_list 567 return result_list
OLDNEW
« no previous file with comments | « tools/findit/blame.py ('k') | tools/findit/findit_for_crash.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698