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-diff.sh [-c ] michael@0: # michael@0: # Compute incremental memory growth from histogram in file to michael@0: # histogram in file , displaying at most rows. michael@0: michael@0: # How many rows are we gonna show? michael@0: COUNT=20 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: *) break michael@0: ;; michael@0: esac michael@0: done michael@0: michael@0: BASE=$1 michael@0: INCR=$2 michael@0: michael@0: # Sort the base and incremental files so that we can `join' them on michael@0: # the type name michael@0: sort $BASE > /tmp/$$.left michael@0: sort $INCR > /tmp/$$.right michael@0: michael@0: # Do the join. The `awk' script computes the difference between michael@0: # the base and the incremental files. michael@0: join /tmp/$$.left /tmp/$$.right \ michael@0: | awk '{ print $1, $2, $3, $4, $5, $4 - $2, $5 - $3; }' \ michael@0: > /tmp/$$.joined michael@0: michael@0: rm -f /tmp/$$.left /tmp/$$.right michael@0: michael@0: # Now compute a `TOTAL' row. michael@0: awk '{ tobj1 += $2; tbytes1 += $3; tobj2 += $4; tbytes2 += $5; tdobj += $6; tdbytes += $7; } END { print "TOTAL", tobj1, tbytes1, tobj2, tbytes2, tdobj, tdbytes; }' /tmp/$$.joined \ michael@0: > /tmp/$$.sorted michael@0: michael@0: # Then, we sort by the largest delta in bytes. michael@0: sort -nr +6 /tmp/$$.joined >> /tmp/$$.sorted michael@0: michael@0: rm -f /tmp/$$.joined michael@0: michael@0: # Pretty-print, including percentages michael@0: cat < /tmp/$$.awk michael@0: BEGIN { michael@0: print " ---- Base ---- ---- Incr ---- ----- Difference ----"; michael@0: print "Type Count Bytes Count Bytes Count Bytes %Total"; michael@0: } michael@0: \$1 == "TOTAL" { michael@0: tbytes = \$7; michael@0: } michael@0: NR <= $COUNT { michael@0: printf "%-22s %6d %8d %6d %8d %6d %8d %6.2lf\n", \$1, \$2, \$3, \$4, \$5, \$6, \$7, 100.0 * \$7 / tbytes; michael@0: } michael@0: NR > $COUNT { michael@0: oobjs1 += \$2; obytes1 += \$3; michael@0: oobjs2 += \$4; obytes2 += \$5; michael@0: odobjs += \$6; odbytes += \$7; michael@0: } michael@0: END { michael@0: printf "%-22s %6d %8d %6d %8d %6d %8d %6.2lf\n", "OTHER", oobjs1, obytes1, oobjs2, obytes2, odobjs, odbytes, odbytes * 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