Merge pull request #377 from bilibili/fix/cpu_nums

fix possible cpus
pull/386/head
Tony 5 years ago committed by GitHub
commit 8a0fee6cd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      pkg/stat/sys/cpu/cgroup.go
  2. 12
      pkg/stat/sys/cpu/cgroupCPU.go

@ -56,8 +56,11 @@ 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)
}
}
return usage, nil
}

@ -8,6 +8,7 @@ import (
"strings"
"github.com/pkg/errors"
pscpu "github.com/shirou/gopsutil/cpu"
)
type cgroupCPU struct {
@ -21,12 +22,17 @@ type cgroupCPU struct {
}
func newCgroupCPU() (cpu *cgroupCPU, err error) {
cpus, err := perCPUUsage()
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 := uint64(len(cpus))
cores = len(cpus)
}
sets, err := cpuSets()
if err != nil {
@ -61,7 +67,7 @@ func newCgroupCPU() (cpu *cgroupCPU, err error) {
cpu = &cgroupCPU{
frequency: maxFreq,
quota: quota,
cores: cores,
cores: uint64(cores),
preSystem: preSystem,
preTotal: preTotal,
}

Loading…
Cancel
Save