Refactor extract_timestamp and rename to dlogutil_entry_ts 58/216458/3
authorMateusz Majewski <m.majewski2@samsung.com>
Thu, 24 Oct 2019 10:11:36 +0000 (12:11 +0200)
committerMateusz Majewski <m.majewski2@samsung.com>
Wed, 6 Nov 2019 13:50:52 +0000 (14:50 +0100)
Change-Id: I0c6ee97ad3a39fe66a8cf64e4957a80d52b4b17e

Makefile.am
include/queued_entry_timestamp.h
src/shared/fd_info.c
src/shared/log_file.c
src/shared/logretrieve.c
src/shared/queued_entry_timestamp.c
src/shared/sort_vector.c
src/tests/fd_info.c
src/tests/log_file.c
src/tests/queued_entry.c

index 99d0419..5b81d09 100644 (file)
@@ -243,7 +243,7 @@ src_tests_sort_vector_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=log_config_get_int,--wr
 
 src_tests_fd_info_SOURCES = src/tests/fd_info.c src/shared/fd_info.c
 src_tests_fd_info_CFLAGS = $(check_CFLAGS)
-src_tests_fd_info_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=sort_vector_push,--wrap=malloc,--wrap=free,--wrap=close,--wrap=extract_timestamp,--wrap=log_should_print_line
+src_tests_fd_info_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=sort_vector_push,--wrap=malloc,--wrap=free,--wrap=close,--wrap=dlogutil_entry_ts,--wrap=log_should_print_line
 
 src_tests_fdi_logger_SOURCES = src/tests/fdi_logger.c src/shared/fdi_logger.c src/shared/ptrs_list.c src/shared/logcommon.c
 src_tests_fdi_logger_CFLAGS = $(check_CFLAGS)
@@ -271,7 +271,7 @@ src_tests_libdlog_base_LDFLAGS = $(AM_LDFLAGS) -lpthread -Wl,--wrap=log_config_r
 
 src_tests_log_file_SOURCES = src/tests/log_file.c src/shared/log_file.c
 src_tests_log_file_CFLAGS = $(check_CFLAGS)
-src_tests_log_file_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=strdup,--wrap=free,--wrap=memcpy,--wrap=snprintf,--wrap=open,--wrap=fstat,--wrap=rename,--wrap=extract_timestamp,--wrap=log_print_log_line,--wrap=log_buffer_get_tag
+src_tests_log_file_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=strdup,--wrap=free,--wrap=memcpy,--wrap=snprintf,--wrap=open,--wrap=fstat,--wrap=rename,--wrap=dlogutil_entry_ts,--wrap=log_print_log_line,--wrap=log_buffer_get_tag
 
 src_tests_queued_entry_SOURCES = src/tests/queued_entry.c src/shared/queued_entry.c src/shared/queued_entry_timestamp.c src/shared/parsers.c src/shared/translate_syslog.c src/shared/logconfig.c src/shared/logcommon.c
 src_tests_queued_entry_CFLAGS = $(check_CFLAGS)
index 40b7d90..b5a3a27 100644 (file)
@@ -29,7 +29,7 @@ enum dlogutil_sorting_order;
 void add_recv_timestamp(struct dlogutil_entry *le);
 void copy_recv_timestamp(struct dlogutil_entry *le);
 bool log_entry_is_earlier(const enum dlogutil_sorting_order sort_by, const struct dlogutil_entry *lhs, const struct dlogutil_entry *rhs);
-void extract_timestamp(const struct dlogutil_entry *le, enum dlogutil_sorting_order stamp_type, struct timespec *ts);
+struct timespec dlogutil_entry_ts(const struct dlogutil_entry *le, enum dlogutil_sorting_order stamp_type);
 clockid_t get_proper_clock(enum dlogutil_sorting_order sort_by);
 
 #endif /* _QUEUED_ENTRY_TIMESTAMP_H */
index 5f4f9ef..478aa1a 100644 (file)
@@ -93,8 +93,7 @@ int fdi_push_log(struct fd_info *fdi, struct sort_vector *logs, dlogutil_write_c
        int r;
 
        if (IS_VECTOR_SIZE_SORTABLE(logs->size)) {
-               struct timespec ts;
-               extract_timestamp(temp, logs->sort_by, &ts);
+               struct timespec ts = dlogutil_entry_ts(temp, logs->sort_by);
 
                /* check if new entry is newer than util's start moment */
                if (ts.tv_sec > logs->start.tv_sec || (ts.tv_sec == logs->start.tv_sec && ts.tv_nsec > logs->start.tv_nsec))
index 88e4ce7..c0d768c 100644 (file)
@@ -222,8 +222,7 @@ int logfile_write_with_rotation(const struct dlogutil_entry *e, struct log_file
 {
        int written_bytes = 0;
 
-       struct timespec ts;
-       extract_timestamp(e, sort_by, &ts);
+       struct timespec ts = dlogutil_entry_ts(e, sort_by);
 
        if (ts.tv_sec < file->prev_sec || (ts.tv_sec == file->prev_sec && ts.tv_nsec < file->prev_nsec)) {
                struct dlogutil_entry_with_msg msg;
index c5880dc..c4d3626 100644 (file)
@@ -105,8 +105,7 @@ struct fd_info *find_earliest_log(struct fd_info **data_fds, int fd_count, enum
                        continue;
 
                const struct dlogutil_entry *const le = fdi->ops->peek_entry(fdi);
-               struct timespec current_ts;
-               extract_timestamp(le, sort_by, &current_ts);
+               struct timespec current_ts = dlogutil_entry_ts(le, sort_by);
 
                if (best_fdi && ((current_ts.tv_sec > best_ts.tv_sec) || (current_ts.tv_sec == best_ts.tv_sec && current_ts.tv_nsec > best_ts.tv_nsec)))
                        continue;
index 27cbe93..67cf8ca 100644 (file)
@@ -95,31 +95,34 @@ bool log_entry_is_earlier(const enum dlogutil_sorting_order sort_by, const struc
        return l_sec < r_sec || (l_sec == r_sec && l_nsec < r_nsec);
 }
 
-void extract_timestamp(const struct dlogutil_entry *le, enum dlogutil_sorting_order stamp_type, struct timespec *ts)
+struct timespec dlogutil_entry_ts(const struct dlogutil_entry *le, enum dlogutil_sorting_order stamp_type)
 {
        assert(le);
-       assert(ts);
+
+       struct timespec ret;
 
        switch (stamp_type) {
        case SORT_SENT_MONO:
-               ts->tv_sec = le->sec_sent_mono;
-               ts->tv_nsec = le->nsec_sent_mono;
+               ret.tv_sec = le->sec_sent_mono;
+               ret.tv_nsec = le->nsec_sent_mono;
                break;
        case SORT_SENT_REAL:
-               ts->tv_sec = le->sec_sent_real;
-               ts->tv_nsec = le->nsec_sent_real;
+               ret.tv_sec = le->sec_sent_real;
+               ret.tv_nsec = le->nsec_sent_real;
                break;
        case SORT_RECV_MONO:
-               ts->tv_sec = le->sec_recv_mono;
-               ts->tv_nsec = le->nsec_recv_mono;
+               ret.tv_sec = le->sec_recv_mono;
+               ret.tv_nsec = le->nsec_recv_mono;
                break;
        case SORT_RECV_REAL:
-               ts->tv_sec = le->sec_recv_real;
-               ts->tv_nsec = le->nsec_recv_real;
+               ret.tv_sec = le->sec_recv_real;
+               ret.tv_nsec = le->nsec_recv_real;
                break;
 
        default: assert(false); // LCOV_EXCL_LINE
        }
+
+       return ret;
 }
 
 clockid_t get_proper_clock(enum dlogutil_sorting_order sort_by)
index 8b180ac..1975902 100644 (file)
@@ -195,13 +195,12 @@ int sort_vector_push(struct sort_vector *logs, struct dlogutil_entry *p, dloguti
 
 long sort_vector_time_span(struct sort_vector *logs)
 {
-       struct timespec now, oldest;
        long diff_s, diff_ns;
        if (sort_vector_empty(logs))
                return 0;
 
+       struct timespec now, oldest = dlogutil_entry_ts(sort_vector_back(logs), logs->sort_by);
        clock_gettime(get_proper_clock(logs->sort_by), &now);
-       extract_timestamp(sort_vector_back(logs), logs->sort_by, &oldest);
 
        diff_s = now.tv_sec - oldest.tv_sec;
        diff_ns = now.tv_nsec - oldest.tv_nsec;
@@ -233,8 +232,7 @@ bool process_log(const struct dlogutil_entry *e, struct timespec reference_ts, e
 
        if (timeout != -1) {
 
-               struct timespec log_ts;
-               extract_timestamp(e, stamp_type, &log_ts);
+               struct timespec log_ts = dlogutil_entry_ts(e, stamp_type);
 
                long  s = reference_ts.tv_sec  - log_ts.tv_sec;
                long ns = reference_ts.tv_nsec - log_ts.tv_nsec;
index e2818c6..fcb856f 100644 (file)
@@ -65,11 +65,13 @@ struct dlogutil_entry *test_extract(struct fd_info *fdi)
        return fail_extract ? NULL : (struct dlogutil_entry *) 0xBADFEEL;
 }
 
-void __wrap_extract_timestamp(const struct dlogutil_entry *le, enum dlogutil_sorting_order stamp_type, struct timespec *ts)
+struct timespec __wrap_dlogutil_entry_ts(const struct dlogutil_entry *le, enum dlogutil_sorting_order stamp_type)
 {
        assert(le == (struct dlogutil_entry *)0xBADFEEL);
-       ts->tv_sec = 1;
-       ts->tv_nsec = 1;
+       return (struct timespec) {
+               .tv_sec = 1,
+               .tv_nsec = 1,
+       };
 }
 
 static struct fd_info *expected_destroyee;
index c5b5e1e..f03d45c 100644 (file)
@@ -34,12 +34,14 @@ int __wrap_rename(const char *oldpath, const char *newpath)
        return -1;
 }
 
-void __wrap_extract_timestamp(const struct dlogutil_entry *le, enum dlogutil_sorting_order stamp_type, struct timespec *ts)
+struct timespec __wrap_dlogutil_entry_ts(const struct dlogutil_entry *le, enum dlogutil_sorting_order stamp_type)
 {
        assert(stamp_type == SORT_SENT_MONO);
        assert(le == (struct dlogutil_entry *) 0xBA5EBALL);
-       ts->tv_sec = 3333;
-       ts->tv_nsec = 9999;
+       return (struct timespec) {
+               .tv_sec = 3333,
+               .tv_nsec = 9999,
+       };
 }
 
 char *__wrap_log_buffer_get_tag(const struct dlogutil_entry *entry)
index e0a9714..d35492d 100644 (file)
@@ -58,16 +58,16 @@ int main()
                 .sec_recv_real = 7,
                .nsec_recv_real = 8,
        };
-       extract_timestamp(&le, SORT_SENT_MONO, &ts);
+       ts = dlogutil_entry_ts(&le, SORT_SENT_MONO);
        assert(ts.tv_sec  == le. sec_sent_mono);
        assert(ts.tv_nsec == le.nsec_sent_mono);
-       extract_timestamp(&le, SORT_RECV_REAL, &ts);
+       ts = dlogutil_entry_ts(&le, SORT_RECV_REAL);
        assert(ts.tv_sec  == le. sec_recv_real);
        assert(ts.tv_nsec == le.nsec_recv_real);
-       extract_timestamp(&le, SORT_SENT_REAL, &ts);
+       ts = dlogutil_entry_ts(&le, SORT_SENT_REAL);
        assert(ts.tv_sec  == le. sec_sent_real);
        assert(ts.tv_nsec == le.nsec_sent_real);
-       extract_timestamp(&le, SORT_RECV_MONO, &ts);
+       ts = dlogutil_entry_ts(&le, SORT_RECV_MONO);
        assert(ts.tv_sec  == le. sec_recv_mono);
        assert(ts.tv_nsec == le.nsec_recv_mono);