Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nickolai-voyage/ae421f7c5fa879b2c9ba1ba2fe0bcc45 to your computer and use it in GitHub Desktop.
Save nickolai-voyage/ae421f7c5fa879b2c9ba1ba2fe0bcc45 to your computer and use it in GitHub Desktop.
Processor utilization of process as perfcentage
# Output CPU update, proccess stats, and system ticks/second all at once
# Replace newlines with spaces, to be able to analyze the thing as a single line
# Using awk, evaluate ((utime + stime)/CLK_TCK)/(uptime - starttime/CLK_TCK)
cat /proc/uptime /proc/16901/stat <(getconf CLK_TCK) | tr '\n' ' ' | awk '{print (($16+$17)/$NF) / ($1 - $24/$NF)}'
# $16 is utime
# $17 is stime
# $1 is uptime
# $24 is start time
# These numbers are from man page for /prod/[pid]/stat, but plus 2 since /proc/uptime is at the start of the line
# NF refers to `getconf CLK_TCK`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment