mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
Fix #2440 omit cpuacct.usage_all when not available
Signed-off-by: Katarzyna Kujawa <katarzyna.kujawa@intel.com>
This commit is contained in:
@@ -144,7 +144,9 @@ func getPercpuUsageInModes(path string) ([]uint64, []uint64, error) {
|
|||||||
usageUserMode := []uint64{}
|
usageUserMode := []uint64{}
|
||||||
|
|
||||||
file, err := os.Open(filepath.Join(path, cgroupCpuacctUsageAll))
|
file, err := os.Open(filepath.Join(path, cgroupCpuacctUsageAll))
|
||||||
if err != nil {
|
if os.IsNotExist(err) {
|
||||||
|
return usageKernelMode, usageUserMode, nil
|
||||||
|
} else if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|||||||
@@ -59,3 +59,35 @@ func TestCpuacctStats(t *testing.T) {
|
|||||||
expectedStats, actualStats.CpuStats.CpuUsage)
|
expectedStats, actualStats.CpuStats.CpuUsage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCpuacctStatsWithoutUsageAll(t *testing.T) {
|
||||||
|
helper := NewCgroupTestUtil("cpuacct.", t)
|
||||||
|
defer helper.cleanup()
|
||||||
|
helper.writeFileContents(map[string]string{
|
||||||
|
"cpuacct.usage": cpuAcctUsageContents,
|
||||||
|
"cpuacct.usage_percpu": cpuAcctUsagePerCPUContents,
|
||||||
|
"cpuacct.stat": cpuAcctStatContents,
|
||||||
|
})
|
||||||
|
|
||||||
|
cpuacct := &CpuacctGroup{}
|
||||||
|
actualStats := *cgroups.NewStats()
|
||||||
|
err := cpuacct.GetStats(helper.CgroupPath, &actualStats)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expectedStats := cgroups.CpuUsage{
|
||||||
|
TotalUsage: uint64(12262454190222160),
|
||||||
|
PercpuUsage: []uint64{1564936537989058, 1583937096487821, 1604195415465681, 1596445226820187,
|
||||||
|
1481069084155629, 1478735613864327, 1477610593414743, 1476362015778086},
|
||||||
|
PercpuUsageInKernelmode: []uint64{},
|
||||||
|
PercpuUsageInUsermode: []uint64{},
|
||||||
|
UsageInKernelmode: (uint64(291429664) * nanosecondsInSecond) / clockTicks,
|
||||||
|
UsageInUsermode: (uint64(452278264) * nanosecondsInSecond) / clockTicks,
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(expectedStats, actualStats.CpuStats.CpuUsage) {
|
||||||
|
t.Errorf("Expected CPU usage %#v but found %#v\n",
|
||||||
|
expectedStats, actualStats.CpuStats.CpuUsage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user