Skip to content

Commit 3d643b9

Browse files
xca1075xca1075
xca1075
authored and
xca1075
committed
parse cpu values as float
1 parent b3ab156 commit 3d643b9

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

cpu/cpu_aix_nocgo.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
3131
h := whiteSpaces.Split(lines[len(lines)-3], -1) // headers
3232
v := whiteSpaces.Split(lines[len(lines)-2], -1) // values
3333
for i, header := range h {
34-
if t, err := strconv.ParseUint(v[i], 10, 64); err == nil {
34+
if t, err := strconv.ParseFloat(v[i], 64); err == nil {
3535
switch header {
3636
case `%usr`:
37-
ret.User = float64(t)
37+
ret.User = t
3838
case `%sys`:
39-
ret.System = float64(t)
39+
ret.System = t
4040
case `%wio`:
41-
ret.Iowait = float64(t)
41+
ret.Iowait = t
4242
case `%idle`:
43-
ret.Idle = float64(t)
43+
ret.Idle = t
4444
}
4545
}
4646
}
@@ -67,16 +67,16 @@ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
6767
} else if strings.HasPrefix(line, "Processor Clock Speed:") {
6868
p := whiteSpaces.Split(line, 5)
6969
if len(p) > 4 {
70-
if t, err := strconv.ParseUint(p[3], 10, 64); err == nil {
70+
if t, err := strconv.ParseFloat(p[3], 64); err == nil {
7171
switch strings.ToUpper(p[4]) {
7272
case "MHZ":
73-
ret.Mhz = float64(t)
73+
ret.Mhz = t
7474
case "GHZ":
75-
ret.Mhz = float64(t) * 1000.0
75+
ret.Mhz = t * 1000.0
7676
case "KHZ":
77-
ret.Mhz = float64(t) / 1000.0
77+
ret.Mhz = t / 1000.0
7878
default:
79-
ret.Mhz = float64(t)
79+
ret.Mhz = t
8080
}
8181
}
8282
}

0 commit comments

Comments
 (0)