summaryrefslogtreecommitdiff
path: root/vendor/github.com/power-devops/perfstat/cpustat.go
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-05-14 13:18:54 -0600
committermo khan <mo@mokhan.ca>2025-05-14 13:18:54 -0600
commit4b2d609a0efcc1d9b2f1a08f954d067ad1d9cd1e (patch)
tree0afacf9217b0569130da6b97d4197331681bf119 /vendor/github.com/power-devops/perfstat/cpustat.go
parentab373d1fe698cd3f53258c09bc8515d88a6d0b9e (diff)
test: use playwright to test out an OIDC login
Diffstat (limited to 'vendor/github.com/power-devops/perfstat/cpustat.go')
-rw-r--r--vendor/github.com/power-devops/perfstat/cpustat.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/vendor/github.com/power-devops/perfstat/cpustat.go b/vendor/github.com/power-devops/perfstat/cpustat.go
index 902727f..10f543f 100644
--- a/vendor/github.com/power-devops/perfstat/cpustat.go
+++ b/vendor/github.com/power-devops/perfstat/cpustat.go
@@ -1,3 +1,4 @@
+//go:build aix
// +build aix
package perfstat
@@ -20,6 +21,13 @@ import (
"unsafe"
)
+var old_cpu_total_stat *C.perfstat_cpu_total_t
+
+func init() {
+ old_cpu_total_stat = (*C.perfstat_cpu_total_t)(C.malloc(C.sizeof_perfstat_cpu_total_t))
+ C.perfstat_cpu_total(nil, old_cpu_total_stat, C.sizeof_perfstat_cpu_total_t, 1)
+}
+
func CpuStat() ([]CPU, error) {
var cpustat *C.perfstat_cpu_t
var cpu C.perfstat_id_t
@@ -96,3 +104,35 @@ func CpuUtilStat(intvl time.Duration) (*CPUUtil, error) {
u := perfstatcpuutil2cpuutil(cpuutil)
return &u, nil
}
+
+func CpuUtilTotalStat() (*CPUUtil, error) {
+ var cpuutil *C.perfstat_cpu_util_t
+ var new_cpu_total_stat *C.perfstat_cpu_total_t
+ var data C.perfstat_rawdata_t
+
+ new_cpu_total_stat = (*C.perfstat_cpu_total_t)(C.malloc(C.sizeof_perfstat_cpu_total_t))
+ cpuutil = (*C.perfstat_cpu_util_t)(C.malloc(C.sizeof_perfstat_cpu_util_t))
+ defer C.free(unsafe.Pointer(cpuutil))
+
+ r := C.perfstat_cpu_total(nil, new_cpu_total_stat, C.sizeof_perfstat_cpu_total_t, 1)
+ if r <= 0 {
+ C.free(unsafe.Pointer(new_cpu_total_stat))
+ return nil, fmt.Errorf("error perfstat_cpu_total()")
+ }
+
+ data._type = C.UTIL_CPU_TOTAL
+ data.curstat = unsafe.Pointer(new_cpu_total_stat)
+ data.prevstat = unsafe.Pointer(old_cpu_total_stat)
+ data.sizeof_data = C.sizeof_perfstat_cpu_total_t
+ data.cur_elems = 1
+ data.prev_elems = 1
+
+ r = C.perfstat_cpu_util(&data, cpuutil, C.sizeof_perfstat_cpu_util_t, 1)
+ C.free(unsafe.Pointer(old_cpu_total_stat))
+ old_cpu_total_stat = new_cpu_total_stat
+ if r <= 0 {
+ return nil, fmt.Errorf("error perfstat_cpu_util()")
+ }
+ u := perfstatcpuutil2cpuutil(cpuutil)
+ return &u, nil
+}