mirror of https://github.com/containers/podman.git
Merge pull request #3471 from giuseppe/small-fixes-cgroups
cgroups v2: fix cpu time
This commit is contained in:
commit
26d02e9739
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ type CgroupControl struct {
|
|||
additionalControllers []controller
|
||||
}
|
||||
|
||||
// CPUUsage keeps stats for the CPU usage
|
||||
// CPUUsage keeps stats for the CPU usage (unit: nanoseconds)
|
||||
type CPUUsage struct {
|
||||
Kernel uint64
|
||||
Total uint64
|
||||
|
|
|
|||
|
|
@ -85,12 +85,14 @@ func (c *cpuHandler) Stat(ctr *CgroupControl, m *Metrics) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
usage.Kernel *= 1000
|
||||
}
|
||||
if val, found := values["system_usec"]; found {
|
||||
usage.Total, err = strconv.ParseUint(cleanString(val[0]), 10, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
usage.Total *= 1000
|
||||
}
|
||||
// FIXME: How to read usage.PerCPU?
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue