Logger changes from process to thread

This commit is contained in:
Sukchan Lee 2017-08-04 18:02:19 +09:00
parent 9a91870324
commit 08f260f6d9
8 changed files with 108 additions and 106 deletions

View File

@ -83,23 +83,67 @@ status_t pkbuf_final(void)
void pkbuf_show(void)
{
d_trace(1, "[64] %d/%d in pkbuf, [64] %d/%d in clbuf\n",
if (pool_size(&pkbuf_pool) != pool_avail(&pkbuf_pool))
d_warn("%d not freed in pkbuf_pool[%d]",
pool_size(&pkbuf_pool) - pool_avail(&pkbuf_pool),
pool_size(&pkbuf_pool));
d_trace(3, "%d not freed in pkbuf_pool[%d]\n",
pool_size(&pkbuf_pool) - pool_avail(&pkbuf_pool),
pool_size(&pkbuf_pool),
pool_size(&pkbuf_pool));
if (pool_size(&clbuf_pool) != pool_avail(&clbuf_pool))
d_warn("%d not freed in clbuf_pool[%d]",
pool_size(&clbuf_pool) - pool_avail(&clbuf_pool),
pool_size(&clbuf_pool));
d_trace(3, "%d not freed in clbuf_pool[%d]\n",
pool_size(&clbuf_pool) - pool_avail(&clbuf_pool),
pool_size(&clbuf_pool));
d_trace(1, "[128] %d/%d [256] %d/%d [512] %d/%d [1024] %d/%d [2048] %d/%d "
"[8192] %d/%d in cluster\n",
if (pool_size(&cluster_128_pool) != pool_avail(&cluster_128_pool))
d_warn("%d not freed in cluster128_pool[%d]",
pool_size(&cluster_128_pool) - pool_avail(&cluster_128_pool),
pool_size(&cluster_128_pool));
d_trace(3, "%d not freed in cluster128_pool[%d]\n",
pool_size(&cluster_128_pool) - pool_avail(&cluster_128_pool),
pool_size(&cluster_128_pool),
pool_size(&cluster_128_pool));
if (pool_size(&cluster_256_pool) != pool_avail(&cluster_256_pool))
d_warn("%d not freed in cluster256_pool[%d]",
pool_size(&cluster_256_pool) - pool_avail(&cluster_256_pool),
pool_size(&cluster_256_pool));
d_trace(3, "%d not freed in cluster256_pool[%d]\n",
pool_size(&cluster_256_pool) - pool_avail(&cluster_256_pool),
pool_size(&cluster_256_pool),
pool_size(&cluster_256_pool));
if (pool_size(&cluster_512_pool) != pool_avail(&cluster_512_pool))
d_warn("%d not freed in cluster512_pool[%d]",
pool_size(&cluster_512_pool) - pool_avail(&cluster_512_pool),
pool_size(&cluster_512_pool));
d_trace(3, "%d not freed in cluster512_pool[%d]\n",
pool_size(&cluster_512_pool) - pool_avail(&cluster_512_pool),
pool_size(&cluster_512_pool),
pool_size(&cluster_512_pool));
if (pool_size(&cluster_1024_pool) != pool_avail(&cluster_1024_pool))
d_warn("%d not freed in cluster1024_pool[%d]",
pool_size(&cluster_1024_pool) - pool_avail(&cluster_1024_pool),
pool_size(&cluster_1024_pool));
d_trace(3, "%d not freed in cluster1024_pool[%d]\n",
pool_size(&cluster_1024_pool) - pool_avail(&cluster_1024_pool),
pool_size(&cluster_1024_pool),
pool_size(&cluster_1024_pool));
if (pool_size(&cluster_2048_pool) != pool_avail(&cluster_2048_pool))
d_warn("%d not freed in cluster2048_pool[%d]",
pool_size(&cluster_2048_pool) - pool_avail(&cluster_2048_pool),
pool_size(&cluster_2048_pool));
d_trace(3, "%d not freed in cluster2048_pool[%d]\n",
pool_size(&cluster_2048_pool) - pool_avail(&cluster_2048_pool),
pool_size(&cluster_2048_pool),
pool_size(&cluster_2048_pool));
if (pool_size(&cluster_8192_pool) != pool_avail(&cluster_8192_pool))
d_warn("%d not freed in cluster8192_pool[%d]",
pool_size(&cluster_8192_pool) - pool_avail(&cluster_8192_pool),
pool_size(&cluster_8192_pool));
d_trace(3, "%d not freed in cluster8192_pool[%d]\n",
pool_size(&cluster_8192_pool) - pool_avail(&cluster_8192_pool),
pool_size(&cluster_8192_pool));
}

View File

@ -56,17 +56,16 @@ status_t proc_create(proc_id *id,
semaphore_post(new->sem1);
d_trace(3, "core proc try to terminate\n");
rv = new->start_func((proc_id)new, new->data);
d_trace(3, "start_func done(rv = %d)\n", rv);
d_trace(3, "[%d] start_func done(rv = %d)\n", new->proc, rv);
semaphore_wait(new->sem2);
d_trace(3, "received post from parent\n");
d_trace(3, "[%d] semaphore wait in child\n", new->proc);
if (rv == CORE_OK)
{
new->stop_func(new->proc, new->data);
d_trace(3, "stop_func done(rv = %d)\n", rv);
d_trace(3, "[%d] stop_func done(rv = %d)\n", new->proc, rv);
}
semaphore_post(new->sem1);
@ -74,10 +73,10 @@ status_t proc_create(proc_id *id,
semaphore_delete(new->sem1);
semaphore_delete(new->sem2);
pool_free_node(&proc_pool, new);
d_trace(3, "delete core proc memory\n");
d_trace(3, "[%d] delete core proc memory in child\n", new->proc);
core_terminate();
d_trace(3, "core proc terminate...done\n");
d_trace(3, "[%d[ core proc terminate...done\n", new->proc);
_exit(EXIT_SUCCESS);
}
@ -95,21 +94,19 @@ status_t proc_delete(proc_id id)
{
proc_t *proc = (proc_t *)id;
semaphore_post(proc->sem2);
d_trace(3, "[%d] post semaphore to start deleting\n", proc->proc);
d_trace(3, "core_kill for %d\n", proc->proc);
#if 0
core_kill(proc->proc, SIGTERM);
d_trace(3, "core_kill done for %d\n", proc->proc);
#endif
d_trace(3, "proc_delete wait\n");
semaphore_post(proc->sem2);
semaphore_wait(proc->sem1);
d_trace(3, "proc_delete done\n");
d_trace(3, "[%d] semaphore wait in parent\n", proc->proc);
semaphore_delete(proc->sem1);
semaphore_delete(proc->sem2);
pool_free_node(&proc_pool, proc);
d_trace(3, "delete proc-related memory\n");
d_trace(3, "[%d] delete core proc memory in parent\n", proc->proc);
return CORE_OK;
}

View File

@ -40,17 +40,12 @@ ED4(c_uint8_t version:3;,
};
} __attribute__ ((packed)) gtpv2c_header_t;
static int gtp_xact_pool_initialized = 0;
index_declare(gtp_xact_pool, gtp_xact_t, SIZE_OF_GTP_XACT_POOL);
status_t gtp_xact_init(gtp_xact_ctx_t *context,
tm_service_t *tm_service, c_uintptr_t event)
{
if (gtp_xact_pool_initialized == 0)
{
index_init(&gtp_xact_pool, SIZE_OF_GTP_XACT_POOL);
}
gtp_xact_pool_initialized = 1;
index_init(&gtp_xact_pool, SIZE_OF_GTP_XACT_POOL);
memset(context, 0, sizeof(gtp_xact_ctx_t));
@ -64,16 +59,15 @@ status_t gtp_xact_init(gtp_xact_ctx_t *context,
status_t gtp_xact_final(void)
{
if (gtp_xact_pool_initialized == 1 &&
pool_size(&gtp_xact_pool) == pool_avail(&gtp_xact_pool))
{
d_trace(1, "%d not freed in gtp_xact_pool[%d] of GTP Transaction\n",
if (pool_size(&gtp_xact_pool) != pool_avail(&gtp_xact_pool))
d_warn("%d not freed in gtp_xact_pool[%d] of GTP Transaction",
pool_size(&gtp_xact_pool) - pool_avail(&gtp_xact_pool),
pool_size(&gtp_xact_pool));
index_final(&gtp_xact_pool);
gtp_xact_pool_initialized = 0;
}
d_trace(3, "%d not freed in gtp_xact_pool[%d] of GTP Transaction\n",
pool_size(&gtp_xact_pool) - pool_avail(&gtp_xact_pool),
pool_size(&gtp_xact_pool));
index_final(&gtp_xact_pool);
return CORE_OK;
}

View File

@ -4,7 +4,7 @@
#include "core_debug.h"
#include "core_param.h"
#include "core_file.h"
#include "core_signal.h"
#include "core_thread.h"
#include <stdio.h>
#include <sys/socket.h>
@ -17,11 +17,9 @@
#define FILE_CHECK_CYCLE 15
static char g_buffer[1024];
static char g_path[MAX_FILENAME_SIZE] = "wemania.log";
static char g_path[MAX_FILENAME_SIZE] = "nextepc.log";
static file_t *g_file = NULL;
static int request_stop = 0;
status_t log_file_backup()
{
status_t rv;
@ -154,8 +152,7 @@ int logger_start(const char *path)
return -1;
}
while (!request_stop)
while (!thread_should_stop())
{
timer_val.tv_sec = 0;
timer_val.tv_usec = 50000;
@ -217,8 +214,3 @@ int logger_start(const char *path)
return 0;
}
void logger_stop()
{
request_stop = 1;
}

View File

@ -2,20 +2,14 @@
#include "core_debug.h"
#include "core_thread.h"
#include "core_net.h"
#include "core_signal.h"
#include "core_proc.h"
#include "core_semaphore.h"
#include "context.h"
#include "logger.h"
#include "app.h"
static proc_id logger_proc;
static status_t PROC_FUNC logger_start_func(proc_id id, void *data);
static status_t PROC_FUNC logger_stop_func(proc_id id, void *data);
static void check_signal(int signum);
static thread_id logger_thread;
static void *THREAD_FUNC logger_main(thread_id id, void *data);
status_t app_will_initialize(char *config_path, char *log_path)
{
@ -34,10 +28,6 @@ status_t app_will_initialize(char *config_path, char *log_path)
if (others)
{
d_trace_level(&_app_init, others);
#if 0
extern int _proc;
d_trace_level(&_proc, 3);
#endif
}
if (log_path)
@ -45,8 +35,9 @@ status_t app_will_initialize(char *config_path, char *log_path)
if (context_self()->log_path)
{
rv = proc_create(&logger_proc,
logger_start_func, logger_stop_func, context_self()->log_path);
d_print(" Logging '%s'\n", context_self()->log_path);
rv = thread_create(&logger_thread, NULL,
logger_main, context_self()->log_path);
if (rv != CORE_OK) return rv;
}
@ -77,55 +68,19 @@ void app_did_terminate(void)
if (context_self()->log_path)
{
proc_delete(logger_proc);
thread_delete(logger_thread);
}
context_final();
}
static status_t PROC_FUNC logger_start_func(proc_id id, void *data)
static void *THREAD_FUNC logger_main(thread_id id, void *data)
{
status_t rv;
int ret;
char *path = data;
umask(027);
ret = logger_start(path);
d_assert(ret == 0, return NULL, "Failed to intialize Logger");
signal_unblock(SIGINT);
signal_unblock(SIGTERM);
core_signal(SIGINT, check_signal);
core_signal(SIGTERM, check_signal);
d_print(" Logging '%s'\n", path);
rv = logger_start(path);
d_assert(rv == CORE_OK, return rv, "Failed to intialize Logger");
return CORE_OK;
}
static status_t PROC_FUNC logger_stop_func(proc_id id, void *data)
{
d_trace(1, "LOGGER terminate...done\n");
return CORE_OK;
}
static void check_signal(int signum)
{
switch (signum)
{
case SIGTERM:
case SIGINT:
{
d_info("%s received",
signum == SIGTERM ? "SIGTERM" : "SIGINT");
logger_stop();
break;
}
default:
{
d_error("Unknown signal number = %d\n", signum);
break;
}
}
return NULL;
}

View File

@ -606,7 +606,12 @@ void mme_s6a_final(void)
{
d_assert(fd_sess_handler_destroy(&mme_s6a_reg, NULL) == 0,,);
d_trace(1, "%d not freed in sess_state_pool[%d] of S6A-SM\n",
if (pool_size(&sess_state_pool) != pool_avail(&sess_state_pool))
d_warn("%d not freed in sess_state_pool[%d] of S6A-SM",
pool_size(&sess_state_pool) - pool_avail(&sess_state_pool),
pool_size(&sess_state_pool));
d_trace(3, "%d not freed in sess_state_pool[%d] of S6A-SM\n",
pool_size(&sess_state_pool) - pool_avail(&sess_state_pool),
pool_size(&sess_state_pool));

View File

@ -49,10 +49,21 @@ status_t pgw_context_final()
gtp_xact_delete_all(&self.s5c_node);
pgw_sess_remove_all();
d_trace(1, "%d not freed in pgw_sess_pool[%d] in PGW-Context\n",
if (index_size(&pgw_sess_pool) != pool_avail(&pgw_sess_pool))
d_warn("%d not freed in pgw_sess_pool[%d] in PGW-Context",
index_size(&pgw_sess_pool) - pool_avail(&pgw_sess_pool),
index_size(&pgw_sess_pool));
d_trace(3, "%d not freed in pgw_sess_pool[%d] in PGW-Context\n",
index_size(&pgw_sess_pool) - pool_avail(&pgw_sess_pool),
index_size(&pgw_sess_pool));
d_trace(1, "%d not freed in pgw_ip_pool[%d] in PGW-Context\n",
if (index_size(&pgw_ip_pool_pool) != pool_avail(&pgw_ip_pool_pool))
{
d_warn("%d not freed in pgw_ip_pool[%d] in PGW-Context",
index_size(&pgw_ip_pool_pool) - pool_avail(&pgw_ip_pool_pool),
index_size(&pgw_ip_pool_pool));
}
d_trace(3, "%d not freed in pgw_ip_pool[%d] in PGW-Context\n",
index_size(&pgw_ip_pool_pool) - pool_avail(&pgw_ip_pool_pool),
index_size(&pgw_ip_pool_pool));

View File

@ -50,7 +50,11 @@ status_t sgw_context_final()
sgw_sess_remove_all();
d_trace(1, "%d not freed in sgw_sess_pool[%d] in SGW-Context\n",
if (index_size(&sgw_sess_pool) != pool_avail(&sgw_sess_pool))
d_warn("%d not freed in sgw_sess_pool[%d] in SGW-Context",
index_size(&sgw_sess_pool) - pool_avail(&sgw_sess_pool),
index_size(&sgw_sess_pool));
d_trace(3, "%d not freed in sgw_sess_pool[%d] in SGW-Context\n",
index_size(&sgw_sess_pool) - pool_avail(&sgw_sess_pool),
index_size(&sgw_sess_pool));
index_final(&sgw_bearer_pool);