提交 4a0ce1d1 编写于 作者: S shirou

Merge pull request #33 from codeskyblue/master

change cpu_linux.go: on some android, runtime.NumCPU() will not return r...
...@@ -12,10 +12,18 @@ import ( ...@@ -12,10 +12,18 @@ import (
func CPUTimes(percpu bool) ([]CPUTimesStat, error) { func CPUTimes(percpu bool) ([]CPUTimesStat, error) {
filename := "/proc/stat" filename := "/proc/stat"
var lines []string var lines = []string{}
if percpu { if percpu {
ncpu, _ := CPUCounts(true) var startIdx uint = 1
lines, _ = common.ReadLinesOffsetN(filename, 1, ncpu) for {
linen, _ := common.ReadLinesOffsetN(filename, startIdx, 1)
line := linen[0]
if !strings.HasPrefix(line, "cpu") {
break
}
lines = append(lines, line)
startIdx += 1
}
} else { } else {
lines, _ = common.ReadLinesOffsetN(filename, 0, 1) lines, _ = common.ReadLinesOffsetN(filename, 0, 1)
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册