Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Unified Diff: tools/llvm_coverage_run.py

Issue 1227523004: Add nanobench-style JSON output to llvm_coverage_run (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix potential issue in _nanobench_json Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/llvm_coverage_run.py
diff --git a/tools/llvm_coverage_run.py b/tools/llvm_coverage_run.py
index 902b1c6b04f1833dc3b6d48c5bfa919f3311bb16..676e670fcf991698c2212b4e4b208c74ad161723 100755
--- a/tools/llvm_coverage_run.py
+++ b/tools/llvm_coverage_run.py
@@ -10,6 +10,7 @@
import argparse
import json
import os
+import re
import shlex
import subprocess
import sys
@@ -96,11 +97,78 @@ def run_coverage(cmd):
return results
+def _testname(filename):
+ """Transform the file name into an ingestible test name."""
+ return re.sub(r'[^a-zA-Z0-9]', '_', filename)
+
+
+def _nanobench_json(results, properties, key):
+ """Return the results in JSON format like that produced by nanobench."""
+ rv = {}
+ # Copy over the properties first, then set the 'key' and 'results' keys,
+ # in order to avoid bad formatting in case the user passes in a properties
+ # dict containing those keys.
+ rv.update(properties)
+ rv['key'] = key
+ rv['results'] = {
+ _testname(f): {
+ 'coverage': {
+ 'percent': percent,
+ 'options': {
+ 'fullname': f,
+ 'dir': os.path.dirname(f),
+ },
+ },
+ } for percent, f in results
+ }
+ return rv
+
+
+def _parse_key_value(kv_list):
+ """Return a dict whose key/value pairs are derived from the given list.
+
+ For example:
+
+ ['k1', 'v1', 'k2', 'v2']
+ becomes:
+
+ {'k1': 'v1',
+ 'k2': 'v2'}
+ """
+ if len(kv_list) % 2 != 0:
+ raise Exception('Invalid key/value pairs: %s' % kv_list)
+
+ rv = {}
+ for i in xrange(len(kv_list) / 2):
+ rv[kv_list[i*2]] = kv_list[i*2+1]
+ return rv
+
+
def main():
- res = run_coverage(sys.argv[1:])
- print '% Covered\tFilename'
- for percent, f in res:
- print '%f\t%s' % (percent, f)
+ """Run coverage and generate a report."""
+ # Parse args.
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--outResultsFile')
+ parser.add_argument(
+ '--key', metavar='key_or_value', nargs='+',
+ help='key/value pairs identifying this bot.')
+ parser.add_argument(
+ '--properties', metavar='key_or_value', nargs='+',
+ help='key/value pairs representing properties of this build.')
+ args, cmd = parser.parse_known_args()
+ key = _parse_key_value(args.key)
+ properties = _parse_key_value(args.properties)
+
+ # Run coverage.
+ results = run_coverage(cmd)
+
+ # Write results.
+ format_results = _nanobench_json(results, properties, key)
+ if args.outResultsFile:
+ with open(args.outResultsFile, 'w') as f:
+ json.dump(format_results, f)
+ else:
+ print json.dumps(format_results, indent=4, sort_keys=True)
if __name__ == '__main__':
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698