MCPcopy Create free account
hub / github.com/containerd/nerdctl / calculateCgroupCPUPercent

Function calculateCgroupCPUPercent

pkg/statsutil/stats_linux.go:117–134  ·  view source on GitHub ↗
(previousStats *ContainerStats, metrics *v1.Metrics, systemInfo SystemInfo)

Source from the content-addressed store, hash-verified

115}
116
117func calculateCgroupCPUPercent(previousStats *ContainerStats, metrics *v1.Metrics, systemInfo SystemInfo) float64 {
118 var (
119 cpuPercent = 0.0
120 // calculate the change for the cpu usage of the container in between readings
121 cpuDelta = float64(metrics.CPU.Usage.Total) - float64(previousStats.CgroupCPU)
122 // calculate the change for the entire system between readings
123 systemDelta = float64(systemInfo.SystemUsage) - float64(previousStats.CgroupSystem)
124 onlineCPUs = systemInfo.OnlineCPUs
125 )
126
127 if onlineCPUs == 0 {
128 onlineCPUs = uint32(len(metrics.CPU.Usage.PerCPU))
129 }
130 if systemDelta > 0.0 && cpuDelta > 0.0 {
131 cpuPercent = (cpuDelta / systemDelta) * float64(onlineCPUs) * 100.0
132 }
133 return cpuPercent
134}
135
136// PercpuUsage is not supported in CgroupV2
137func calculateCgroup2CPUPercent(previousStats *ContainerStats, metrics *v2.Metrics) float64 {

Callers 1

SetCgroupStatsFieldsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…