zlogger: don't call get_time() twice 58/283058/2
authorMarek Szyprowski <m.szyprowski@samsung.com>
Mon, 17 Oct 2022 10:08:19 +0000 (12:08 +0200)
committerMarek Szyprowski <m.szyprowski@samsung.com>
Wed, 19 Oct 2022 16:22:46 +0000 (18:22 +0200)
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Change-Id: I1e57a2dae628b0fc4aa2d2a954bfc6ad269ba09f

include/zero_copy_backend.h
src/libdlog/log_zero_copy.c

index 07a7a9e..082a3ea 100644 (file)
 
 #define ZERO_COPY_DEVICE_NAME "/dev/zlogger"
 
+static inline uint64_t to_zlog_clock(struct timespec *t)
+{
+       return (uint64_t)t->tv_nsec + (uint64_t)t->tv_sec * NSEC_PER_SEC;
+}
+
 static inline uint64_t get_zlog_clock(void)
 {
        struct timespec begin;
        clock_gettime(CLOCK_MONOTONIC, &begin);
-       return (uint64_t)begin.tv_nsec + (uint64_t)begin.tv_sec * NSEC_PER_SEC;
+       return to_zlog_clock(&begin);
 }
-
index 371c440..67054a5 100644 (file)
@@ -87,13 +87,13 @@ static inline struct zlogger_block *get_valid_block(int tid, size_t len)
 
 static int zero_copy_write(log_id_t log_id, log_priority prio, const char *tag, const char *msg, struct timespec *tp_mono)
 {
-       // TODO: log_id and tp_mono ignored for now
+       // TODO: log_id ignored for now
 
        /* TODO: drop zlogger_entry and just write
         * dlogutil_entry directly. Needs kernel support
         * for stdout logs though. */
 
-       uint64_t ts = get_zlog_clock();
+       uint64_t ts = tp_mono ? to_zlog_clock(tp_mono) : get_zlog_clock();
        const int tid = gettid();
        size_t hd_size = sizeof(struct zlogger_entry);
        size_t prio_size = 1;