Under Linux, CPU utilization is divided into user state, system state and idle state, which represent the execution time of the CPU in user state, the execution time of the system kernel, and the execution time of idle system processes. The sum of the three is the total CPU utilization. Time, when there is no user process, system process, etc. to be executed, the CPU executes the system default idle process. From the usual way of thinking, CPU utilization is the proportion of the time occupied by non-idle processes, that is, the time the CPU executes non-idle processes/the total execution time of the CPU.
for example:
|
The first line is the sum, if the CPU is multi-core (including hyper-threading) there will be cpu 0 ~ cpu n
|
The calculation formula of the instant utilization of CPU:
Total CPU usage time from t1 to t2 = ( user2+ nice2+ system2+ idle2+ iowait2+ irq2+ softirq2) - ( user1+ nice1+ system1+ idle1+ iowait1+ irq1+ softirq1)
CPU idle usage time from t1 to t2 = (idle2 - idle1)
CPU instant utilization in the time period from t1 to t2 = 1 - CPU idle usage time / total CPU usage time