summaryrefslogtreecommitdiffstats
path: root/memprof
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2011-06-14 10:41:09 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2011-06-14 10:41:09 +0200
commit1afd50d265ed70e9db1d79c43c1ce3003efa7410 (patch)
treeb8e63279696c0953c4133f7a6f7e5f8610048a2c /memprof
parenta3a16705841f7af375f8a7000649fcf289213116 (diff)
downloadbin-1afd50d265ed70e9db1d79c43c1ce3003efa7410.zip
bin-1afd50d265ed70e9db1d79c43c1ce3003efa7410.tar.gz
add memprof
Diffstat (limited to 'memprof')
-rwxr-xr-xmemprof47
1 files changed, 47 insertions, 0 deletions
diff --git a/memprof b/memprof
new file mode 100755
index 0000000..d73c49a
--- /dev/null
+++ b/memprof
@@ -0,0 +1,47 @@
+#! /bin/sh
+if [ $# -lt 1 ]; then
+ echo "usage $0 cmd or $0 -p PID";
+ exit 1;
+fi
+
+if [ "$1X" = "-pX" ]; then
+ PID=$2
+else
+ $1 & PID=$!
+fi
+
+STATUS_FILE="/proc/$PID/status"
+LOG_FILE="${PID}.dat"
+PLOT_FILE="${PID}.plt"
+
+draw() {
+ cat << EOF >$PLOT_FILE
+set term postscript
+set output "$PID.ps"
+plot '${LOG_FILE}' using 1:2 with lines title 'VmSize', \
+'${LOG_FILE}' using 1:3 with lines title 'VmRss', \
+'${LOG_FILE}' using 1:4 with lines title 'VmLib'
+set term x11
+replot
+EOF
+
+ gnuplot -persist $PLOT_FILE
+ exit 0
+}
+
+trap draw SIGINT
+
+CPT=0
+while [ 1 ]; do
+ if [ ! -e $STATUS_FILE ]; then break; fi
+ awk "BEGIN{ vmSize=0; vmRss=0; vmLib=0; }
+ /VmSize/ {vmSize = \$2 }
+ /VmRSS/ { vmRss = \$2 }
+ /VmLib/ { vmLib = \$2 }
+ END { print $CPT\" \"vmSize\" \"vmRss\" \"vmLib }
+ " $STATUS_FILE >> $LOG_FILE
+ sleep 1
+ ((CPT=CPT+1));
+done
+
+draw