tools/trace-malloc/histogram-pretty.sh

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rwxr-xr-x

Implement a real Private Browsing Mode condition by changing the API/ABI;
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-pretty.sh [-c <count>] [-w <width>] <file>
     8 #
     9 # Pretty-print the histogram in file <file>, displaying at most
    10 # <count> rows.
    12 # How many rows are we gonna show?
    13 COUNT=20
    14 WIDTH=22
    16 # Read arguments
    17 while [ $# -gt 0 ]; do
    18     case "$1" in
    19     -c) COUNT=$2
    20         shift 2
    21         ;;
    22     -w) WIDTH=$2
    23         shift 2
    24         ;;
    25     *)  break
    26         ;;
    27     esac
    28 done
    30 FILE=$1
    32 # The first `awk' script computes a `TOTAL' row. Then, we sort by the
    33 # larges delta in bytes.
    34 awk '{ tobj += $2; tbytes += $3; } END { print "TOTAL", tobj, tbytes; }' ${FILE} > /tmp/$$.sorted
    36 sort -nr +2 ${FILE} >> /tmp/$$.sorted
    38 # Pretty-print, including percentages
    39 cat <<EOF > /tmp/$$.awk
    40 BEGIN {
    41   printf "%-${WIDTH}s  Count    Bytes %Total   %Cov\n", "Type";
    42   }
    43 \$1 == "TOTAL" {
    44   tbytes = \$3;
    45   }
    46 NR <= $COUNT {
    47   if (\$1 != "TOTAL") {
    48     covered += \$3;
    49   }
    50   printf "%-${WIDTH}s %6d %8d %6.2lf %6.2lf\n", \$1, \$2, \$3, 100.0 * \$3 / tbytes, 100.0 * covered / tbytes;
    51   }
    52 NR > $COUNT {
    53   oobjs += \$2;  obytes += \$3; covered += \$3;
    54   }
    55 END {
    56   printf "%-${WIDTH}s %6d %8d %6.2lf %6.2lf\n", "OTHER", oobjs, obytes, obytes * 100.0 / tbytes, covered * 100.0 / tbytes;
    57   }
    58 EOF
    60 # Now pretty print the file, and spit it out on stdout.
    61 awk -f /tmp/$$.awk /tmp/$$.sorted
    63 rm -f /tmp/$$.awk /tmp/$$.sorted

mercurial