diff options
| author | Ron Yorston <rmy@pobox.com> | 2021-03-10 08:57:42 +0000 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2021-03-10 09:00:58 +0000 |
| commit | 35f7c5e6e8519ca16363c799fb1b112edf1eb12b (patch) | |
| tree | 48d6d8f7e31b568033c5da64c28613c3492997a8 /scripts | |
| parent | 9da193543f73e3e3c97a40221959e5ea2aea2054 (diff) | |
| download | busybox-w32-35f7c5e6e8519ca16363c799fb1b112edf1eb12b.tar.gz busybox-w32-35f7c5e6e8519ca16363c799fb1b112edf1eb12b.tar.bz2 busybox-w32-35f7c5e6e8519ca16363c799fb1b112edf1eb12b.zip | |
build system: add support for 'make bloatcheck'
Plus a few other make targets that make measurements on the binary.
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/bloat-o-meter | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/scripts/bloat-o-meter b/scripts/bloat-o-meter index b4a1d2811..26474595f 100755 --- a/scripts/bloat-o-meter +++ b/scripts/bloat-o-meter | |||
| @@ -43,6 +43,8 @@ if f1 is None or f2 is None: | |||
| 43 | 43 | ||
| 44 | sym_args = " ".join(sys.argv[3 + flag_timing + dashes:]) | 44 | sym_args = " ".join(sys.argv[3 + flag_timing + dashes:]) |
| 45 | def getsizes(file): | 45 | def getsizes(file): |
| 46 | if file.endswith(".exe"): | ||
| 47 | return getsizes_pe(file) | ||
| 46 | sym, alias, lut, section = {}, {}, {}, {} | 48 | sym, alias, lut, section = {}, {}, {}, {} |
| 47 | for l in os.popen("readelf -W -S " + file).readlines(): | 49 | for l in os.popen("readelf -W -S " + file).readlines(): |
| 48 | x = l.replace("[ ", "[", 1).split() | 50 | x = l.replace("[ ", "[", 1).split() |
| @@ -80,6 +82,29 @@ def getsizes(file): | |||
| 80 | sym[alias[(addr, sz)]["name"]] = {"addr" : addr, "size": sz} | 82 | sym[alias[(addr, sz)]["name"]] = {"addr" : addr, "size": sz} |
| 81 | return sym | 83 | return sym |
| 82 | 84 | ||
| 85 | def getsizes_pe(file): | ||
| 86 | sym, sections = {}, {} | ||
| 87 | prefix = os.getenv("CROSS_COMPILE", "") | ||
| 88 | for l in os.popen(prefix + "objdump -h " + file).readlines(): | ||
| 89 | x = l.split() | ||
| 90 | if len(x) != 7: continue | ||
| 91 | sections[x[1]] = 1 | ||
| 92 | if x[1] not in [".rdata"]: continue | ||
| 93 | sym[x[1]] = {"addr" : int(x[3], 16), "size" : int(x[2], 16)} | ||
| 94 | for l in os.popen(prefix + "nm -S --size-sort %s %s" % (sym_args, file)).readlines(): | ||
| 95 | if len(l.split()) != 4: continue | ||
| 96 | value, size, typ, name = l.split() | ||
| 97 | if typ in ["N"]: continue # skip debug symbols | ||
| 98 | if name in sections: continue # bare reference to section | ||
| 99 | value = int(value, 16) | ||
| 100 | size = int(size, 16) | ||
| 101 | if "$" in name: | ||
| 102 | section, name = name.split("$") | ||
| 103 | if section in sym: | ||
| 104 | sym[section]["size"] -= size | ||
| 105 | sym[name] = {"addr" : value, "size": size} | ||
| 106 | return sym | ||
| 107 | |||
| 83 | if flag_timing: | 108 | if flag_timing: |
| 84 | start_t1 = int(time.time() * 1e9) | 109 | start_t1 = int(time.time() * 1e9) |
| 85 | old = getsizes(f1) | 110 | old = getsizes(f1) |
