mirror of
https://github.com/xzeldon/htop.git
synced 2025-07-12 20:24:35 +03:00
Unhardcode tick-to-ms conversion
Division by 100000.0 worked because `sysconf(_SC_CLK_TCK)` happened to be 100. By unhardcoding: 1) It becomes more clear what this 100000.0 figure comes from. 2) It protects against bugs in the case `sysconf(_SC_CLK_TCK)` ever changes.
This commit is contained in:

committed by
cgzones

parent
f614b8a19f
commit
67ccd6b909
@ -10,16 +10,18 @@ in the source distribution for its full text.
|
||||
|
||||
#include "Platform.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <unistd.h>
|
||||
#include <CoreFoundation/CFString.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <IOKit/ps/IOPowerSources.h>
|
||||
#include <IOKit/ps/IOPSKeys.h>
|
||||
|
||||
#include "ClockMeter.h"
|
||||
#include "CPUMeter.h"
|
||||
#include "CRT.h"
|
||||
#include "DarwinProcessList.h"
|
||||
#include "DateMeter.h"
|
||||
#include "DateTimeMeter.h"
|
||||
@ -112,6 +114,8 @@ const MeterClass* const Platform_meterTypes[] = {
|
||||
|
||||
double Platform_timebaseToNS = 1.0;
|
||||
|
||||
long Platform_clockTicksPerSec = -1;
|
||||
|
||||
void Platform_init(void) {
|
||||
// Check if we can determine the timebase used on this system.
|
||||
// If the API is unavailable assume we get our timebase in nanoseconds.
|
||||
@ -122,6 +126,14 @@ void Platform_init(void) {
|
||||
#else
|
||||
Platform_timebaseToNS = 1.0;
|
||||
#endif
|
||||
|
||||
// Determine the number of clock ticks per second
|
||||
errno = 0;
|
||||
Platform_clockTicksPerSec = sysconf(_SC_CLK_TCK);
|
||||
|
||||
if (errno || Platform_clockTicksPerSec < 1) {
|
||||
CRT_fatalError("Unable to retrieve clock tick rate");
|
||||
}
|
||||
}
|
||||
|
||||
void Platform_done(void) {
|
||||
|
Reference in New Issue
Block a user