#define MUSE_LWIPC_WAIT_TIME 1000
#endif
+
static const char *channel_name[MUSE_CHANNEL_MAX] = {
"msg",
"data"
static void _ms_check_connection_event(void)
{
ms_connection_state_e state = MUSE_CONNECTION_STATE_INVALID;
+ int fd = -1;
muse_return_if_fail(muse_server);
- if (ms_connection_get_state(&state)) {
+ if (ms_connection_get_state(&state, &fd)) {
gettimeofday(&muse_server->tv_s, NULL);
if (state == MUSE_CONNECTION_STATE_CONNECTED) {
/* will be updated about connection at the next patch */
} else if (state == MUSE_CONNECTION_STATE_DISCONNECTED) {
LOGD("Diagnostic thread checks the memory of idle");
- ms_check_memory(muse_server->pid);
+ ms_check_cpu_memory(fd);
}
}
}
muse_core_create_fd_table();
+ muse_server->cpu_threshold = ms_config_get_cpu_threshold();
+
muse_server->main_loop = g_main_loop_new(NULL, FALSE);
muse_return_if_fail(muse_server->main_loop);
return retval;
}
-void ms_check_memory(int pid)
+void ms_check_cpu_memory(int fd)
{
- int used_pss, memory_threshold;
+ int used_pss, memory_threshold, cpu_usage;
char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
ms_connection_t *connection = NULL;
connection = muse_server->connection;
muse_return_if_fail(connection);
- _ms_lock_state();
-
ms_connection_lock(connection);
+ while (muse_core_fd_is_valid(fd)) {
+ g_cond_wait(&connection->cond, &connection->lock);
+ LOGI("[%d] is_valid : %d", fd, muse_core_fd_is_valid(fd));
+ }
+
if (g_queue_is_empty(connection->instance_queue) && ms_is_server_ready()) {
- used_pss = ms_system_get_memory_usage(pid);
+ used_pss = ms_system_get_memory_usage(muse_server->pid);
+ cpu_usage = muse_core_get_process_cpu_usage(muse_server->pid);
- LOGW("[%d] Proportional set size %d (KByte)", pid, used_pss);
+ LOGW("[%d] Proportional set size %d (KByte) (CPU %d)", muse_server->pid, used_pss, cpu_usage);
memory_threshold = ms_config_get_memory_threshold();
- if (used_pss > memory_threshold) {
+
+ if (used_pss >= memory_threshold || cpu_usage >= muse_server->cpu_threshold) {
ms_set_state(MUSE_SERVER_STATE_IDLE);
- ms_log_process_info(pid);
+ ms_log_process_info(muse_server->pid);
- snprintf(err_msg, sizeof(err_msg), "[Memory Leak] %d > %d (KByte)", used_pss, memory_threshold);
+ snprintf(err_msg, sizeof(err_msg), "[Memory Leak] %d >= %d (KByte) [CPU] %d >= %d (percent)",
+ used_pss, memory_threshold, cpu_usage, muse_server->cpu_threshold);
LOGE("%s", err_msg);
ms_connection_unlock(connection);
- _ms_unlock_state();
ms_respawn(SIGTERM);
}
muse_core_remove_all_fd_table();
+ } else {
+ LOGI("skip cpu memory check due to instance queue length : %d", g_queue_get_length(connection->instance_queue));
}
ms_connection_unlock(connection);
-
- _ms_unlock_state();
}
int ms_kill_thread(int signo)