mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-07 23:02:12 +02:00
fix possible cpus
This commit is contained in:
parent
3dfb8232a2
commit
68e1fc1a99
1
go.mod
1
go.mod
@ -23,6 +23,7 @@ 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
|
||||
|
@ -56,7 +56,10 @@ func (c *cgroup) CPUAcctUsagePerCPU() ([]uint64, error) {
|
||||
if u, err = parseUint(v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
usage = append(usage, u)
|
||||
// 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()
|
||||
if err != nil {
|
||||
err = errors.Errorf("perCPUUsage() failed!err:=%v", err)
|
||||
return
|
||||
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)
|
||||
}
|
||||
cores := uint64(len(cpus))
|
||||
|
||||
sets, err := cpuSets()
|
||||
if err != nil {
|
||||
@ -61,10 +67,11 @@ func newCgroupCPU() (cpu *cgroupCPU, err error) {
|
||||
cpu = &cgroupCPU{
|
||||
frequency: maxFreq,
|
||||
quota: quota,
|
||||
cores: cores,
|
||||
cores: uint64(cores),
|
||||
preSystem: preSystem,
|
||||
preTotal: preTotal,
|
||||
}
|
||||
fmt.Printf("get cpu info:%+v \n", cpu)
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user