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-diff.sh [-c <count>] <base> <incr>
9 # Compute incremental memory growth from histogram in file <base> to
10 # histogram in file <incr>, displaying at most <count> rows.
12 # How many rows are we gonna show?
16 while [ $# -gt 0 ]; do
29 # Sort the base and incremental files so that we can `join' them on
31 sort $BASE > /tmp
/$$.left
32 sort $INCR > /tmp
/$$.right
34 # Do the join. The `awk' script computes the difference between
35 # the base and the incremental files.
36 join /tmp
/$$.left
/tmp
/$$.right \
37 |
awk '{ print $1, $2, $3, $4, $5, $4 - $2, $5 - $3; }' \
40 rm -f /tmp
/$$.left
/tmp
/$$.right
42 # Now compute a `TOTAL' row.
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 \
46 # Then, we sort by the largest delta in bytes.
47 sort -nr +6 /tmp
/$$.joined
>> /tmp
/$$.sorted
51 # Pretty-print, including percentages
52 cat <<EOF > /tmp/$$.awk
54 print " ---- Base ---- ---- Incr ---- ----- Difference ----";
55 print "Type Count Bytes Count Bytes Count Bytes %Total";
61 printf "%-22s %6d %8d %6d %8d %6d %8d %6.2lf\n", \$1, \$2, \$3, \$4, \$5, \$6, \$7, 100.0 * \$7 / tbytes;
64 oobjs1 += \$2; obytes1 += \$3;
65 oobjs2 += \$4; obytes2 += \$5;
66 odobjs += \$6; odbytes += \$7;
69 printf "%-22s %6d %8d %6d %8d %6d %8d %6.2lf\n", "OTHER", oobjs1, obytes1, oobjs2, obytes2, odobjs, odbytes, odbytes * 100.0 / tbytes;
73 # Now pretty print the file, and spit it out on stdout.
74 awk -f /tmp
/$$.
awk /tmp
/$$.sorted
76 rm -f /tmp
/$$.
awk /tmp
/$$.sorted