michael@0: #!/bin/sh michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: # Treats the arguments as a command that is to be forked and observed; michael@0: # e.g., michael@0: # michael@0: # watch.sh ./mozilla -f bloaturls.txt michael@0: # michael@0: # Periodically snap-shots the virtual memory info of the process, and michael@0: # dumps the output to ``watch.out'' michael@0: michael@0: # Clear the output file michael@0: OUTPUT_FILE=watch.out michael@0: INTERVAL=10 michael@0: michael@0: while [ $# -gt 0 ]; do michael@0: case "$1" in michael@0: -o) OUTPUT_FILE=$2 michael@0: shift 2 michael@0: ;; michael@0: -i) INTERVAL=$2 michael@0: shift 2 michael@0: ;; michael@0: *) break michael@0: ;; michael@0: esac michael@0: done michael@0: michael@0: rm -f ${OUTPUT_FILE} michael@0: michael@0: echo "vmsize vmexe vmlib vmdata vmstk vmrss" > ${OUTPUT_FILE} michael@0: michael@0: # treat the arguments as the command to execute michael@0: $* & michael@0: michael@0: # remember the process ID michael@0: PID=$! michael@0: michael@0: while [ -e /proc/${PID} ]; do michael@0: cat /proc/${PID}/status |\ michael@0: awk '$1=="VmSize:" { vmsize = $2; } michael@0: $1=="VmData:" { vmdata = $2; } michael@0: $1=="VmStk:" { vmstk = $2; } michael@0: $1=="VmExe:" { vmexe = $2; } michael@0: $1=="VmLib:" { vmlib = $2; } michael@0: $1=="VmRSS:" { vmrss = $2; } michael@0: END { print vmsize, vmexe, vmlib, vmdata, vmstk, vmrss; }' >> ${OUTPUT_FILE} michael@0: sleep ${INTERVAL} michael@0: done