From 9313c5bd9548a8c334c37b889d7cc94774f939d9 Mon Sep 17 00:00:00 2001 From: Tony Date: Sat, 12 Oct 2019 12:15:38 +0800 Subject: [PATCH] Revert "fix possible cpus" This reverts commit 68e1fc1a997ea80c1a1c2ba83d3e6279ba765190. --- go.mod | 1 - pkg/stat/sys/cpu/cgroup.go | 5 +---- pkg/stat/sys/cpu/cgroupCPU.go | 19 ++++++------------- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index de240ece7..d32f668ce 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,6 @@ require ( github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect github.com/leodido/go-urn v1.1.0 // indirect github.com/mattn/go-colorable v0.1.2 // indirect - github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/montanaflynn/stats v0.5.0 github.com/openzipkin/zipkin-go v0.2.1 github.com/otokaze/mock v0.0.0-20190125081256-8282b7a7c7c3 diff --git a/pkg/stat/sys/cpu/cgroup.go b/pkg/stat/sys/cpu/cgroup.go index b297f611f..a3edd52f4 100644 --- a/pkg/stat/sys/cpu/cgroup.go +++ b/pkg/stat/sys/cpu/cgroup.go @@ -56,10 +56,7 @@ func (c *cgroup) CPUAcctUsagePerCPU() ([]uint64, error) { if u, err = parseUint(v); err != nil { return nil, err } - // fix possible_cpu:https://www.ibm.com/support/knowledgecenter/en/linuxonibm/com.ibm.linux.z.lgdd/lgdd_r_posscpusparm.html - if u != 0 { - usage = append(usage, u) - } + usage = append(usage, u) } return usage, nil } diff --git a/pkg/stat/sys/cpu/cgroupCPU.go b/pkg/stat/sys/cpu/cgroupCPU.go index 4555a4bc1..dda467ee7 100644 --- a/pkg/stat/sys/cpu/cgroupCPU.go +++ b/pkg/stat/sys/cpu/cgroupCPU.go @@ -8,7 +8,6 @@ import ( "strings" "github.com/pkg/errors" - pscpu "github.com/shirou/gopsutil/cpu" ) type cgroupCPU struct { @@ -22,17 +21,12 @@ type cgroupCPU struct { } func newCgroupCPU() (cpu *cgroupCPU, err error) { - var cores int - cores, err = pscpu.Counts(true) - if err != nil || cores == 0 { - var cpus []uint64 - cpus, err = perCPUUsage() - if err != nil { - err = errors.Errorf("perCPUUsage() failed!err:=%v", err) - return - } - cores = len(cpus) + cpus, err := perCPUUsage() + if err != nil { + err = errors.Errorf("perCPUUsage() failed!err:=%v", err) + return } + cores := uint64(len(cpus)) sets, err := cpuSets() if err != nil { @@ -67,11 +61,10 @@ func newCgroupCPU() (cpu *cgroupCPU, err error) { cpu = &cgroupCPU{ frequency: maxFreq, quota: quota, - cores: uint64(cores), + cores: cores, preSystem: preSystem, preTotal: preTotal, } - fmt.Printf("get cpu info:%+v \n", cpu) return }