I am looking to log CPU usage to a file over time on an RHEL system, and have seen this, but it doesn't seem to produce the right results - it seems like an anomaly between how ps and top calculate CPU usage.
I am trying to profile an Openfire server's CPU usage as we run various load tests against it. The script I am using does this:
while true; do dateStamp=$(($(date +%s%N)/1000000000)) echo -n $dateStamp >>usage.log ps -o pcpu,rsz -p $1 | tail -n1 >>usage.log; sleep $2; done But the first data item from ps (pcpu) seems to be cumulative - I would like a simple number for current CPU usage, as is provided by top.
Does anyone know of an approach that provides this?
Thanks in advance
Rich