tools/trace-malloc/histogram-diff.sh

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rwxr-xr-x

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 #!/bin/sh
     2 #
     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>
     8 #
     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?
    13 COUNT=20
    15 # Read arguments
    16 while [ $# -gt 0 ]; do
    17     case "$1" in
    18     -c) COUNT=$2
    19         shift 2
    20         ;;
    21     *)  break
    22         ;;
    23     esac
    24 done
    26 BASE=$1
    27 INCR=$2
    29 # Sort the base and incremental files so that we can `join' them on
    30 # the type name
    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; }' \
    38     > /tmp/$$.joined
    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 \
    44     > /tmp/$$.sorted
    46 # Then, we sort by the largest delta in bytes.
    47 sort -nr +6 /tmp/$$.joined >> /tmp/$$.sorted
    49 rm -f /tmp/$$.joined
    51 # Pretty-print, including percentages
    52 cat <<EOF > /tmp/$$.awk
    53 BEGIN {
    54   print "                        ---- Base ----   ---- Incr ----   ----- Difference ----";
    55   print "Type                    Count    Bytes   Count    Bytes   Count    Bytes %Total";
    56   }
    57 \$1 == "TOTAL" {
    58   tbytes = \$7;
    59   }
    60 NR <= $COUNT {
    61   printf "%-22s %6d %8d  %6d %8d  %6d %8d %6.2lf\n", \$1, \$2, \$3, \$4, \$5, \$6, \$7, 100.0 * \$7 / tbytes;
    62   }
    63 NR > $COUNT {
    64   oobjs1 += \$2;  obytes1 += \$3;
    65   oobjs2 += \$4;  obytes2 += \$5;
    66   odobjs += \$6;  odbytes += \$7;
    67   }
    68 END {
    69   printf "%-22s %6d %8d  %6d %8d  %6d %8d %6.2lf\n", "OTHER", oobjs1, obytes1, oobjs2, obytes2, odobjs, odbytes, odbytes * 100.0 / tbytes;
    70   }
    71 EOF
    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

mercurial