| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 argparse | 5 import argparse |
| 6 import json | 6 import json |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 import threading | 10 import threading |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 from crash.type_enums import CrashClient | 26 from crash.type_enums import CrashClient |
| 27 from crash_queries.delta_test import delta_util | 27 from crash_queries.delta_test import delta_util |
| 28 from git_checkout.local_git_repository import LocalGitRepository | 28 from git_checkout.local_git_repository import LocalGitRepository |
| 29 from model.crash.crash_config import CrashConfig | 29 from model.crash.crash_config import CrashConfig |
| 30 import remote_api | 30 import remote_api |
| 31 | 31 |
| 32 _FRACAS_FEEDBACK_URL_TEMPLATE = ( | 32 _FRACAS_FEEDBACK_URL_TEMPLATE = ( |
| 33 'https://%s.appspot.com/crash/fracas-result-feedback?key=%s') | 33 'https://%s.appspot.com/crash/fracas-result-feedback?key=%s') |
| 34 | 34 |
| 35 | 35 |
| 36 def StoreResults(crash, client_id, app_id, id_to_culprits, lock, verbose=False): | 36 def StoreResults(crash, client_id, app_id, id_to_culprits, lock, config, |
| 37 verbose=False): |
| 37 """Stores findit result of crash into id_to_culprits dict.""" | 38 """Stores findit result of crash into id_to_culprits dict.""" |
| 38 crash_url = _FRACAS_FEEDBACK_URL_TEMPLATE % (app_id, crash['id']) | 39 crash_url = _FRACAS_FEEDBACK_URL_TEMPLATE % (app_id, crash['id']) |
| 39 try: | 40 try: |
| 40 findit = FinditForClientID(client_id, LocalGitRepository) | 41 findit = FinditForClientID(client_id, LocalGitRepository, config) |
| 41 stacktrace = findit._stacktrace_parser.Parse( | 42 stacktrace = findit._stacktrace_parser.Parse( |
| 42 crash['stack_trace'], | 43 crash['stack_trace'], |
| 43 ChromeDependencyFetcher(LocalGitRepository.Factory()).GetDependency( | 44 ChromeDependencyFetcher(LocalGitRepository.Factory()).GetDependency( |
| 44 crash['crashed_version'], | 45 crash['crashed_version'], |
| 45 crash['platform'])) | 46 crash['platform'])) |
| 46 if stacktrace: | 47 if stacktrace: |
| 47 culprit = findit._predator.FindCulprit(CrashReport( | 48 culprit = findit._predator.FindCulprit(CrashReport( |
| 48 crashed_version=crash['crashed_version'], | 49 crashed_version=crash['crashed_version'], |
| 49 signature=crash['signature'], | 50 signature=crash['signature'], |
| 50 platform=crash['platform'], | 51 platform=crash['platform'], |
| (...skipping 11 matching lines...) Expand all Loading... |
| 62 with lock: | 63 with lock: |
| 63 id_to_culprits[crash['id']] = None | 64 id_to_culprits[crash['id']] = None |
| 64 print '\n\nCrash:', crash_url | 65 print '\n\nCrash:', crash_url |
| 65 print traceback.format_exc() | 66 print traceback.format_exc() |
| 66 | 67 |
| 67 | 68 |
| 68 def GetCulprits(crashes, client_id, app_id, verbose=False): | 69 def GetCulprits(crashes, client_id, app_id, verbose=False): |
| 69 """Run predator analysis on crashes locally.""" | 70 """Run predator analysis on crashes locally.""" |
| 70 # Enable remote access to app engine services. | 71 # Enable remote access to app engine services. |
| 71 remote_api.EnableRemoteApi(app_id) | 72 remote_api.EnableRemoteApi(app_id) |
| 72 origin_get = CrashConfig.Get | 73 id_to_culprits = {} |
| 73 try: | 74 tasks = [] |
| 74 # This hack is to solve flaky BadStatusLine excepion(crbug.com/666150) in | 75 lock = threading.Lock() |
| 75 # remote api when key.get() gets called in threads. | 76 config = CrashConfig.Get() |
| 76 # TODO(katesonia): Remove this hack after crbug.com/659354 is done. | 77 for crash in crashes: |
| 77 CrashConfig.Get = script_util.GetLockedMethod(CrashConfig, 'Get', | 78 crash['regression_range'] = DetectRegressionRange( |
| 78 threading.Lock()) | 79 crash['historical_metadata']) |
| 79 id_to_culprits = {} | 80 tasks.append({ |
| 80 tasks = [] | 81 'function': StoreResults, |
| 81 lock = threading.Lock() | 82 'args': [crash, client_id, app_id, id_to_culprits, lock, config], |
| 82 for crash in crashes: | 83 'kwargs': {'verbose': verbose} |
| 83 crash['regression_range'] = DetectRegressionRange( | 84 }) |
| 84 crash['historical_metadata']) | 85 script_util.RunTasks(tasks) |
| 85 tasks.append({ | |
| 86 'function': StoreResults, | |
| 87 'args': [crash, client_id, app_id, id_to_culprits, lock], | |
| 88 'kwargs': {'verbose': verbose} | |
| 89 }) | |
| 90 script_util.RunTasks(tasks) | |
| 91 | 86 |
| 92 return id_to_culprits | 87 return id_to_culprits |
| 93 finally: | |
| 94 CrashConfig.Get = origin_get | |
| 95 | 88 |
| 96 | 89 |
| 97 def RunPredator(): | 90 def RunPredator(): |
| 98 """Runs delta testing between 2 different Findit versions.""" | 91 """Runs delta testing between 2 different Findit versions.""" |
| 99 argparser = argparse.ArgumentParser( | 92 argparser = argparse.ArgumentParser( |
| 100 description='Run Predator on a batch of crashes.') | 93 description='Run Predator on a batch of crashes.') |
| 101 argparser.add_argument('result_path', help='Path to store results') | 94 argparser.add_argument('result_path', help='Path to store results') |
| 102 argparser.add_argument('client', help=('Possible values are: fracas, cracas, ' | 95 argparser.add_argument('client', help=('Possible values are: fracas, cracas, ' |
| 103 'clusterfuzz. Right now, only fracas ' | 96 'clusterfuzz. Right now, only fracas ' |
| 104 'is supported.')) | 97 'is supported.')) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 117 return | 110 return |
| 118 | 111 |
| 119 culprits = GetCulprits(crashes, args.client, args.app, args.verbose) | 112 culprits = GetCulprits(crashes, args.client, args.app, args.verbose) |
| 120 delta_util.FlushResult(culprits, args.result_path) | 113 delta_util.FlushResult(culprits, args.result_path) |
| 121 | 114 |
| 122 | 115 |
| 123 if __name__ == '__main__': | 116 if __name__ == '__main__': |
| 124 # Disable the trivial loggings inside predator. | 117 # Disable the trivial loggings inside predator. |
| 125 logging.basicConfig(level=logging.ERROR) | 118 logging.basicConfig(level=logging.ERROR) |
| 126 RunPredator() | 119 RunPredator() |
| OLD | NEW |