Chromium Code Reviews| Index: appengine/findit/util_scripts/crash_queries/delta_test/run-delta-test.py |
| diff --git a/appengine/findit/util_scripts/crash_queries/delta_test/run-delta-test.py b/appengine/findit/util_scripts/crash_queries/delta_test/run-delta-test.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..771d901070f0ed26233cae8d63cfa7ba87a78bbb |
| --- /dev/null |
| +++ b/appengine/findit/util_scripts/crash_queries/delta_test/run-delta-test.py |
| @@ -0,0 +1,135 @@ |
| +# Copyright 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Runs delta test on 2 findit versions.""" |
| + |
| +import argparse |
| +from datetime import date |
| +from datetime import timedelta |
| +import logging |
| +import os |
| +import sys |
| + |
| +from crash.type_enums import CrashClient |
| +from crash_queries.delta_test import delta_test |
| +from crash_queries.delta_test import delta_util |
| + |
| +_TODAY = date.today().strftime('%Y-%m-%d') |
| +_A_YEAR_AGO = (date.today() - timedelta(days=365)).strftime('%Y-%m-%d') |
| + |
| +# App Engine APIs will fail if batch size is more than 1000. |
| +_MAX_BATCH_SIZE = 1000 |
| +_DEFAULT_BATCH_SIZE = _MAX_BATCH_SIZE |
| + |
| +DELTA_RESULTS_DIRECTORY = os.path.join(os.path.dirname(__file__), |
| + 'delta_results') |
| +CHROMIUM_REPO = 'https://chromium.googlesource.com/chromium/src' |
| + |
| + |
| +def RunDeltaTest(): |
| + """Runs delta testing between 2 different Findit versions.""" |
| + argparser = argparse.ArgumentParser( |
| + description='Run delta test between 2 findit versions.') |
| + |
| + argparser.add_argument( |
| + '--revisions', |
| + '-r', |
| + nargs='+', |
| + default=['HEAD^', 'HEAD'], |
| + help=('2 findit revisions to be compared. It can take ' |
| + '1 or 2 revisions.\n' |
| + '(1)-r rev1 rev2: compare rev1 and rev2\n' |
| + '(2)-r rev: compare rev and current HEAD\n' |
| + '(3)no revisions provided, default to compare ' |
| + 'HEAD^ and HEAD')) |
| + |
| + argparser.add_argument( |
| + '--client', |
| + '-c', |
| + default='fracas', |
| + help=('Possible values are: fracas, cracas, clusterfuzz. Right now, only ' |
| + 'fracas is supported.')) |
| + |
| + argparser.add_argument( |
| + '--since', |
| + '--after', |
|
stgao
2016/10/14 01:40:40
same as the other CL, why two different names?
Sharu Jiang
2016/10/15 01:24:47
As answered in the other cl, this is similar to th
stgao
2016/10/20 01:40:20
The other was updated. Why not here?
Two names for
Sharu Jiang
2016/10/20 22:39:06
Done.
|
| + default=_A_YEAR_AGO, |
| + help=('Query data since this date (including this date). ' |
| + 'Should be in YYYY-MM-DD format. E.g. 2015-09-31. ' |
| + 'Defaults to a year ago.')) |
| + |
| + argparser.add_argument( |
| + '--until', |
| + '--before', |
| + default=_TODAY, |
| + help=('Query data until this date (not including this date). ' |
| + 'Should be in YYYY-MM-DD format. E.g. 2015-09-31. ' |
| + 'Defaults to today.')) |
| + |
| + argparser.add_argument( |
| + '--batch', |
| + '-b', |
| + type=int, |
| + default=_DEFAULT_BATCH_SIZE, |
| + help=('The size of batch that can be processed at one time.\n' |
| + 'Note, the batch size cannot be greater than 1000, or app engine ' |
| + 'APIs would fail.')) |
| + |
| + argparser.add_argument( |
| + '--verbose', |
| + '-v', |
| + action='store_true', |
| + default=False, |
| + help='Print findit results.') |
| + |
| + args = argparser.parse_args() |
| + |
| + # If in verbose mode, prints debug infos about Gqlquery. |
|
stgao
2016/10/14 01:40:40
Just Gqlquery?
Sharu Jiang
2016/10/15 01:24:47
Oops, needs to be updated.
|
| + if args.verbose: |
| + logging.basicConfig(level=logging.DEBUG) |
| + else: |
| + logging.basicConfig(level=logging.INFO) |
| + |
| + if len(args.revisions) > 2: |
| + logging.error('Only support delta test between 2 versions.') |
| + sys.exit(1) |
| + |
| + if args.batch > _MAX_BATCH_SIZE: |
| + logging.error('Batch size cannot be greater than %s, or app engine APIs ' |
| + 'would fail.', _MAX_BATCH_SIZE) |
| + sys.exit(1) |
| + |
| + # If only one revision provided, default the rev2 to HEAD. |
| + if len(args.revisions) == 1: |
| + args.revisions.append('HEAD') |
| + |
| + git_hash1 = delta_util.ParseGitHash(args.revisions[0]) |
| + git_hash2 = delta_util.ParseGitHash(args.revisions[1]) |
| + |
| + delta_path = os.path.join(DELTA_RESULTS_DIRECTORY, |
| + '%s_%s_%s..%s.delta.csv' % (git_hash1[:7], |
| + git_hash2[:7], |
| + args.since, args.until)) |
| + |
| + # Check if delta results already existed. |
| + if os.path.exists(delta_path): |
| + logging.info('Delta results already existed in\n%s', delta_path) |
|
stgao
2016/10/14 01:40:40
For this case, what's the expected action by the u
Sharu Jiang
2016/10/15 01:24:47
In this case, user can check out the csv result fi
stgao
2016/10/20 01:40:20
Why not add that the the message? It is not clear
Sharu Jiang
2016/10/20 22:39:06
I meant open the csv file to see the results.
Mo
|
| + return |
| + |
| + logging.info('Running delta test...') |
| + # Get delta of results between git_hash1 and git_hash2. |
| + deltas, crash_num = delta_test.DeltaEvaluator( |
| + git_hash1, git_hash2, args.client, |
| + start_date=args.since, end_date=args.until, |
| + batch_size=args.batch, verbose=args.verbose, |
| + app_id=os.getenv('APP_ID')) |
| + |
| + logging.info('\n========================= Summary =========================') |
| + delta_util.PrintDelta(deltas, crash_num) |
| + delta_util.WriteDeltaToCSV(deltas, crash_num, |
| + git_hash1, git_hash2, delta_path) |
| + |
| + |
| +if __name__ == '__main__': |
| + RunDeltaTest() |