-
Notifications
You must be signed in to change notification settings - Fork 2
/
memprof
51 lines (33 loc) · 1.2 KB
/
memprof
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
## This is a simple script for recording the memory usage of a process over time.
## LINUX ONLY!
#echo " ** memprof: Launching command $1"> /dev/stderr
########################################
# Relegate all its output to stdout, so that we can put ours to stderr.
$* &> /dev/stdout &
#$* &
########################################
PID=$!
#echo " ** Pid of child $PID" > /dev/stderr
JOBNUM=1
#echo "# ProgSize MemSize SharedPages CodePages DataPages LibPages DirtyPages"
echo "# Selected fields from /proc/$PID/status: " >> /dev/stderr
#PAT="Vm(HWM|RSS|Data|Stk|Exe|Lib)"
PAT="(Vm(HWM|RSS|Data|Stk|Exe|Lib))|Threads"
header=`egrep "$PAT" /proc/$$/status | awk '{ print $1 }' | xargs echo `
echo "# $header" >> /dev/stderr
function printstats () {
#stats=`egrep "Vm(HWM|RSS|Data)" /proc/$PID/status`
#stats=`egrep "Vm(HWM|RSS|Data|Stk|Exe|Lib)" /proc/$PID/status | awk '{ print $2 }' | xargs echo `
egrep "$PAT" /proc/$PID/status | awk '{ print " "$2 }' | xargs echo >> /dev/stderr
##echo $stats | awk '{ print $2" "$5" "$8 }' > /dev/stderr
}
#echo "# PeakMem ResidentMem DataMem" > /dev/stderr
while [ "`jobs -r`" != "" ];
do
printstats
sleep 1
done
#printstats
wait $PID
#kill $PID