Add timer support for Windows.
This commit is contained in:
parent
92d72eeef0
commit
8693a9ea05
@ -7,9 +7,12 @@
|
|||||||
&& _POSIX_MONOTONIC_CLOCK >= 0
|
&& _POSIX_MONOTONIC_CLOCK >= 0
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
#if JEMALLOC_CLOCK_GETTIME
|
#ifdef _WIN32
|
||||||
struct timespec tv0;
|
FILETIME ft0;
|
||||||
struct timespec tv1;
|
FILETIME ft1;
|
||||||
|
#elif JEMALLOC_CLOCK_GETTIME
|
||||||
|
struct timespec ts0;
|
||||||
|
struct timespec ts1;
|
||||||
int clock_id;
|
int clock_id;
|
||||||
#else
|
#else
|
||||||
struct timeval tv0;
|
struct timeval tv0;
|
||||||
|
@ -4,12 +4,14 @@ void
|
|||||||
timer_start(timedelta_t *timer)
|
timer_start(timedelta_t *timer)
|
||||||
{
|
{
|
||||||
|
|
||||||
#if JEMALLOC_CLOCK_GETTIME
|
#ifdef _WIN32
|
||||||
|
GetSystemTimeAsFileTime(&timer->ft0);
|
||||||
|
#elif JEMALLOC_CLOCK_GETTIME
|
||||||
if (sysconf(_SC_MONOTONIC_CLOCK) <= 0)
|
if (sysconf(_SC_MONOTONIC_CLOCK) <= 0)
|
||||||
timer->clock_id = CLOCK_REALTIME;
|
timer->clock_id = CLOCK_REALTIME;
|
||||||
else
|
else
|
||||||
timer->clock_id = CLOCK_MONOTONIC;
|
timer->clock_id = CLOCK_MONOTONIC;
|
||||||
clock_gettime(timer->clock_id, &timer->tv0);
|
clock_gettime(timer->clock_id, &timer->ts0);
|
||||||
#else
|
#else
|
||||||
gettimeofday(&timer->tv0, NULL);
|
gettimeofday(&timer->tv0, NULL);
|
||||||
#endif
|
#endif
|
||||||
@ -19,8 +21,10 @@ void
|
|||||||
timer_stop(timedelta_t *timer)
|
timer_stop(timedelta_t *timer)
|
||||||
{
|
{
|
||||||
|
|
||||||
#if JEMALLOC_CLOCK_GETTIME
|
#ifdef _WIN32
|
||||||
clock_gettime(timer->clock_id, &timer->tv1);
|
GetSystemTimeAsFileTime(&timer->ft0);
|
||||||
|
#elif JEMALLOC_CLOCK_GETTIME
|
||||||
|
clock_gettime(timer->clock_id, &timer->ts1);
|
||||||
#else
|
#else
|
||||||
gettimeofday(&timer->tv1, NULL);
|
gettimeofday(&timer->tv1, NULL);
|
||||||
#endif
|
#endif
|
||||||
@ -30,9 +34,16 @@ uint64_t
|
|||||||
timer_usec(const timedelta_t *timer)
|
timer_usec(const timedelta_t *timer)
|
||||||
{
|
{
|
||||||
|
|
||||||
#if JEMALLOC_CLOCK_GETTIME
|
#ifdef _WIN32
|
||||||
return (((timer->tv1.tv_sec - timer->tv0.tv_sec) * 1000000) +
|
uint64_t t0, t1;
|
||||||
(timer->tv1.tv_nsec - timer->tv0.tv_nsec) / 1000);
|
t0 = (((uint64_t)timer->ft0.dwHighDateTime) << 32) |
|
||||||
|
timer->ft0.dwLowDateTime;
|
||||||
|
t1 = (((uint64_t)timer->ft1.dwHighDateTime) << 32) |
|
||||||
|
timer->ft1.dwLowDateTime;
|
||||||
|
return ((t1 - t0) / 10);
|
||||||
|
#elif JEMALLOC_CLOCK_GETTIME
|
||||||
|
return (((timer->ts1.tv_sec - timer->ts0.tv_sec) * 1000000) +
|
||||||
|
(timer->ts1.tv_nsec - timer->ts0.tv_nsec) / 1000);
|
||||||
#else
|
#else
|
||||||
return (((timer->tv1.tv_sec - timer->tv0.tv_sec) * 1000000) +
|
return (((timer->tv1.tv_sec - timer->tv0.tv_sec) * 1000000) +
|
||||||
timer->tv1.tv_usec - timer->tv0.tv_usec);
|
timer->tv1.tv_usec - timer->tv0.tv_usec);
|
||||||
|
Loading…
Reference in New Issue
Block a user