From 1b7a18c27190863443e3938f9412726b5ba4ad3f Mon Sep 17 00:00:00 2001 From: stuart nelson Date: Sat, 17 Sep 2016 14:05:36 +0200 Subject: [PATCH] Creating slice from C-array Might not be lined up correctly? Weird output data in the second CPU. --- collector/cpu_dragonfly.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/collector/cpu_dragonfly.go b/collector/cpu_dragonfly.go index 0d414617..4dde7b22 100644 --- a/collector/cpu_dragonfly.go +++ b/collector/cpu_dragonfly.go @@ -18,6 +18,7 @@ package collector import ( "errors" "fmt" + "unsafe" "github.com/prometheus/client_golang/prometheus" ) @@ -175,9 +176,11 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) (err error) { if C.getCPUTimes(&ncpu, &cpuTimesC, &cpuTimesLength) == -1 { return errors.New("could not retrieve CPU times") } + // TODO: Remember to free variables // defer C.freeCPUTimes(cpuTimesC) - fmt.Println(cpuTimesC) - fmt.Println(uint64(cpuTimesLength)) + + cpuTimes := (*[1 << 30]C.struct_kinfo_cputime)(unsafe.Pointer(&cpuTimesC))[:ncpu:ncpu] + fmt.Println(cpuTimes) return errors.New("early kill") if cpuTimesLength > maxCPUTimesLen { return errors.New("more CPU's than MAXCPU?")