Change fd dump format of a time structure to monotonic system clock at destroy 65/239265/6
authorYoungHun Kim <yh8004.kim@samsung.com>
Thu, 23 Jul 2020 08:03:30 +0000 (17:03 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Fri, 24 Jul 2020 04:24:34 +0000 (13:24 +0900)
 - change log level

Change-Id: I06462498edbdc39342206188677e7a0f3a10859c

core/include/muse_core.h
core/src/muse_core.c
server/src/muse_server_private.c

index 542128b..b28d2f8 100644 (file)
@@ -107,9 +107,8 @@ void muse_core_msg_free(char *msg);
 void *muse_core_msg_object_new(char *str, int *parse_len, muse_core_msg_parse_err_e *err);
 bool muse_core_msg_object_get_value(const char *key, void *jobj, muse_core_msg_type_e m_type, void *data);
 void muse_core_msg_object_free(void *msg_obj);
-
+void muse_core_change_time_format(int val, char *time_buf);
 void muse_core_dump_fd_state(int fd);
-
 void muse_core_create_fd_table(void);
 void muse_core_remove_all_fd_table(void);
 void muse_core_destroy_fd_table(void);
index 986db19..67c3365 100644 (file)
@@ -27,6 +27,9 @@
 #define LOG_TAG                                                                "MUSED_CORE"
 
 #define STR_TIME_FORMAT                                                "%m-%d %H:%M:%S"
+#define MUSE_MIN_SEC_VALUE                                     60
+#define MUSE_HOUR_MIN_VALUE                                    60
+#define MUSE_DAY_HOUR_VALUE                                    24
 
 #define MUSE_WATCHDOG_CHECK_PERIOD                     10
 #define MUSE_WATCHDOG_CHECK_COUNT                      3
@@ -694,24 +697,46 @@ bool muse_core_msg_recv_len(int fd, char *buf, int msg_len)
        return true;
 }
 
+void muse_core_change_time_format(int val, char *time_buf)
+{
+       int sec, min, hour, day;
+
+       muse_return_if_fail(time_buf);
+
+       min = val / MUSE_MIN_SEC_VALUE;
+       hour = min / MUSE_HOUR_MIN_VALUE;
+       day = hour / MUSE_DAY_HOUR_VALUE;
+
+       sec = val % MUSE_MIN_SEC_VALUE;
+       min = min % MUSE_HOUR_MIN_VALUE;
+       hour = hour % MUSE_DAY_HOUR_VALUE;
+
+       snprintf(time_buf, MUSE_MSG_TIME_LEN, "%dd %dh %dm %ds", day, hour, min, sec);
+}
+
 void muse_core_dump_fd_state(int fd)
 {
+       int sec = 0;
+       char time_buf[MUSE_MSG_LEN];
+
        g_mutex_lock(&fd_state_lock);
-       LOGI("[%d] %s", fd, (char *)g_hash_table_lookup(fd_state_table, GINT_TO_POINTER(fd)));
+       sec = GPOINTER_TO_INT(g_hash_table_lookup(fd_state_table, GINT_TO_POINTER(fd)));
+       muse_core_change_time_format(sec, time_buf);
+       LOGI("[%d] %s", fd, time_buf);
        g_mutex_unlock(&fd_state_lock);
 }
 
 void muse_core_update_fd_state(int fd)
 {
-       char atime[MUSE_MSG_TIME_LEN] = {'\0',};
+       struct timespec tv;
 
        g_mutex_lock(&fd_state_lock);
 
        if (!fd_state_table)
-               fd_state_table = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
+               fd_state_table = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL);
 
-       muse_core_get_cur_time(NULL, atime);
-       g_hash_table_insert(fd_state_table, GINT_TO_POINTER(fd), g_strdup(atime));
+       muse_core_get_cur_time(&tv, NULL);
+       g_hash_table_insert(fd_state_table, GINT_TO_POINTER(fd), GINT_TO_POINTER((int)tv.tv_sec));
 
        g_mutex_unlock(&fd_state_lock);
 }
@@ -725,7 +750,7 @@ void muse_core_create_fd_table(void)
                goto out;
        }
 
-       fd_state_table = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
+       fd_state_table = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL);
        if (!fd_state_table)
                LOGE("fail to create new fd state table");
 out:
@@ -811,7 +836,7 @@ int muse_core_get_process_cpu_usage(int pid)
 
        if (fp) {
                while (fgets(buf, MUSE_MSG_LEN_MAX, fp)) {
-                       LOGW("%s", buf);
+                       LOGI("%s", buf);
                        cpu += atoi(g_strstrip(buf));
                }
 
index c83859b..597c656 100644 (file)
@@ -261,6 +261,7 @@ static gboolean _ms_connection_handler(GIOChannel *source, GIOCondition conditio
        intptr_t module_addr = 0;
        GQueue *instance_queue = NULL;
        ms_connection_t *connection = NULL;
+       char time_buf[MUSE_MSG_LEN];
 
        muse_return_val_if_fail(channel == MUSE_CHANNEL_MSG || channel == MUSE_CHANNEL_DATA, FALSE);
 
@@ -377,8 +378,8 @@ static gboolean _ms_connection_handler(GIOChannel *source, GIOCondition conditio
        }
 
        muse_core_get_cur_time(&muse_server->tv, NULL);
-
-       LOGW("connected time %lu", muse_server->tv.tv_sec);
+       muse_core_change_time_format((int)muse_server->tv.tv_sec, time_buf);
+       LOGW("connected time (%s)", time_buf);
 
        _ms_unlock_state();
 
@@ -411,6 +412,7 @@ static void _ms_check_idle_state(void)
        uint32_t elapsed_time;
        struct timespec tv;
        static int period_idx = 1;
+       char time_buf[MUSE_MSG_LEN];
 
        muse_return_if_fail(muse_server);
        muse_return_if_fail(muse_server->state == MUSE_SERVER_STATE_READY);
@@ -435,8 +437,9 @@ static void _ms_check_idle_state(void)
        instance_number = g_queue_get_length(connection->instance_q);
 
        if (elapsed_time >= (uint32_t)(period * period_idx)) {
-               LOGW("[#%d] %u sec [period %d] [last connected time %lu] total number of modules = %d ( %s)", period_idx,
-                       elapsed_time, period, muse_server->tv.tv_sec, instance_number, muse_server->instance_pid_info);
+               muse_core_change_time_format((int)muse_server->tv.tv_sec, time_buf);
+               LOGW("[#%d] %u sec [period %d] [last connected time %s] total number of modules = %d ( %s)", period_idx,
+                       elapsed_time, period, time_buf, instance_number, muse_server->instance_pid_info);
                period_idx++;
        }
 
@@ -576,6 +579,7 @@ static void _ms_diag_deinit(void)
 static gboolean _ms_idle_cb(gpointer user_data)
 {
        struct timespec tv;
+       char time_buf[MUSE_MSG_LEN];
 
        if (!ms_create_ready_file())
                LOGE("%s file creation is failed", MUSE_SERVER_READY);
@@ -584,7 +588,9 @@ static gboolean _ms_idle_cb(gpointer user_data)
 
        muse_core_get_cur_time(&tv, NULL);
 
-       LOGW("muse server is completed to ready %lu", tv.tv_sec);
+       muse_core_change_time_format((int)tv.tv_sec, time_buf);
+
+       LOGW("muse server is completed to ready (%s)", time_buf);
 
        return G_SOURCE_REMOVE;
 }