From 3b43a3f4966fcc4b0f684a56cdac9ed1d3065ca8 Mon Sep 17 00:00:00 2001 From: codeskyblue Date: Tue, 13 Jan 2015 18:32:25 +0800 Subject: [PATCH] change cpu_linux.go: on some android, runtime.NumCPU() will not return right number of cpu cores --- cpu/cpu_linux.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/cpu/cpu_linux.go b/cpu/cpu_linux.go index 4a303ba..d3a77b5 100644 --- a/cpu/cpu_linux.go +++ b/cpu/cpu_linux.go @@ -12,10 +12,18 @@ import ( func CPUTimes(percpu bool) ([]CPUTimesStat, error) { filename := "/proc/stat" - var lines []string + var lines = []string{} if percpu { - ncpu, _ := CPUCounts(true) - lines, _ = common.ReadLinesOffsetN(filename, 1, ncpu) + var startIdx uint = 1 + for { + linen, _ := common.ReadLinesOffsetN(filename, startIdx, 1) + line := linen[0] + if !strings.HasPrefix(line, "cpu") { + break + } + lines = append(lines, line) + startIdx += 1 + } } else { lines, _ = common.ReadLinesOffsetN(filename, 0, 1) }