comparison scripts/bloatcheck @ 492:f3169b2492f1

Replace GPL python debug script with BSD shell script.
author Rob Landley <rob@landley.net>
date Tue, 21 Feb 2012 21:27:10 -0600
parents
children ca297cc8a204
comparison
equal deleted inserted replaced
491:176667e320f0 492:f3169b2492f1
1 #!/bin/bash
2
3 if [ $# -ne 2 ]
4 then
5 echo "usage: bloatcheck old new"
6 exit 1
7 fi
8
9 addline()
10 {
11 NEXT="$(printf "%s% $((50-${#LASTNAME}))d% 10d %10d" "$LASTNAME" "$OLD" "$NEW" "$DELTA")"
12 [ -z "$STUFF" ] &&
13 STUFF="$NEXT" ||
14 STUFF="$(printf "%s\n%s" "$STUFF" "$NEXT")"
15 }
16
17 diff <(nm --size-sort "$1" | sort -k3,3) \
18 <(nm --size-sort "$2" | sort -k3,3) | grep '^[<>]' | sort -k4,4 | \
19 (
20 LASTNAME=
21 DELTA=0
22 TOTAL=0
23 OLD=0
24 NEW=0
25 STUFF=
26
27 printf "name% 46s% 10s% 11s\n" old new delta
28 echo "-----------------------------------------------------------------------"
29 while read a b c d
30 do
31 THISNAME=$(echo " $d" | sed 's/[.][0-9]*$//')
32
33 if [ "$LASTNAME" != "$THISNAME" ]
34 then
35 TOTAL=$(($TOTAL+$DELTA))
36 [ $DELTA -ne 0 ] && addline
37 LASTNAME="$THISNAME"
38 DELTA=0
39 OLD=0
40 NEW=0
41 fi
42
43 SIZE=$(printf "%d" "0x$b")
44 if [ "$a" == "<" ]
45 then
46 OLD=$(($OLD+$SIZE))
47 SIZE=$((-1*$SIZE))
48 else
49 NEW=$(($NEW+$SIZE))
50 fi
51 DELTA=$(($DELTA+$SIZE))
52 done
53
54 TOTAL=$(($TOTAL+$DELTA))
55 [ $DELTA -ne 0 ] && addline
56
57 echo "$STUFF" | sort -k4,4nr
58 echo "-----------------------------------------------------------------------"
59 printf "% 71d total\n" "$TOTAL"
60 )