mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-11-14 01:24:12 -08:00
Use correct frequency for calculating cpu time
The correct frequency is the systimer frequency, not the stathz. From one of the DragonFly developers: The bump upon each statclock is: ((cur_systimer - prev_systimer) * systimer_freq) >> 32 systimer_freq can be extracted from following sysctl in userspace: sysctl kern.cputimer.freq
This commit is contained in:
parent
8cc06aab04
commit
45ac033d9e
|
@ -63,16 +63,16 @@ getCPUTimes(char **cputime) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve clockrate
|
// The bump on each statclock is
|
||||||
struct clockinfo clockrate;
|
// ((cur_systimer - prev_systimer) * systimer_freq) >> 32
|
||||||
size_t clockrate_size = sizeof(clockrate);
|
// where
|
||||||
if (sysctl(mib_kern_clockrate, mib_kern_clockrate_len, &clockrate, &clockrate_size, NULL, 0) == -1 ||
|
// systimer_freq = sysctl kern.cputimer.freq
|
||||||
sizeof(clockrate) != clockrate_size) {
|
long freq;
|
||||||
|
len = sizeof(freq);
|
||||||
|
if (sysctlbyname("kern.cputimer.freq", &freq, &len, NULL, 0)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
long freq = clockrate.stathz > 0 ? clockrate.stathz : clockrate.hz;
|
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
Loading…
Reference in a new issue