tools/trace-malloc/histogram-diff.sh

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rwxr-xr-x

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 #!/bin/sh
michael@0 2 #
michael@0 3 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 6
michael@0 7 # histogram-diff.sh [-c <count>] <base> <incr>
michael@0 8 #
michael@0 9 # Compute incremental memory growth from histogram in file <base> to
michael@0 10 # histogram in file <incr>, displaying at most <count> rows.
michael@0 11
michael@0 12 # How many rows are we gonna show?
michael@0 13 COUNT=20
michael@0 14
michael@0 15 # Read arguments
michael@0 16 while [ $# -gt 0 ]; do
michael@0 17 case "$1" in
michael@0 18 -c) COUNT=$2
michael@0 19 shift 2
michael@0 20 ;;
michael@0 21 *) break
michael@0 22 ;;
michael@0 23 esac
michael@0 24 done
michael@0 25
michael@0 26 BASE=$1
michael@0 27 INCR=$2
michael@0 28
michael@0 29 # Sort the base and incremental files so that we can `join' them on
michael@0 30 # the type name
michael@0 31 sort $BASE > /tmp/$$.left
michael@0 32 sort $INCR > /tmp/$$.right
michael@0 33
michael@0 34 # Do the join. The `awk' script computes the difference between
michael@0 35 # the base and the incremental files.
michael@0 36 join /tmp/$$.left /tmp/$$.right \
michael@0 37 | awk '{ print $1, $2, $3, $4, $5, $4 - $2, $5 - $3; }' \
michael@0 38 > /tmp/$$.joined
michael@0 39
michael@0 40 rm -f /tmp/$$.left /tmp/$$.right
michael@0 41
michael@0 42 # Now compute a `TOTAL' row.
michael@0 43 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 44 > /tmp/$$.sorted
michael@0 45
michael@0 46 # Then, we sort by the largest delta in bytes.
michael@0 47 sort -nr +6 /tmp/$$.joined >> /tmp/$$.sorted
michael@0 48
michael@0 49 rm -f /tmp/$$.joined
michael@0 50
michael@0 51 # Pretty-print, including percentages
michael@0 52 cat <<EOF > /tmp/$$.awk
michael@0 53 BEGIN {
michael@0 54 print " ---- Base ---- ---- Incr ---- ----- Difference ----";
michael@0 55 print "Type Count Bytes Count Bytes Count Bytes %Total";
michael@0 56 }
michael@0 57 \$1 == "TOTAL" {
michael@0 58 tbytes = \$7;
michael@0 59 }
michael@0 60 NR <= $COUNT {
michael@0 61 printf "%-22s %6d %8d %6d %8d %6d %8d %6.2lf\n", \$1, \$2, \$3, \$4, \$5, \$6, \$7, 100.0 * \$7 / tbytes;
michael@0 62 }
michael@0 63 NR > $COUNT {
michael@0 64 oobjs1 += \$2; obytes1 += \$3;
michael@0 65 oobjs2 += \$4; obytes2 += \$5;
michael@0 66 odobjs += \$6; odbytes += \$7;
michael@0 67 }
michael@0 68 END {
michael@0 69 printf "%-22s %6d %8d %6d %8d %6d %8d %6.2lf\n", "OTHER", oobjs1, obytes1, oobjs2, obytes2, odobjs, odbytes, odbytes * 100.0 / tbytes;
michael@0 70 }
michael@0 71 EOF
michael@0 72
michael@0 73 # Now pretty print the file, and spit it out on stdout.
michael@0 74 awk -f /tmp/$$.awk /tmp/$$.sorted
michael@0 75
michael@0 76 rm -f /tmp/$$.awk /tmp/$$.sorted

mercurial