3 from __future__
import print_function
5 """Prepare a code coverage artifact.
7 - Collate raw profiles into one indexed profile.
8 - Generate html reports for the given binaries.
10 Caution: The positional arguments to this script must be specified before any
11 optional arguments, such as --restrict.
21 def merge_raw_profiles(host_llvm_profdata
, profile_data_dir
, preserve_profiles
):
22 print(":: Merging raw profiles...", end
="")
24 raw_profiles
= glob
.glob(os
.path
.join(profile_data_dir
, "*.profraw"))
25 manifest_path
= os
.path
.join(profile_data_dir
, "profiles.manifest")
26 profdata_path
= os
.path
.join(profile_data_dir
, "Coverage.profdata")
27 with
open(manifest_path
, "w") as manifest
:
28 manifest
.write("\n".join(raw_profiles
))
29 subprocess
.check_call(
40 if not preserve_profiles
:
41 for raw_profile
in raw_profiles
:
42 os
.remove(raw_profile
)
43 os
.remove(manifest_path
)
48 def prepare_html_report(
49 host_llvm_cov
, profile
, report_dir
, binaries
, restricted_dirs
, compilation_dir
51 print(":: Preparing html report for {0}...".format(binaries
), end
="")
54 for i
, binary
in enumerate(binaries
):
56 objects
.append(binary
)
58 objects
.extend(("-object", binary
))
60 [host_llvm_cov
, "show"]
69 "-show-line-counts-or-regions",
70 "-show-directory-coverage",
79 invocation
+= ["-compilation-dir=" + compilation_dir
]
80 subprocess
.check_call(invocation
)
81 with
open(os
.path
.join(report_dir
, "summary.txt"), "wb") as Summary
:
82 subprocess
.check_call(
83 [host_llvm_cov
, "report"]
85 + ["-instr-profile", profile
]
92 def prepare_html_reports(
111 for binary
in binaries
:
112 binary_report_dir
= os
.path
.join(report_dir
, os
.path
.basename(binary
))
123 if __name__
== "__main__":
124 parser
= argparse
.ArgumentParser(description
=__doc__
)
125 parser
.add_argument("host_llvm_profdata", help="Path to llvm-profdata")
126 parser
.add_argument("host_llvm_cov", help="Path to llvm-cov")
128 "profile_data_dir", help="Path to the directory containing the raw profiles"
131 "report_dir", help="Path to the output directory for html reports"
138 help="Path to an instrumented binary",
143 help="Only merge raw profiles together, skip report " "generation",
146 "--preserve-profiles", help="Do not delete raw profiles", action
="store_true"
149 "--use-existing-profdata", help="Specify an existing indexed profile to use"
154 help="Emit a unified report for all binaries",
162 help="Restrict the reporting to the given source paths"
163 " (must be specified after all other positional arguments)",
170 help="The compilation directory of the binary",
172 args
= parser
.parse_args()
174 if args
.use_existing_profdata
and args
.only_merge
:
175 print("--use-existing-profdata and --only-merge are incompatible")
178 if args
.use_existing_profdata
:
179 profdata_path
= args
.use_existing_profdata
181 profdata_path
= merge_raw_profiles(
182 args
.host_llvm_profdata
, args
.profile_data_dir
, args
.preserve_profiles
185 if not len(args
.binaries
):
186 print("No binaries specified, no work to do!")
189 if not args
.only_merge
:
190 prepare_html_reports(
197 args
.compilation_dir
,