Do not call clock_gettime() if dedup is not configured 32/241332/8
authorHyotaek Shim <hyotaek.shim@samsung.com>
Wed, 19 Aug 2020 08:39:51 +0000 (17:39 +0900)
committerMichal Bloch <m.bloch@partner.samsung.com>
Wed, 19 Aug 2020 15:55:17 +0000 (15:55 +0000)
Change-Id: I04982e00fc15b09c7c2a826ec001cd18ba934227
Signed-off-by: Hyotaek Shim <hyotaek.shim@samsung.com>
include/deduplicate.h
src/libdlog/deduplicate.c
src/libdlog/log.c
src/libdlog/log_android.c

index 17bcd57..8e875a0 100644 (file)
@@ -32,7 +32,7 @@
 #include "logconfig.h"
 
 void __configure_deduplicate(struct log_config *config);
-bool deduplicate(const char *msg, size_t len, struct timespec *tp);
 void __deduplicate_destroy();
+extern bool (*deduplicate_func)(const char *, size_t, struct timespec *);
 
 #endif /* _DEDUPLICATE_H_ */
index 09431a5..651392c 100644 (file)
@@ -127,11 +127,6 @@ void __configure_deduplicate(struct log_config *config)
        }
 }
 
-bool deduplicate(const char *msg, size_t len, struct timespec *tp)
-{
-       return deduplicate_func && deduplicate_func(msg, len, tp);
-}
-
 void __deduplicate_destroy()
 {
        known_hashes_size = 0;
index bbf9480..f33df1a 100644 (file)
@@ -356,13 +356,13 @@ static int __write_to_log_critical_section(log_id_t log_id, int prio, const char
                len = sizeof buf - 1;
 
        struct timespec tp;
-       int result = clock_gettime(CLOCK_MONOTONIC, &tp);
-       if (result < 0)
-               return DLOG_ERROR_NONE;
+       if (deduplicate_func && !clock_gettime(CLOCK_MONOTONIC, &tp)) {
+               if (deduplicate_func(buf, len, &tp))
+                       return DLOG_ERROR_NONE;
+               return write_to_log(log_id, prio, tag, buf, &tp);
+       }
 
-       if (deduplicate(buf, len, &tp))
-               return 0;
-       return write_to_log(log_id, prio, tag, buf, &tp);
+       return write_to_log(log_id, prio, tag, buf, NULL);
 }
 
 static int __write_to_log(log_id_t log_id, int prio, const char *tag, const char *fmt, va_list ap, bool check_should_log, bool secure_log)
index e07b689..4ca940a 100644 (file)
@@ -72,10 +72,22 @@ static int __write_to_log_android(log_id_t log_id, log_priority prio, const char
 #ifdef USE_ANDROID_MONOTONIC
        struct iovec vec[4];
        struct android_logger_footer alf;
+       struct timespec ts;
+
+       if (!tp_mono) {
+               int result = clock_gettime(CLOCK_MONOTONIC, &ts);
+               if (result >= 0)
+                       tp_mono = &ts;
+       }
 
        alf.magic = ANDROID_LOGGER_FOOTER_MAGIC;
-       alf.sec_sent_mono = tp_mono->tv_sec;
-       alf.nsec_sent_mono = tp_mono->tv_nsec;
+       if (tp_mono) {
+               alf.sec_sent_mono = tp_mono->tv_sec;
+               alf.nsec_sent_mono = tp_mono->tv_nsec;
+       } else {
+               alf.sec_sent_mono = 0;
+               alf.nsec_sent_mono = -1;
+       }
 
        vec[3].iov_base = (void *) &alf;
        vec[3].iov_len = sizeof alf;