Is there any way to measure a specific process CPU usage by cores?
I know top is good for measuring the whole system\'s CPU usage by cores and taskset can provide inform
The ps solution was nearly what I needed and with some bash thrown in does exactly what the original question asked for: to see per-core usage of specific processes
This shows per-core usage of multi-threaded processes too.
Use like: cpustat `pgrep processname` `pgrep otherprocessname` ...
#!/bin/bash
pids=()
while [ $# != 0 ]; do
pids=("${pids[@]}" "$1")
shift
done
if [ -z "${pids[0]}" ]; then
echo "Usage: $0 [pid2] ..."
exit 1
fi
for pid in "${pids[@]}"; do
if [ ! -e /proc/$pid ]; then
echo "Error: pid $pid doesn't exist"
exit 1
fi
done
while [ true ]; do
echo -e "\033[H\033[J"
for pid in "${pids[@]}"; do
ps -p $pid -L -o pid,tid,psr,pcpu,comm=
done
sleep 1
done
Note: These stats are based on process lifetime, not the last X seconds, so you'll need to restart your process to reset the counter.