-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
cpu_aix_cgo.go
66 lines (60 loc) · 1.29 KB
/
cpu_aix_cgo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// SPDX-License-Identifier: BSD-3-Clause
//go:build aix && cgo
package cpu
import (
"context"
"github.com/power-devops/perfstat"
)
func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
var ret []TimesStat
if percpu {
cpus, err := perfstat.CpuStat()
if err != nil {
return nil, err
}
for _, c := range cpus {
ct := &TimesStat{
CPU: c.Name,
Idle: float64(c.Idle),
User: float64(c.User),
System: float64(c.Sys),
Iowait: float64(c.Wait),
}
ret = append(ret, *ct)
}
} else {
c, err := perfstat.CpuUtilTotalStat()
if err != nil {
return nil, err
}
ct := &TimesStat{
CPU: "cpu-total",
Idle: float64(c.IdlePct),
User: float64(c.UserPct),
System: float64(c.KernPct),
Iowait: float64(c.WaitPct),
}
ret = append(ret, *ct)
}
return ret, nil
}
func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
c, err := perfstat.CpuTotalStat()
if err != nil {
return nil, err
}
info := InfoStat{
CPU: 0,
Mhz: float64(c.ProcessorHz / 1000000),
Cores: int32(c.NCpusCfg),
}
result := []InfoStat{info}
return result, nil
}
func CountsWithContext(ctx context.Context, logical bool) (int, error) {
c, err := perfstat.CpuTotalStat()
if err != nil {
return 0, err
}
return c.NCpusCfg, nil
}