Update to add the app pid and dispatcher name information when log enabled 74/114074/6
authorYoungHun Kim <yh8004.kim@samsung.com>
Fri, 10 Feb 2017 01:58:40 +0000 (10:58 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Tue, 21 Feb 2017 10:40:13 +0000 (19:40 +0900)
Change-Id: Ib745ff9074d11714d7fe7b38bf65a12e2e936bda

include/muse_core.h
include/muse_core_log.h
include/muse_core_private.h
packaging/mused.spec
src/muse_core.c
src/muse_core_ipc.c
src/muse_core_log.c
src/muse_core_module.c

index fefee96..9a31fe0 100644 (file)
@@ -68,6 +68,7 @@ bool muse_core_msg_object_get_value(void *msg_obj, const char *key, int m_type,
 void muse_core_msg_object_free(void *msg_obj);
 void muse_core_respawn(int signo);
 int  muse_core_get_api_module(char *module_name, int *api_module);
+int  muse_core_get_pid(muse_module_h module);
 
 #ifdef __cplusplus
 }
index 6ffceab..11f0074 100644 (file)
@@ -44,7 +44,7 @@ typedef struct muse_core_log {
        void(*set_msg)(char *);
        char *(*get_msg)(void);
        void(*flush_msg)(void);
-       void(*log_api_name)(gpointer);
+       void(*log_api_name)(int, gpointer);
        void(*save_debug_info)(pid_t pid);
        void(*free)(void);
        GMutex log_lock;
index d03d388..e10509d 100644 (file)
@@ -59,6 +59,8 @@ typedef struct muse_module {
        int msg_offset;
        int api_module;
        int disp_api;
+       int pid;
+       int last_cmd;
        gpointer usr_data;
        intptr_t handle;
        gboolean is_create_api_called; /* If false, corresponding to the static function */
index d7bddf8..15721f2 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mused
 Summary:    A Multimedia Daemon in Tizen Native API
-Version:    0.1.50
+Version:    0.1.51
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index 07faa31..8ae1445 100644 (file)
@@ -690,3 +690,8 @@ gboolean muse_core_is_log_enabled(void)
        return muse_core_config_get_instance()->log_enabled;
 }
 
+int  muse_core_get_pid(muse_module_h module)
+{
+       return module->pid;
+}
+
index 806329f..ce5f338 100644 (file)
@@ -90,7 +90,7 @@ static void _muse_core_ipc_client_cleanup(muse_module_h module)
 
 static gpointer _muse_core_ipc_dispatch_worker(gpointer data)
 {
-       int len, cmd, api_module;
+       int len, cmd, api_module, pid;
        int parse_len = 0;
        muse_module_h module = NULL;
        gboolean value = TRUE;
@@ -132,6 +132,8 @@ static gpointer _muse_core_ipc_dispatch_worker(gpointer data)
                                                pthread_mutex_lock(&muse_core_workqueue_get_instance()->jobs_mutex);
                                                if (muse_core_msg_json_object_get_value(MUSE_MODULE, jobj, &api_module, MUSE_TYPE_INT)) {
                                                        module->api_module = api_module;
+                                                       if (muse_core_msg_json_object_get_value(PID, jobj, &pid, MUSE_TYPE_INT))
+                                                               module->pid = pid;
                                                        module->is_create_api_called = true;
                                                        module->ch[MUSE_CHANNEL_MSG].dll_handle = muse_core_module_get_instance()->load(api_module);
 #ifndef MUSE_USE_LWIPC
index 23f56c7..03cb019 100644 (file)
@@ -43,7 +43,7 @@ static void _muse_core_log_latest_msgs(void);
 static void _muse_core_log_pid_info(pid_t pid);
 static void _muse_core_log_cmdline(pid_t pid);
 static void _muse_core_log_process_info(pid_t pid);
-static void _muse_core_log_api_name(gpointer ptr);
+static void _muse_core_log_api_name(int pid, gpointer ptr);
 static void _muse_core_log_api_info(void);
 static void _muse_core_log_binary_info(void);
 static int _muse_core_log_fd_set_block(int fd);
@@ -51,7 +51,7 @@ static void _muse_core_log_set_log_fd(void);
 static void _muse_core_log_write_buffer(const void *buf, size_t len);
 static void _muse_core_log_attributes(const char *msg, ...);
 static void _muse_core_log_monitor(char *msg);
-static void _muse_core_log_cache_latest_msg(char *msg);
+static void _muse_core_log_cache_latest_msg(int pid, char *msg);
 static void _muse_core_log_fatal(char *msg);
 static void _muse_core_log_set_msg(char *msg);
 static char *_muse_core_log_get_msg(void);
@@ -59,7 +59,7 @@ static void _muse_core_log_flush_msg(void);
 static void _muse_core_log_free(void);
 static void _muse_core_log_init_instance(void(*log)(char *), void(*log_attr)(const char *, ...), void(*fatal)(char *),
                                                void(*set_msg)(char *), char *(*get_msg)(void), void(*flush_msg)(void),
-                                               void(*log_api_name)(gpointer), void(*save_debug_info)(pid_t), void(*free)(void));
+                                               void(*log_api_name)(int, gpointer), void(*save_debug_info)(pid_t), void(*free)(void));
 
 static gboolean _muse_core_log_pid_is_valid(pid_t pid)
 {
@@ -79,7 +79,7 @@ static gboolean _muse_core_log_pid_is_valid(pid_t pid)
 
 static void _muse_core_log_latest_msgs(void)
 {
-       int idx, start_idx;
+       int idx = 0;
 
        g_return_if_fail(muse_core_is_log_enabled());
        g_return_if_fail(g_muse_core_log);
@@ -87,21 +87,22 @@ static void _muse_core_log_latest_msgs(void)
        g_mutex_lock(&g_muse_core_log->log_lock);
 
        if (muse_core_ipc_fd_is_valid(g_muse_core_log->log_fd)) {
-               start_idx = (g_muse_core_log->currnt_index + 1) % MUSE_LOG_MSG_NUM;
-
-               for (idx = start_idx; idx < MUSE_LOG_MSG_NUM; idx++) {
+               LOGE("----------LATEST MUSE COMMAND----------");
+               for (idx = g_muse_core_log->currnt_index; idx < MUSE_LOG_MSG_NUM; idx++) {
+                       LOGE("%s", g_muse_core_log->latest_msgs[idx]);
                        if (write(g_muse_core_log->log_fd, g_muse_core_log->latest_msgs[idx], strlen(g_muse_core_log->latest_msgs[idx])) == WRITE_FAIL)
                                LOGE("fail to write sequentially the latest message by first step");
                        else if (write(g_muse_core_log->log_fd, "\n", 1) == WRITE_FAIL)
                                LOGE("fail to write new line character");
                }
-
-               for (idx = 0; idx < start_idx; idx++) {
+               for (idx = 0; idx < g_muse_core_log->currnt_index; idx++) {
+                       LOGE("%s", g_muse_core_log->latest_msgs[idx]);
                        if (write(g_muse_core_log->log_fd, g_muse_core_log->latest_msgs[idx], strlen(g_muse_core_log->latest_msgs[idx])) == WRITE_FAIL)
                                LOGE("fail to write sequentially the latest message by second step");
                        else if (write(g_muse_core_log->log_fd, "\n", 1) == WRITE_FAIL)
                                LOGE("fail to write new line character");
                }
+               LOGE("---------------------------------------");
        }
 
        g_mutex_unlock(&g_muse_core_log->log_lock);
@@ -175,7 +176,7 @@ static void _muse_core_log_process_info(pid_t pid)
        }
 }
 
-static void _muse_core_log_api_name(gpointer ptr)
+static void _muse_core_log_api_name(int pid, gpointer ptr)
 {
        Dl_info info;
 
@@ -185,7 +186,7 @@ static void _muse_core_log_api_name(gpointer ptr)
        memset(&info, 0, sizeof(info));
 
        if (dladdr((const void *) ptr, &info) && info.dli_sname)
-               _muse_core_log_cache_latest_msg((char *)info.dli_sname);
+               _muse_core_log_cache_latest_msg(pid, (char *)info.dli_sname);
        else
                LOGE("fail to log api name");
 }
@@ -394,7 +395,7 @@ static void _muse_core_log_monitor(char *msg)
        g_mutex_unlock(&g_muse_core_log->log_lock);
 }
 
-static void _muse_core_log_cache_latest_msg(char *msg)
+static void _muse_core_log_cache_latest_msg(int pid, char *msg)
 {
        g_return_if_fail(msg);
        g_return_if_fail(g_muse_core_log);
@@ -407,7 +408,7 @@ static void _muse_core_log_cache_latest_msg(char *msg)
 
        gettimeofday(&tv, NULL);
        strftime(time_buf, sizeof(time_buf), "%m-%d %H:%M:%S", localtime_r(&(tv.tv_sec), &newtime));
-       snprintf(g_muse_core_log->latest_msgs[g_muse_core_log->currnt_index], MUSE_LOG_MSG_LEN, "%s.%03ld %s ", time_buf, tv.tv_usec / 1000, msg);
+       snprintf(g_muse_core_log->latest_msgs[g_muse_core_log->currnt_index], MUSE_LOG_MSG_LEN, "[P%5d] %s.%03ld %s ", pid, time_buf, tv.tv_usec / 1000, msg);
 
        g_muse_core_log->currnt_index = (g_muse_core_log->currnt_index + 1) % MUSE_LOG_MSG_NUM;
 
@@ -480,7 +481,7 @@ static void _muse_core_log_flush_msg(void)
 
 static void _muse_core_log_init_instance(void(*log)(char *), void(*log_attr)(const char *, ...), void(*fatal)(char *),
                                                void(*set_msg)(char *), char *(*get_msg)(void), void(*flush_msg)(void),
-                                               void(*log_api_name)(gpointer), void(*save_debug_info)(pid_t), void(*free)(void))
+                                               void(*log_api_name)(int, gpointer), void(*save_debug_info)(pid_t), void(*free)(void))
 {
        g_return_if_fail(log);
        g_return_if_fail(fatal);
index bdbfd36..a047b6f 100644 (file)
 #include "muse_core_module.h"
 #include "muse_core_private.h"
 
-#define API_SET_URI 5
-#define API_SET_PROGRESSIVE_DOWNLOAD_PATH 49
-#define API_SET_SUBTITLE_PATH 55
-
 static muse_core_module_t *g_muse_core_module = NULL;
 
 static GModule *_muse_core_module_load(int api_module);
@@ -72,7 +68,17 @@ static GModule *_muse_core_module_load(int api_module)
 
 static gboolean _muse_core_module_dispatch_callback(gpointer data)
 {
+       muse_module_h module = (muse_module_h)data;
+
        LOGE("Restart muse server");
+
+       if (module) {
+               LOGE("module[%p], pid[%d], api_module[%d], cmd[%d]",
+                       module, module->pid, module->api_module, module->last_cmd);
+       } else {
+               LOGE("invalid pointer for module");
+       }
+
        muse_core_respawn(SIGABRT);
 
        return FALSE;
@@ -80,40 +86,41 @@ static gboolean _muse_core_module_dispatch_callback(gpointer data)
 
 static gboolean _muse_core_module_enable_dispatch_callback(int cmd, muse_module_h module)
 {
-       if (module->api_module == MUSE_PLAYER) {
-               if (cmd == API_SET_URI || cmd == API_SET_PROGRESSIVE_DOWNLOAD_PATH || cmd == API_SET_SUBTITLE_PATH)
-                       return FALSE;
-               else
-                       return TRUE;
-       } else {
+       if (module->api_module == MUSE_CAMERA || module->api_module == MUSE_RECORDER) {
                if (cmd == API_CREATE)
                        return FALSE;
-               else
-                       return TRUE;
        }
+
+       return TRUE;
 }
 
 static void _muse_core_module_dispatch(int cmd, muse_module_h module)
 {
        guint id = 0;
-       gboolean rm_success;
-       gboolean enable_dispatch_callback;
+       gboolean rm_success = FALSE;
+       gboolean enable_dispatch_callback = FALSE;
        muse_module_dispatchfunc *dispatcher = NULL;
 
        if (module->ch[MUSE_CHANNEL_MSG].dll_handle) {
                g_module_symbol(module->ch[MUSE_CHANNEL_MSG].dll_handle, DISPATCHER, (gpointer *)&dispatcher);
 
+               module->last_cmd = cmd;
+
                if (dispatcher && dispatcher[cmd]) {
                        enable_dispatch_callback = _muse_core_module_enable_dispatch_callback(cmd, module);
+
                        if (enable_dispatch_callback) {
                                id = g_timeout_add_seconds((guint)g_muse_core_module->disp_timeout[module->api_module][module->disp_api],
                                        (GSourceFunc) _muse_core_module_dispatch_callback, (gpointer) module);
                        }
+
                        if (muse_core_is_log_enabled()) {
                                _muse_core_module_set_dllsymbol_value(module->api_module, DISPATCHER_PTR, (gpointer) dispatcher[cmd]);
-                               muse_core_log_get_instance()->log_api_name((gpointer) dispatcher[cmd]);
+                               muse_core_log_get_instance()->log_api_name(module->pid, (gpointer) dispatcher[cmd]);
                        }
+
                        dispatcher[cmd](module);
+
                        if (enable_dispatch_callback) {
                                rm_success = g_source_remove(id);
                                if (!rm_success)