-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmonitor.sh
executable file
·37 lines (31 loc) · 883 Bytes
/
monitor.sh
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
#!/bin/bash
# prefix a command with `monitor.sh`, but you'll need a tmpfs mounted
# to monitor the size used. Mount one with:
#
# sudo mount -t tmpfs tmpfs /tmp/test -o rw,nosuid,noatime,nodev,size=8G,mode=1777
cmd=$*
tmpfs=/tmp/test
startts=$(date +'%s')
TMPDIR=$tmpfs $cmd &
cmdpid=$!
sleep 0.2
peakmem=0
peakrss=0
peakdisk=0
while kill -0 $cmdpid >& /dev/null
do
peakmem=$(cat "/proc/${cmdpid}/status" | grep VmPeak | awk '{print $2}')
rss=$(cat "/proc/${cmdpid}/status" | grep VmRSS | awk '{print $2}')
if (( $rss > $peakrss )); then
peakrss=$rss
fi
disk=$(df $tmpfs --output=used | tail -1)
if (( $disk > $peakdisk )); then
peakdisk=$disk
fi
sleep 0.2
done
echo "Took ~$(expr $(date +'%s') - $startts) seconds"
echo "Peak disk $(expr $peakdisk / 1024) Mb"
echo "Peak mem $(expr $peakmem / 1024) Mb"
echo "Peak mem RSS $(expr $peakrss / 1024) Mb"