#ifdef PERF_ACTIVATE
-#include <sys/time.h>
-static struct timeval __g_base_time = {
+#include <time.h>
+
+static struct timespec __g_base_time = {
.tv_sec = 0,
- .tv_usec = 0
+ .tv_nsec = 0
};
-#define INIT_PERF(kb) \
- do { \
- const char *tmp; \
- struct timeval tv; \
- tmp = bundle_get_val(kb, AUL_K_STARTTIME); \
- if (tmp != NULL) \
- sscanf(tmp, "%ld/%ld", &tv.tv_sec, &tv.tv_usec); \
- else \
- gettimeofday(&tv, NULL); \
- __g_base_time.tv_sec = tv.tv_sec; \
- __g_base_time.tv_usec = tv.tv_usec; \
- } while (0)
-
-#define PERF(fmt, arg...) \
- do { \
- struct timeval cur; \
- struct timeval res; \
- gettimeofday(&cur, NULL); \
- if (__g_base_time.tv_sec != 0) { \
- timersub(&cur, &__g_base_time, &res); \
- printf("%c[1;31m[%s,%d] %ld sec %ld msec "fmt \
- " %c[0m\n", 27, __func__, \
- __LINE__, res.tv_sec, \
- res.tv_usec/1000, ##arg, 27);\
- } \
- } while (0)
+#define INIT_PERF(kb) do { \
+ const char *tmp; \
+ struct timespec tv; \
+ tmp = bundle_get_val(kb, AUL_K_STARTTIME); \
+ if (tmp != NULL) \
+ sscanf(tmp, "%ld/%ld", &tv.tv_sec, &tv.tv_nsec); \
+ else \
+ clock_gettime(CLOCK_MONOTONIC, &tv); \
+ __g_base_time.tv_sec = tv.tv_sec; \
+ __g_base_time.tv_nsec = tv.tv_nsec; \
+} while (0)
+
+#define PERF(fmt, arg...) do { \
+ struct timespec cur; \
+ struct timespec res; \
+ clock_gettime(CLOCK_MONOTONIC, &cur); \
+ if (__g_base_time.tv_sec != 0) { \
+ res->tv_sec = cur.tv_sec - __g_base_time.tv_sec; \
+ res->tv_nsec = cur.tv_nsec - __g_base_time.tv_nsec; \
+ printf("%c[1;31m[%s,%d] %ld sec %ld msec "fmt \
+ " %c[0m\n", 27, __func__, \
+ __LINE__, res.tv_sec, \
+ res.tv_nsec / 1e6, ##arg, 27); \
+ } \
+} while (0)
#else