#!/bin/bash
while true; do
    pid=$(ps ax -o pid,comm | grep $1 | awk '{print $1}')
    d=$(date +"%Y-%m-%d %T")
    if [ -z "$pid" ]; then
        echo ${d} process \'$1\' not found
    else
        m=$(cat /proc/$pid/statm | awk '{print "size=" $1 * 4 " rss=" $2 * 4 " shared=" $3 * 4 " text=" $4 * 4 " data=" $6 * 4}')
        heap=$(cat /proc/$pid/maps | grep "\[heap\]"|awk -F "[- ]" '{print (strtonum("0x"$2) - strtonum("0x"$1)) / 1024}')
        echo "${d} $1($pid) ${m} heap=${heap}"
    fi

    sleep 20s
done
