michael@0: #!/bin/sh michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: # histogram-pretty.sh [-c ] [-w ] michael@0: # michael@0: # Pretty-print the histogram in file , displaying at most michael@0: # rows. michael@0: michael@0: # How many rows are we gonna show? michael@0: COUNT=20 michael@0: WIDTH=22 michael@0: michael@0: # Read arguments michael@0: while [ $# -gt 0 ]; do michael@0: case "$1" in michael@0: -c) COUNT=$2 michael@0: shift 2 michael@0: ;; michael@0: -w) WIDTH=$2 michael@0: shift 2 michael@0: ;; michael@0: *) break michael@0: ;; michael@0: esac michael@0: done michael@0: michael@0: FILE=$1 michael@0: michael@0: # The first `awk' script computes a `TOTAL' row. Then, we sort by the michael@0: # larges delta in bytes. michael@0: awk '{ tobj += $2; tbytes += $3; } END { print "TOTAL", tobj, tbytes; }' ${FILE} > /tmp/$$.sorted michael@0: michael@0: sort -nr +2 ${FILE} >> /tmp/$$.sorted michael@0: michael@0: # Pretty-print, including percentages michael@0: cat < /tmp/$$.awk michael@0: BEGIN { michael@0: printf "%-${WIDTH}s Count Bytes %Total %Cov\n", "Type"; michael@0: } michael@0: \$1 == "TOTAL" { michael@0: tbytes = \$3; michael@0: } michael@0: NR <= $COUNT { michael@0: if (\$1 != "TOTAL") { michael@0: covered += \$3; michael@0: } michael@0: printf "%-${WIDTH}s %6d %8d %6.2lf %6.2lf\n", \$1, \$2, \$3, 100.0 * \$3 / tbytes, 100.0 * covered / tbytes; michael@0: } michael@0: NR > $COUNT { michael@0: oobjs += \$2; obytes += \$3; covered += \$3; michael@0: } michael@0: END { michael@0: printf "%-${WIDTH}s %6d %8d %6.2lf %6.2lf\n", "OTHER", oobjs, obytes, obytes * 100.0 / tbytes, covered * 100.0 / tbytes; michael@0: } michael@0: EOF michael@0: michael@0: # Now pretty print the file, and spit it out on stdout. michael@0: awk -f /tmp/$$.awk /tmp/$$.sorted michael@0: michael@0: rm -f /tmp/$$.awk /tmp/$$.sorted