10f66f451Sopenharmony_ci#!/bin/bash
20f66f451Sopenharmony_ci
30f66f451Sopenharmony_ciif [ $# -ne 2 ]
40f66f451Sopenharmony_cithen
50f66f451Sopenharmony_ci  echo "usage: bloatcheck old new"
60f66f451Sopenharmony_ci  exit 1
70f66f451Sopenharmony_cifi
80f66f451Sopenharmony_ci
90f66f451Sopenharmony_ciaddline()
100f66f451Sopenharmony_ci{
110f66f451Sopenharmony_ci  NEXT="$(printf "%s% $((50-${#LASTNAME}))d% 10d %10d" "$LASTNAME" "$OLD" "$NEW" "$DELTA")"
120f66f451Sopenharmony_ci  [ -z "$STUFF" ] &&
130f66f451Sopenharmony_ci    STUFF="$NEXT" ||
140f66f451Sopenharmony_ci    STUFF="$(printf "%s\n%s" "$STUFF" "$NEXT")"
150f66f451Sopenharmony_ci}
160f66f451Sopenharmony_ci
170f66f451Sopenharmony_cido_bloatcheck()
180f66f451Sopenharmony_ci{
190f66f451Sopenharmony_ci  LASTNAME=
200f66f451Sopenharmony_ci  DELTA=0
210f66f451Sopenharmony_ci  TOTAL=0
220f66f451Sopenharmony_ci  OLD=0
230f66f451Sopenharmony_ci  NEW=0
240f66f451Sopenharmony_ci  STUFF=
250f66f451Sopenharmony_ci
260f66f451Sopenharmony_ci  printf "name% 46s% 10s% 11s\n" old new delta
270f66f451Sopenharmony_ci  echo "-----------------------------------------------------------------------"
280f66f451Sopenharmony_ci  while read a b c d
290f66f451Sopenharmony_ci  do
300f66f451Sopenharmony_ci    THISNAME=$(echo "$d" | sed 's/[.][0-9]*$//')
310f66f451Sopenharmony_ci
320f66f451Sopenharmony_ci    if [ "$LASTNAME" != "$THISNAME" ]
330f66f451Sopenharmony_ci    then
340f66f451Sopenharmony_ci      TOTAL=$(($TOTAL+$DELTA))
350f66f451Sopenharmony_ci      [ $DELTA -ne 0 ] && addline
360f66f451Sopenharmony_ci      LASTNAME="$THISNAME"
370f66f451Sopenharmony_ci      DELTA=0
380f66f451Sopenharmony_ci      OLD=0
390f66f451Sopenharmony_ci      NEW=0
400f66f451Sopenharmony_ci    fi
410f66f451Sopenharmony_ci
420f66f451Sopenharmony_ci    SIZE=$(printf "%d" "0x$b")
430f66f451Sopenharmony_ci    if [ "$a" == "-" ]
440f66f451Sopenharmony_ci    then
450f66f451Sopenharmony_ci      OLD=$(($OLD+$SIZE))
460f66f451Sopenharmony_ci      SIZE=$((-1*$SIZE))
470f66f451Sopenharmony_ci    else
480f66f451Sopenharmony_ci      NEW=$(($NEW+$SIZE))
490f66f451Sopenharmony_ci    fi
500f66f451Sopenharmony_ci    DELTA=$(($DELTA+$SIZE))
510f66f451Sopenharmony_ci  done
520f66f451Sopenharmony_ci
530f66f451Sopenharmony_ci  TOTAL=$(($TOTAL+$DELTA))
540f66f451Sopenharmony_ci  [ $DELTA -ne 0 ] && addline
550f66f451Sopenharmony_ci
560f66f451Sopenharmony_ci  echo "$STUFF" | sort -k4,4nr
570f66f451Sopenharmony_ci  echo "-----------------------------------------------------------------------"
580f66f451Sopenharmony_ci  printf "% 71d total\n" "$TOTAL"
590f66f451Sopenharmony_ci}
600f66f451Sopenharmony_ci
610f66f451Sopenharmony_ciDIFF1=`mktemp base.XXXXXXX`
620f66f451Sopenharmony_ciDIFF2=`mktemp bloat.XXXXXXX`
630f66f451Sopenharmony_citrap "rm $DIFF1 $DIFF2" EXIT
640f66f451Sopenharmony_cinm --size-sort "$1" | sort -k3,3 > $DIFF1
650f66f451Sopenharmony_cinm --size-sort "$2" | sort -k3,3 > $DIFF2
660f66f451Sopenharmony_cidiff -U 0 $DIFF1 $DIFF2 | tail -n +3 | sed -n 's/^\([-+]\)/\1 /p' \
670f66f451Sopenharmony_ci  | sort -k4,4 | do_bloatcheck
68