mirror of
https://github.com/OpenNebula/one.git
synced 2026-12-01 20:56:42 +09:00
B #8195: Guard against cpu_j <= 0 and exited PIDs in ProcessList.cpu_info
Check cpu_j > 0 and j_end >= cpu_ini[pid] in ProcessList.cpu_info before computing per-process CPU percentage to avoid FloatDomainError (NaN) and negative CPU usage when a process terminates during the sampling window. Signed-off-by: Iurii Trukhin <yuri@trukhin.com>
This commit is contained in:
1 parent
e563b898f8
commit
c46d2253e4
1 file changed
+8
-2
@@ -79,8 +79,14 @@ module ProcessList
|
||||
cpu = {}
|
||||
|
||||
pids.each do |pid|
|
||||
cpu[pid] = (proc_jiffies(pid) - cpu_ini[pid]) / cpu_j
|
||||
cpu[pid] = (cpu[pid] * multiplier).round(2)
|
||||
j_end = proc_jiffies(pid)
|
||||
|
||||
if cpu_j > 0 && j_end >= cpu_ini[pid]
|
||||
cpu[pid] = (j_end - cpu_ini[pid]) / cpu_j
|
||||
cpu[pid] = (cpu[pid] * multiplier).round(2)
|
||||
else
|
||||
cpu[pid] = 0.0
|
||||
end
|
||||
end
|
||||
|
||||
cpu
|
||||
|
||||
Reference in new issue
Block a user