"Fossies" - the Fresh Open Source Software Archive

Member "mpr-2.8/mprsize" (3 Nov 2002, 932 Bytes) of package /linux/misc/old/mpr-2.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/sh
    2 # NOTE: considers realloc(p, n) == malloc(n)
    3 
    4 MPRAWK=${MPRAWK-awk}
    5 percent=true
    6 sortpos=2
    7 
    8 for arg in "$@"; do
    9     case "$1" in
   10     -n) percent=; sortpos=0;;
   11     --) shift; break;;
   12     -*) echo "mprsize: warning: ignoring unknown option $1" >&2;;
   13     *)  break;;
   14     esac
   15     shift
   16 done
   17 
   18 case "$#" in
   19 0|1)    ;;
   20 *)  echo "usage: mprsize [log]" >&2
   21     exit 1;;
   22 esac
   23 
   24 MPRFILTER=`mprfilter mprsize "$@"` || exit 1
   25 
   26 trap 'exit 0' 13
   27 
   28 $MPRFILTER |
   29 
   30 $MPRAWK -F: -v percent=$percent '
   31     /^m/ && $NF {
   32         size[$(NF-1)]++
   33         tot += $(NF-1)
   34     }
   35     /^r/ && $NF {
   36         size[$(NF-2)]++
   37         tot += $(NF-2)
   38     }
   39     END  {
   40         for (f in size) {
   41             printf "%d %d %f", f, size[f], f*size[f]
   42             if (percent != "")
   43                 printf " %.02f%%", 100.0*f*size[f]/tot
   44             printf "\n"
   45         }
   46     }' |
   47 
   48 sort -n +$sortpos |
   49 
   50 $MPRAWK '
   51 {
   52     printf "%-16d%-16d", $1, $2
   53     if ($3 <= 2147483647.0)     # 2^31-1
   54         printf "%-16d", $3
   55     else
   56         printf "%-16.5g", $3
   57     if (NF == 4)
   58         printf "%s", $4
   59     printf "\n"
   60 }'
   61 
   62 exit 0