MCPcopy Create free account
hub / github.com/Loafter/WebTop / getCPUAverage

Function getCPUAverage

SystemStatLinux.go:183–199  ·  view source on GitHub ↗
(first CPUSample, second CPUSample)

Source from the content-addressed store, hash-verified

181}
182
183func getCPUAverage(first CPUSample, second CPUSample) (avg CPUAverage) {
184 dTot := float64(second.Total - first.Total)
185 invQuotient := 100.00 / dTot
186
187 avg.UserPct = subtractAndConvertTicks(second.User, first.User) * invQuotient
188 avg.NicePct = subtractAndConvertTicks(second.Nice, first.Nice) * invQuotient
189 avg.SystemPct = subtractAndConvertTicks(second.System, first.System) * invQuotient
190 avg.IdlePct = subtractAndConvertTicks(second.Idle, first.Idle) * invQuotient
191 avg.IowaitPct = subtractAndConvertTicks(second.Iowait, first.Iowait) * invQuotient
192 avg.IrqPct = subtractAndConvertTicks(second.Irq, first.Irq) * invQuotient
193 avg.SoftIrqPct = subtractAndConvertTicks(second.SoftIrq, first.SoftIrq) * invQuotient
194 avg.StealPct = subtractAndConvertTicks(second.Steal, first.Steal) * invQuotient
195 avg.GuestPct = subtractAndConvertTicks(second.Guest, first.Guest) * invQuotient
196 avg.Time = second.Time
197 avg.Seconds = second.Time.Sub(first.Time).Seconds()
198 return
199}
200
201func getProcCPUAverage(first ProcCPUSample, second ProcCPUSample, procUptime float64) (avg ProcCPUAverage) {
202 dT := second.Time.Sub(first.Time).Seconds()

Callers 1

GetCPUAverageFunction · 0.85

Calls 1

subtractAndConvertTicksFunction · 0.85

Tested by

no test coverage detected