|
|
@ -31,7 +31,7 @@ import (
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
int
|
|
|
|
getCPUTimes(uint64_t **cputime, size_t *cpu_times_len, long *freq) {
|
|
|
|
getCPUTimes(uint64_t **cputime, size_t *cpu_times_len) {
|
|
|
|
size_t len;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
|
|
|
|
// Get number of cpu cores.
|
|
|
|
// Get number of cpu cores.
|
|
|
@ -44,15 +44,6 @@ getCPUTimes(uint64_t **cputime, size_t *cpu_times_len, long *freq) {
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The bump on each statclock is
|
|
|
|
|
|
|
|
// ((cur_systimer - prev_systimer) * systimer_freq) >> 32
|
|
|
|
|
|
|
|
// where
|
|
|
|
|
|
|
|
// systimer_freq = sysctl kern.cputimer.freq
|
|
|
|
|
|
|
|
len = sizeof(*freq);
|
|
|
|
|
|
|
|
if (sysctlbyname("kern.cputimer.freq", freq, &len, NULL, 0)) {
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get the cpu times.
|
|
|
|
// Get the cpu times.
|
|
|
|
struct kinfo_cputime cp_t[ncpu];
|
|
|
|
struct kinfo_cputime cp_t[ncpu];
|
|
|
|
bzero(cp_t, sizeof(struct kinfo_cputime)*ncpu);
|
|
|
|
bzero(cp_t, sizeof(struct kinfo_cputime)*ncpu);
|
|
|
@ -103,18 +94,16 @@ func getDragonFlyCPUTimes() ([]float64, error) {
|
|
|
|
// CPUSTATES (number of CPUSTATES) is defined as 5U.
|
|
|
|
// CPUSTATES (number of CPUSTATES) is defined as 5U.
|
|
|
|
// States: CP_USER | CP_NICE | CP_SYS | CP_IDLE | CP_INTR
|
|
|
|
// States: CP_USER | CP_NICE | CP_SYS | CP_IDLE | CP_INTR
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Each value is a counter incremented at frequency
|
|
|
|
// Each value is in microseconds
|
|
|
|
// kern.cputimer.freq
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Look into sys/kern/kern_clock.c for details.
|
|
|
|
// Look into sys/kern/kern_clock.c for details.
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
cpuTimesC *C.uint64_t
|
|
|
|
cpuTimesC *C.uint64_t
|
|
|
|
cpuTimerFreq C.long
|
|
|
|
|
|
|
|
cpuTimesLength C.size_t
|
|
|
|
cpuTimesLength C.size_t
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if C.getCPUTimes(&cpuTimesC, &cpuTimesLength, &cpuTimerFreq) == -1 {
|
|
|
|
if C.getCPUTimes(&cpuTimesC, &cpuTimesLength) == -1 {
|
|
|
|
return nil, errors.New("could not retrieve CPU times")
|
|
|
|
return nil, errors.New("could not retrieve CPU times")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
defer C.free(unsafe.Pointer(cpuTimesC))
|
|
|
|
defer C.free(unsafe.Pointer(cpuTimesC))
|
|
|
@ -123,7 +112,7 @@ func getDragonFlyCPUTimes() ([]float64, error) {
|
|
|
|
|
|
|
|
|
|
|
|
cpuTimes := make([]float64, cpuTimesLength)
|
|
|
|
cpuTimes := make([]float64, cpuTimesLength)
|
|
|
|
for i, value := range cput {
|
|
|
|
for i, value := range cput {
|
|
|
|
cpuTimes[i] = float64(value) / float64(cpuTimerFreq)
|
|
|
|
cpuTimes[i] = float64(value) / float64(1000000)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cpuTimes, nil
|
|
|
|
return cpuTimes, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|