13 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
14 stdout, stderr = p.communicate()
16 p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
17 stdout, stderr = p.communicate(input=data)
19 return stdout.decode(
'utf-8'), stderr.decode(
'utf-8'), p.returncode
23 parser = argparse.ArgumentParser(description=
'llvm-coverage')
24 parser.add_argument(
'--insights', help=
'C++ Insights binary', required=
True)
25 parser.add_argument(
'--llvm-prof-dir', help=
'LLVM profiles data dir', default=
'')
26 parser.add_argument(
'--llvm-prof', help=
'llvm-profdata binary', default=
'llvm-profdata')
27 parser.add_argument(
'--llvm-cov', help=
'llvm-cov binary', default=
'llvm-cov')
28 parser.add_argument(
'--format', help=
'Output format: html/text', default=
'text')
29 parser.add_argument(
'--output', help=
'Output filename', required=
True)
30 parser.add_argument(
'args', nargs=argparse.REMAINDER)
31 args = vars(parser.parse_args())
33 insightsPath = args[
'insights']
34 rawProfiles = glob.glob(os.path.join(args[
'llvm_prof_dir'],
"*.profraw"))
35 profilesManifest = os.path.join(args[
'llvm_prof_dir'],
'profiles.manifest')
36 profilesData = os.path.join(args[
'llvm_prof_dir'],
'insights.profdata')
38 with open(profilesManifest,
"w")
as manifest:
39 manifest.write(
"\n".join(rawProfiles))
41 cmd = [args[
'llvm_prof'],
'merge',
'-sparse',
'-f', profilesManifest,
'-o', profilesData]
42 stdout, stderr, returncode =
runCmd(cmd)
45 action =
'show' if args[
'format'] !=
'lcov' else 'export'
47 cmd = [args[
'llvm_cov'], action, insightsPath, f
'-instr-profile={profilesData}', f
'--format={args["format"]}',
'-ignore-filename-regex=build/']
49 stdout, stderr, returncode =
runCmd(cmd)
52 open(args[
'output'],
'w').write(stdout)
def runCmd(cmd, data=None)