tools/footprint/watch.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.

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 # Treats the arguments as a command that is to be forked and observed;
michael@0 8 # e.g.,
michael@0 9 #
michael@0 10 # watch.sh ./mozilla -f bloaturls.txt
michael@0 11 #
michael@0 12 # Periodically snap-shots the virtual memory info of the process, and
michael@0 13 # dumps the output to ``watch.out''
michael@0 14
michael@0 15 # Clear the output file
michael@0 16 OUTPUT_FILE=watch.out
michael@0 17 INTERVAL=10
michael@0 18
michael@0 19 while [ $# -gt 0 ]; do
michael@0 20 case "$1" in
michael@0 21 -o) OUTPUT_FILE=$2
michael@0 22 shift 2
michael@0 23 ;;
michael@0 24 -i) INTERVAL=$2
michael@0 25 shift 2
michael@0 26 ;;
michael@0 27 *) break
michael@0 28 ;;
michael@0 29 esac
michael@0 30 done
michael@0 31
michael@0 32 rm -f ${OUTPUT_FILE}
michael@0 33
michael@0 34 echo "vmsize vmexe vmlib vmdata vmstk vmrss" > ${OUTPUT_FILE}
michael@0 35
michael@0 36 # treat the arguments as the command to execute
michael@0 37 $* &
michael@0 38
michael@0 39 # remember the process ID
michael@0 40 PID=$!
michael@0 41
michael@0 42 while [ -e /proc/${PID} ]; do
michael@0 43 cat /proc/${PID}/status |\
michael@0 44 awk '$1=="VmSize:" { vmsize = $2; }
michael@0 45 $1=="VmData:" { vmdata = $2; }
michael@0 46 $1=="VmStk:" { vmstk = $2; }
michael@0 47 $1=="VmExe:" { vmexe = $2; }
michael@0 48 $1=="VmLib:" { vmlib = $2; }
michael@0 49 $1=="VmRSS:" { vmrss = $2; }
michael@0 50 END { print vmsize, vmexe, vmlib, vmdata, vmstk, vmrss; }' >> ${OUTPUT_FILE}
michael@0 51 sleep ${INTERVAL}
michael@0 52 done

mercurial