Mercurial > hg > toybox
annotate scripts/bloatcheck @ 1339:a3844a8132bc draft
Isaac Dunham also reported that some diff implementations can't handle nonseekable input, so write to a temporary file instead of <(command).
Use trap EXIT to make sure the temporary files get deleted.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sun, 08 Jun 2014 14:01:37 -0500 |
parents | e084440e6995 |
children |
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 |
1338
e084440e6995
Isaac Dunham pointed out that busybox diff only implements unified diffs, and sent a patch to convert bloatcheck to use that. I tweaked it a bit.
Rob Landley <rob@landley.net>
parents:
1337
diff
changeset
|
30 THISNAME=$(echo "$d" | sed 's/[.][0-9]*$//') |
1337
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") |
1338
e084440e6995
Isaac Dunham pointed out that busybox diff only implements unified diffs, and sent a patch to convert bloatcheck to use that. I tweaked it a bit.
Rob Landley <rob@landley.net>
parents:
1337
diff
changeset
|
43 if [ "$a" == "-" ] |
1337
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 |
1339
a3844a8132bc
Isaac Dunham also reported that some diff implementations can't handle nonseekable input, so write to a temporary file instead of <(command).
Rob Landley <rob@landley.net>
parents:
1338
diff
changeset
|
61 DIFF1=`mktemp base.XXXXXXX` |
a3844a8132bc
Isaac Dunham also reported that some diff implementations can't handle nonseekable input, so write to a temporary file instead of <(command).
Rob Landley <rob@landley.net>
parents:
1338
diff
changeset
|
62 DIFF2=`mktemp bloat.XXXXXXX` |
a3844a8132bc
Isaac Dunham also reported that some diff implementations can't handle nonseekable input, so write to a temporary file instead of <(command).
Rob Landley <rob@landley.net>
parents:
1338
diff
changeset
|
63 trap "rm $DIFF1 $DIFF2" EXIT |
a3844a8132bc
Isaac Dunham also reported that some diff implementations can't handle nonseekable input, so write to a temporary file instead of <(command).
Rob Landley <rob@landley.net>
parents:
1338
diff
changeset
|
64 nm --size-sort "$1" | sort -k3,3 > $DIFF1 |
a3844a8132bc
Isaac Dunham also reported that some diff implementations can't handle nonseekable input, so write to a temporary file instead of <(command).
Rob Landley <rob@landley.net>
parents:
1338
diff
changeset
|
65 nm --size-sort "$2" | sort -k3,3 > $DIFF2 |
a3844a8132bc
Isaac Dunham also reported that some diff implementations can't handle nonseekable input, so write to a temporary file instead of <(command).
Rob Landley <rob@landley.net>
parents:
1338
diff
changeset
|
66 diff -U 0 $DIFF1 $DIFF2 | tail -n +3 | sed -n 's/^\([-+]\)/\1 /p' \ |
a3844a8132bc
Isaac Dunham also reported that some diff implementations can't handle nonseekable input, so write to a temporary file instead of <(command).
Rob Landley <rob@landley.net>
parents:
1338
diff
changeset
|
67 | sort -k4,4 | do_bloatcheck |