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