mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
daemon/stats: use const for clockTicksPerSecond
The value comes from `C.sysconf(C._SC_CLK_TCK)`, and on Linux it's a constant which is safe to be hard coded. See for example in the Musl libc source code https://git.musl-libc.org/cgit/musl/tree/src/conf/sysconf.c#n29 This removes the github.com/opencontainers/runc/libcontainer/system dependency from this package. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
c833222d54
commit
b42ac8d370
3 changed files with 9 additions and 20 deletions
|
@ -19,9 +19,6 @@ type Collector struct {
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
publishers map[*container.Container]*pubsub.Publisher
|
publishers map[*container.Container]*pubsub.Publisher
|
||||||
bufReader *bufio.Reader
|
bufReader *bufio.Reader
|
||||||
|
|
||||||
// The following fields are not set on Windows currently.
|
|
||||||
clockTicksPerSecond uint64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCollector creates a stats collector that will poll the supervisor with the specified interval
|
// NewCollector creates a stats collector that will poll the supervisor with the specified interval
|
||||||
|
@ -33,9 +30,6 @@ func NewCollector(supervisor supervisor, interval time.Duration) *Collector {
|
||||||
bufReader: bufio.NewReaderSize(nil, 128),
|
bufReader: bufio.NewReaderSize(nil, 128),
|
||||||
}
|
}
|
||||||
s.cond = sync.NewCond(&s.m)
|
s.cond = sync.NewCond(&s.m)
|
||||||
|
|
||||||
platformNewStatsCollector(s)
|
|
||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,17 +8,17 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/opencontainers/runc/libcontainer/system"
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
// platformNewStatsCollector performs platform specific initialisation of the
|
const (
|
||||||
// Collector structure.
|
// The value comes from `C.sysconf(C._SC_CLK_TCK)`, and
|
||||||
func platformNewStatsCollector(s *Collector) {
|
// on Linux it's a constant which is safe to be hard coded,
|
||||||
s.clockTicksPerSecond = uint64(system.GetClockTicks())
|
// so we can avoid using cgo here. For details, see:
|
||||||
}
|
// https://github.com/containerd/cgroups/pull/12
|
||||||
|
clockTicksPerSecond = 100
|
||||||
const nanoSecondsPerSecond = 1e9
|
nanoSecondsPerSecond = 1e9
|
||||||
|
)
|
||||||
|
|
||||||
// getSystemCPUUsage returns the host system's cpu usage in
|
// getSystemCPUUsage returns the host system's cpu usage in
|
||||||
// nanoseconds. An error is returned if the format of the underlying
|
// nanoseconds. An error is returned if the format of the underlying
|
||||||
|
@ -59,7 +59,7 @@ func (s *Collector) getSystemCPUUsage() (uint64, error) {
|
||||||
totalClockTicks += v
|
totalClockTicks += v
|
||||||
}
|
}
|
||||||
return (totalClockTicks * nanoSecondsPerSecond) /
|
return (totalClockTicks * nanoSecondsPerSecond) /
|
||||||
s.clockTicksPerSecond, nil
|
clockTicksPerSecond, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0, fmt.Errorf("invalid stat format. Error trying to parse the '/proc/stat' file")
|
return 0, fmt.Errorf("invalid stat format. Error trying to parse the '/proc/stat' file")
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
package stats // import "github.com/docker/docker/daemon/stats"
|
package stats // import "github.com/docker/docker/daemon/stats"
|
||||||
|
|
||||||
// platformNewStatsCollector performs platform specific initialisation of the
|
|
||||||
// Collector structure. This is a no-op on Windows.
|
|
||||||
func platformNewStatsCollector(s *Collector) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// getSystemCPUUsage returns the host system's cpu usage in
|
// getSystemCPUUsage returns the host system's cpu usage in
|
||||||
// nanoseconds. An error is returned if the format of the underlying
|
// nanoseconds. An error is returned if the format of the underlying
|
||||||
// file does not match. This is a no-op on Windows.
|
// file does not match. This is a no-op on Windows.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue