-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter-output.py
executable file
·40 lines (35 loc) · 1.21 KB
/
filter-output.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
#sdobrev 2003-6
'filter (=count-generalize) instance-or-run -specific things, e.g. memory addresses, to compare different test runs'
replaces = {
'^Ran \d+ tests? in (?P<time>[\d.]+)s\s*$' : [],
# 'instance at (?P<address>0x[0-9a-f]+)>' : {},
'at (?P<address>0x[0-9a-f]+)>' : {},
'[".!; ](?P<fid>f(_m)?\d+)[".]' : {},
'@-(?P<address>0x[0-9a-f]+)' : {},
'(?P<address>-?0x[0-9a-f]+)' : {},
}
import re,sys
for v in sys.argv[1:]:
replaces[ v] = {}
rc = {}
for r,counter in replaces.iteritems():
rc[ re.compile( r)] = counter
for l in sys.stdin:
for r in rc:
def repl( m):
founds = rc[r]
count = len(founds)+1
#count = rc[r]+1
d = m.groupdict()
assert len(d) ==1, 'one group only per regexp !'
for k,v in d.iteritems():
name = '<%(k)s%(count)d>' % locals()
if isinstance( founds, dict):
name = founds.setdefault( v, name)
else:
founds.append( v)
return m.string[ m.start(0): m.start( k)] + name + l[m.end( k):m.end(0)]
l = r.sub( repl, l)
sys.stdout.write( l)
# vim:ts=4:sw=4:expandtab