Merge pull request #226 from giganteous/fix-386-on-freebsd

Fix compilation on freebsd/386
pull/237/head
Tobias Schmidt 2016-05-05 01:08:14 -04:00
commit 6683a89f9e
1 changed files with 6 additions and 1 deletions

View File

@ -103,6 +103,8 @@ void freeCPUTimes(double *cpu_times) {
*/ */
import "C" import "C"
const maxCPUTimesLen = C.MAXCPU * C.CPUSTATES
type statCollector struct { type statCollector struct {
cpu *prometheus.CounterVec cpu *prometheus.CounterVec
} }
@ -150,9 +152,12 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) (err error) {
return errors.New("could not retrieve CPU times") return errors.New("could not retrieve CPU times")
} }
defer C.freeCPUTimes(cpuTimesC) defer C.freeCPUTimes(cpuTimesC)
if cpuTimesLength > maxCPUTimesLen {
return errors.New("more CPU's than MAXCPU?")
}
// Convert C.double array to Go array (https://github.com/golang/go/wiki/cgo#turning-c-arrays-into-go-slices). // Convert C.double array to Go array (https://github.com/golang/go/wiki/cgo#turning-c-arrays-into-go-slices).
cpuTimes := (*[1 << 30]C.double)(unsafe.Pointer(cpuTimesC))[:cpuTimesLength:cpuTimesLength] cpuTimes := (*[maxCPUTimesLen]C.double)(unsafe.Pointer(cpuTimesC))[:cpuTimesLength:cpuTimesLength]
for cpu := 0; cpu < int(ncpu); cpu++ { for cpu := 0; cpu < int(ncpu); cpu++ {
base_idx := C.CPUSTATES * cpu base_idx := C.CPUSTATES * cpu