mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-11-10 07:34:09 -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;
|
||||
}
|
||||
|
||||
// Retrieve clockrate
|
||||
struct clockinfo clockrate;
|
||||
size_t clockrate_size = sizeof(clockrate);
|
||||
if (sysctl(mib_kern_clockrate, mib_kern_clockrate_len, &clockrate, &clockrate_size, NULL, 0) == -1 ||
|
||||
sizeof(clockrate) != clockrate_size) {
|
||||
// The bump on each statclock is
|
||||
// ((cur_systimer - prev_systimer) * systimer_freq) >> 32
|
||||
// where
|
||||
// systimer_freq = sysctl kern.cputimer.freq
|
||||
long freq;
|
||||
len = sizeof(freq);
|
||||
if (sysctlbyname("kern.cputimer.freq", &freq, &len, NULL, 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
long freq = clockrate.stathz > 0 ? clockrate.stathz : clockrate.hz;
|
||||
|
||||
// Get the cpu times.
|
||||
struct kinfo_cputime cp_t[ncpu];
|
||||
bzero(cp_t, sizeof(struct kinfo_cputime)*ncpu);
|
||||
|
|
Loading…
Reference in a new issue