diff options
author | Doug Rabson <dfr@rabson.org> | 2022-08-19 07:59:59 +0100 |
---|---|---|
committer | Doug Rabson <dfr@rabson.org> | 2022-08-24 10:55:52 +0100 |
commit | b0700aa48291d7b1f697e757b13c7f6ae3efed43 (patch) | |
tree | d6cb52659552c95e8cf7226348fe3cbd48f880d5 | |
parent | ff20c74e973abd7090b1ef76bc0d4de420513d34 (diff) | |
download | podman-b0700aa48291d7b1f697e757b13c7f6ae3efed43.tar.gz podman-b0700aa48291d7b1f697e757b13c7f6ae3efed43.tar.bz2 podman-b0700aa48291d7b1f697e757b13c7f6ae3efed43.zip |
libpod: Enable 'podman info' for FreeBSD
[NO NEW TESTS NEEDED]
Signed-off-by: Doug Rabson <dfr@rabson.org>
-rw-r--r-- | libpod/info.go | 3 | ||||
-rw-r--r-- | libpod/info_freebsd.go | 40 | ||||
-rw-r--r-- | libpod/info_unsupported.go | 4 |
3 files changed, 42 insertions, 5 deletions
diff --git a/libpod/info.go b/libpod/info.go index 20ea007cf..1990dc044 100644 --- a/libpod/info.go +++ b/libpod/info.go @@ -1,6 +1,3 @@ -//go:build linux -// +build linux - package libpod import ( diff --git a/libpod/info_freebsd.go b/libpod/info_freebsd.go new file mode 100644 index 000000000..ef7b6817c --- /dev/null +++ b/libpod/info_freebsd.go @@ -0,0 +1,40 @@ +package libpod + +import ( + "fmt" + "unsafe" + + "github.com/containers/podman/v4/libpod/define" + "golang.org/x/sys/unix" +) + +func (r *Runtime) setPlatformHostInfo(info *define.HostInfo) error { + return nil +} + +func timeToPercent(time uint64, total uint64) float64 { + return 100.0 * float64(time) / float64(total) +} + +// getCPUUtilization Returns a CPUUsage object that summarizes CPU +// usage for userspace, system, and idle time. +func getCPUUtilization() (*define.CPUUsage, error) { + buf, err := unix.SysctlRaw("kern.cp_time") + if err != nil { + return nil, fmt.Errorf("error reading sysctl kern.cp_time: %w", err) + } + + var total uint64 = 0 + var times [unix.CPUSTATES]uint64 + + for i := 0; i < unix.CPUSTATES; i++ { + val := *(*uint64)(unsafe.Pointer(&buf[8*i])) + times[i] = val + total += val + } + return &define.CPUUsage{ + UserPercent: timeToPercent(times[unix.CP_USER], total), + SystemPercent: timeToPercent(times[unix.CP_SYS], total), + IdlePercent: timeToPercent(times[unix.CP_IDLE], total), + }, nil +} diff --git a/libpod/info_unsupported.go b/libpod/info_unsupported.go index 53ee4b32f..0aed51247 100644 --- a/libpod/info_unsupported.go +++ b/libpod/info_unsupported.go @@ -1,5 +1,5 @@ -//go:build !linux -// +build !linux +//go:build !linux && !freebsd +// +build !linux,!freebsd package libpod |