mirror of
https://github.com/containers/podman.git
synced 2025-08-06 03:19:52 +08:00
stats: use runtime.NumCPU when percpu counters are not available
in the cgroup v2 implementation we don't have yet percpu times. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
package libpod
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
@ -105,7 +106,11 @@ func calculateCPUPercent(stats *cgroups.Metrics, previousCPU, previousSystem uin
|
||||
if systemDelta > 0.0 && cpuDelta > 0.0 {
|
||||
// gets a ratio of container cpu usage total, multiplies it by the number of cores (4 cores running
|
||||
// at 100% utilization should be 400% utilization), and multiplies that by 100 to get a percentage
|
||||
cpuPercent = (cpuDelta / systemDelta) * float64(len(stats.CPU.Usage.PerCPU)) * 100
|
||||
nCPUS := len(stats.CPU.Usage.PerCPU)
|
||||
if nCPUS == 0 {
|
||||
nCPUS = runtime.NumCPU()
|
||||
}
|
||||
cpuPercent = (cpuDelta / systemDelta) * float64(nCPUS) * 100
|
||||
}
|
||||
return cpuPercent
|
||||
}
|
||||
|
Reference in New Issue
Block a user