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

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

Issue 2391823006: [Findit] Add iterator and crash_iterator for delta test (Closed)
Patch Set: Fix nits. Created 4 years, 2 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
OLDNEW
(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
stgao 2016/10/10 23:39:39 Need clean-up.
Sharu Jiang 2016/10/12 00:52:10 Done.
14
15 import dev_appserver
16 dev_appserver.fix_sys_path()
17
18 import iterator
19 from crash import findit_for_client
20 from crash.type_enums import CrashClient
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_FIELDS = ['crashed_version', 'stack_trace', 'signature',
30 'platform', 'client_id', 'customized_data']
31
32
33 # TODO(katesonia): Switch to use fuction of objects encapsulating CrashClients,
34 # after the refactoring is done.
35 def GetAnalysisClassForClient(client_id):
36 if client_id == CrashClient.FRACAS:
37 return FracasCrashAnalysis
38 elif client_id == CrashClient.CRACAS:
39 return CracasCrashAnalysis
40 elif client_id == CrashClient.CLUSTERFUZZ:
41 # TODO(katesonia): Define ClusterfuzzCrashAnalysis.
42 return None
43
44 return None
45
46
47 def GetQueryForClient(client_id, property_values, start_date, end_date,
48 datetime_pattern='%Y-%m-%d'):
49 if property_values is None:
50 property_values = {}
51
52 start_date = datetime.strptime(start_date, datetime_pattern)
53 end_date = datetime.strptime(end_date, datetime_pattern)
54 cls = GetAnalysisClassForClient(client_id)
55 return cls.query(**property_values).filter(
stgao 2016/10/10 23:39:39 Can we use https://cloud.google.com/appengine/docs
Sharu Jiang 2016/10/12 00:52:10 Problem is only indexed property can be projected,
56 cls.requested_time >= start_date).filter(
57 cls.requested_time < end_date)
58
59
60 def IterateCrashes(client_id,
61 fields=None,
62 property_values=None,
63 start_date=_A_YEAR_AGO,
64 end_date=_TODAY,
65 batch_size=_DEFAULT_BATCH_SIZE,
66 batch_run=False):
67 """Genrates query to query crashes and iterates crashes.
68
69 Args:
70 client_id (CrashClient): One of CrashClient.FRACAS, CrashClient.CRACAS,
71 CrashClient.CLUSTERFUZZ.
72 fields (list): Field names of CrashAnalysis entity to project.
73 property_values (dict): Property values to query.
stgao 2016/10/10 23:39:39 nit: "to filter"?
Sharu Jiang 2016/10/12 00:52:10 Done.
74 start_date (str): Only iterate testcases after this date including this
75 date, format '%Y-%m-%d'.
76 end_date (str): Only iterate testcases before this date excluding this date,
77 format '%Y-%m-%d'.
78 batch_size (int): The number of crashes to query at one time.
79 batch_run (bool): If True, iterate batches of crashes, if
80 False, iterate each crash.
81
82 An example is available in crash_printer/print_crash.py.
83 """
84 if fields is None:
85 fields = COMMON_CRASH_FIELDS
86
87 if property_values is None:
88 property_values = {}
89
90 query = GetQueryForClient(client_id, property_values, start_date, end_date)
91 for crash in iterator.Iterate(query, fields, batch_size=batch_size,
92 batch_run=batch_run):
93 yield crash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698