Accumulated documentation changes.
[scons.git] / bin / objcounts.py
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2005 The SCons Foundation
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24 import re
25 import sys
26
27 filenames = sys.argv[1:]
28
29 if len(sys.argv) != 3:
30     print """Usage:  objcounts.py file1 file2
31
32 Compare the --debug=object counts from two build logs.
33 """
34     sys.exit(0)
35
36 def fetch_counts(fname):
37     contents = open(fname).read()
38     m = re.search('\nObject counts:\n(.*)\n[^\s]', contents, re.S)
39     lines = m.group().split('\n')
40     list = [l.split() for l in lines if re.match('\s+\d', l)]
41     d = {}
42     for l in list:
43         d[l[-1]] = map(int, l[:-1])
44     return d
45
46 c1 = fetch_counts(sys.argv[1])
47 c2 = fetch_counts(sys.argv[2])
48
49 common = {}
50 for k in c1.keys():
51     try:
52         common[k] = (c1[k], c2[k])
53     except KeyError:
54         pass
55     else:
56         del c1[k]
57         del c2[k]
58
59 def diffstr(c1, c2):
60     try:
61         d = c2 - c1
62     except TypeError:
63         d = ''
64     else:
65         if d:
66             d = '[%+d]' % d
67         else:
68             d = ''
69     return " %5s/%-5s %-8s" % (c1, c2, d)
70
71 def printline(c1, c2, classname):
72     print \
73           diffstr(c1[2], c2[2]) + \
74           diffstr(c1[3], c2[3]) + \
75           ' ' + classname
76
77 keys = common.keys()
78 keys.sort()
79 for k in keys:
80     c = common[k]
81     printline(c[0], c[1], k)
82
83 keys = c1.keys()
84 keys.sort()
85 for k in keys:
86     printline(c1[k], ['--']*4, k)
87
88 keys = c2.keys()
89 keys.sort()
90 for k in keys:
91     printline(['--']*4, c2[k], k)