Chromium Code Reviews| 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 """Parse an LLVM coverage report to generate useable results.""" | 7 """Parse an LLVM coverage report to generate useable results.""" |
| 8 | 8 |
| 9 | 9 |
| 10 import argparse | 10 import argparse |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 | 96 |
| 97 | 97 |
| 98 def _nanobench_json(results, properties, key): | 98 def _nanobench_json(results, properties, key): |
| 99 """Return the results in JSON format like that produced by nanobench.""" | 99 """Return the results in JSON format like that produced by nanobench.""" |
| 100 rv = {} | 100 rv = {} |
| 101 # Copy over the properties first, then set the 'key' and 'results' keys, | 101 # Copy over the properties first, then set the 'key' and 'results' keys, |
| 102 # in order to avoid bad formatting in case the user passes in a properties | 102 # in order to avoid bad formatting in case the user passes in a properties |
| 103 # dict containing those keys. | 103 # dict containing those keys. |
| 104 rv.update(properties) | 104 rv.update(properties) |
| 105 rv['key'] = key | 105 rv['key'] = key |
| 106 rv['key'].update({'source_type': 'coverage'}) | |
| 106 rv['results'] = { | 107 rv['results'] = { |
| 107 _testname(f): { | 108 _testname(f): { |
| 108 'coverage': { | 109 'covered_percent': { |
|
mtklein
2015/07/22 12:20:26
Am I remembering this format wrong or do we want i
borenet
2015/07/22 13:01:59
So one of my concerns was preventing clustering wi
| |
| 109 'percent': percent, | 110 'value': percent, |
| 110 'options': { | 111 'options': { |
| 111 'fullname': f, | 112 'fullname': f, |
| 112 'dir': os.path.dirname(f), | 113 'dir': os.path.dirname(f), |
| 113 }, | 114 }, |
| 114 }, | 115 }, |
| 115 } for percent, f in results | 116 'lines_not_covered': { |
| 117 'value': not_covered_lines, | |
| 118 'options': { | |
| 119 'fullname': f, | |
| 120 'dir': os.path.dirname(f), | |
| 121 }, | |
| 122 }, | |
| 123 } for percent, not_covered_lines, f in results | |
| 116 } | 124 } |
| 117 return rv | 125 return rv |
| 118 | 126 |
| 119 | 127 |
| 120 def _parse_key_value(kv_list): | 128 def _parse_key_value(kv_list): |
| 121 """Return a dict whose key/value pairs are derived from the given list. | 129 """Return a dict whose key/value pairs are derived from the given list. |
| 122 | 130 |
| 123 For example: | 131 For example: |
| 124 | 132 |
| 125 ['k1', 'v1', 'k2', 'v2'] | 133 ['k1', 'v1', 'k2', 'v2'] |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 143 for filepath, lines in line_by_line.iteritems(): | 151 for filepath, lines in line_by_line.iteritems(): |
| 144 total_lines = 0 | 152 total_lines = 0 |
| 145 covered_lines = 0 | 153 covered_lines = 0 |
| 146 for _, cov, _ in lines: | 154 for _, cov, _ in lines: |
| 147 if cov is not None: | 155 if cov is not None: |
| 148 total_lines += 1 | 156 total_lines += 1 |
| 149 if cov > 0: | 157 if cov > 0: |
| 150 covered_lines += 1 | 158 covered_lines += 1 |
| 151 if total_lines > 0: | 159 if total_lines > 0: |
| 152 per_file.append((float(covered_lines)/float(total_lines)*100.0, | 160 per_file.append((float(covered_lines)/float(total_lines)*100.0, |
| 161 total_lines - covered_lines, | |
| 153 filepath)) | 162 filepath)) |
| 154 return per_file | 163 return per_file |
| 155 | 164 |
| 156 | 165 |
| 157 def main(): | 166 def main(): |
| 158 """Generate useful data from a coverage report.""" | 167 """Generate useful data from a coverage report.""" |
| 159 # Parse args. | 168 # Parse args. |
| 160 parser = argparse.ArgumentParser() | 169 parser = argparse.ArgumentParser() |
| 161 parser.add_argument('--report', help='input file; an llvm coverage report.', | 170 parser.add_argument('--report', help='input file; an llvm coverage report.', |
| 162 required=True) | 171 required=True) |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 192 per_file = _get_per_file_summaries(line_by_line) | 201 per_file = _get_per_file_summaries(line_by_line) |
| 193 | 202 |
| 194 # Write results. | 203 # Write results. |
| 195 format_results = _nanobench_json(per_file, properties, key) | 204 format_results = _nanobench_json(per_file, properties, key) |
| 196 with open(args.nanobench, 'w') as f: | 205 with open(args.nanobench, 'w') as f: |
| 197 json.dump(format_results, f) | 206 json.dump(format_results, f) |
| 198 | 207 |
| 199 | 208 |
| 200 if __name__ == '__main__': | 209 if __name__ == '__main__': |
| 201 main() | 210 main() |
| OLD | NEW |