summaryrefslogtreecommitdiff
path: root/utils/prepare-code-coverage-artifact.py
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2016-06-13 23:33:48 +0000
committerVedant Kumar <vsk@apple.com>2016-06-13 23:33:48 +0000
commitd1714dc208f77c2e4466aed8d6a1f36fbb07bb76 (patch)
tree24d997f14fb0dbe4079025fb8b38eb3b8d1f3df3 /utils/prepare-code-coverage-artifact.py
parentba53b88904876e44f84742485a0f53918db13290 (diff)
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
Diffstat (limited to 'utils/prepare-code-coverage-artifact.py')
-rw-r--r--utils/prepare-code-coverage-artifact.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/utils/prepare-code-coverage-artifact.py b/utils/prepare-code-coverage-artifact.py
new file mode 100644
index 00000000000..e233c2c6efe
--- /dev/null
+++ b/utils/prepare-code-coverage-artifact.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+
+'''Prepare a code coverage artifact.
+
+- Collate raw profiles into one indexed profile.
+- Delete the raw profiles.
+- Copy the coverage mappings in the binaries directory.
+'''
+
+import argparse
+import glob
+import os
+import subprocess
+import sys
+
+def merge_raw_profiles(host_llvm_profdata, profile_data_dir):
+ print ':: Merging raw profiles...',
+ sys.stdout.flush()
+ raw_profiles = glob.glob(os.path.join(profile_data_dir, '*.profraw'))
+ manifest_path = os.path.join(profile_data_dir, 'profiles.manifest')
+ profdata_path = os.path.join(profile_data_dir, 'Coverage.profdata')
+ with open(manifest_path, 'w') as manifest:
+ manifest.write('\n'.join(raw_profiles))
+ subprocess.check_call([host_llvm_profdata, 'merge', '-sparse', '-f',
+ manifest_path, '-o', profdata_path])
+ for raw_profile in raw_profiles:
+ os.remove(raw_profile)
+ print 'Done!'
+
+def extract_covmappings(host_llvm_cov, profile_data_dir, llvm_bin_dir):
+ print ':: Extracting covmappings...',
+ sys.stdout.flush()
+ for prog in os.listdir(llvm_bin_dir):
+ if prog == 'llvm-lit':
+ continue
+ covmapping_path = os.path.join(profile_data_dir,
+ os.path.basename(prog) + '.covmapping')
+ subprocess.check_call([host_llvm_cov, 'convert-for-testing',
+ os.path.join(llvm_bin_dir, prog), '-o',
+ covmapping_path])
+ print 'Done!'
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(description=__doc__)
+ parser.add_argument('host_llvm_profdata', help='Path to llvm-profdata')
+ parser.add_argument('host_llvm_cov', help='Path to llvm-cov')
+ parser.add_argument('profile_data_dir',
+ help='Path to the directory containing the raw profiles')
+ parser.add_argument('llvm_bin_dir',
+ help='Path to the directory containing llvm binaries')
+ args = parser.parse_args()
+
+ merge_raw_profiles(args.host_llvm_profdata, args.profile_data_dir)
+ extract_covmappings(args.host_llvm_cov, args.profile_data_dir,
+ args.llvm_bin_dir)