Use monotonic time 00/220600/4
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 20 Dec 2019 01:17:04 +0000 (10:17 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 20 Dec 2019 02:25:17 +0000 (11:25 +0900)
To measure launching time properly, we should use monotonic time.

Requires:
 - https://review.tizen.org/gerrit/#/c/platform/core/appfw/aul-1/+/220595/
 - https://review.tizen.org/gerrit/#/c/platform/core/appfw/amd/+/220598/
 - https://review.tizen.org/gerrit/#/c/platform/core/appfw/launchpad/+/220600/

Change-Id: I3df67a01234fcd5cb54248bbfc0519d9564a08d6
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
inc/perf.h

index 3bc169fdfb9cac559bb7244a8a2a88c84657f24e..ca87d125aaddd10fb97186a21d0e9f2fbc03ee3d 100644 (file)
 
 #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