|
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/. |
|
6 |
|
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'' |
|
14 |
|
15 # Clear the output file |
|
16 OUTPUT_FILE=watch.out |
|
17 INTERVAL=10 |
|
18 |
|
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 |
|
31 |
|
32 rm -f ${OUTPUT_FILE} |
|
33 |
|
34 echo "vmsize vmexe vmlib vmdata vmstk vmrss" > ${OUTPUT_FILE} |
|
35 |
|
36 # treat the arguments as the command to execute |
|
37 $* & |
|
38 |
|
39 # remember the process ID |
|
40 PID=$! |
|
41 |
|
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 |