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

Side by Side Diff: appengine/findit/util_scripts/crash_queries/delta_test/delta_test.py

Issue 2432203003: [Predator] Run predator. (Closed)
Patch Set: Fix nits. Created 4 years, 1 month 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
OLDNEW
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 json 5 import json
6 import logging 6 import logging
7 import os 7 import os
8 import pickle 8 import pickle
9 import subprocess 9 import subprocess
10 10
11 from crash_queries import crash_iterator 11 from crash_queries import crash_iterator
12 from crash_queries.delta_test import delta_util 12 from crash_queries.delta_test import delta_util
13 13
14 AZALEA_RESULTS_DIRECTORY = os.path.join(os.path.dirname(__file__), 14 PREDATOR_RESULTS_DIRECTORY = os.path.join(os.path.dirname(__file__),
15 'azalea_results') 15 'predator_results')
16 DELTA_TEST_DIRECTORY = os.path.dirname(__file__) 16 DELTA_TEST_DIRECTORY = os.path.dirname(__file__)
17 CRASH_FIELDS = ['crashed_version', 'stack_trace', 'signature',
18 'platform', 'client_id', 'regression_range',
19 'customized_data', 'historical_metadata']
17 20
18 21
19 # TODO(crbug.com/662540): Add unittests. 22 # TODO(crbug.com/662540): Add unittests.
20 class Delta(object): # pragma: no cover. 23 class Delta(object): # pragma: no cover.
21 """Stands for delta between two results. 24 """Stands for delta between two results.
22 25
23 Note, the 2 results should be the same kind and have the same structure. 26 Note, the 2 results should be the same kind and have the same structure.
24 """ 27 """
25 28
26 def __init__(self, result1, result2, fields): 29 def __init__(self, result1, result2, fields):
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 """ 94 """
92 deltas = {} 95 deltas = {}
93 for result_id, result1 in set1.iteritems(): 96 for result_id, result1 in set1.iteritems():
94 # Even when the command are exactly the same, it's possible that one set is 97 # Even when the command are exactly the same, it's possible that one set is
95 # loaded from local result file, another is just queried from database, 98 # loaded from local result file, another is just queried from database,
96 # sometimes some crash results would get deleted. 99 # sometimes some crash results would get deleted.
97 if result_id not in set2: 100 if result_id not in set2:
98 continue 101 continue
99 102
100 result2 = set2[result_id] 103 result2 = set2[result_id]
101 delta = Delta(result1, result2, result1.fields) 104 if result1:
105 fields = result1.fields
106 elif result2:
107 fields = result2.fields
108 else:
109 fields = None
110
111 delta = Delta(result1, result2, fields)
102 if delta: 112 if delta:
103 deltas[result_id] = delta 113 deltas[result_id] = delta
104 114
105 return deltas 115 return deltas
106 116
107 117
108 # TODO(crbug.com/662540): Add unittests. 118 # TODO(crbug.com/662540): Add unittests.
109 def GetResults(crashes, client_id, git_hash, result_path, 119 def GetResults(crashes, client_id, app_id, git_hash, result_path,
110 verbose=False): # pragma: no cover. 120 verbose=False): # pragma: no cover.
111 """Returns an evaluator function to compute delta between 2 findit githashes. 121 """Returns an evaluator function to compute delta between 2 findit githashes.
112 122
113 Args: 123 Args:
114 crashes (list): A list of crash infos. 124 crashes (list): A list of crash infos.
115 client_id (str): Possible values - fracas/cracas/clustefuzz. 125 client_id (str): Possible values - fracas/cracas/clustefuzz.
126 app_id (str): Appengine app id to query.
116 git_hash (str): A git hash of findit repository. 127 git_hash (str): A git hash of findit repository.
117 result_path (str): file path for subprocess to write results on. 128 result_path (str): file path for subprocess to write results on.
118 verbose (bool): If True, print all the findit results. 129 verbose (bool): If True, print all the findit results.
119 130
120 Return: 131 Return:
121 A dict mapping crash id to culprit for every crashes analyzed by 132 A dict mapping crash id to culprit for every crashes analyzed by
122 git_hash version. 133 git_hash version.
123 """ 134 """
124 if not crashes: 135 if not crashes:
125 return {} 136 return {}
126 137
127 if verbose: 138 if verbose:
128 logging.info('\n\n***************************') 139 logging.info('***************************')
129 logging.info('Switching to git %s', git_hash) 140 logging.info('Switching to git %s', git_hash)
130 logging.info('***************************\n\n') 141 logging.info('***************************\n\n')
131 142
132 with open(os.devnull, 'w') as null_handle: 143 with open(os.devnull, 'w') as null_handle:
133 subprocess.check_call( 144 subprocess.check_call(
134 'cd %s; git checkout %s' % (DELTA_TEST_DIRECTORY, git_hash), 145 'cd %s; git checkout %s' % (DELTA_TEST_DIRECTORY, git_hash),
135 stdout=null_handle, 146 stdout=null_handle,
136 stderr=null_handle, 147 stderr=null_handle,
137 shell=True) 148 shell=True)
138 149
139 if not os.path.exists(result_path): 150 if not os.path.exists(result_path):
140 args = ['python', 'run-predator.py', result_path, '--client', client_id] 151 args = ['python', 'run-predator.py', result_path, client_id, app_id]
141 if verbose: 152 if verbose:
142 args.append('--verbose') 153 args.append('--verbose')
143 p = subprocess.Popen(args, stdin=subprocess.PIPE) 154 p = subprocess.Popen(args, stdin=subprocess.PIPE)
144 # TODO(katesonia): Cache crashes for crash_iterator and let subprocess read 155 # TODO(katesonia): Cache crashes for crash_iterator and let subprocess read
145 # corresponding cache file instead. 156 # corresponding cache file instead.
146 p.communicate(input=json.dumps(crashes)) 157 p.communicate(input=json.dumps(crashes))
147 else: 158 else:
148 logging.info('\nLoading results from %s', result_path) 159 logging.info('\nLoading results from %s', result_path)
149 160
150 if not os.path.exists(result_path): 161 if not os.path.exists(result_path):
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 deltas (dict): Mappings id to delta for each culprit value. 194 deltas (dict): Mappings id to delta for each culprit value.
184 crash_count (int): Total count of all the crashes. 195 crash_count (int): Total count of all the crashes.
185 """ 196 """
186 head_branch_name = subprocess.check_output( 197 head_branch_name = subprocess.check_output(
187 ['git', 'rev-parse', '--abbrev-ref', 'HEAD']).replace('\n', '') 198 ['git', 'rev-parse', '--abbrev-ref', 'HEAD']).replace('\n', '')
188 try: 199 try:
189 deltas = {} 200 deltas = {}
190 crash_count = 0 201 crash_count = 0
191 for index, crashes in enumerate( 202 for index, crashes in enumerate(
192 crash_iterator.IterateCrashes(client_id, app_id, 203 crash_iterator.IterateCrashes(client_id, app_id,
204 fields=CRASH_FIELDS,
193 property_values=property_values, 205 property_values=property_values,
194 start_date=start_date, 206 start_date=start_date,
195 end_date=end_date, 207 end_date=end_date,
196 batch_size=batch_size, 208 batch_size=batch_size,
197 batch_run=True)): 209 batch_run=True)):
198 210
199 results = [] 211 results = []
200 for git_hash in [git_hash1, git_hash2]: 212 for git_hash in [git_hash1, git_hash2]:
201 result_path = os.path.join( 213 result_path = os.path.join(
202 AZALEA_RESULTS_DIRECTORY, delta_util.GenerateFileName( 214 PREDATOR_RESULTS_DIRECTORY, delta_util.GenerateFileName(
203 client_id, property_values, start_date, end_date, 215 client_id, property_values, start_date, end_date,
204 batch_size, index, git_hash)) 216 batch_size, index, git_hash))
205 results.append(GetResults(crashes, client_id, git_hash, result_path, 217 results.append(GetResults(crashes, client_id, app_id,
218 git_hash, result_path,
206 verbose=verbose)) 219 verbose=verbose))
207 220
208 crash_count += len(crashes) 221 crash_count += len(crashes)
209 deltas.update(GetDeltasFromTwoSetsOfResults(*results)) 222 batch_deltas = GetDeltasFromTwoSetsOfResults(*results)
210 223 # Print deltas of the current batch.
224 delta_util.PrintDelta(batch_deltas, len(crashes))
225 deltas.update(batch_deltas)
211 return deltas, crash_count 226 return deltas, crash_count
212 finally: 227 finally:
213 with open(os.devnull, 'w') as null_handle: 228 with open(os.devnull, 'w') as null_handle:
214 subprocess.check_call(['git', 'checkout', head_branch_name], 229 subprocess.check_call(['git', 'checkout', head_branch_name],
215 stdout=null_handle, 230 stdout=null_handle,
216 stderr=null_handle) 231 stderr=null_handle)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698