Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import json | 5 import json |
| 6 import sys | 6 import sys |
| 7 | 7 |
| 8 import fieldtrial_to_struct | |
| 8 | 9 |
| 9 def _hex(ch): | 10 def _hex(ch): |
| 10 hv = hex(ord(ch)).replace('0x', '') | 11 hv = hex(ord(ch)).replace('0x', '') |
| 11 hv.zfill(2) | 12 hv.zfill(2) |
| 12 return hv.upper() | 13 return hv.upper() |
| 13 | 14 |
| 14 # URL escapes the delimiter characters from the output. urllib.quote is not | 15 # URL escapes the delimiter characters from the output. urllib.quote is not |
| 15 # used because it cannot escape '.'. | 16 # used because it cannot escape '.'. |
| 16 def _escape(str): | 17 def _escape(str): |
| 17 result = str | 18 result = str |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 39 if len(disable_features_set) != len(disable_features): | 40 if len(disable_features_set) != len(disable_features): |
| 40 raise Exception('Duplicate feature(s) in disable_features: ' + | 41 raise Exception('Duplicate feature(s) in disable_features: ' + |
| 41 ', '.join(_FindDuplicates(disable_features))) | 42 ', '.join(_FindDuplicates(disable_features))) |
| 42 features_in_both = enable_features_set.intersection(disable_features_set) | 43 features_in_both = enable_features_set.intersection(disable_features_set) |
| 43 if len(features_in_both) > 0: | 44 if len(features_in_both) > 0: |
| 44 raise Exception('Conflicting features set as both enabled and disabled: ' + | 45 raise Exception('Conflicting features set as both enabled and disabled: ' + |
| 45 ', '.join(features_in_both)) | 46 ', '.join(features_in_both)) |
| 46 | 47 |
| 47 # Generate a list of command-line switches to enable field trials defined in | 48 # Generate a list of command-line switches to enable field trials defined in |
| 48 # fieldtrial_testing_config_*.json. | 49 # fieldtrial_testing_config_*.json. |
| 49 def GenerateArgs(config_path): | 50 def GenerateArgs(config_path, platform): |
| 50 try: | 51 try: |
| 51 with open(config_path, 'r') as base_file: | 52 with open(config_path, 'r') as config_file: |
| 52 variations = json.load(base_file) | 53 config = json.load(config_file) |
| 53 except (IOError, ValueError): | 54 except (IOError, ValueError): |
| 54 return [] | 55 return [] |
| 55 | 56 |
| 56 field_trials = [] | 57 platform_studies = fieldtrial_to_struct.ConfigToStudies(config, platform) |
| 58 | |
| 59 studies = [] | |
| 57 params = [] | 60 params = [] |
| 58 enable_features = [] | 61 enable_features = [] |
| 59 disable_features = [] | 62 disable_features = [] |
| 60 for trial, groups in variations.iteritems(): | 63 |
| 61 if not len(groups): | 64 for study in platform_studies: |
| 62 continue | 65 study_name = study['name'] |
| 63 # For now, only take the first group. | 66 experiments = study['experiments'] |
| 64 group = groups[0] | 67 # For now, only take the first experiment. |
| 65 trial_group = [trial, group['group_name']] | 68 experiment = experiments[0] |
| 66 field_trials.extend(trial_group) | 69 selected_study = [study_name, experiment['name']] |
| 70 studies.extend(selected_study) | |
| 67 param_list = [] | 71 param_list = [] |
| 68 if 'params' in group: | 72 if 'params' in experiment: |
| 69 for key, value in group['params'].iteritems(): | 73 for param in experiment['params']: |
| 70 param_list.append(key) | 74 param_list.append(param['key']) |
| 71 param_list.append(value) | 75 param_list.append(param['value']) |
| 72 if len(param_list): | 76 if len(param_list): |
| 73 # Escape the variables for the command-line. | 77 # Escape the variables for the command-line. |
| 74 trial_group = [_escape(x) for x in trial_group] | 78 selected_study = [_escape(x) for x in selected_study] |
| 75 param_list = [_escape(x) for x in param_list] | 79 param_list = [_escape(x) for x in param_list] |
| 76 param = '%s:%s' % ('.'.join(trial_group), '/'.join(param_list)) | 80 param = '%s:%s' % ('.'.join(selected_study), '/'.join(param_list)) |
| 77 params.append(param) | 81 params.append(param) |
| 78 if 'enable_features' in group: | 82 if 'enable_features' in experiment: |
| 79 enable_features.extend(group['enable_features']) | 83 enable_features.extend(experiment['enable_features']) |
| 80 if 'disable_features' in group: | 84 if 'disable_features' in experiment: |
| 81 disable_features.extend(group['disable_features']) | 85 disable_features.extend(experiment['disable_features']) |
| 82 if not len(field_trials): | 86 |
| 87 if not len(studies): | |
| 83 return [] | 88 return [] |
| 84 _CheckForDuplicateFeatures(enable_features, disable_features) | 89 _CheckForDuplicateFeatures(enable_features, disable_features) |
| 85 args = ['--force-fieldtrials=%s' % '/'.join(field_trials)] | 90 args = ['--force-fieldtrials=%s' % '/'.join(studies)] |
| 86 if len(params): | 91 if len(params): |
| 87 args.append('--force-fieldtrial-params=%s' % ','.join(params)) | 92 args.append('--force-fieldtrial-params=%s' % ','.join(params)) |
| 88 if len(enable_features): | 93 if len(enable_features): |
| 89 args.append('--enable-features=%s' % ','.join(enable_features)) | 94 args.append('--enable-features=%s' % ','.join(enable_features)) |
| 90 if len(disable_features): | 95 if len(disable_features): |
| 91 args.append('--disable-features=%s' % ','.join(disable_features)) | 96 args.append('--disable-features=%s' % ','.join(disable_features)) |
| 92 return args | 97 return args |
| 93 | 98 |
| 94 def main(): | 99 def main(): |
| 95 if len(sys.argv) < 3: | 100 if len(sys.argv) < 3: |
| 96 print 'Usage: fieldtrial_util.py [base_config_path] [platform_config_path]' | 101 print 'Usage: fieldtrial_util.py [config_path] [platform]' |
| 97 exit(-1) | 102 exit(-1) |
| 103 | |
| 104 supported_platforms = ['android', 'chromeos', 'ios', 'linux', 'mac', 'win'] | |
| 105 if sys.argv[2] not in supported_platforms: | |
| 106 print ('\'%s\' is an unknown platform. Supported platforms: %s' % | |
| 107 (sys.argv[2], supported_platforms)) | |
|
aiolos (Not reviewing)
2016/09/27 19:26:03
I'm not sure why you don't exit here. Does it make
robliao
2016/09/27 19:31:23
Nope. Done.
| |
| 98 print GenerateArgs(sys.argv[1], sys.argv[2]) | 108 print GenerateArgs(sys.argv[1], sys.argv[2]) |
| 99 | 109 |
| 100 if __name__ == '__main__': | 110 if __name__ == '__main__': |
| 101 main() | 111 main() |
| OLD | NEW |