#! /usr/bin/env bash

WATCHER_PID=$(pgrep wtr.watcher || echo false)
test "$WATCHER_PID" = false && {
  echo 'watcher not running.'; exit 1; }

TIME_SPAN=5
test $# -eq 1 \
  && test $1 -gt 0 \
    && TIME_SPAN=$1

RESULT="$( \
  top \
    -pid $WATCHER_PID \
    -s $TIME_SPAN \
    -l 2 \
    -c a \
    -stats cpu,mem \
      | tail -n 1)"

echo "time span: ${TIME_SPAN}s"
echo "$RESULT" | sed -E 's/(.+)( +)(.+)/cpu usage: \1\nmemory usage: \3/g'
