mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +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
|
package libpod
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
@ -105,7 +106,11 @@ func calculateCPUPercent(stats *cgroups.Metrics, previousCPU, previousSystem uin
|
|||||||
if systemDelta > 0.0 && cpuDelta > 0.0 {
|
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
|
// 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
|
// 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
|
return cpuPercent
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user