Merge pull request #311 from sparrc/cpu-times-panic
fix panic when /proc/stat is empty
This commit is contained in:
commit
77b5d0080a
|
@ -36,6 +36,9 @@ func Times(percpu bool) ([]TimesStat, error) {
|
||||||
var startIdx uint = 1
|
var startIdx uint = 1
|
||||||
for {
|
for {
|
||||||
linen, _ := common.ReadLinesOffsetN(filename, startIdx, 1)
|
linen, _ := common.ReadLinesOffsetN(filename, startIdx, 1)
|
||||||
|
if len(linen) == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
line := linen[0]
|
line := linen[0]
|
||||||
if !strings.HasPrefix(line, "cpu") {
|
if !strings.HasPrefix(line, "cpu") {
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue