tools/footprint/watch.sh

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/footprint/watch.sh	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,52 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.7 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.9 +
    1.10 +# Treats the arguments as a command that is to be forked and observed;
    1.11 +# e.g.,
    1.12 +#
    1.13 +#   watch.sh ./mozilla -f bloaturls.txt
    1.14 +#
    1.15 +# Periodically snap-shots the virtual memory info of the process, and
    1.16 +# dumps the output to ``watch.out''
    1.17 +
    1.18 +# Clear the output file
    1.19 +OUTPUT_FILE=watch.out
    1.20 +INTERVAL=10
    1.21 +
    1.22 +while [ $# -gt 0 ]; do
    1.23 +    case "$1" in
    1.24 +    -o) OUTPUT_FILE=$2
    1.25 +        shift 2
    1.26 +        ;;
    1.27 +    -i) INTERVAL=$2
    1.28 +        shift 2
    1.29 +        ;;
    1.30 +    *)  break
    1.31 +        ;;
    1.32 +    esac
    1.33 +done
    1.34 +
    1.35 +rm -f ${OUTPUT_FILE}
    1.36 +
    1.37 +echo "vmsize vmexe vmlib vmdata vmstk vmrss" > ${OUTPUT_FILE}
    1.38 +
    1.39 +# treat the arguments as the command to execute
    1.40 +$* &
    1.41 +
    1.42 +# remember the process ID
    1.43 +PID=$!
    1.44 +
    1.45 +while [ -e /proc/${PID} ]; do
    1.46 +    cat /proc/${PID}/status |\
    1.47 +    awk '$1=="VmSize:" { vmsize = $2; }
    1.48 +$1=="VmData:" { vmdata = $2; }
    1.49 +$1=="VmStk:" { vmstk = $2; }
    1.50 +$1=="VmExe:" { vmexe = $2; }
    1.51 +$1=="VmLib:" { vmlib = $2; }
    1.52 +$1=="VmRSS:" { vmrss = $2; }
    1.53 +END { print vmsize, vmexe, vmlib, vmdata, vmstk, vmrss; }' >> ${OUTPUT_FILE}
    1.54 +    sleep ${INTERVAL}
    1.55 +done

mercurial