From: Hyotaek Shim Date: Wed, 19 Aug 2020 08:39:51 +0000 (+0900) Subject: Do not call clock_gettime() if dedup is not configured X-Git-Tag: accepted/tizen/unified/20200820.133531~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3ed6af88b4559f95086b033e2b40e8743da26401;p=platform%2Fcore%2Fsystem%2Fdlog.git Do not call clock_gettime() if dedup is not configured Change-Id: I04982e00fc15b09c7c2a826ec001cd18ba934227 Signed-off-by: Hyotaek Shim --- diff --git a/include/deduplicate.h b/include/deduplicate.h index 17bcd57..8e875a0 100644 --- a/include/deduplicate.h +++ b/include/deduplicate.h @@ -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_ */ diff --git a/src/libdlog/deduplicate.c b/src/libdlog/deduplicate.c index 09431a5..651392c 100644 --- a/src/libdlog/deduplicate.c +++ b/src/libdlog/deduplicate.c @@ -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; diff --git a/src/libdlog/log.c b/src/libdlog/log.c index bbf9480..f33df1a 100644 --- a/src/libdlog/log.c +++ b/src/libdlog/log.c @@ -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) diff --git a/src/libdlog/log_android.c b/src/libdlog/log_android.c index e07b689..4ca940a 100644 --- a/src/libdlog/log_android.c +++ b/src/libdlog/log_android.c @@ -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;