Created
April 26, 2019 21:48
-
-
Save nickolai-voyage/ae421f7c5fa879b2c9ba1ba2fe0bcc45 to your computer and use it in GitHub Desktop.
Processor utilization of process as perfcentage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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