summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-09-14 14:21:30 +0200
committerGitHub <noreply@github.com>2022-09-14 14:21:30 +0200
commit82651e5974741aec9d9a0b8926c8ff2f715eed8c (patch)
treee326843e191473539f2fa1a3d008af85c9c19ffc /pkg
parentae20f19351c03398d10ba94a31f21dcf3d86f31c (diff)
parentb47ce9a6e0e9fa8e137c8338a08dffa256081b48 (diff)
downloadpodman-82651e5974741aec9d9a0b8926c8ff2f715eed8c.tar.gz
podman-82651e5974741aec9d9a0b8926c8ff2f715eed8c.tar.bz2
podman-82651e5974741aec9d9a0b8926c8ff2f715eed8c.zip
Merge pull request #15769 from dfr/freebsd-stats
Add support for 'podman stats' on FreeBSD
Diffstat (limited to 'pkg')
-rw-r--r--pkg/rctl/rctl.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/pkg/rctl/rctl.go b/pkg/rctl/rctl.go
new file mode 100644
index 000000000..135cc60cb
--- /dev/null
+++ b/pkg/rctl/rctl.go
@@ -0,0 +1,47 @@
+//go:build freebsd
+// +build freebsd
+
+package rctl
+
+// #include <sys/rctl.h>
+import "C"
+
+import (
+ "bytes"
+ "fmt"
+ "strconv"
+ "strings"
+ "syscall"
+ "unsafe"
+
+ "github.com/sirupsen/logrus"
+)
+
+func GetRacct(filter string) (map[string]uint64, error) {
+ bp, err := syscall.ByteSliceFromString(filter)
+ if err != nil {
+ return nil, err
+ }
+ var buf [1024]byte
+ _, _, errno := syscall.Syscall6(syscall.SYS_RCTL_GET_RACCT,
+ uintptr(unsafe.Pointer(&bp[0])),
+ uintptr(len(bp)),
+ uintptr(unsafe.Pointer(&buf[0])),
+ uintptr(len(buf)), 0, 0)
+ if errno != 0 {
+ return nil, fmt.Errorf("error calling rctl_get_racct with filter %s: %v", errno)
+ }
+ len := bytes.IndexByte(buf[:], byte(0))
+ entries := strings.Split(string(buf[:len]), ",")
+ res := make(map[string]uint64)
+ for _, entry := range entries {
+ kv := strings.SplitN(entry, "=", 2)
+ key := kv[0]
+ val, err := strconv.ParseUint(kv[1], 10, 0)
+ if err != nil {
+ logrus.Warnf("unexpected rctl entry, ignoring: %s", entry)
+ }
+ res[key] = val
+ }
+ return res, nil
+}