some typos + rename smt to smtEnabled for readability

pull/1244/head
Omar Polo 3 years ago
parent 9203029aae
commit 73db061652

@ -18,18 +18,18 @@ import (
const ( const (
// sys/sched.h // sys/sched.h
CPUser = 0 cpUser = 0
cpNice = 1 cpNice = 1
cpSys = 2 cpSys = 2
cpSpin = 3 cpSpin = 3
cpIntr = 4 cpIntr = 4
cpIdle = 5 cpIdle = 5
cpUStates = 6 cpuStates = 6
// sys/sysctl.h // sys/sysctl.h
ctlKern = 1 // "high kernel": proc, limits ctlKern = 1 // "high kernel": proc, limits
ctlHw = 6 // CTL_HW ctlHw = 6 // CTL_HW
sMT = 24 // HW_sMT smt = 24 // HW_SMT
kernCptime = 40 // KERN_CPTIME kernCptime = 40 // KERN_CPTIME
kernCptime2 = 71 // KERN_CPTIME2 kernCptime2 = 71 // KERN_CPTIME2
) )
@ -44,8 +44,8 @@ func init() {
} }
} }
func smt() (bool, error) { func smtEnabled() (bool, error) {
mib := []int32{ctlHw, sMT} mib := []int32{ctlHw, smt}
buf, _, err := common.CallSyscall(mib) buf, _, err := common.CallSyscall(mib)
if err != nil { if err != nil {
return false, err return false, err
@ -74,7 +74,7 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
ncpu = 1 ncpu = 1
} }
smt, err := smt() smt, err := smtEnabled()
if err == syscall.EOPNOTSUPP { if err == syscall.EOPNOTSUPP {
// if hw.smt is not applicable for this platform (e.g. i386), // if hw.smt is not applicable for this platform (e.g. i386),
// pretend it's enabled // pretend it's enabled
@ -89,7 +89,7 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
j *= 2 j *= 2
} }
cpuTimes := make([]int32, cpUStates) cpuTimes := make([]int32, cpuStates)
var mib []int32 var mib []int32
if percpu { if percpu {
mib = []int32{ctlKern, kernCptime2, int32(j)} mib = []int32{ctlKern, kernCptime2, int32(j)}
@ -107,7 +107,7 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
return ret, err return ret, err
} }
c := TimesStat{ c := TimesStat{
User: float64(cpuTimes[CPUser]) / ClocksPerSec, User: float64(cpuTimes[cpUser]) / ClocksPerSec,
Nice: float64(cpuTimes[cpNice]) / ClocksPerSec, Nice: float64(cpuTimes[cpNice]) / ClocksPerSec,
System: float64(cpuTimes[cpSys]) / ClocksPerSec, System: float64(cpuTimes[cpSys]) / ClocksPerSec,
Idle: float64(cpuTimes[cpIdle]) / ClocksPerSec, Idle: float64(cpuTimes[cpIdle]) / ClocksPerSec,

Loading…
Cancel
Save