|
|
@ -8,7 +8,6 @@ import ( |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/pkg/errors" |
|
|
|
"github.com/pkg/errors" |
|
|
|
pscpu "github.com/shirou/gopsutil/cpu" |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
type cgroupCPU struct { |
|
|
|
type cgroupCPU struct { |
|
|
@ -22,17 +21,12 @@ type cgroupCPU struct { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func newCgroupCPU() (cpu *cgroupCPU, err error) { |
|
|
|
func newCgroupCPU() (cpu *cgroupCPU, err error) { |
|
|
|
var cores int |
|
|
|
cpus, err := perCPUUsage() |
|
|
|
cores, err = pscpu.Counts(true) |
|
|
|
|
|
|
|
if err != nil || cores == 0 { |
|
|
|
|
|
|
|
var cpus []uint64 |
|
|
|
|
|
|
|
cpus, err = perCPUUsage() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
err = errors.Errorf("perCPUUsage() failed!err:=%v", err) |
|
|
|
err = errors.Errorf("perCPUUsage() failed!err:=%v", err) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
cores = len(cpus) |
|
|
|
cores := uint64(len(cpus)) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sets, err := cpuSets() |
|
|
|
sets, err := cpuSets() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -67,11 +61,10 @@ func newCgroupCPU() (cpu *cgroupCPU, err error) { |
|
|
|
cpu = &cgroupCPU{ |
|
|
|
cpu = &cgroupCPU{ |
|
|
|
frequency: maxFreq, |
|
|
|
frequency: maxFreq, |
|
|
|
quota: quota, |
|
|
|
quota: quota, |
|
|
|
cores: uint64(cores), |
|
|
|
cores: cores, |
|
|
|
preSystem: preSystem, |
|
|
|
preSystem: preSystem, |
|
|
|
preTotal: preTotal, |
|
|
|
preTotal: preTotal, |
|
|
|
} |
|
|
|
} |
|
|
|
fmt.Printf("get cpu info:%+v \n", cpu) |
|
|
|
|
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|