1#!/usr/bin/env python 2# Copyright 2019 The Chromium Authors 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5"""This script merges code coverage profiles from multiple steps.""" 6 7import argparse 8import logging 9import sys 10 11import merge_lib as merger 12 13 14def _merge_steps_argument_parser(*args, **kwargs): 15 parser = argparse.ArgumentParser(*args, **kwargs) 16 parser.add_argument('--input-dir', required=True, help=argparse.SUPPRESS) 17 parser.add_argument('--output-file', 18 required=True, 19 help='where to store the merged data') 20 parser.add_argument('--llvm-profdata', 21 required=True, 22 help='path to llvm-profdata executable') 23 parser.add_argument( 24 '--profdata-filename-pattern', 25 default='.*', 26 help='regex pattern of profdata filename to merge for current test type. ' 27 'If not present, all profdata files will be merged.') 28 parser.add_argument('--sparse', 29 action='store_true', 30 dest='sparse', 31 help='run llvm-profdata with the sparse flag.') 32 parser.add_argument( 33 '--profile-merge-timeout', 34 default=3600, 35 help='Timeout (sec) for the call to merge profiles. Defaults to 3600.') 36 parser.add_argument( 37 '--weight', 38 action='append', 39 default=[], 40 help='The weight to use for a particular benchmark. Format ' 41 'is benchmark:weight. Matching of benchmark is done using ends with.') 42 return parser 43 44 45def main(): 46 desc = 'Merge profdata files in <--input-dir> into a single profdata.' 47 parser = _merge_steps_argument_parser(description=desc) 48 params = parser.parse_args() 49 50 weights = {} 51 for name_and_weight in params.weight: 52 parts = name_and_weight.split(':') 53 if len(parts) != 2: 54 logging.error('Invalid weight:\n%r', name_and_weight) 55 return 1 56 weights[parts[0]] = parts[1] 57 58 # counter overflow profiles should be logged as warnings as part of the 59 # merger.merge_profiles call. 60 invalid_profiles, _ = merger.merge_profiles( 61 params.input_dir, 62 params.output_file, 63 '.profdata', 64 params.llvm_profdata, 65 params.profdata_filename_pattern, 66 sparse=params.sparse, 67 merge_timeout=params.profile_merge_timeout, 68 weights=weights) 69 if invalid_profiles: 70 logging.error('Invalid profiles were generated:\n%r', invalid_profiles) 71 return 1 72 73 return 0 74 75 76if __name__ == '__main__': 77 logging.basicConfig(format='[%(asctime)s %(levelname)s] %(message)s', 78 level=logging.INFO) 79 sys.exit(main()) 80