Linux Per-Process CPU Runtime Statistics: Difference between revisions
Jump to navigation
Jump to search
(Created page with "=External= * https://stackoverflow.com/questions/16726779/how-do-i-get-the-total-cpu-usage-of-an-application-from-proc-pid-stat =Internal= * Linux CPU Info =Overview=") |
No edit summary |
||
(9 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
=Internal= | =Internal= | ||
* [[Linux CPU Info]] | * [[Linux_CPU_Info#Per-Process_CPU_Runtime_Statistics|Linux CPU Info]] | ||
* [[/proc/pid/stat#Overview|/proc/pid/stat]] | |||
=Overview= | =Overview= | ||
To determine total time spend by the process in user and kernel modes: | |||
total-time-proc = [[/proc/pid/stat#Field_14_-_utime|utime]] + [[/proc/pid/stat#Field_15_-_stime|stime]] | |||
If we want to include time from children processes: | |||
total-time-proc-plus-children = total-time-proc + [[/proc/pid/stat#Field_16_-_cutime|cutime]] + [[/proc/pid/stat#Field_17_-_cstime|cstime]] | |||
Running time for process (in seconds) | |||
process-running-time(seconds) = [[/proc/uptime#System_Uptime|system-uptime]](seconds) - ([[/proc/pid/stat#Field_22_-_starttime|starttime]] / [[Linux_General_Concepts#USER_HZ|USER_HZ]]) | |||
CPU usage percentage: | |||
cpu-usage = (total-time-proc-plus-children / [[Linux_General_Concepts#USER_HZ|USER_HZ]]) / process-running-time * 100 | |||
=Tools= | |||
{{Internal|Novaordis-linux#Overview|novaordis-linux collector}} |
Latest revision as of 21:22, 2 May 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