resource: system: Calculate average cpu utilization with per-cpu stat 84/279984/3
authorDongwoo Lee <dwoo08.lee@samsung.com>
Fri, 19 Aug 2022 10:05:05 +0000 (19:05 +0900)
committerDongwoo Lee <dwlee08@gmail.com>
Tue, 23 Aug 2022 00:04:34 +0000 (17:04 -0700)
commitb869d9e23f45b756475c07943308003f8ed5c71c
tree5094410dc43f36b586f8cc954188f6e65ecdf8f6
parent744ff5034b204b9188acc4effd9bcb0442bc9e62
resource: system: Calculate average cpu utilization with per-cpu stat

In a situation where the number of online cpus is dynamically changed,
measuring the total system cpu usage by using the sum of the online
cpus usage time located at the top of '/proc/stat' will result in
inaccurate results. For example, suppose that the number of online
cpus changed from 2 to 1 between two time intervals. In this case, the
sum of the cpu time measured later is rather reduced than the sum of
the cpu time measured first, and if the cpu usage rate is calculated
using the difference between these two cpu times, a negative result
will come out. To prevent this situation, the average usage is
calculated by summing the usage time of each CPU; assuming that the
usage rate is 0% for offline CPUs.

Change-Id: I93e4561f525b54488df46bf0f895fa76b3b710ca
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
src/resource/resource-system.c