• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3if [ $# -ne 2 ]
4then
5  echo "usage: bloatcheck old new"
6  exit 1
7fi
8
9addline()
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
17do_bloatcheck()
18{
19  LASTNAME=
20  DELTA=0
21  TOTAL=0
22  OLD=0
23  NEW=0
24  STUFF=
25
26  printf "name% 46s% 10s% 11s\n" old new delta
27  echo "-----------------------------------------------------------------------"
28  while read a b c d
29  do
30    THISNAME=$(echo "$d" | sed 's/[.][0-9]*$//')
31
32    if [ "$LASTNAME" != "$THISNAME" ]
33    then
34      TOTAL=$(($TOTAL+$DELTA))
35      [ $DELTA -ne 0 ] && addline
36      LASTNAME="$THISNAME"
37      DELTA=0
38      OLD=0
39      NEW=0
40    fi
41
42    SIZE=$(printf "%d" "0x$b")
43    if [ "$a" == "-" ]
44    then
45      OLD=$(($OLD+$SIZE))
46      SIZE=$((-1*$SIZE))
47    else
48      NEW=$(($NEW+$SIZE))
49    fi
50    DELTA=$(($DELTA+$SIZE))
51  done
52
53  TOTAL=$(($TOTAL+$DELTA))
54  [ $DELTA -ne 0 ] && addline
55
56  echo "$STUFF" | sort -k4,4nr
57  echo "-----------------------------------------------------------------------"
58  printf "% 71d total\n" "$TOTAL"
59}
60
61DIFF1=`mktemp base.XXXXXXX`
62DIFF2=`mktemp bloat.XXXXXXX`
63trap "rm $DIFF1 $DIFF2" EXIT
64nm --size-sort "$1" | sort -k3,3 > $DIFF1
65nm --size-sort "$2" | sort -k3,3 > $DIFF2
66diff -U 0 $DIFF1 $DIFF2 | tail -n +3 | sed -n 's/^\([-+]\)/\1 /p' \
67  | sort -k4,4 | do_bloatcheck
68