aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-07-16 15:31:07 -0400
committerNick Mathewson <nickm@torproject.org>2013-07-16 15:31:07 -0400
commitdd44ff663e074d07a8bf8b94dc5d8b9d8dc3fb32 (patch)
treecbfaeb9459395dce483dbd4cd36a9649c9b9ff0b /contrib
parentf797ac465fa474bc530d76dd92e499584be18ca3 (diff)
downloadtor-dd44ff663e074d07a8bf8b94dc5d8b9d8dc3fb32.tar
tor-dd44ff663e074d07a8bf8b94dc5d8b9d8dc3fb32.tar.gz
A python script to combin gcov output with git blame
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/cov-blame48
1 files changed, 48 insertions, 0 deletions
diff --git a/contrib/cov-blame b/contrib/cov-blame
new file mode 100755
index 000000000..601f21195
--- /dev/null
+++ b/contrib/cov-blame
@@ -0,0 +1,48 @@
+#!/usr/bin/python
+
+import os
+import re
+import subprocess
+import sys
+
+def handle_file(source_fname, cov_fname):
+
+ lines_blm = subprocess.Popen(["git", "blame", source_fname], stdout=subprocess.PIPE).stdout.readlines()
+ lines_cov = open(cov_fname).readlines()
+
+ # XXXX expensive!
+ while re.match(r'\s*-:\s*0:', lines_cov[0]):
+ del lines_cov[0]
+
+ if len(lines_blm) != len(lines_cov):
+ print >>sys.stderr, "MISMATCH IN NUMBER OF LINES in",source_fname
+
+ for b,c in zip(lines_blm, lines_cov):
+ m = re.match(r'\s*([^\s:]+):', c)
+ if not m:
+ print >>sys.stderr, "CONFUSING LINE %r"% c
+ cov = 'X'
+ elif m.group(1) == '-':
+ cov = '-'
+ elif m.group(1)[0] == '#':
+ cov = '#'
+ elif m.group(1)[0].isdigit():
+ cov = '1'
+ else:
+ print >>sys.stderr, "CONFUSING LINE %r"% c
+ cov = 'X'
+
+ print cov, b,
+
+COV_DIR = sys.argv[1]
+SOURCES = sys.argv[2:]
+
+for fn in SOURCES:
+ _, base = os.path.split(fn)
+ cfn = os.path.join(COV_DIR, base)
+ cfn += ".gcov"
+ if os.path.exists(cfn):
+ handle_file(fn, cfn)
+ else:
+ print >>sys.stderr, "NO FILE EXISTS CALLED ",cfn
+