Updates and slight refactor in fix
[scons.git] / bin / memoicmp.py
blobd6aae13574c739b41da0d6b7d7a647658ab737ee
1 #!/usr/bin/env python
3 # A script to compare the --debug=memoizer output found in
4 # two different files.
6 import sys
8 def memoize_output(fname):
9 mout = {}
10 #lines=filter(lambda words:
11 # len(words) == 5 and
12 # words[1] == 'hits' and words[3] == 'misses',
13 # map(string.split, open(fname,'r').readlines()))
14 #for line in lines:
15 # mout[line[-1]] = ( int(line[0]), int(line[2]) )
16 for line in open(fname,'r').readlines():
17 words = line.split()
18 if len(words) == 5 and words[1] == 'hits' and words[3] == 'misses':
19 mout[words[-1]] = ( int(words[0]), int(words[2]) )
20 return mout
22 def memoize_cmp(filea, fileb):
23 ma = memoize_output(filea)
24 mb = memoize_output(fileb)
26 print('All output: %s / %s [delta]'%(filea, fileb))
27 print('----------HITS---------- ---------MISSES---------')
28 cfmt='%7d/%-7d [%d]'
29 ma_o = []
30 mb_o = []
31 mab = []
32 for k in list(ma.keys()):
33 if k in list(mb.keys()):
34 if k not in mab:
35 mab.append(k)
36 else:
37 ma_o.append(k)
38 for k in list(mb.keys()):
39 if k in list(ma.keys()):
40 if k not in mab:
41 mab.append(k)
42 else:
43 mb_o.append(k)
45 mab.sort()
46 ma_o.sort()
47 mb_o.sort()
49 for k in mab:
50 hits = cfmt%(ma[k][0], mb[k][0], mb[k][0]-ma[k][0])
51 miss = cfmt%(ma[k][1], mb[k][1], mb[k][1]-ma[k][1])
52 print('%-24s %-24s %s'%(hits, miss, k))
54 for k in ma_o:
55 hits = '%7d/ --'%(ma[k][0])
56 miss = '%7d/ --'%(ma[k][1])
57 print('%-24s %-24s %s'%(hits, miss, k))
59 for k in mb_o:
60 hits = ' -- /%-7d'%(mb[k][0])
61 miss = ' -- /%-7d'%(mb[k][1])
62 print('%-24s %-24s %s'%(hits, miss, k))
64 print('-'*(24+24+1+20))
67 if __name__ == "__main__":
68 if len(sys.argv) != 3:
69 print("""Usage: %s file1 file2
71 Compares --debug=memomize output from file1 against file2."""%sys.argv[0])
72 sys.exit(1)
74 memoize_cmp(sys.argv[1], sys.argv[2])
75 sys.exit(0)
77 # Local Variables:
78 # tab-width:4
79 # indent-tabs-mode:nil
80 # End:
81 # vim: set expandtab tabstop=4 shiftwidth=4: