170 """Generate useful data from a coverage report."""
171
172 parser = argparse.ArgumentParser()
173 parser.add_argument('--report', help='input file; an llvm coverage report.',
174 required=True)
175 parser.add_argument('--nanobench', help='output file for nanobench data.')
176 parser.add_argument(
177 '--key', metavar='key_or_value', nargs='+',
178 help='key/value pairs identifying this bot.')
179 parser.add_argument(
180 '--properties', metavar='key_or_value', nargs='+',
181 help='key/value pairs representing properties of this build.')
182 parser.add_argument('--linebyline',
183 help='output file for line-by-line JSON data.')
184 args = parser.parse_args()
185
186 if args.nanobench and not (args.key and args.properties):
187 raise Exception('--key and --properties are required with --nanobench')
188
189 with open(args.report) as f:
190 report = f.read()
191
192 line_by_line = _get_per_file_per_line_coverage(report)
193
194 if args.linebyline:
195 with open(args.linebyline, 'w') as f:
196 json.dump(line_by_line, f)
197
198 if args.nanobench:
199
200 key = _parse_key_value(args.key)
201 properties = _parse_key_value(args.properties)
202
203
204 per_file = _get_per_file_summaries(line_by_line)
205
206
207 format_results = _nanobench_json(per_file, properties, key)
208 with open(args.nanobench, 'w') as f:
209 json.dump(format_results, f)
210
211