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

Side by Side Diff: appengine/findit/util_scripts/crash_queries/delta_test/run-delta-test.py

Issue 2400283003: [Findit] Add skeleton code for delta test script. (Closed)
Patch Set: Address comments. 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 """Runs delta test on 2 findit versions."""
6
7 import argparse
8 from datetime import date
9 from datetime import timedelta
10 import json
11 import logging
12 import os
13 import sys
14
15 _SCRIPT_DIR = os.path.join(os.path.dirname(__file__), os.path.pardir,
16 os.path.pardir)
17 sys.path.insert(1, _SCRIPT_DIR)
18
19 import script_util
20 script_util.SetUpSystemPaths()
21
22 from crash.type_enums import CrashClient
23 from crash_queries.delta_test import delta_test
24 from crash_queries.delta_test import delta_util
25
26 _TODAY = date.today().strftime('%Y-%m-%d')
27 _A_YEAR_AGO = (date.today() - timedelta(days=365)).strftime('%Y-%m-%d')
28
29 # App Engine APIs will fail if batch size is more than 1000.
30 _MAX_BATCH_SIZE = 1000
31 _DEFAULT_BATCH_SIZE = _MAX_BATCH_SIZE
32
33 DELTA_RESULTS_DIRECTORY = os.path.join(os.path.dirname(__file__),
34 'delta_results')
35 CHROMIUM_REPO = 'https://chromium.googlesource.com/chromium/src'
36
37
38 def RunDeltaTest():
39 """Runs delta testing between 2 different Findit versions."""
40 argparser = argparse.ArgumentParser(
41 description='Run delta test between 2 findit versions.')
42
43 argparser.add_argument(
44 '--revisions',
45 '-r',
46 nargs='+',
47 default=['HEAD^', 'HEAD'],
48 help=('2 findit revisions to be compared. It can take '
49 '1 or 2 revisions.\n'
50 '(1)-r rev1 rev2: compare rev1 and rev2\n'
51 '(2)-r rev: compare rev and current HEAD\n'
52 '(3)no revisions provided, default to compare '
53 'HEAD^ and HEAD'))
54
55 argparser.add_argument(
56 '--client',
57 '-c',
58 default='fracas',
59 help=('Possible values are: fracas, cracas, clusterfuzz. Right now, only '
60 'fracas is supported.'))
61
62 argparser.add_argument(
63 '--app',
64 '-a',
65 default='findit-for-me-dev',
66 help=('App id of the App engine app that query needs to access. '
67 'Defualts to findit-for-me-dev.'))
68
69 argparser.add_argument(
70 '--since',
71 '-s',
72 default=_A_YEAR_AGO,
73 help=('Query data since this date (including this date). '
74 'Should be in YYYY-MM-DD format. E.g. 2015-09-31. '
75 'Defaults to a year ago.'))
76
77 argparser.add_argument(
78 '--until',
79 '-u',
80 default=_TODAY,
81 help=('Query data until this date (not including this date). '
82 'Should be in YYYY-MM-DD format. E.g. 2015-09-31. '
83 'Defaults to today.'))
84
85 argparser.add_argument(
86 '--batch',
87 '-b',
88 type=int,
89 default=_DEFAULT_BATCH_SIZE,
90 help=('The size of batch that can be processed at one time.\n'
91 'Note, the batch size cannot be greater than 1000, or app engine '
92 'APIs would fail.\nDefaults to maximum number 1000.'))
93
94 argparser.add_argument(
95 '--verbose',
96 '-v',
97 action='store_true',
98 default=False,
99 help='Print findit results. Defaults to False.')
100
101 args = argparser.parse_args()
102
103 # If in verbose mode, prints debug information.
104 if args.verbose:
105 logging.basicConfig(level=logging.DEBUG)
106 else:
107 logging.basicConfig(level=logging.INFO)
108
109 if len(args.revisions) > 2:
110 logging.error('Only support delta test between 2 versions.')
111 sys.exit(1)
112
113 if args.batch > _MAX_BATCH_SIZE:
114 logging.error('Batch size cannot be greater than %s, or app engine APIs '
115 'would fail.', _MAX_BATCH_SIZE)
116 sys.exit(1)
117
118 # If only one revision provided, default the rev2 to HEAD.
119 if len(args.revisions) == 1:
120 args.revisions.append('HEAD')
121
122 git_hash1 = delta_util.ParseGitHash(args.revisions[0])
123 git_hash2 = delta_util.ParseGitHash(args.revisions[1])
124
125 delta_result_prefix = '%s_%s_%s..%s.delta' % (git_hash1[:7], git_hash2[:7],
126 args.since, args.until)
127 delta_csv_path = os.path.join(
128 DELTA_RESULTS_DIRECTORY, '%s.csv' % delta_result_prefix)
129 delta_json_path = os.path.join(
130 DELTA_RESULTS_DIRECTORY, '%s.json' % delta_result_prefix)
131
132 # Check if delta results already existed.
133 if os.path.exists(delta_csv_path):
134 logging.info('Delta results existed in\n%s', delta_csv_path)
135 if not os.path.exists(delta_json_path):
136 logging.info('Cannot print out delta results, '
137 'please open %s to see the results.')
138 return
139
140 with open(delta_json_path) as f:
141 deltas, crash_num = json.load(f)
142 else:
143 logging.info('Running delta test...')
144 # Get delta of results between git_hash1 and git_hash2.
145 deltas, crash_num = delta_test.DeltaEvaluator(
146 git_hash1, git_hash2, args.client, args.app,
147 start_date=args.since, end_date=args.until,
148 batch_size=args.batch, verbose=args.verbose)
149 delta_util.FlushResult([deltas, crash_num], delta_json_path)
150 delta_util.WriteDeltaToCSV(deltas, crash_num,
151 git_hash1, git_hash2, delta_csv_path)
152
153 # Print delta results to users.
154 logging.info('\n========================= Summary =========================')
155 delta_util.PrintDelta(deltas, crash_num)
156
157
158 if __name__ == '__main__':
159 RunDeltaTest()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698