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.

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

mercurial