fixed error message
using stdlib's perror()
This commit is contained in:
parent
4b8185c7fc
commit
70802cde6d
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
/* === Dependencies === */
|
/* === Dependencies === */
|
||||||
|
|
||||||
|
#include <stdlib.h> /* perror, abort */
|
||||||
|
|
||||||
#include "timefn.h"
|
#include "timefn.h"
|
||||||
|
|
||||||
|
|
||||||
@ -27,8 +29,10 @@ PTime UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd)
|
|||||||
static LARGE_INTEGER ticksPerSecond;
|
static LARGE_INTEGER ticksPerSecond;
|
||||||
static int init = 0;
|
static int init = 0;
|
||||||
if (!init) {
|
if (!init) {
|
||||||
if (!QueryPerformanceFrequency(&ticksPerSecond))
|
if (!QueryPerformanceFrequency(&ticksPerSecond)) {
|
||||||
UTIL_DISPLAYLEVEL(1, "ERROR: QueryPerformanceFrequency() failure\n");
|
perror("timefn::QueryPerformanceFrequency");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
init = 1;
|
init = 1;
|
||||||
}
|
}
|
||||||
return 1000000ULL*(clockEnd.QuadPart - clockStart.QuadPart)/ticksPerSecond.QuadPart;
|
return 1000000ULL*(clockEnd.QuadPart - clockStart.QuadPart)/ticksPerSecond.QuadPart;
|
||||||
@ -39,13 +43,17 @@ PTime UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd)
|
|||||||
static LARGE_INTEGER ticksPerSecond;
|
static LARGE_INTEGER ticksPerSecond;
|
||||||
static int init = 0;
|
static int init = 0;
|
||||||
if (!init) {
|
if (!init) {
|
||||||
if (!QueryPerformanceFrequency(&ticksPerSecond))
|
if (!QueryPerformanceFrequency(&ticksPerSecond)) {
|
||||||
UTIL_DISPLAYLEVEL(1, "ERROR: QueryPerformanceFrequency() failure\n");
|
perror("timefn::QueryPerformanceFrequency");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
init = 1;
|
init = 1;
|
||||||
}
|
}
|
||||||
return 1000000000ULL*(clockEnd.QuadPart - clockStart.QuadPart)/ticksPerSecond.QuadPart;
|
return 1000000000ULL*(clockEnd.QuadPart - clockStart.QuadPart)/ticksPerSecond.QuadPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#elif defined(__APPLE__) && defined(__MACH__)
|
#elif defined(__APPLE__) && defined(__MACH__)
|
||||||
|
|
||||||
UTIL_time_t UTIL_getTime(void) { return mach_absolute_time(); }
|
UTIL_time_t UTIL_getTime(void) { return mach_absolute_time(); }
|
||||||
@ -72,14 +80,18 @@ PTime UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd)
|
|||||||
return ((clockEnd - clockStart) * (PTime)rate.numer) / ((PTime)rate.denom);
|
return ((clockEnd - clockStart) * (PTime)rate.numer) / ((PTime)rate.denom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#elif (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */) \
|
#elif (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) /* C11 */) \
|
||||||
&& defined (CLOCK_MONOTONIC)
|
&& defined (CLOCK_MONOTONIC)
|
||||||
|
|
||||||
UTIL_time_t UTIL_getTime(void)
|
UTIL_time_t UTIL_getTime(void)
|
||||||
{
|
{
|
||||||
UTIL_time_t time;
|
UTIL_time_t time;
|
||||||
if (clock_gettime(CLOCK_MONOTONIC, &time))
|
if (clock_gettime(CLOCK_MONOTONIC, &time)) {
|
||||||
UTIL_DISPLAYLEVEL(1, "ERROR: Failed to get time\n"); /* we could also exit() */
|
perror("timefb::clock_gettime");
|
||||||
|
abort();
|
||||||
|
}
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +126,9 @@ PTime UTIL_getSpanTimeNano(UTIL_time_t begin, UTIL_time_t end)
|
|||||||
return nano;
|
return nano;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* relies on standard C (note : clock_t measurements can be wrong when using multi-threading) */
|
|
||||||
|
|
||||||
|
#else /* relies on standard C90 (note : clock_t measurements can be wrong when using multi-threading) */
|
||||||
|
|
||||||
UTIL_time_t UTIL_getTime(void) { return clock(); }
|
UTIL_time_t UTIL_getTime(void) { return clock(); }
|
||||||
PTime UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd) { return 1000000ULL * (clockEnd - clockStart) / CLOCKS_PER_SEC; }
|
PTime UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd) { return 1000000ULL * (clockEnd - clockStart) / CLOCKS_PER_SEC; }
|
||||||
@ -122,6 +136,8 @@ PTime UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd) { retur
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* returns time span in microseconds */
|
/* returns time span in microseconds */
|
||||||
PTime UTIL_clockSpanMicro(UTIL_time_t clockStart )
|
PTime UTIL_clockSpanMicro(UTIL_time_t clockStart )
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user