testing/merge_scripts/code_coverage/merge_lib.py
def merge_profiles(input_dir,
                   output_file,
                   input_extension,
                   profdata_tool_path,
                   input_filename_pattern='.*',
                   sparse=False,
                   skip_validation=False):
  """Merges the profiles produced by the shards using llvm-profdata.

  Args:
    input_dir (str): The path to traverse to find input profiles.
    output_file (str): Where to write the merged profile.
    input_extension (str): File extension to look for in the input_dir.
        e.g. '.profdata' or '.profraw'
    profdata_tool_path: The path to the llvm-profdata executable.
    input_filename_pattern (str): The regex pattern of input filename. Should be
        a valid regex pattern if present.
    sparse (bool): flag to indicate whether to run llvm-profdata with --sparse.
      Doc: https://llvm.org/docs/CommandGuide/llvm-profdata.html#profdata-merge
    skip_validation (bool): flag to skip the _validate_and_convert_profraws
        invocation. only applicable when input_extension is .profraw.

  Returns:
    The list of profiles that had to be excluded to get the merge to
    succeed and a list of profiles that had a counter overflow.
  """
  profile_input_file_paths = _get_profile_paths(input_dir,
                                                input_extension,
                                                input_filename_pattern)
  invalid_profraw_files = []
  counter_overflows = []

  if skip_validation:
    logging.warning('--skip-validation has been enabled. Skipping conversion '
                    'to ensure that profiles are valid.')

  if input_extension == '.profraw' and not skip_validation:
    profile_input_file_paths, invalid_profraw_files, counter_overflows = (
        _validate_and_convert_profraws(profile_input_file_paths,
                                       profdata_tool_path,
                                       sparse=sparse))
    logging.info((
        'List of invalid .profraw files that failed to validate and convert: %r'
    ), invalid_profraw_files)

    if counter_overflows:
      logging.warning('There were %d profiles with counter overflows',
                      len(counter_overflows))

  # The list of input files could be empty in the following scenarios:
  # 1. The test target is pure Python scripts test which doesn't execute any
  #    C/C++ binaries, such as devtools_type_check.
  # 2. The test target executes binary and does dumps coverage profile data
  #    files, however, all of them turned out to be invalid.
  if not profile_input_file_paths:
    logging.info('There is no valid profraw/profdata files to merge, skip '
                 'invoking profdata tools.')
    return invalid_profraw_files, counter_overflows

  invalid_profdata_files = _call_profdata_tool(
      profile_input_file_paths=profile_input_file_paths,
      profile_output_file_path=output_file,
      profdata_tool_path=profdata_tool_path,
      sparse=sparse)

  # Remove inputs when merging profraws as they won't be needed and they can be
  # pretty large. If the inputs are profdata files, do not remove them as they
  # might be used again for multiple test types coverage.
  if input_extension == '.profraw':
    for input_file in profile_input_file_paths:
      os.remove(input_file)

  return invalid_profraw_files + invalid_profdata_files, counter_overflows
Merges the profiles produced by the shards using llvm-profdata.

  Args:
    input_dir (str): The path to traverse to find input profiles.
    output_file (str): Where to write the merged profile.
    input_extension (str): File extension to look for in the input_dir.
        e.g. '.profdata' or '.profraw'
    profdata_tool_path: The path to the llvm-profdata executable.
    input_filename_pattern (str): The regex pattern of input filename. Should be
        a valid regex pattern if present.
    sparse (bool): flag to indicate whether to run llvm-profdata with --sparse.
      Doc: https://llvm.org/docs/CommandGuide/llvm-profdata.html#profdata-merge
    skip_validation (bool): flag to skip the _validate_and_convert_profraws
        invocation. only applicable when input_extension is .profraw.

  Returns:
    The list of profiles that had to be excluded to get the merge to
    succeed and a list of profiles that had a counter overflow.
  
Merges the profiles produced by the shards using llvm-profdata.
Merges the profiles produced by the shards using llvm - profdata .
def merge_profiles(input_dir,
                   output_file,
                   input_extension,
                   profdata_tool_path,
                   input_filename_pattern='.*',
                   sparse=False,
                   skip_validation=False):
  profile_input_file_paths = _get_profile_paths(input_dir,
                                                input_extension,
                                                input_filename_pattern)
  invalid_profraw_files = []
  counter_overflows = []
  if skip_validation:
    logging.warning('--skip-validation has been enabled. Skipping conversion '
                    'to ensure that profiles are valid.')
  if input_extension == '.profraw' and not skip_validation:
    profile_input_file_paths, invalid_profraw_files, counter_overflows = (
        _validate_and_convert_profraws(profile_input_file_paths,
                                       profdata_tool_path,
                                       sparse=sparse))
    logging.info((
        'List of invalid .profraw files that failed to validate and convert: %r'
    ), invalid_profraw_files)
    if counter_overflows:
      logging.warning('There were %d profiles with counter overflows',
                      len(counter_overflows))
  if not profile_input_file_paths:
    logging.info('There is no valid profraw/profdata files to merge, skip '
                 'invoking profdata tools.')
    return invalid_profraw_files, counter_overflows
  invalid_profdata_files = _call_profdata_tool(
      profile_input_file_paths=profile_input_file_paths,
      profile_output_file_path=output_file,
      profdata_tool_path=profdata_tool_path,
      sparse=sparse)
  if input_extension == '.profraw':
    for input_file in profile_input_file_paths:
      os.remove(input_file)
  return invalid_profraw_files + invalid_profdata_files, counter_overflows
def merge_profiles ( input_dir , output_file , input_extension , profdata_tool_path , input_filename_pattern = '.*' , sparse = False , skip_validation = False ) : profile_input_file_paths = _get_profile_paths ( input_dir , input_extension , input_filename_pattern ) invalid_profraw_files = [ ] counter_overflows = [ ] if skip_validation : logging . warning ( '--skip-validation has been enabled. Skipping conversion ' 'to ensure that profiles are valid.' ) if input_extension == '.profraw' and not skip_validation : profile_input_file_paths , invalid_profraw_files , counter_overflows = ( _validate_and_convert_profraws ( profile_input_file_paths , profdata_tool_path , sparse = sparse ) ) logging . info ( ( 'List of invalid .profraw files that failed to validate and convert: %r' ) , invalid_profraw_files ) if counter_overflows : logging . warning ( 'There were %d profiles with counter overflows' , len ( counter_overflows ) ) if not profile_input_file_paths : logging . info ( 'There is no valid profraw/profdata files to merge, skip ' 'invoking profdata tools.' ) return invalid_profraw_files , counter_overflows invalid_profdata_files = _call_profdata_tool ( profile_input_file_paths = profile_input_file_paths , profile_output_file_path = output_file , profdata_tool_path = profdata_tool_path , sparse = sparse ) if input_extension == '.profraw' : for input_file in profile_input_file_paths : os . remove ( input_file ) return invalid_profraw_files + invalid_profdata_files , counter_overflows
Merges the profiles produced by the shards using llvm-profdata.
Merges the profiles produced by the shards using llvm - profdata .
"""Merges the profiles produced by the shards using llvm-profdata.

  Args:
    input_dir (str): The path to traverse to find input profiles.
    output_file (str): Where to write the merged profile.
    input_extension (str): File extension to look for in the input_dir.
        e.g. '.profdata' or '.profraw'
    profdata_tool_path: The path to the llvm-profdata executable.
    input_filename_pattern (str): The regex pattern of input filename. Should be
        a valid regex pattern if present.
    sparse (bool): flag to indicate whether to run llvm-profdata with --sparse.
      Doc: https://llvm.org/docs/CommandGuide/llvm-profdata.html#profdata-merge
    skip_validation (bool): flag to skip the _validate_and_convert_profraws
        invocation. only applicable when input_extension is .profraw.

  Returns:
    The list of profiles that had to be excluded to get the merge to
    succeed and a list of profiles that had a counter overflow.
  """ # The list of input files could be empty in the following scenarios: # 1. The test target is pure Python scripts test which doesn't execute any #    C/C++ binaries, such as devtools_type_check. # 2. The test target executes binary and does dumps coverage profile data #    files, however, all of them turned out to be invalid. # Remove inputs when merging profraws as they won't be needed and they can be # pretty large. If the inputs are profdata files, do not remove them as they # might be used again for multiple test types coverage.
The list of profiles that had to be excluded to get the merge to
succeed and a list of profiles that had a counter overflow.
The list of profiles that had to be excluded to get the merge to succeed and a list of profiles that had a counter overflow .
input_dir
The path to traverse to find input profiles.
The path to traverse to find input profiles .
output_file
None
input_extension
File extension to look for in the input_dir.
e.g. '.profdata' or '.profraw'
File extension to look for in the input_dir . e . g . ' . profdata ' or ' . profraw '
profdata_tool_path
The path to the llvm-profdata executable.
The path to the llvm - profdata executable .
input_filename_pattern
The regex pattern of input filename. Should be
a valid regex pattern if present.
The regex pattern of input filename . Should be a valid regex pattern if present .
sparse
flag to indicate whether to run llvm-profdata with --sparse.
flag to indicate whether to run llvm - profdata with -- sparse .
skip_validation
flag to skip the _validate_and_convert_profraws
invocation. only applicable when input_extension is .profraw.
flag to skip the _validate_and_convert_profraws invocation . only applicable when input_extension is . profraw .