MCPcopy
hub / github.com/CodisLabs/codis / CPUUsage

Function CPUUsage

pkg/utils/usage.go:8–21  ·  view source on GitHub ↗
(d time.Duration)

Source from the content-addressed store, hash-verified

6import "time"
7
8func CPUUsage(d time.Duration) (float64, *Usage, error) {
9 var now = time.Now()
10 b, err := GetUsage()
11 if err != nil {
12 return 0, nil, err
13 }
14 time.Sleep(d)
15 e, err := GetUsage()
16 if err != nil {
17 return 0, nil, err
18 }
19 usage := e.CPUTotal() - b.CPUTotal()
20 return float64(usage) / float64(time.Since(now)), e, nil
21}

Callers

nothing calls this directly

Calls 3

GetUsageFunction · 0.70
SleepMethod · 0.65
CPUTotalMethod · 0.45

Tested by

no test coverage detected