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 json | 5 import json |
6 import os | 6 import os |
7 import pickle | 7 import pickle |
8 import subprocess | 8 import subprocess |
9 | 9 |
10 from crash_queries import crash_iterator | 10 from crash_queries import crash_iterator |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 # ``run-predator``. | 177 # ``run-predator``. |
178 with open(result_path) as f: | 178 with open(result_path) as f: |
179 return pickle.load(f) | 179 return pickle.load(f) |
180 | 180 |
181 return {} | 181 return {} |
182 | 182 |
183 | 183 |
184 # TODO(crbug.com/662540): Add unittests. | 184 # TODO(crbug.com/662540): Add unittests. |
185 def DeltaEvaluator(git_hash1, git_hash2, | 185 def DeltaEvaluator(git_hash1, git_hash2, |
186 client_id, app_id, | 186 client_id, app_id, |
187 start_date, end_date, batch_size, | 187 start_date, end_date, batch_size, max_n, |
188 property_values=None, verbose=False): # pragma: no cover. | 188 property_values=None, verbose=False): # pragma: no cover. |
189 """Evaluates delta between git_hash1 and git_hash2 on a set of Testcases. | 189 """Evaluates delta between git_hash1 and git_hash2 on a set of Testcases. |
190 | 190 |
191 Args: | 191 Args: |
192 git_hash1 (str): A git hash of findit repository. | 192 git_hash1 (str): A git hash of findit repository. |
193 git_hash2 (str): A git hash of findit repository. | 193 git_hash2 (str): A git hash of findit repository. |
194 start_date (str): Run delta test on testcases after (including) | 194 start_date (str): Run delta test on testcases after (including) |
195 the start_date, format should be '%Y-%m-%d'. | 195 the start_date, format should be '%Y-%m-%d'. |
196 end_date (str): Run delta test on testcases before (not including) | 196 end_date (str): Run delta test on testcases before (not including) |
197 the end_date, format should be '%Y-%m-%d'. | 197 the end_date, format should be '%Y-%m-%d'. |
198 client_id (CrashClient): Possible values are 'fracas', 'cracas', | 198 client_id (CrashClient): Possible values are 'fracas', 'cracas', |
199 'cluterfuzz'. | 199 'cluterfuzz'. |
200 app_id (str): Appengine app id to query. | 200 app_id (str): Appengine app id to query. |
201 batch_size (int): Size of a batch that can be queried at one time. | 201 batch_size (int): Size of a batch that can be queried at one time. |
202 max_n: (int): Maximum total number of crashes. | |
lijeffrey
2017/01/24 02:22:49
nit: why not just give this the full name max_numb
| |
202 property_values (dict): Property values to query. | 203 property_values (dict): Property values to query. |
203 batch_size (int): The size of crashes that can be queried at one time. | 204 batch_size (int): The size of crashes that can be queried at one time. |
204 verbose (bool): If True, print all the findit results. | 205 verbose (bool): If True, print all the findit results. |
205 Return: | 206 Return: |
206 (deltas, crash_count). | 207 (deltas, crash_count). |
207 deltas (dict): Mappings id to delta for each culprit value. | 208 deltas (dict): Mappings id to delta for each culprit value. |
208 crash_count (int): Total count of all the crashes. | 209 crash_count (int): Total count of all the crashes. |
209 """ | 210 """ |
210 head_branch_name = subprocess.check_output( | 211 head_branch_name = subprocess.check_output( |
211 ['git', 'rev-parse', '--abbrev-ref', 'HEAD']).replace('\n', '') | 212 ['git', 'rev-parse', '--abbrev-ref', 'HEAD']).replace('\n', '') |
212 try: | 213 try: |
213 deltas = {} | 214 deltas = {} |
214 crash_count = 0 | 215 crash_count = 0 |
215 # Iterate batches of crash informations. | 216 # Iterate batches of crash informations. |
216 for index, crashes in enumerate( | 217 for index, crashes in enumerate( |
217 crash_iterator.CachedCrashIterator(client_id, app_id, | 218 crash_iterator.CachedCrashIterator(client_id, app_id, |
218 fields=CRASH_FIELDS, | 219 fields=CRASH_FIELDS, |
219 property_values=property_values, | 220 property_values=property_values, |
220 start_date=start_date, | 221 start_date=start_date, |
221 end_date=end_date, | 222 end_date=end_date, |
222 batch_size=batch_size, | 223 batch_size=batch_size, |
223 batch_run=True)): | 224 batch_run=True)): |
225 # Trucates the crashes and make it contains at most max_n crashes. | |
chanli
2017/01/23 21:59:38
nit: Truncates
Sharu Jiang
2017/01/24 01:59:39
Done.
| |
226 if crash_count + len(crashes) > max_n: | |
227 crashes = crashes[:(max_n - crash_count)] | |
228 | |
224 results = [] | 229 results = [] |
225 for git_hash in [git_hash1, git_hash2]: | 230 for git_hash in [git_hash1, git_hash2]: |
231 # Generate result path to store culprit results for this batch. | |
226 result_path = os.path.join( | 232 result_path = os.path.join( |
227 PREDATOR_RESULTS_DIRECTORY, delta_util.GenerateFileName( | 233 PREDATOR_RESULTS_DIRECTORY, delta_util.GenerateFileName( |
228 client_id, property_values, start_date, end_date, | 234 client_id, property_values, start_date, end_date, |
229 batch_size, index, git_hash)) | 235 batch_size, index, max_n, git_hash)) |
230 # Get the culprit results of this batch of crashes. | 236 # Get the culprit results of this batch of crashes. |
231 results.append(GetResults(crashes, client_id, app_id, | 237 results.append(GetResults(crashes, client_id, app_id, |
232 git_hash, result_path, | 238 git_hash, result_path, |
233 verbose=verbose)) | 239 verbose=verbose)) |
234 | 240 |
235 crash_count += len(crashes) | 241 crash_count += len(crashes) |
chanli
2017/01/23 21:59:38
If has truncated above, crash_count should equal t
Sharu Jiang
2017/01/24 01:59:39
Yes.
| |
236 # Compute delta between 2 versions of culprit results for this batch. | 242 # Compute delta between 2 versions of culprit results for this batch. |
237 batch_deltas = GetDeltasFromTwoSetsOfResults(*results) | 243 batch_deltas = GetDeltasFromTwoSetsOfResults(*results) |
238 # Print the deltas of the current batch. | 244 # Print the deltas of the current batch. |
239 print '========= Delta of this batch =========' | 245 print '========= Delta of this batch =========' |
240 delta_util.PrintDelta(batch_deltas, len(crashes), app_id) | 246 delta_util.PrintDelta(batch_deltas, len(crashes), app_id) |
241 deltas.update(batch_deltas) | 247 deltas.update(batch_deltas) |
248 if crash_count >= max_n: | |
249 break | |
242 | 250 |
243 return deltas, crash_count | 251 return deltas, crash_count |
244 finally: | 252 finally: |
245 with open(os.devnull, 'w') as null_handle: | 253 with open(os.devnull, 'w') as null_handle: |
246 subprocess.check_call(['git', 'checkout', head_branch_name], | 254 subprocess.check_call(['git', 'checkout', head_branch_name], |
247 stdout=null_handle, | 255 stdout=null_handle, |
248 stderr=null_handle) | 256 stderr=null_handle) |
OLD | NEW |