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