Linux Per-Process CPU Runtime Statistics: Difference between revisions
Jump to navigation
Jump to search
Line 21: | Line 21: | ||
process-running-time(seconds) = [[/proc/uptime#System_Uptime|system-uptime]](seconds) - ([[/proc/pid/stat#Field_22_-_starttime|starttime]] / [[Linux_7_General_Concepts#USER_HZ|USER_HZ]]) | process-running-time(seconds) = [[/proc/uptime#System_Uptime|system-uptime]](seconds) - ([[/proc/pid/stat#Field_22_-_starttime|starttime]] / [[Linux_7_General_Concepts#USER_HZ|USER_HZ]]) | ||
CPU usage percentage: | |||
cpu-usage = (total-time-proc-plus-children / [[Linux_7_General_Concepts#USER_HZ|USER_HZ]]) / process-running-time * 100 |
Revision as of 00:59, 2 March 2018
External
Internal
Overview
To determine total time spend by the process in user and kernel modes:
total-time-proc = utime + stime
If we want to include time from children processes:
total-time-proc-plus-children = total-time-proc + cutime + cstime
Running time for process (in seconds)
process-running-time(seconds) = system-uptime(seconds) - (starttime / USER_HZ)
CPU usage percentage:
cpu-usage = (total-time-proc-plus-children / USER_HZ) / process-running-time * 100