#!/bin/sh

PROCESSNAMES="devicestack knxstack iscwebservice iscapphost"

if [ -f /bin/SdaService ]; then
	PROCESSNAMES="${PROCESSNAMES} SdaService"
fi

if [ -f /bin/SdaKnxIpRouter ]; then
	PROCESSNAMES="${PROCESSNAMES} SdaKnxIpRouter"
fi

if [ -f /usr/bin/mono ]; then
	PROCESSNAMES="${PROCESSNAMES} mono"
fi

while
    for name in ${PROCESSNAMES}; do
        if [ "$(pidof $name)" != "" ]; then
            statm=$(cat /proc/$(pidof $name)/statm);
            printf "%s %s\n" "$(date +%s)" "$statm" >> /opt/userdata/log/$name.statm;
        fi
        if [ "$(wc -c /opt/userdata/log/$name.statm | cut -d ' ' -f1)" -gt 512000 ]; then
            mv /opt/userdata/log/$name.statm /opt/userdata/log/$name.statm.1
        fi 
    done
        # sleep 1 minute (60 seconds)
        sleep 60
do :; done
