shared: add a bunch of sorting helper functions 46/185946/2
authorMichal Bloch <m.bloch@samsung.com>
Fri, 3 Aug 2018 09:46:38 +0000 (11:46 +0200)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Tue, 21 Aug 2018 02:50:39 +0000 (02:50 +0000)
 * sorting order -> clock type mapping
 * format -> sorting order mapping
 * config -> sorting order getter

Change-Id: I7af5029f7ed9a4ba74bb34f09cc210f625109dd4
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
Makefile.am
include/logprint.h
include/queued_entry.h
src/logger/logger.c
src/shared/logprint.c
src/shared/queued_entry.c

index b700c28..b0a1ff7 100644 (file)
@@ -182,6 +182,8 @@ src_tests_kmsg_parser_SOURCES = src/tests/kmsg_parser.c \
        src/shared/queued_entry.c \
        src/shared/logprint.c \
        src/shared/parsers.c \
+       src/shared/logconfig.c \
+       src/shared/logcommon.c \
        src/shared/translate_syslog.c
 src_tests_kmsg_parser_CFLAGS = $(AM_CFLAGS)
 src_tests_kmsg_parser_LDFLAGS = $(AM_LDFLAGS)
@@ -190,6 +192,8 @@ src_tests_syslog_parser_SOURCES = src/tests/syslog_parser.c \
        src/shared/queued_entry.c \
        src/shared/logprint.c \
        src/shared/parsers.c \
+       src/shared/logconfig.c \
+       src/shared/logcommon.c \
        src/shared/translate_syslog.c
 src_tests_syslog_parser_CFLAGS = $(AM_CFLAGS)
 src_tests_syslog_parser_LDFLAGS = $(AM_LDFLAGS)
@@ -197,6 +201,8 @@ src_tests_syslog_parser_LDFLAGS = $(AM_LDFLAGS)
 src_tests_pipe_message_SOURCES = src/tests/pipe_message.c \
        src/shared/queued_entry.c \
        src/shared/translate_syslog.c \
+       src/shared/logconfig.c \
+       src/shared/logcommon.c \
        src/shared/parsers.c
 src_tests_pipe_message_CFLAGS = $(AM_CFLAGS)
 src_tests_pipe_message_LDFLAGS = $(AM_LDFLAGS)
index 0d42eac..1fa265e 100644 (file)
@@ -167,6 +167,7 @@ int log_print_log_line(
 log_priority filter_char_to_pri(char c);
 
 char filter_pri_to_char(log_priority pri);
+enum sorting_order get_format_sorting(const log_format *format);
 
 #ifdef __cplusplus
 }
index c6a5d5f..b5f88d7 100644 (file)
@@ -31,7 +31,8 @@ enum sorting_order {
        SORT_SENT_REAL,
        SORT_RECV_MONO,
        SORT_RECV_REAL,
-       SORT_MAX
+       SORT_MAX,
+       SORT_DEFAULT,
 };
 
 
@@ -114,6 +115,8 @@ void parse_androidlogger_message(struct android_logger_entry *ale, struct logger
 void parse_pipe_message(struct pipe_logger_entry *ple, struct logger_entry *le, size_t msg_size);
 void add_recv_timestamp(struct logger_entry *le);
 enum sorting_order get_proper_sorting_order(bool is_pipe, log_id_t buf_id, enum sorting_order sort_by);
+enum sorting_order get_order_from_config(const struct log_config *conf);
+clockid_t get_proper_clock(enum sorting_order sort_by);
 
 #ifdef __cplusplus
 }
index d9da7f1..4974863 100755 (executable)
@@ -1982,16 +1982,7 @@ int prepare_config_data(struct logger_config_data *data, int argc, char **argv)
        if (ret < 0)
                return ret;
 
-       enum sorting_order sort_by = SORT_SENT_MONO;
-       const char * sort_str = log_config_get(&conf, "sort_by");
-       if (sort_str) {
-               if (!strcmp(sort_str, "sent_real"))
-                       sort_by = SORT_SENT_REAL;
-               else if (!strcmp(sort_str, "recv_real"))
-                       sort_by = SORT_RECV_REAL;
-               else if (!strcmp(sort_str, "recv_mono"))
-                       sort_by = SORT_RECV_MONO;
-       }
+       const enum sorting_order sort_by = get_order_from_config(&conf);
 
        const char * const backend = log_config_get(&conf, "backend");
        if (!backend) {
index 55bb2d5..9ab7746 100644 (file)
@@ -586,6 +586,33 @@ char* log_buffer_get_message(const struct logger_entry *entry)
        return (char*)entry->msg + entry->tag_len + 1 /* NULL delimiter */;
 }
 
+enum sorting_order get_format_sorting(const log_format *format)
+{
+       assert(format);
+
+       switch (format->format) {
+       case FORMAT_TAG:
+       case FORMAT_PROCESS:
+       case FORMAT_THREAD:
+       case FORMAT_RAW:
+       case FORMAT_BRIEF:
+               return SORT_DEFAULT;
+
+       case FORMAT_TIME:
+       case FORMAT_THREADTIME:
+       case FORMAT_KERNELTIME:
+       case FORMAT_LONG:
+               return SORT_SENT_MONO;
+
+       case FORMAT_RWTIME:
+       case FORMAT_RECV_REALTIME:
+               return SORT_RECV_REAL;
+
+       default:
+               assert(false);
+       }
+}
+
 /**
  * @brief Format log line
  * @details Formats a log entry for direct printing
index d29dea0..ebc6292 100644 (file)
@@ -356,6 +356,39 @@ enum sorting_order get_proper_sorting_order(bool is_pipe, log_id_t buf_id, enum
        return sort_by;
 }
 
+clockid_t get_proper_clock(enum sorting_order sort_by)
+{
+       switch (sort_by) {
+       case SORT_SENT_MONO:
+       case SORT_RECV_MONO:
+               return CLOCK_MONOTONIC;
+
+       case SORT_SENT_REAL:
+       case SORT_RECV_REAL:
+               return CLOCK_REALTIME;
+
+       default:
+               assert(false);
+       }
+}
+
+enum sorting_order get_order_from_config(const struct log_config *conf)
+{
+       enum sorting_order ret = SORT_RECV_MONO;
+
+       const char *const sort_str = log_config_get(conf, "sort_by");
+       if (sort_str) {
+               if (!strcmp(sort_str, "sent_real"))
+                       ret = SORT_SENT_REAL;
+               else if (!strcmp(sort_str, "recv_real"))
+                       ret = SORT_RECV_REAL;
+               else if (!strcmp(sort_str, "recv_mono"))
+                       ret = SORT_RECV_MONO;
+       }
+
+       return ret;
+}
+
 /**
  * @}
  */