|
|
@ -33,18 +33,15 @@ func Times(percpu bool) ([]TimesStat, error) {
|
|
|
|
filename := common.HostProc("stat")
|
|
|
|
filename := common.HostProc("stat")
|
|
|
|
var lines = []string{}
|
|
|
|
var lines = []string{}
|
|
|
|
if percpu {
|
|
|
|
if percpu {
|
|
|
|
var startIdx uint = 1
|
|
|
|
statlines, err := common.ReadLines(filename)
|
|
|
|
for {
|
|
|
|
if err != nil || len(statlines) < 2 {
|
|
|
|
linen, _ := common.ReadLinesOffsetN(filename, startIdx, 1)
|
|
|
|
return []TimesStat{}, nil
|
|
|
|
if len(linen) == 0 {
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
line := linen[0]
|
|
|
|
for _, line := range statlines[1:] {
|
|
|
|
if !strings.HasPrefix(line, "cpu") {
|
|
|
|
if !strings.HasPrefix(line, "cpu") {
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lines = append(lines, line)
|
|
|
|
lines = append(lines, line)
|
|
|
|
startIdx++
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
lines, _ = common.ReadLinesOffsetN(filename, 0, 1)
|
|
|
|
lines, _ = common.ReadLinesOffsetN(filename, 0, 1)
|
|
|
|