-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathmemsample
executable file
·55 lines (45 loc) · 1.15 KB
/
memsample
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
52
53
54
55
#!/bin/sh
# Collect data about memory usage of all processes
DOCS="https://github.com/yast/yast-installation/blob/master/doc/memsample.md"
# save memory by switching to a smaller shell
# bash RSS is at least 3 MB per process, dash RSS is around 1 MB
if [ -n "$BASH_VERSION" ] && [ -x /bin/dash ]; then
exec /bin/dash "$0" "$@"
fi
while [ -n "$1" ]; do
case "$1" in
--archive=*)
ARCHIVE=${1#--archive=}
shift
;;
--sleep=*)
SLEEP=${1#--sleep=}
shift
esac
done
# default values
: "${ARCHIVE=./memsample.zcat}"
: "${SLEEP=5}"
echo >&2 "Sampling every $SLEEP s to $ARCHIVE"
{
echo "### comment-0000-$(date -Iseconds)"
echo "See $DOCS"
} | gzip -c >> "$ARCHIVE"
memsample_ps() {
ps -e -H -o pid,tname,vsize:8,drs:8,trs:8,rss:8,size:8,ppid,args
}
I=0
while true; do
I=$((I + 1))
I_TIME=$(printf %04d $I)-$(date -Iseconds)
# redirect STDERR to not break the YaST UI (bsc#1195116)
{
echo "### df-$I_TIME"
df -k /
echo "### free-$I_TIME"
free -k
echo "### ps-$I_TIME"
memsample_ps
} 2>&1 | gzip -c >> "$ARCHIVE"
sleep "$SLEEP"
done