mirror of
https://github.com/yse/easy_profiler.git
synced 2025-01-14 16:47:55 +08:00
Fix mac os build
- Work around lack of clock_gettime() on OS X
This commit is contained in:
parent
c608665e06
commit
504648d613
@ -60,6 +60,11 @@
|
||||
#include "event_trace_win.h"
|
||||
#include "current_time.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <mach/clock.h>
|
||||
#include <mach/mach.h>
|
||||
#endif
|
||||
|
||||
#if EASY_OPTION_LOG_ENABLED != 0
|
||||
# include <iostream>
|
||||
|
||||
@ -157,14 +162,26 @@ const decltype(LARGE_INTEGER::QuadPart) CPU_FREQUENCY = ([](){ LARGE_INTEGER fre
|
||||
int64_t calculate_cpu_frequency()
|
||||
{
|
||||
double g_TicksPerNanoSec;
|
||||
struct timespec begints, endts;
|
||||
uint64_t begin = 0, end = 0;
|
||||
#ifdef __APPLE__
|
||||
clock_serv_t cclock;
|
||||
mach_timespec_t begints, endts;
|
||||
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
|
||||
clock_get_time(cclock, &begints);
|
||||
#else
|
||||
struct timespec begints, endts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &begints);
|
||||
#endif
|
||||
begin = getCurrentTime();
|
||||
volatile uint64_t i;
|
||||
for (i = 0; i < 100000000; i++); /* must be CPU intensive */
|
||||
end = getCurrentTime();
|
||||
#ifdef __APPLE__
|
||||
clock_get_time(cclock, &endts);
|
||||
mach_port_deallocate(mach_task_self(), cclock);
|
||||
#else
|
||||
clock_gettime(CLOCK_MONOTONIC, &endts);
|
||||
#endif
|
||||
struct timespec tmpts;
|
||||
const int NANO_SECONDS_IN_SEC = 1000000000;
|
||||
tmpts.tv_sec = endts.tv_sec - begints.tv_sec;
|
||||
|
Loading…
x
Reference in New Issue
Block a user