mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Fix CPUUsage() method in cgroup v2 version.
CPUUsage() returns the CPU usage used in calculating the pod CPU utilization. The cgroup v1 version returns this value in nanoseconds,but the v2 version was returning in microseconds which resulted in incorrect CPU usage values when cgroupv2 was used as default. Fix this by changing the return value of CPUUsage() in cgroupv2 to nanoseconds PiperOrigin-RevId: 617903260
This commit is contained in:
committed by
gVisor bot
parent
53f976dede
commit
094b83e18a
@@ -643,7 +643,7 @@ func (c *cgroupV1) CPUQuota() (float64, error) {
|
||||
return float64(quota) / float64(period), nil
|
||||
}
|
||||
|
||||
// CPUUsage returns the total CPU usage of the cgroup.
|
||||
// CPUUsage returns the total CPU usage of the cgroup in nanoseconds.
|
||||
func (c *cgroupV1) CPUUsage() (uint64, error) {
|
||||
path := c.MakePath("cpuacct")
|
||||
usage, err := getValue(path, "cpuacct.usage")
|
||||
|
||||
@@ -286,7 +286,7 @@ func parseCPUQuota(cpuMax string) (float64, error) {
|
||||
|
||||
}
|
||||
|
||||
// CPUUsage returns the total CPU usage of the cgroup.
|
||||
// CPUUsage returns the total CPU usage of the cgroup in nanoseconds.
|
||||
func (c *cgroupV2) CPUUsage() (uint64, error) {
|
||||
cpuStat, err := getValue(c.MakePath(""), "cpu.stat")
|
||||
if err != nil {
|
||||
@@ -300,7 +300,7 @@ func (c *cgroupV2) CPUUsage() (uint64, error) {
|
||||
return 0, err
|
||||
}
|
||||
if key == "usage_usec" {
|
||||
return value, nil
|
||||
return value * 1000, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user