#!/bin/bash set -eu pid=$1 rss=$(ps -orss -p $pid | tail -n 1) run=0 echo "ts,current,diff,running_total" echo "$( date -u +'%Y-%m-%d %T'),$rss,0,0" while true; do sleep 20 rss2=$(ps -orss -p $pid | tail -n 1) [[ -z "$rss2" ]] && exit 0 diff=$((rss2 - rss)) run=$((run + diff)) echo "$( date -u +'%Y-%m-%d %T'),$rss2,$diff,$run" rss=$rss2 done