OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2015 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 | 6 |
7 """Run the given command through LLVM's coverage tools.""" | 7 """Run the given command through LLVM's coverage tools.""" |
8 | 8 |
9 | 9 |
10 import argparse | 10 import argparse |
11 import json | 11 import json |
12 import os | 12 import os |
13 import re | 13 import re |
14 import shlex | 14 import shlex |
15 import subprocess | 15 import subprocess |
16 import sys | 16 import sys |
17 | 17 |
18 | 18 |
19 BUILDTYPE = 'Coverage' | 19 BUILDTYPE = 'Coverage' |
20 OUT_DIR = os.path.realpath(os.path.join('out', BUILDTYPE)) | |
21 PROFILE_DATA = 'default.profraw' | 20 PROFILE_DATA = 'default.profraw' |
22 PROFILE_DATA_MERGED = 'prof_merged' | 21 PROFILE_DATA_MERGED = 'prof_merged' |
| 22 SKIA_OUT = 'SKIA_OUT' |
23 | 23 |
24 | 24 |
25 def _fix_filename(filename): | 25 def _fix_filename(filename): |
26 """Return a filename which we can use to identify the file. | 26 """Return a filename which we can use to identify the file. |
27 | 27 |
28 The file paths printed by llvm-cov take the form: | 28 The file paths printed by llvm-cov take the form: |
29 | 29 |
30 /path/to/repo/out/dir/../../src/filename.cpp | 30 /path/to/repo/out/dir/../../src/filename.cpp |
31 | 31 |
32 And then they're truncated to 22 characters with leading ellipses: | 32 And then they're truncated to 22 characters with leading ellipses: |
(...skipping 27 matching lines...) Expand all Loading... |
60 matched.append(f) | 60 matched.append(f) |
61 if len(matched) == 1: | 61 if len(matched) == 1: |
62 filtered.append((percent, matched[0])) | 62 filtered.append((percent, matched[0])) |
63 elif len(matched) > 1: | 63 elif len(matched) > 1: |
64 print >> sys.stderr, ('WARNING: multiple matches for %s; skipping:\n\t%s' | 64 print >> sys.stderr, ('WARNING: multiple matches for %s; skipping:\n\t%s' |
65 % (new_file, '\n\t'.join(matched))) | 65 % (new_file, '\n\t'.join(matched))) |
66 print 'Filtered out %d files.' % (len(results) - len(filtered)) | 66 print 'Filtered out %d files.' % (len(results) - len(filtered)) |
67 return filtered | 67 return filtered |
68 | 68 |
69 | 69 |
| 70 def _get_out_dir(): |
| 71 """Determine the location for compiled binaries.""" |
| 72 return os.path.join(os.environ.get(SKIA_OUT, os.path.realpath('out')), |
| 73 BUILDTYPE) |
| 74 |
| 75 |
70 def run_coverage(cmd): | 76 def run_coverage(cmd): |
71 """Run the given command and return per-file coverage data. | 77 """Run the given command and return per-file coverage data. |
72 | 78 |
73 Assumes that the binary has been built using llvm_coverage_build and that | 79 Assumes that the binary has been built using llvm_coverage_build and that |
74 LLVM 3.6 or newer is installed. | 80 LLVM 3.6 or newer is installed. |
75 """ | 81 """ |
76 binary_path = os.path.join(OUT_DIR, cmd[0]) | 82 binary_path = os.path.join(_get_out_dir(), cmd[0]) |
77 subprocess.call([binary_path] + cmd[1:]) | 83 subprocess.call([binary_path] + cmd[1:]) |
78 try: | 84 try: |
79 subprocess.check_call( | 85 subprocess.check_call( |
80 ['llvm-profdata', 'merge', PROFILE_DATA, | 86 ['llvm-profdata', 'merge', PROFILE_DATA, |
81 '-output=%s' % PROFILE_DATA_MERGED]) | 87 '-output=%s' % PROFILE_DATA_MERGED]) |
82 finally: | 88 finally: |
83 os.remove(PROFILE_DATA) | 89 os.remove(PROFILE_DATA) |
84 try: | 90 try: |
85 report = subprocess.check_output( | 91 report = subprocess.check_output( |
86 ['llvm-cov', 'report', '-instr-profile', PROFILE_DATA_MERGED, | 92 ['llvm-cov', 'report', '-instr-profile', PROFILE_DATA_MERGED, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 format_results = _nanobench_json(results, properties, key) | 172 format_results = _nanobench_json(results, properties, key) |
167 if args.outResultsFile: | 173 if args.outResultsFile: |
168 with open(args.outResultsFile, 'w') as f: | 174 with open(args.outResultsFile, 'w') as f: |
169 json.dump(format_results, f) | 175 json.dump(format_results, f) |
170 else: | 176 else: |
171 print json.dumps(format_results, indent=4, sort_keys=True) | 177 print json.dumps(format_results, indent=4, sort_keys=True) |
172 | 178 |
173 | 179 |
174 if __name__ == '__main__': | 180 if __name__ == '__main__': |
175 main() | 181 main() |
OLD | NEW |