summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiaan van Stijn <github@gone.nl>2020-07-08 12:50:28 +0200
committerSebastiaan van Stijn <github@gone.nl>2020-07-08 14:22:04 +0200
commitb42ac8d370a8ef8ec720dff0ca9dfb3530ac0a6a (patch)
treec3025c37031fec33a83838ba6176f8ed7cddab7a
parentc833222d54c00d64a0fc44c561a5973ecd414053 (diff)
downloaddocker-b42ac8d370a8ef8ec720dff0ca9dfb3530ac0a6a.tar.gz
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>
-rw-r--r--daemon/stats/collector.go6
-rw-r--r--daemon/stats/collector_unix.go18
-rw-r--r--daemon/stats/collector_windows.go5
3 files changed, 9 insertions, 20 deletions
diff --git a/daemon/stats/collector.go b/daemon/stats/collector.go
index cd431515d2..5f1d84fe4f 100644
--- a/daemon/stats/collector.go
+++ b/daemon/stats/collector.go
@@ -19,9 +19,6 @@ type Collector struct {
interval time.Duration
publishers map[*container.Container]*pubsub.Publisher
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
@@ -33,9 +30,6 @@ func NewCollector(supervisor supervisor, interval time.Duration) *Collector {
bufReader: bufio.NewReaderSize(nil, 128),
}
s.cond = sync.NewCond(&s.m)
-
- platformNewStatsCollector(s)
-
return s
}
diff --git a/daemon/stats/collector_unix.go b/daemon/stats/collector_unix.go
index 417713f6ab..d36454d384 100644
--- a/daemon/stats/collector_unix.go
+++ b/daemon/stats/collector_unix.go
@@ -8,17 +8,17 @@ import (
"strconv"
"strings"
- "github.com/opencontainers/runc/libcontainer/system"
"golang.org/x/sys/unix"
)
-// platformNewStatsCollector performs platform specific initialisation of the
-// Collector structure.
-func platformNewStatsCollector(s *Collector) {
- s.clockTicksPerSecond = uint64(system.GetClockTicks())
-}
-
-const nanoSecondsPerSecond = 1e9
+const (
+ // The value comes from `C.sysconf(C._SC_CLK_TCK)`, and
+ // on Linux it's a constant which is safe to be hard coded,
+ // so we can avoid using cgo here. For details, see:
+ // https://github.com/containerd/cgroups/pull/12
+ clockTicksPerSecond = 100
+ nanoSecondsPerSecond = 1e9
+)
// getSystemCPUUsage returns the host system's cpu usage in
// nanoseconds. An error is returned if the format of the underlying
@@ -59,7 +59,7 @@ func (s *Collector) getSystemCPUUsage() (uint64, error) {
totalClockTicks += v
}
return (totalClockTicks * nanoSecondsPerSecond) /
- s.clockTicksPerSecond, nil
+ clockTicksPerSecond, nil
}
}
return 0, fmt.Errorf("invalid stat format. Error trying to parse the '/proc/stat' file")
diff --git a/daemon/stats/collector_windows.go b/daemon/stats/collector_windows.go
index 018e9065f1..d8e4b37507 100644
--- a/daemon/stats/collector_windows.go
+++ b/daemon/stats/collector_windows.go
@@ -1,10 +1,5 @@
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
// nanoseconds. An error is returned if the format of the underlying
// file does not match. This is a no-op on Windows.