diff options
Diffstat (limited to 'scripts/tiny')
| -rwxr-xr-x | scripts/tiny/dirsize.py | 75 | ||||
| -rwxr-xr-x | scripts/tiny/ksize.py | 156 | ||||
| -rwxr-xr-x | scripts/tiny/ksum.py | 154 |
3 files changed, 0 insertions, 385 deletions
diff --git a/scripts/tiny/dirsize.py b/scripts/tiny/dirsize.py deleted file mode 100755 index 501516b0d4..0000000000 --- a/scripts/tiny/dirsize.py +++ /dev/null | |||
| @@ -1,75 +0,0 @@ | |||
| 1 | #!/usr/bin/env python3 | ||
| 2 | # | ||
| 3 | # Copyright (c) 2011, Intel Corporation. | ||
| 4 | # | ||
| 5 | # SPDX-License-Identifier: GPL-2.0-or-later | ||
| 6 | # | ||
| 7 | # Display details of the root filesystem size, broken up by directory. | ||
| 8 | # Allows for limiting by size to focus on the larger files. | ||
| 9 | # | ||
| 10 | # Author: Darren Hart <dvhart@linux.intel.com> | ||
| 11 | # | ||
| 12 | |||
| 13 | import os | ||
| 14 | import sys | ||
| 15 | import stat | ||
| 16 | |||
| 17 | class Record: | ||
| 18 | def create(path): | ||
| 19 | r = Record(path) | ||
| 20 | |||
| 21 | s = os.lstat(path) | ||
| 22 | if stat.S_ISDIR(s.st_mode): | ||
| 23 | for p in os.listdir(path): | ||
| 24 | pathname = path + "/" + p | ||
| 25 | ss = os.lstat(pathname) | ||
| 26 | if not stat.S_ISLNK(ss.st_mode): | ||
| 27 | r.records.append(Record.create(pathname)) | ||
| 28 | r.size += r.records[-1].size | ||
| 29 | r.records.sort(reverse=True) | ||
| 30 | else: | ||
| 31 | r.size = os.lstat(path).st_size | ||
| 32 | |||
| 33 | return r | ||
| 34 | create = staticmethod(create) | ||
| 35 | |||
| 36 | def __init__(self, path): | ||
| 37 | self.path = path | ||
| 38 | self.size = 0 | ||
| 39 | self.records = [] | ||
| 40 | |||
| 41 | def __lt__(this, that): | ||
| 42 | if that is None: | ||
| 43 | return False | ||
| 44 | if not isinstance(that, Record): | ||
| 45 | raise TypeError | ||
| 46 | if len(this.records) > 0 and len(that.records) == 0: | ||
| 47 | return False | ||
| 48 | if this.size > that.size: | ||
| 49 | return False | ||
| 50 | return True | ||
| 51 | |||
| 52 | def show(self, minsize): | ||
| 53 | total = 0 | ||
| 54 | if self.size <= minsize: | ||
| 55 | return 0 | ||
| 56 | print("%10d %s" % (self.size, self.path)) | ||
| 57 | for r in self.records: | ||
| 58 | total += r.show(minsize) | ||
| 59 | if len(self.records) == 0: | ||
| 60 | total = self.size | ||
| 61 | return total | ||
| 62 | |||
| 63 | |||
| 64 | def main(): | ||
| 65 | minsize = 0 | ||
| 66 | if len(sys.argv) == 2: | ||
| 67 | minsize = int(sys.argv[1]) | ||
| 68 | rootfs = Record.create(".") | ||
| 69 | total = rootfs.show(minsize) | ||
| 70 | print("Displayed %d/%d bytes (%.2f%%)" % \ | ||
| 71 | (total, rootfs.size, 100 * float(total) / rootfs.size)) | ||
| 72 | |||
| 73 | |||
| 74 | if __name__ == "__main__": | ||
| 75 | main() | ||
diff --git a/scripts/tiny/ksize.py b/scripts/tiny/ksize.py deleted file mode 100755 index db2b9ec39f..0000000000 --- a/scripts/tiny/ksize.py +++ /dev/null | |||
| @@ -1,156 +0,0 @@ | |||
| 1 | #!/usr/bin/env python3 | ||
| 2 | # | ||
| 3 | # Copyright (c) 2011, Intel Corporation. | ||
| 4 | # | ||
| 5 | # SPDX-License-Identifier: GPL-2.0-or-later | ||
| 6 | # | ||
| 7 | # Display details of the kernel build size, broken up by built-in.[o,a]. Sort | ||
| 8 | # the objects by size. Run from the top level kernel build directory. | ||
| 9 | # | ||
| 10 | # Author: Darren Hart <dvhart@linux.intel.com> | ||
| 11 | # | ||
| 12 | |||
| 13 | import sys | ||
| 14 | import getopt | ||
| 15 | import os | ||
| 16 | from subprocess import * | ||
| 17 | |||
| 18 | def usage(): | ||
| 19 | prog = os.path.basename(sys.argv[0]) | ||
| 20 | print('Usage: %s [OPTION]...' % prog) | ||
| 21 | print(' -d, display an additional level of drivers detail') | ||
| 22 | print(' -h, --help display this help and exit') | ||
| 23 | print('') | ||
| 24 | print('Run %s from the top-level Linux kernel build directory.' % prog) | ||
| 25 | |||
| 26 | |||
| 27 | class Sizes: | ||
| 28 | def __init__(self, glob): | ||
| 29 | self.title = glob | ||
| 30 | p = Popen("size -t " + str(glob), shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True) | ||
| 31 | output = p.communicate()[0].splitlines() | ||
| 32 | if len(output) > 2: | ||
| 33 | sizes = output[-1].split()[0:4] | ||
| 34 | self.text = int(sizes[0]) | ||
| 35 | self.data = int(sizes[1]) | ||
| 36 | self.bss = int(sizes[2]) | ||
| 37 | self.total = int(sizes[3]) | ||
| 38 | else: | ||
| 39 | self.text = self.data = self.bss = self.total = 0 | ||
| 40 | |||
| 41 | def show(self, indent=""): | ||
| 42 | print("%-32s %10d | %10d %10d %10d" % \ | ||
| 43 | (indent+self.title, self.total, self.text, self.data, self.bss)) | ||
| 44 | |||
| 45 | |||
| 46 | class Report: | ||
| 47 | def create(filename, title, subglob=None): | ||
| 48 | r = Report(filename, title) | ||
| 49 | path = os.path.dirname(filename) | ||
| 50 | |||
| 51 | p = Popen("ls " + str(path) + "/*.o | grep -v built-in.o", | ||
| 52 | shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True) | ||
| 53 | glob = ' '.join(p.communicate()[0].splitlines()) | ||
| 54 | oreport = Report(glob, str(path) + "/*.o") | ||
| 55 | oreport.sizes.title = str(path) + "/*.o" | ||
| 56 | r.parts.append(oreport) | ||
| 57 | |||
| 58 | if subglob: | ||
| 59 | p = Popen("ls " + subglob, shell=True, stdout=PIPE, stderr=PIPE, universal_newlines=True) | ||
| 60 | for f in p.communicate()[0].splitlines(): | ||
| 61 | path = os.path.dirname(f) | ||
| 62 | r.parts.append(Report.create(f, path, str(path) + "/*/built-in.[o,a]")) | ||
| 63 | r.parts.sort(reverse=True) | ||
| 64 | |||
| 65 | for b in r.parts: | ||
| 66 | r.totals["total"] += b.sizes.total | ||
| 67 | r.totals["text"] += b.sizes.text | ||
| 68 | r.totals["data"] += b.sizes.data | ||
| 69 | r.totals["bss"] += b.sizes.bss | ||
| 70 | |||
| 71 | r.deltas["total"] = r.sizes.total - r.totals["total"] | ||
| 72 | r.deltas["text"] = r.sizes.text - r.totals["text"] | ||
| 73 | r.deltas["data"] = r.sizes.data - r.totals["data"] | ||
| 74 | r.deltas["bss"] = r.sizes.bss - r.totals["bss"] | ||
| 75 | return r | ||
| 76 | create = staticmethod(create) | ||
| 77 | |||
| 78 | def __init__(self, glob, title): | ||
| 79 | self.glob = glob | ||
| 80 | self.title = title | ||
| 81 | self.sizes = Sizes(glob) | ||
| 82 | self.parts = [] | ||
| 83 | self.totals = {"total":0, "text":0, "data":0, "bss":0} | ||
| 84 | self.deltas = {"total":0, "text":0, "data":0, "bss":0} | ||
| 85 | |||
| 86 | def show(self, indent=""): | ||
| 87 | rule = str.ljust(indent, 80, '-') | ||
| 88 | print("%-32s %10s | %10s %10s %10s" % \ | ||
| 89 | (indent+self.title, "total", "text", "data", "bss")) | ||
| 90 | print(rule) | ||
| 91 | self.sizes.show(indent) | ||
| 92 | print(rule) | ||
| 93 | for p in self.parts: | ||
| 94 | if p.sizes.total > 0: | ||
| 95 | p.sizes.show(indent) | ||
| 96 | print(rule) | ||
| 97 | print("%-32s %10d | %10d %10d %10d" % \ | ||
| 98 | (indent+"sum", self.totals["total"], self.totals["text"], | ||
| 99 | self.totals["data"], self.totals["bss"])) | ||
| 100 | print("%-32s %10d | %10d %10d %10d" % \ | ||
| 101 | (indent+"delta", self.deltas["total"], self.deltas["text"], | ||
| 102 | self.deltas["data"], self.deltas["bss"])) | ||
| 103 | print("\n") | ||
| 104 | |||
| 105 | def __lt__(this, that): | ||
| 106 | if that is None: | ||
| 107 | return 1 | ||
| 108 | if not isinstance(that, Report): | ||
| 109 | raise TypeError | ||
| 110 | return this.sizes.total < that.sizes.total | ||
| 111 | |||
| 112 | def __cmp__(this, that): | ||
| 113 | if that is None: | ||
| 114 | return 1 | ||
| 115 | if not isinstance(that, Report): | ||
| 116 | raise TypeError | ||
| 117 | if this.sizes.total < that.sizes.total: | ||
| 118 | return -1 | ||
| 119 | if this.sizes.total > that.sizes.total: | ||
| 120 | return 1 | ||
| 121 | return 0 | ||
| 122 | |||
| 123 | |||
| 124 | def main(): | ||
| 125 | try: | ||
| 126 | opts, args = getopt.getopt(sys.argv[1:], "dh", ["help"]) | ||
| 127 | except getopt.GetoptError as err: | ||
| 128 | print('%s' % str(err)) | ||
| 129 | usage() | ||
| 130 | sys.exit(2) | ||
| 131 | |||
| 132 | driver_detail = False | ||
| 133 | for o, a in opts: | ||
| 134 | if o == '-d': | ||
| 135 | driver_detail = True | ||
| 136 | elif o in ('-h', '--help'): | ||
| 137 | usage() | ||
| 138 | sys.exit(0) | ||
| 139 | else: | ||
| 140 | assert False, "unhandled option" | ||
| 141 | |||
| 142 | glob = "arch/*/built-in.[o,a] */built-in.[o,a]" | ||
| 143 | vmlinux = Report.create("vmlinux", "Linux Kernel", glob) | ||
| 144 | |||
| 145 | vmlinux.show() | ||
| 146 | for b in vmlinux.parts: | ||
| 147 | if b.totals["total"] > 0 and len(b.parts) > 1: | ||
| 148 | b.show() | ||
| 149 | if b.title == "drivers" and driver_detail: | ||
| 150 | for d in b.parts: | ||
| 151 | if d.totals["total"] > 0 and len(d.parts) > 1: | ||
| 152 | d.show(" ") | ||
| 153 | |||
| 154 | |||
| 155 | if __name__ == "__main__": | ||
| 156 | main() | ||
diff --git a/scripts/tiny/ksum.py b/scripts/tiny/ksum.py deleted file mode 100755 index 8f0e4c0517..0000000000 --- a/scripts/tiny/ksum.py +++ /dev/null | |||
| @@ -1,154 +0,0 @@ | |||
| 1 | #!/usr/bin/env python3 | ||
| 2 | # | ||
| 3 | # Copyright (c) 2016, Intel Corporation. | ||
| 4 | # | ||
| 5 | # SPDX-License-Identifier: GPL-2.0-only | ||
| 6 | # | ||
| 7 | # DESCRIPTION 'ksum.py' generates a combined summary of vmlinux and | ||
| 8 | # module sizes for a built kernel, as a quick tool for comparing the | ||
| 9 | # overall effects of systemic tinification changes. Execute from the | ||
| 10 | # base directory of the kernel build you want to summarize. Setting | ||
| 11 | # the 'verbose' flag will display the sizes for each file included in | ||
| 12 | # the summary. | ||
| 13 | # | ||
| 14 | # AUTHORS | ||
| 15 | # Tom Zanussi <tom.zanussi (at] linux.intel.com> | ||
| 16 | # | ||
| 17 | |||
| 18 | __version__ = "0.1.0" | ||
| 19 | |||
| 20 | # Python Standard Library modules | ||
| 21 | import os | ||
| 22 | import sys | ||
| 23 | import getopt | ||
| 24 | from subprocess import * | ||
| 25 | |||
| 26 | def usage(): | ||
| 27 | prog = os.path.basename(sys.argv[0]) | ||
| 28 | print('Usage: %s [OPTION]...' % prog) | ||
| 29 | print(' -v, display sizes for each file') | ||
| 30 | print(' -h, --help display this help and exit') | ||
| 31 | print('') | ||
| 32 | print('Run %s from the top-level Linux kernel build directory.' % prog) | ||
| 33 | |||
| 34 | verbose = False | ||
| 35 | |||
| 36 | n_ko_files = 0 | ||
| 37 | ko_file_list = [] | ||
| 38 | |||
| 39 | ko_text = 0 | ||
| 40 | ko_data = 0 | ||
| 41 | ko_bss = 0 | ||
| 42 | ko_total = 0 | ||
| 43 | |||
| 44 | vmlinux_file = "" | ||
| 45 | vmlinux_level = 0 | ||
| 46 | |||
| 47 | vmlinux_text = 0 | ||
| 48 | vmlinux_data = 0 | ||
| 49 | vmlinux_bss = 0 | ||
| 50 | vmlinux_total = 0 | ||
| 51 | |||
| 52 | def is_vmlinux_file(filename): | ||
| 53 | global vmlinux_level | ||
| 54 | if filename == ("vmlinux") and vmlinux_level == 0: | ||
| 55 | vmlinux_level += 1 | ||
| 56 | return True | ||
| 57 | return False | ||
| 58 | |||
| 59 | def is_ko_file(filename): | ||
| 60 | if filename.endswith(".ko"): | ||
| 61 | return True | ||
| 62 | return False | ||
| 63 | |||
| 64 | def collect_object_files(): | ||
| 65 | print("Collecting object files recursively from %s..." % os.getcwd()) | ||
| 66 | for dirpath, dirs, files in os.walk(os.getcwd()): | ||
| 67 | for filename in files: | ||
| 68 | if is_ko_file(filename): | ||
| 69 | ko_file_list.append(os.path.join(dirpath, filename)) | ||
| 70 | elif is_vmlinux_file(filename): | ||
| 71 | global vmlinux_file | ||
| 72 | vmlinux_file = os.path.join(dirpath, filename) | ||
| 73 | print("Collecting object files [DONE]") | ||
| 74 | |||
| 75 | def add_ko_file(filename): | ||
| 76 | p = Popen("size -t " + filename, shell=True, stdout=PIPE, stderr=PIPE) | ||
| 77 | output = p.communicate()[0].splitlines() | ||
| 78 | if len(output) > 2: | ||
| 79 | sizes = output[-1].split()[0:4] | ||
| 80 | if verbose: | ||
| 81 | print(" %10d %10d %10d %10d\t" % \ | ||
| 82 | (int(sizes[0]), int(sizes[1]), int(sizes[2]), int(sizes[3])), end=' ') | ||
| 83 | print("%s" % filename[len(os.getcwd()) + 1:]) | ||
| 84 | global n_ko_files, ko_text, ko_data, ko_bss, ko_total | ||
| 85 | ko_text += int(sizes[0]) | ||
| 86 | ko_data += int(sizes[1]) | ||
| 87 | ko_bss += int(sizes[2]) | ||
| 88 | ko_total += int(sizes[3]) | ||
| 89 | n_ko_files += 1 | ||
| 90 | |||
| 91 | def get_vmlinux_totals(): | ||
| 92 | p = Popen("size -t " + vmlinux_file, shell=True, stdout=PIPE, stderr=PIPE) | ||
| 93 | output = p.communicate()[0].splitlines() | ||
| 94 | if len(output) > 2: | ||
| 95 | sizes = output[-1].split()[0:4] | ||
| 96 | if verbose: | ||
| 97 | print(" %10d %10d %10d %10d\t" % \ | ||
| 98 | (int(sizes[0]), int(sizes[1]), int(sizes[2]), int(sizes[3])), end=' ') | ||
| 99 | print("%s" % vmlinux_file[len(os.getcwd()) + 1:]) | ||
| 100 | global vmlinux_text, vmlinux_data, vmlinux_bss, vmlinux_total | ||
| 101 | vmlinux_text += int(sizes[0]) | ||
| 102 | vmlinux_data += int(sizes[1]) | ||
| 103 | vmlinux_bss += int(sizes[2]) | ||
| 104 | vmlinux_total += int(sizes[3]) | ||
| 105 | |||
| 106 | def sum_ko_files(): | ||
| 107 | for ko_file in ko_file_list: | ||
| 108 | add_ko_file(ko_file) | ||
| 109 | |||
| 110 | def main(): | ||
| 111 | try: | ||
| 112 | opts, args = getopt.getopt(sys.argv[1:], "vh", ["help"]) | ||
| 113 | except getopt.GetoptError as err: | ||
| 114 | print('%s' % str(err)) | ||
| 115 | usage() | ||
| 116 | sys.exit(2) | ||
| 117 | |||
| 118 | for o, a in opts: | ||
| 119 | if o == '-v': | ||
| 120 | global verbose | ||
| 121 | verbose = True | ||
| 122 | elif o in ('-h', '--help'): | ||
| 123 | usage() | ||
| 124 | sys.exit(0) | ||
| 125 | else: | ||
| 126 | assert False, "unhandled option" | ||
| 127 | |||
| 128 | collect_object_files() | ||
| 129 | sum_ko_files() | ||
| 130 | get_vmlinux_totals() | ||
| 131 | |||
| 132 | print("\nTotals:") | ||
| 133 | print("\nvmlinux:") | ||
| 134 | print(" text\tdata\t\tbss\t\ttotal") | ||
| 135 | print(" %-10d\t%-10d\t%-10d\t%-10d" % \ | ||
| 136 | (vmlinux_text, vmlinux_data, vmlinux_bss, vmlinux_total)) | ||
| 137 | print("\nmodules (%d):" % n_ko_files) | ||
| 138 | print(" text\tdata\t\tbss\t\ttotal") | ||
| 139 | print(" %-10d\t%-10d\t%-10d\t%-10d" % \ | ||
| 140 | (ko_text, ko_data, ko_bss, ko_total)) | ||
| 141 | print("\nvmlinux + modules:") | ||
| 142 | print(" text\tdata\t\tbss\t\ttotal") | ||
| 143 | print(" %-10d\t%-10d\t%-10d\t%-10d" % \ | ||
| 144 | (vmlinux_text + ko_text, vmlinux_data + ko_data, \ | ||
| 145 | vmlinux_bss + ko_bss, vmlinux_total + ko_total)) | ||
| 146 | |||
| 147 | if __name__ == "__main__": | ||
| 148 | try: | ||
| 149 | ret = main() | ||
| 150 | except Exception: | ||
| 151 | ret = 1 | ||
| 152 | import traceback | ||
| 153 | traceback.print_exc(5) | ||
| 154 | sys.exit(ret) | ||
