by Hello71 · 8y ago · 0 comments
#!/bin/bash
set -e
pid=$1
if [[ "$pid" = *[^0-9]* ]]; then
pid=$(pgrep -x "$pid")
fi
lasttime=$((2**64))
while sleep 10; do
read pid comm state ppid pgrp session tty_nr tpgid flags minflt cminflt majflt cmajflt utime stime cutime cstime priority nice num_threads itrealvalue starttime vsize rss rsslim startcode endcode startstack kstkesp kstkeip signal blocked sigignore sigcatch wchan nswap cnswap exit_signal processor rt_priority policy delayacct_blkio_ticks guest_time cguest_time start_data end_data start_brk arg_start arg_end env_start env_end exit_code < /proc/$pid/stat
newtime=$((utime+stime))
if (( newtime - lasttime > 1 )); then
gcore $pid
fi
lasttime=$newtime
done
This one has the benefit of being extensible to handle whatever metric you want, or execute whatever command you want, change the polling period...This one has the benefit of being extensible to handle whatever metric you want, or execute whatever command you want, change the polling period...
Yeah, you also have to edit it every time you want to use it. It’s a chunk of shell script, not a reusable tool.