annotate scripts/bloatcheck @ 1337:ca297cc8a204 draft

Replace large parenthetical in bloatcheck with a function.
author Rob Landley <rob@landley.net>
date Sun, 08 Jun 2014 13:24:02 -0500
parents f3169b2492f1
children e084440e6995
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
492
f3169b2492f1 Replace GPL python debug script with BSD shell script.
Rob Landley <rob@landley.net>
parents:
diff changeset
1 #!/bin/bash
f3169b2492f1 Replace GPL python debug script with BSD shell script.
Rob Landley <rob@landley.net>
parents:
diff changeset
2
f3169b2492f1 Replace GPL python debug script with BSD shell script.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 if [ $# -ne 2 ]
f3169b2492f1 Replace GPL python debug script with BSD shell script.
Rob Landley <rob@landley.net>
parents:
diff changeset
4 then
f3169b2492f1 Replace GPL python debug script with BSD shell script.
Rob Landley <rob@landley.net>
parents:
diff changeset
5 echo "usage: bloatcheck old new"
f3169b2492f1 Replace GPL python debug script with BSD shell script.
Rob Landley <rob@landley.net>
parents:
diff changeset
6 exit 1
f3169b2492f1 Replace GPL python debug script with BSD shell script.
Rob Landley <rob@landley.net>
parents:
diff changeset
7 fi
f3169b2492f1 Replace GPL python debug script with BSD shell script.
Rob Landley <rob@landley.net>
parents:
diff changeset
8
f3169b2492f1 Replace GPL python debug script with BSD shell script.
Rob Landley <rob@landley.net>
parents:
diff changeset
9 addline()
f3169b2492f1 Replace GPL python debug script with BSD shell script.
Rob Landley <rob@landley.net>
parents:
diff changeset
10 {
f3169b2492f1 Replace GPL python debug script with BSD shell script.
Rob Landley <rob@landley.net>
parents:
diff changeset
11 NEXT="$(printf "%s% $((50-${#LASTNAME}))d% 10d %10d" "$LASTNAME" "$OLD" "$NEW" "$DELTA")"
f3169b2492f1 Replace GPL python debug script with BSD shell script.
Rob Landley <rob@landley.net>
parents:
diff changeset
12 [ -z "$STUFF" ] &&
f3169b2492f1 Replace GPL python debug script with BSD shell script.
Rob Landley <rob@landley.net>
parents:
diff changeset
13 STUFF="$NEXT" ||
f3169b2492f1 Replace GPL python debug script with BSD shell script.
Rob Landley <rob@landley.net>
parents:
diff changeset
14 STUFF="$(printf "%s\n%s" "$STUFF" "$NEXT")"
f3169b2492f1 Replace GPL python debug script with BSD shell script.
Rob Landley <rob@landley.net>
parents:
diff changeset
15 }
f3169b2492f1 Replace GPL python debug script with BSD shell script.
Rob Landley <rob@landley.net>
parents:
diff changeset
16
1337
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
17 do_bloatcheck()
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
18 {
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
19 LASTNAME=
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
20 DELTA=0
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
21 TOTAL=0
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
22 OLD=0
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
23 NEW=0
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
24 STUFF=
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
25
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
26 printf "name% 46s% 10s% 11s\n" old new delta
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
27 echo "-----------------------------------------------------------------------"
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
28 while read a b c d
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
29 do
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
30 THISNAME=$(echo " $d" | sed 's/[.][0-9]*$//')
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
31
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
32 if [ "$LASTNAME" != "$THISNAME" ]
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
33 then
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
34 TOTAL=$(($TOTAL+$DELTA))
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
35 [ $DELTA -ne 0 ] && addline
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
36 LASTNAME="$THISNAME"
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
37 DELTA=0
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
38 OLD=0
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
39 NEW=0
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
40 fi
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
41
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
42 SIZE=$(printf "%d" "0x$b")
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
43 if [ "$a" == "<" ]
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
44 then
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
45 OLD=$(($OLD+$SIZE))
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
46 SIZE=$((-1*$SIZE))
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
47 else
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
48 NEW=$(($NEW+$SIZE))
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
49 fi
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
50 DELTA=$(($DELTA+$SIZE))
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
51 done
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
52
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
53 TOTAL=$(($TOTAL+$DELTA))
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
54 [ $DELTA -ne 0 ] && addline
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
55
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
56 echo "$STUFF" | sort -k4,4nr
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
57 echo "-----------------------------------------------------------------------"
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
58 printf "% 71d total\n" "$TOTAL"
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
59 }
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
60
492
f3169b2492f1 Replace GPL python debug script with BSD shell script.
Rob Landley <rob@landley.net>
parents:
diff changeset
61 diff <(nm --size-sort "$1" | sort -k3,3) \
f3169b2492f1 Replace GPL python debug script with BSD shell script.
Rob Landley <rob@landley.net>
parents:
diff changeset
62 <(nm --size-sort "$2" | sort -k3,3) | grep '^[<>]' | sort -k4,4 | \
1337
ca297cc8a204 Replace large parenthetical in bloatcheck with a function.
Rob Landley <rob@landley.net>
parents: 492
diff changeset
63 do_bloatcheck