3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 # histogram-pretty.sh [-c <count>] [-w <width>] <file>
9 # Pretty-print the histogram in file <file>, displaying at most
12 # How many rows are we gonna show?
17 while [ $# -gt 0 ]; do
32 # The first `awk' script computes a `TOTAL' row. Then, we sort by the
33 # larges delta in bytes.
34 awk '{ tobj += $2; tbytes += $3; } END { print "TOTAL", tobj, tbytes; }' ${FILE} > /tmp
/$$.sorted
36 sort -nr +2 ${FILE} >> /tmp
/$$.sorted
38 # Pretty-print, including percentages
39 cat <<EOF > /tmp/$$.awk
41 printf "%-${WIDTH}s Count Bytes %Total %Cov\n", "Type";
50 printf "%-${WIDTH}s %6d %8d %6.2lf %6.2lf\n", \$1, \$2, \$3, 100.0 * \$3 / tbytes, 100.0 * covered / tbytes;
53 oobjs += \$2; obytes += \$3; covered += \$3;
56 printf "%-${WIDTH}s %6d %8d %6.2lf %6.2lf\n", "OTHER", oobjs, obytes, obytes * 100.0 / tbytes, covered * 100.0 / tbytes;
60 # Now pretty print the file, and spit it out on stdout.
61 awk -f /tmp
/$$.
awk /tmp
/$$.sorted
63 rm -f /tmp
/$$.
awk /tmp
/$$.sorted