diff options
Diffstat (limited to 'scripts/tiny/ksize.py')
| -rwxr-xr-x | scripts/tiny/ksize.py | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/scripts/tiny/ksize.py b/scripts/tiny/ksize.py new file mode 100755 index 0000000000..4006f2f6f1 --- /dev/null +++ b/scripts/tiny/ksize.py | |||
| @@ -0,0 +1,165 @@ | |||
| 1 | #!/usr/bin/env python | ||
| 2 | # | ||
| 3 | # Copyright (c) 2011, Intel Corporation. | ||
| 4 | # All rights reserved. | ||
| 5 | # | ||
| 6 | # This program is free software; you can redistribute it and/or modify | ||
| 7 | # it under the terms of the GNU General Public License as published by | ||
| 8 | # the Free Software Foundation; either version 2 of the License, or | ||
| 9 | # (at your option) any later version. | ||
| 10 | # | ||
| 11 | # This program is distributed in the hope that it will be useful, | ||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | # GNU General Public License for more details. | ||
| 15 | # | ||
| 16 | # You should have received a copy of the GNU General Public License | ||
| 17 | # along with this program; if not, write to the Free Software | ||
| 18 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 19 | # | ||
| 20 | # | ||
| 21 | # Display details of the kernel build size, broken up by built-in.o. Sort | ||
| 22 | # the objects by size. Run from the top level kernel build directory. | ||
| 23 | # | ||
| 24 | # Author: Darren Hart <dvhart@linux.intel.com> | ||
| 25 | # | ||
| 26 | |||
| 27 | import sys | ||
| 28 | import getopt | ||
| 29 | import os | ||
| 30 | from subprocess import * | ||
| 31 | from string import join | ||
| 32 | |||
| 33 | |||
| 34 | def usage(): | ||
| 35 | prog = os.path.basename(sys.argv[0]) | ||
| 36 | print 'Usage: %s [OPTION]...' % (prog) | ||
| 37 | print ' -d, display an additional level of drivers detail' | ||
| 38 | print ' -h, --help display this help and exit' | ||
| 39 | print '' | ||
| 40 | print 'Run %s from the top-level Linux kernel build directory.' % (prog) | ||
| 41 | |||
| 42 | |||
| 43 | class Sizes: | ||
| 44 | def __init__(self, glob): | ||
| 45 | self.title = glob | ||
| 46 | p = Popen("size -t " + glob, shell=True, stdout=PIPE, stderr=PIPE) | ||
| 47 | output = p.communicate()[0].splitlines() | ||
| 48 | if len(output) > 2: | ||
| 49 | sizes = output[-1].split()[0:4] | ||
| 50 | self.text = int(sizes[0]) | ||
| 51 | self.data = int(sizes[1]) | ||
| 52 | self.bss = int(sizes[2]) | ||
| 53 | self.total = int(sizes[3]) | ||
| 54 | else: | ||
| 55 | self.text = self.data = self.bss = self.total = 0 | ||
| 56 | |||
| 57 | def show(self, indent=""): | ||
| 58 | print "%-32s %10d | %10d %10d %10d" % \ | ||
| 59 | (indent+self.title, self.total, self.text, self.data, self.bss) | ||
| 60 | |||
| 61 | |||
| 62 | class Report: | ||
| 63 | def create(filename, title, subglob=None): | ||
| 64 | r = Report(filename, title) | ||
| 65 | path = os.path.dirname(filename) | ||
| 66 | |||
| 67 | p = Popen("ls " + path + "/*.o | grep -v built-in.o", | ||
| 68 | shell=True, stdout=PIPE, stderr=PIPE) | ||
| 69 | glob = join(p.communicate()[0].splitlines()) | ||
| 70 | oreport = Report(glob, path + "/*.o") | ||
| 71 | oreport.sizes.title = path + "/*.o" | ||
| 72 | r.parts.append(oreport) | ||
| 73 | |||
| 74 | if subglob: | ||
| 75 | p = Popen("ls " + subglob, shell=True, stdout=PIPE, stderr=PIPE) | ||
| 76 | for f in p.communicate()[0].splitlines(): | ||
| 77 | path = os.path.dirname(f) | ||
| 78 | r.parts.append(Report.create(f, path, path + "/*/built-in.o")) | ||
| 79 | r.parts.sort(reverse=True) | ||
| 80 | |||
| 81 | for b in r.parts: | ||
| 82 | r.totals["total"] += b.sizes.total | ||
| 83 | r.totals["text"] += b.sizes.text | ||
| 84 | r.totals["data"] += b.sizes.data | ||
| 85 | r.totals["bss"] += b.sizes.bss | ||
| 86 | |||
| 87 | r.deltas["total"] = r.sizes.total - r.totals["total"] | ||
| 88 | r.deltas["text"] = r.sizes.text - r.totals["text"] | ||
| 89 | r.deltas["data"] = r.sizes.data - r.totals["data"] | ||
| 90 | r.deltas["bss"] = r.sizes.bss - r.totals["bss"] | ||
| 91 | return r | ||
| 92 | create = staticmethod(create) | ||
| 93 | |||
| 94 | def __init__(self, glob, title): | ||
| 95 | self.glob = glob | ||
| 96 | self.title = title | ||
| 97 | self.sizes = Sizes(glob) | ||
| 98 | self.parts = [] | ||
| 99 | self.totals = {"total":0, "text":0, "data":0, "bss":0} | ||
| 100 | self.deltas = {"total":0, "text":0, "data":0, "bss":0} | ||
| 101 | |||
| 102 | def show(self, indent=""): | ||
| 103 | rule = str.ljust(indent, 80, '-') | ||
| 104 | print "%-32s %10s | %10s %10s %10s" % \ | ||
| 105 | (indent+self.title, "total", "text", "data", "bss") | ||
| 106 | print rule | ||
| 107 | self.sizes.show(indent) | ||
| 108 | print rule | ||
| 109 | for p in self.parts: | ||
| 110 | if p.sizes.total > 0: | ||
| 111 | p.sizes.show(indent) | ||
| 112 | print rule | ||
| 113 | print "%-32s %10d | %10d %10d %10d" % \ | ||
| 114 | (indent+"sum", self.totals["total"], self.totals["text"], | ||
| 115 | self.totals["data"], self.totals["bss"]) | ||
| 116 | print "%-32s %10d | %10d %10d %10d" % \ | ||
| 117 | (indent+"delta", self.deltas["total"], self.deltas["text"], | ||
| 118 | self.deltas["data"], self.deltas["bss"]) | ||
| 119 | print "\n" | ||
| 120 | |||
| 121 | def __cmp__(this, that): | ||
| 122 | if that is None: | ||
| 123 | return 1 | ||
| 124 | if not isinstance(that, Report): | ||
| 125 | raise TypeError | ||
| 126 | if this.sizes.total < that.sizes.total: | ||
| 127 | return -1 | ||
| 128 | if this.sizes.total > that.sizes.total: | ||
| 129 | return 1 | ||
| 130 | return 0 | ||
| 131 | |||
| 132 | |||
| 133 | def main(): | ||
| 134 | try: | ||
| 135 | opts, args = getopt.getopt(sys.argv[1:], "dh", ["help"]) | ||
| 136 | except getopt.GetoptError, err: | ||
| 137 | print '%s' % str(err) | ||
| 138 | usage() | ||
| 139 | sys.exit(2) | ||
| 140 | |||
| 141 | driver_detail = False | ||
| 142 | for o, a in opts: | ||
| 143 | if o == '-d': | ||
| 144 | driver_detail = True | ||
| 145 | elif o in ('-h', '--help'): | ||
| 146 | usage() | ||
| 147 | sys.exit(0) | ||
| 148 | else: | ||
| 149 | assert False, "unhandled option" | ||
| 150 | |||
| 151 | glob = "arch/*/built-in.o */built-in.o" | ||
| 152 | vmlinux = Report.create("vmlinux", "Linux Kernel", glob) | ||
| 153 | |||
| 154 | vmlinux.show() | ||
| 155 | for b in vmlinux.parts: | ||
| 156 | if b.totals["total"] > 0 and len(b.parts) > 1: | ||
| 157 | b.show() | ||
| 158 | if b.title == "drivers" and driver_detail: | ||
| 159 | for d in b.parts: | ||
| 160 | if d.totals["total"] > 0 and len(d.parts) > 1: | ||
| 161 | d.show(" ") | ||
| 162 | |||
| 163 | |||
| 164 | if __name__ == "__main__": | ||
| 165 | main() | ||
