From 1afd50d265ed70e9db1d79c43c1ce3003efa7410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 14 Jun 2011 10:41:09 +0200 Subject: add memprof --- memprof | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 memprof 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 -- cgit v1.1-2-g2b99