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 os 10import sys 11 12import merge_lib as merger 13 14 15def _merge_steps_argument_parser(*args, **kwargs): 16 parser = argparse.ArgumentParser(*args, **kwargs) 17 parser.add_argument('--input-dir', required=True, help=argparse.SUPPRESS) 18 parser.add_argument( 19 '--output-file', required=True, help='where to store the merged data') 20 parser.add_argument( 21 '--llvm-profdata', required=True, help='path to llvm-profdata executable') 22 parser.add_argument( 23 '--profdata-filename-pattern', 24 default='.*', 25 help='regex pattern of profdata filename to merge for current test type. ' 26 'If not present, all profdata files will be merged.') 27 parser.add_argument( 28 '--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 return parser 37 38 39def main(): 40 desc = "Merge profdata files in <--input-dir> into a single profdata." 41 parser = _merge_steps_argument_parser(description=desc) 42 params = parser.parse_args() 43 44 # counter overflow profiles should be logged as warnings as part of the 45 # merger.merge_profiles call. 46 invalid_profiles, _ = merger.merge_profiles(params.input_dir, 47 params.output_file, 48 '.profdata', 49 params.llvm_profdata, 50 params.profdata_filename_pattern, 51 sparse=params.sparse, 52 merge_timeout=params.profile_merge_timeout) 53 if invalid_profiles: 54 logging.error('Invalid profiles were generated:\n%r' % invalid_profiles) 55 return 1 56 57 return 0 58 59 60if __name__ == '__main__': 61 logging.basicConfig( 62 format='[%(asctime)s %(levelname)s] %(message)s', level=logging.INFO) 63 sys.exit(main()) 64