Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import base64 | |
| 6 import copy | |
| 7 from datetime import date | |
| 8 from datetime import datetime | |
| 9 from datetime import timedelta | |
| 10 import logging | |
| 11 import json | |
| 12 import os | |
| 13 import zlib | |
| 14 | |
| 15 import dev_appserver | |
| 16 dev_appserver.fix_sys_path() | |
| 17 | |
| 18 from crash import findit_for_client | |
| 19 from crash.type_enums import CrashClient | |
| 20 from crash_queries import crash_iterator | |
| 21 from model.crash.fracas_crash_analysis import FracasCrashAnalysis | |
| 22 from model.crash.cracas_crash_analysis import CracasCrashAnalysis | |
| 23 import remote_api | |
| 24 | |
| 25 _DEFAULT_BATCH_SIZE = 1000 | |
| 26 _TODAY = date.today().strftime('%Y-%m-%d') | |
| 27 _A_YEAR_AGO = (date.today() - timedelta(days=365)).strftime('%Y-%m-%d') | |
| 28 | |
| 29 COMMON_CRASH_INFO_FIELDS = ['crashed_version', 'stack_trace', 'signature', | |
| 30 'platform', 'client_id'] | |
| 31 | |
| 32 | |
| 33 def GetCrashInfoFields(client_id): | |
|
wrengr
2016/10/05 18:41:58
The objects encapsulating the various CrashClients
Sharu Jiang
2016/10/06 18:16:56
There is no need for this function any more, since
| |
| 34 """Gets needed fields for crash info for client. | |
| 35 | |
| 36 The crash info fields are the selected fields from a crash analysis object. | |
| 37 Soa crash analysis can be converted to dict. | |
| 38 """ | |
| 39 crash_info_fields = copy.deepcopy(COMMON_CRASH_INFO_FIELDS) | |
| 40 if client_id == CrashClient.FRACAS or client_id == CrashClient.CRACAS: | |
| 41 crash_info_fields.append('channel') | |
| 42 crash_info_fields.append('historical_metadata') | |
| 43 elif client_id == CrashClient.CLUSTERFUZZ: | |
| 44 # TODO(katesonia): Define CluterfuzzCrashAnalysis. | |
| 45 pass | |
| 46 | |
| 47 return crash_info_fields | |
| 48 | |
| 49 | |
| 50 def GetAnalysisClassForClient(client_id): | |
|
wrengr
2016/10/05 18:41:58
Again, this is too fragile and introduces unnecess
Sharu Jiang
2016/10/06 18:16:56
Added a TODO.
wrengr
2016/10/06 19:20:08
FWIW, I'm in the progress of combining findit_for_
| |
| 51 if client_id == CrashClient.FRACAS: | |
| 52 return FracasCrashAnalysis | |
| 53 elif client_id == CrashClient.CRACAS: | |
| 54 return CracasCrashAnalysis | |
| 55 elif client_id == CrashClient.CLUSTERFUZZ: | |
| 56 # TODO(katesonia): Define ClusterfuzzCrashAnalysis. | |
| 57 return None | |
| 58 | |
| 59 return None | |
| 60 | |
| 61 | |
| 62 def GetQueryForClient(client_id, property_values, start_date, end_date, | |
| 63 datetime_pattern='%Y-%m-%d'): | |
| 64 if property_values is None: | |
| 65 property_values = {} | |
| 66 | |
| 67 start_date = datetime.strptime(start_date, datetime_pattern) | |
| 68 end_date = datetime.strptime(end_date, datetime_pattern) | |
| 69 cls = GetAnalysisClassForClient(client_id) | |
| 70 query = cls.query(**property_values) | |
| 71 return query.filter(cls.requested_time >= start_date).filter( | |
|
wrengr
2016/10/05 18:41:58
Filtering in one pass avoids constructing an inter
Sharu Jiang
2016/10/06 18:16:56
Done.
| |
| 72 cls.requested_time < end_date) | |
| 73 | |
| 74 | |
| 75 def IterateClientCrashes(client_id, | |
| 76 callback_func, | |
|
wrengr
2016/10/05 18:41:58
Rather than passing a callback function, why not s
Sharu Jiang
2016/10/06 18:16:56
This is a good idea :)
| |
| 77 crash_info_fields=None, | |
| 78 property_values=None, | |
| 79 start_date=_A_YEAR_AGO, | |
| 80 end_date=_TODAY, | |
| 81 batch_size=_DEFAULT_BATCH_SIZE, | |
| 82 batch_run=False): | |
| 83 """Pulls crashes from client and passes needed info to callback function. | |
| 84 | |
| 85 Args: | |
| 86 client_id (CrashClient): One of CrashClient.FRACAS, CrashClient.CRACAS, | |
| 87 CrashClient.CLUSTERFUZZ. | |
| 88 callback_func (function): A function with a crash_info dict as the | |
| 89 single parameter. | |
| 90 crash_info_fields (list): Field names of a crash info to pass over to the | |
| 91 callback function. | |
| 92 property_values (dict): Property values to query. | |
| 93 start_date (str): Only iterate testcases after this date including this | |
| 94 date, format '%Y-%m-%d'. | |
| 95 end_date (str): Only iterate testcases before this date excluding this date, | |
| 96 format '%Y-%m-%d'. | |
| 97 batch_size (int): The number of crashes to query at one time. | |
| 98 batch_run (bool): If True, run callback_func on a batch of crashes, if | |
| 99 False, run callback_func on each crash. | |
| 100 | |
| 101 An example is available in crash_printer/print_crash.py. | |
| 102 """ | |
| 103 if crash_info_fields is None: | |
| 104 crash_info_fields = GetCrashInfoFields(client_id) | |
| 105 | |
| 106 if property_values is None: | |
| 107 property_values = {} | |
| 108 | |
| 109 query = GetQueryForClient(client_id, property_values, start_date, end_date) | |
| 110 crash_iterator.IterateCrashes(query, crash_info_fields, callback_func, | |
| 111 batch_size=batch_size, batch_run=batch_run) | |
| OLD | NEW |