Skip to content

Commit

Permalink
[utils] Add a '--unified-report' option to the code coverage prep script
Browse files Browse the repository at this point in the history
In --unified-report mode, a single coverage report is prepared for all
specified binaries and written to *report_dir*. This mode is compatible
with all existing script options, including the --restrict mode which is
used to limit coverage reporting to certain files or directories.

This should not break any existing users of the script.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285249 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
vedantk committed Oct 26, 2016
1 parent 1182ed1 commit 47e18f4
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions utils/prepare-code-coverage-artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,37 @@ def merge_raw_profiles(host_llvm_profdata, profile_data_dir, preserve_profiles):
print('Done!')
return profdata_path

def prepare_html_report(host_llvm_cov, profile, report_dir, binary,
def prepare_html_report(host_llvm_cov, profile, report_dir, binaries,
restricted_dirs):
print(':: Preparing html report for {0}...'.format(binary), end='')
print(':: Preparing html report for {0}...'.format(binaries), end='')
sys.stdout.flush()
binary_report_dir = os.path.join(report_dir, os.path.basename(binary))
invocation = [host_llvm_cov, 'show', binary, '-format', 'html',
'-instr-profile', profile, '-o', binary_report_dir,
objects = []
for i, binary in enumerate(binaries):
if i == 0:
objects.append(binary)
else:
objects.extend(('-object', binary))
invocation = [host_llvm_cov, 'show'] + objects + ['-format', 'html',
'-instr-profile', profile, '-o', report_dir,
'-show-line-counts-or-regions', '-Xdemangler', 'c++filt',
'-Xdemangler', '-n'] + restricted_dirs
subprocess.check_call(invocation)
with open(os.path.join(binary_report_dir, 'summary.txt'), 'wb') as Summary:
subprocess.check_call([host_llvm_cov, 'report', binary,
'-instr-profile', profile], stdout=Summary)
with open(os.path.join(report_dir, 'summary.txt'), 'wb') as Summary:
subprocess.check_call([host_llvm_cov, 'report'] + objects +
['-instr-profile', profile], stdout=Summary)
print('Done!')

def prepare_html_reports(host_llvm_cov, profdata_path, report_dir, binaries,
restricted_dirs):
for binary in binaries:
prepare_html_report(host_llvm_cov, profdata_path, report_dir, binary,
unified_report, restricted_dirs):
if unified_report:
prepare_html_report(host_llvm_cov, profdata_path, report_dir, binaries,
restricted_dirs)
else:
for binary in binaries:
binary_report_dir = os.path.join(report_dir,
os.path.basename(binary))
prepare_html_report(host_llvm_cov, profdata_path, binary_report_dir,
[binary], restricted_dirs)

if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
Expand All @@ -69,6 +80,8 @@ def prepare_html_reports(host_llvm_cov, profdata_path, report_dir, binaries,
help='Do not delete raw profiles', action='store_true')
parser.add_argument('--use-existing-profdata',
help='Specify an existing indexed profile to use')
parser.add_argument('--unified-report', action='store_true',
help='Emit a unified report for all binaries')
parser.add_argument('--restrict', metavar='R', type=str, nargs='*',
default=[],
help='Restrict the reporting to the given source paths')
Expand All @@ -85,6 +98,10 @@ def prepare_html_reports(host_llvm_cov, profdata_path, report_dir, binaries,
args.profile_data_dir,
args.preserve_profiles)

if not len(args.binaries):
print('No binaries specified, no work to do!')
exit(1)

if not args.only_merge:
prepare_html_reports(args.host_llvm_cov, profdata_path, args.report_dir,
args.binaries, args.restrict)
args.binaries, args.unified_report, args.restrict)

0 comments on commit 47e18f4

Please sign in to comment.