llvm.org GIT mirror llvm / d1714dc
Add support for collating profiles for use with code coverage Differential Revision: http://reviews.llvm.org/D20993 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272599 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 4 years ago
3 changed file(s) with 79 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
429429 set(LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUTION FALSE CACHE INTERNAL "For Visual Studio 2013, manually copy natvis files to Documents\\Visual Studio 2013\\Visualizers" FORCE)
430430 endif()
431431
432 if (LLVM_BUILD_INSTRUMENTED OR LLVM_BUILD_INSTRUMENTED_COVERAGE)
433 if(NOT LLVM_PROFILE_MERGE_POOL_SIZE)
434 # A pool size of 1-2 is probably sufficient on a SSD. 3-4 should be fine
435 # for spining disks. Anything higher may only help on slower mediums.
436 set(LLVM_PROFILE_MERGE_POOL_SIZE "4")
437 endif()
438 if(NOT LLVM_PROFILE_FILE_PATTERN)
439 if(NOT LLVM_PROFILE_DATA_DIR)
440 set(LLVM_PROFILE_FILE_PATTERN "%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw")
441 else()
442 file(TO_NATIVE_PATH "${LLVM_PROFILE_DATA_DIR}/%${LLVM_PROFILE_MERGE_POOL_SIZE}m.profraw" LLVM_PROFILE_FILE_PATTERN)
443 endif()
444 endif()
445 endif()
446
432447 # All options referred to from HandleLLVMOptions have to be specified
433448 # BEFORE this include, otherwise options will not be correctly set on
434449 # first cmake run
597597
598598 option(LLVM_BUILD_INSTRUMENTED "Build LLVM and tools with PGO instrumentation (experimental)" Off)
599599 mark_as_advanced(LLVM_BUILD_INSTRUMENTED)
600 append_if(LLVM_BUILD_INSTRUMENTED "-fprofile-instr-generate"
600 append_if(LLVM_BUILD_INSTRUMENTED "-fprofile-instr-generate='${LLVM_PROFILE_FILE_PATTERN}'"
601 CMAKE_CXX_FLAGS
602 CMAKE_C_FLAGS
603 CMAKE_EXE_LINKER_FLAGS
604 CMAKE_SHARED_LINKER_FLAGS)
605
606 option(LLVM_BUILD_INSTRUMENTED_COVERAGE "Build LLVM and tools with Code Coverage instrumentation (experimental)" Off)
607 mark_as_advanced(LLVM_BUILD_INSTRUMENTED_COVERAGE)
608 append_if(LLVM_BUILD_INSTRUMENTED_COVERAGE "-fprofile-instr-generate='${LLVM_PROFILE_FILE_PATTERN}' -fcoverage-mapping"
601609 CMAKE_CXX_FLAGS
602610 CMAKE_C_FLAGS
603611 CMAKE_EXE_LINKER_FLAGS
0 #!/usr/bin/env python
1
2 '''Prepare a code coverage artifact.
3
4 - Collate raw profiles into one indexed profile.
5 - Delete the raw profiles.
6 - Copy the coverage mappings in the binaries directory.
7 '''
8
9 import argparse
10 import glob
11 import os
12 import subprocess
13 import sys
14
15 def merge_raw_profiles(host_llvm_profdata, profile_data_dir):
16 print ':: Merging raw profiles...',
17 sys.stdout.flush()
18 raw_profiles = glob.glob(os.path.join(profile_data_dir, '*.profraw'))
19 manifest_path = os.path.join(profile_data_dir, 'profiles.manifest')
20 profdata_path = os.path.join(profile_data_dir, 'Coverage.profdata')
21 with open(manifest_path, 'w') as manifest:
22 manifest.write('\n'.join(raw_profiles))
23 subprocess.check_call([host_llvm_profdata, 'merge', '-sparse', '-f',
24 manifest_path, '-o', profdata_path])
25 for raw_profile in raw_profiles:
26 os.remove(raw_profile)
27 print 'Done!'
28
29 def extract_covmappings(host_llvm_cov, profile_data_dir, llvm_bin_dir):
30 print ':: Extracting covmappings...',
31 sys.stdout.flush()
32 for prog in os.listdir(llvm_bin_dir):
33 if prog == 'llvm-lit':
34 continue
35 covmapping_path = os.path.join(profile_data_dir,
36 os.path.basename(prog) + '.covmapping')
37 subprocess.check_call([host_llvm_cov, 'convert-for-testing',
38 os.path.join(llvm_bin_dir, prog), '-o',
39 covmapping_path])
40 print 'Done!'
41
42 if __name__ == '__main__':
43 parser = argparse.ArgumentParser(description=__doc__)
44 parser.add_argument('host_llvm_profdata', help='Path to llvm-profdata')
45 parser.add_argument('host_llvm_cov', help='Path to llvm-cov')
46 parser.add_argument('profile_data_dir',
47 help='Path to the directory containing the raw profiles')
48 parser.add_argument('llvm_bin_dir',
49 help='Path to the directory containing llvm binaries')
50 args = parser.parse_args()
51
52 merge_raw_profiles(args.host_llvm_profdata, args.profile_data_dir)
53 extract_covmappings(args.host_llvm_cov, args.profile_data_dir,
54 args.llvm_bin_dir)