"Fossies" - the Fresh Open Source Software Archive 
Member "mpr-2.8/mprhisto" (3 Nov 2002, 1216 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
3 MPRAWK=${MPRAWK-awk}
4
5 chainlen=0
6 width=${COLUMNS-80}
7 blocksz=1024
8
9 for arg in "$@"; do
10 case "$1" in
11 -c ) chainlen=$2; shift;;
12 -c*) chainlen=`echo $1 | sed 's/-c//'`;;
13 -w ) width=$2; shift;;
14 -w*) width=`echo $1 | sed 's/-w//'`;;
15 -b ) blocksz=$2; shift;;
16 -b*) blocksz=`echo $1 | sed 's/-b//'`;;
17 --) shift; break;;
18 -*) echo "mprhisto: warning: ignoring unknown option $1" >&2;;
19 *) break;;
20 esac
21 shift
22 done
23
24 case "$#" in
25 0|1) ;;
26 *) echo "usage: mprhisto [-c N] [-w N] [-b N] [log]" >&2
27 exit 1;;
28 esac
29
30 MPRFILTER=`mprfilter mprhisto "$@"` || exit 1
31
32 trap 'exit 0' 13
33
34 $MPRFILTER |
35
36 $MPRAWK -F: -v blocksz=$blocksz -v chainlen=$chainlen -v width=$width '
37 function histo( n,i) {
38 n = int(total/blocksz)
39 if (n == lastn && !chainlen)
40 return
41 for (i=0; i<n; i++)
42 printf "*"
43 if (chainlen) {
44 f = $1
45 for (j=2; j<=chainlen+1 && j<=NF; j++)
46 f = f":"$j
47 printf("%*s\n", width-i, f)
48 }
49 else
50 printf "\n"
51 lastn = n
52 }
53 function malloc(n, p) {
54 if (p) {
55 size[p] = n
56 total += n
57 histo()
58 }
59 }
60 function free(p) {
61 total -= size[p]
62 delete size[p]
63 histo()
64 }
65 /^m/ { malloc($(NF-1), $NF) }
66 /^f/ { free($NF) }
67 /^r/ { free($(NF-1)); malloc($(NF-2), $NF) }'
68
69 exit 0