|
|
|
@ -42,7 +42,7 @@ var kstatSplit = regexp.MustCompile(`[:\s]+`)
|
|
|
|
|
func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
|
|
|
|
|
kstatSysOut, err := invoke.CommandWithContext(ctx, "kstat", "-p", "cpu_stat:*:*:/^idle$|^user$|^kernel$|^iowait$|^swap$/")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("cannot execute kstat: %s", err)
|
|
|
|
|
return nil, fmt.Errorf("cannot execute kstat: %w", err)
|
|
|
|
|
}
|
|
|
|
|
cpu := make(map[float64]float64)
|
|
|
|
|
idle := make(map[float64]float64)
|
|
|
|
@ -57,29 +57,29 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
|
|
|
|
|
}
|
|
|
|
|
cpuNumber, err := strconv.ParseFloat(fields[1], 64)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("cannot parse cpu number: %s", err)
|
|
|
|
|
return nil, fmt.Errorf("cannot parse cpu number: %w", err)
|
|
|
|
|
}
|
|
|
|
|
cpu[cpuNumber] = cpuNumber
|
|
|
|
|
switch fields[3] {
|
|
|
|
|
case "idle":
|
|
|
|
|
idle[cpuNumber], err = strconv.ParseFloat(fields[4], 64)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("cannot parse idle: %s", err)
|
|
|
|
|
return nil, fmt.Errorf("cannot parse idle: %w", err)
|
|
|
|
|
}
|
|
|
|
|
case "user":
|
|
|
|
|
user[cpuNumber], err = strconv.ParseFloat(fields[4], 64)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("cannot parse user: %s", err)
|
|
|
|
|
return nil, fmt.Errorf("cannot parse user: %w", err)
|
|
|
|
|
}
|
|
|
|
|
case "kernel":
|
|
|
|
|
kern[cpuNumber], err = strconv.ParseFloat(fields[4], 64)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("cannot parse kernel: %s", err)
|
|
|
|
|
return nil, fmt.Errorf("cannot parse kernel: %w", err)
|
|
|
|
|
}
|
|
|
|
|
case "iowait":
|
|
|
|
|
iowt[cpuNumber], err = strconv.ParseFloat(fields[4], 64)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("cannot parse iowait: %s", err)
|
|
|
|
|
return nil, fmt.Errorf("cannot parse iowait: %w", err)
|
|
|
|
|
}
|
|
|
|
|
//not sure how this translates, don't report, add to kernel, something else?
|
|
|
|
|
/*case "swap":
|
|
|
|
@ -121,22 +121,22 @@ func Info() ([]InfoStat, error) {
|
|
|
|
|
func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
|
|
|
|
|
psrInfoOut, err := invoke.CommandWithContext(ctx, "psrinfo", "-p", "-v")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("cannot execute psrinfo: %s", err)
|
|
|
|
|
return nil, fmt.Errorf("cannot execute psrinfo: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
procs, err := parseProcessorInfo(string(psrInfoOut))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("error parsing psrinfo output: %s", err)
|
|
|
|
|
return nil, fmt.Errorf("error parsing psrinfo output: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isaInfoOut, err := invoke.CommandWithContext(ctx, "isainfo", "-b", "-v")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("cannot execute isainfo: %s", err)
|
|
|
|
|
return nil, fmt.Errorf("cannot execute isainfo: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
flags, err := parseISAInfo(string(isaInfoOut))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("error parsing isainfo output: %s", err)
|
|
|
|
|
return nil, fmt.Errorf("error parsing isainfo output: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result := make([]InfoStat, 0, len(flags))
|
|
|
|
@ -160,7 +160,7 @@ func parseISAInfo(cmdOutput string) ([]string, error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
flags := make([]string, len(words)-4)
|
|
|
|
|
for i, val := range words[4:] {
|
|
|
|
|
for i, val := range words[4:] { //nolint:gosimple //FIXME
|
|
|
|
|
flags[i] = val
|
|
|
|
|
}
|
|
|
|
|
sort.Strings(flags)
|
|
|
|
@ -194,7 +194,7 @@ func parseProcessorInfo(cmdOutput string) ([]InfoStat, error) {
|
|
|
|
|
if physicalCPU[psrStepOffset] != "" {
|
|
|
|
|
stepParsed, err := strconv.ParseInt(physicalCPU[psrStepOffset], 10, 32)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("cannot parse value %q for step as 32-bit integer: %s", physicalCPU[9], err)
|
|
|
|
|
return nil, fmt.Errorf("cannot parse value %q for step as 32-bit integer: %w", physicalCPU[9], err)
|
|
|
|
|
}
|
|
|
|
|
step = int32(stepParsed)
|
|
|
|
|
}
|
|
|
|
@ -202,7 +202,7 @@ func parseProcessorInfo(cmdOutput string) ([]InfoStat, error) {
|
|
|
|
|
if physicalCPU[psrClockOffset] != "" {
|
|
|
|
|
clockParsed, err := strconv.ParseInt(physicalCPU[psrClockOffset], 10, 64)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("cannot parse value %q for clock as 32-bit integer: %s", physicalCPU[10], err)
|
|
|
|
|
return nil, fmt.Errorf("cannot parse value %q for clock as 32-bit integer: %w", physicalCPU[10], err)
|
|
|
|
|
}
|
|
|
|
|
clock = float64(clockParsed)
|
|
|
|
|
}
|
|
|
|
@ -214,7 +214,7 @@ func parseProcessorInfo(cmdOutput string) ([]InfoStat, error) {
|
|
|
|
|
case physicalCPU[psrNumCoresOffset] != "":
|
|
|
|
|
numCores, err = strconv.ParseInt(physicalCPU[psrNumCoresOffset], 10, 32)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("cannot parse value %q for core count as 32-bit integer: %s", physicalCPU[1], err)
|
|
|
|
|
return nil, fmt.Errorf("cannot parse value %q for core count as 32-bit integer: %w", physicalCPU[1], err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for i := 0; i < int(numCores); i++ {
|
|
|
|
@ -235,12 +235,12 @@ func parseProcessorInfo(cmdOutput string) ([]InfoStat, error) {
|
|
|
|
|
case physicalCPU[psrNumCoresHTOffset] != "":
|
|
|
|
|
numCores, err = strconv.ParseInt(physicalCPU[psrNumCoresHTOffset], 10, 32)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("cannot parse value %q for core count as 32-bit integer: %s", physicalCPU[3], err)
|
|
|
|
|
return nil, fmt.Errorf("cannot parse value %q for core count as 32-bit integer: %w", physicalCPU[3], err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
numHT, err = strconv.ParseInt(physicalCPU[psrNumHTOffset], 10, 32)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("cannot parse value %q for hyperthread count as 32-bit integer: %s", physicalCPU[4], err)
|
|
|
|
|
return nil, fmt.Errorf("cannot parse value %q for hyperthread count as 32-bit integer: %w", physicalCPU[4], err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for i := 0; i < int(numCores); i++ {
|
|
|
|
|