MCPcopy
hub / github.com/google/cadvisor / checkCPUStats

Function checkCPUStats

integration/tests/api/test_utils.go:48–67  ·  view source on GitHub ↗

Checks that CPU stats are valid.

(t *testing.T, stat *info.CpuStats)

Source from the content-addressed store, hash-verified

46
47// Checks that CPU stats are valid.
48func checkCPUStats(t *testing.T, stat *info.CpuStats) {
49 assert := assert.New(t)
50
51 assert.NotEqual(0, stat.Usage.Total, "Total CPU usage should not be zero")
52
53 // PerCPU CPU usage is not supported in cgroupv2 (cpuacct.usage_percpu)
54 // https://github.com/google/cadvisor/issues/3065
55 if !cgroups.IsCgroup2UnifiedMode() {
56 assert.NotEmpty(stat.Usage.PerCpu, "Per-core usage should not be empty")
57
58 totalUsage := uint64(0)
59 for _, usage := range stat.Usage.PerCpu {
60 totalUsage += usage
61 }
62 inDelta(t, stat.Usage.Total, totalUsage, uint64((5 * time.Millisecond).Nanoseconds()), "Per-core CPU usage")
63 }
64
65 inDelta(t, stat.Usage.Total, stat.Usage.User+stat.Usage.System, uint64((500 * time.Millisecond).Nanoseconds()), "User + system CPU usage")
66 // TODO(rjnagal): Add verification for cpu load.
67}
68
69func checkMemoryStats(t *testing.T, stat *info.MemoryStats) {
70 assert := assert.New(t)

Callers 2

Calls 1

inDeltaFunction · 0.70

Tested by 2

Used in the wild real call sites across dependent graphs

searching dependent graphs…