Skip to content

Commit c51e245

Browse files
committed
extract nproc to variable
1 parent 89f7e8d commit c51e245

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cli/clistat/stat.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515

1616
const procOneCgroup = "/proc/1/cgroup"
1717

18+
var nproc = float64(runtime.NumCPU())
19+
1820
// Result is a generic result type for a statistic.
1921
// Total is the total amount of the resource available.
2022
// It is nil if the resource is not a finite quantity.
@@ -83,9 +85,9 @@ func New(opts ...Option) (*Statter, error) {
8385
// and scaling it by the number of cores.
8486
// Units are in "cores".
8587
func (s *Statter) HostCPU() (*Result, error) {
86-
nproc := float64(runtime.NumCPU())
8788
r := &Result{
88-
Unit: "cores",
89+
Unit: "cores",
90+
Total: ptr.To(nproc),
8991
}
9092
c1, err := s.hi.CPUTime()
9193
if err != nil {
@@ -96,7 +98,6 @@ func (s *Statter) HostCPU() (*Result, error) {
9698
if err != nil {
9799
return nil, xerrors.Errorf("get second cpu sample: %w", err)
98100
}
99-
r.Total = ptr.To(nproc)
100101
total := c2.Total() - c1.Total()
101102
idle := c2.Idle - c1.Idle
102103
used := total - idle

0 commit comments

Comments
 (0)