Commit afcdb1e6 authored by Haruki NAOI's avatar Haruki NAOI

enb-log-mem_sp2.patch into closed_item

(cherry picked from commit 3432385280c3155ee63a54be7c2e4846a17299de)

# Conflicts:
#	openair2/UTIL/LOG/log.c
parent 7b4298a6
...@@ -35,9 +35,11 @@ ...@@ -35,9 +35,11 @@
#ifndef ASSERTIONS_H_ #ifndef ASSERTIONS_H_
#define ASSERTIONS_H_ #define ASSERTIONS_H_
void output_log_mem(void);
#define _Assert_Exit_ \ #define _Assert_Exit_ \
{ \ { \
fprintf(stderr, "\nExiting execution\n"); \ fprintf(stderr, "\nExiting execution\n"); \
output_log_mem(); \
display_backtrace(); \ display_backtrace(); \
fflush(stdout); \ fflush(stdout); \
fflush(stderr); \ fflush(stderr); \
......
...@@ -117,16 +117,19 @@ int signal_handle(int *end) ...@@ -117,16 +117,19 @@ int signal_handle(int *end)
case SIGUSR1: case SIGUSR1:
SIG_DEBUG("Received SIGUSR1\n"); SIG_DEBUG("Received SIGUSR1\n");
*end = 1; *end = 1;
output_log_mem();
break; break;
case SIGSEGV: /* Fall through */ case SIGSEGV: /* Fall through */
case SIGABRT: case SIGABRT:
SIG_DEBUG("Received SIGABORT\n"); SIG_DEBUG("Received SIGABORT\n");
output_log_mem();
backtrace_handle_signal(&info); backtrace_handle_signal(&info);
break; break;
case SIGINT: case SIGINT:
printf("Received SIGINT\n"); printf("Received SIGINT\n");
output_log_mem();
itti_send_terminate_message(TASK_UNKNOWN); itti_send_terminate_message(TASK_UNKNOWN);
*end = 1; *end = 1;
break; break;
......
...@@ -48,6 +48,26 @@ ...@@ -48,6 +48,26 @@
// main log variables // main log variables
log_t *g_log; log_t *g_log;
typedef struct {
char* buf_p;
int buf_index;
int enable_flag;
} log_mem_cnt_t;
log_mem_cnt_t log_mem_d[2];
int log_mem_flag=0;
int log_mem_multi=1;
volatile int log_mem_side=0;
pthread_mutex_t log_mem_lock;
pthread_cond_t log_mem_notify;
pthread_t log_mem_thread;
int log_mem_file_cnt=0;
volatile int log_mem_write_flag=0;
volatile int log_mem_write_side=0;
char __log_mem_filename[1024]={0};
char * log_mem_filename = &__log_mem_filename[0];
mapping log_level_names[] = { mapping log_level_names[] = {
{"emerg", LOG_EMERG}, {"emerg", LOG_EMERG},
{"alert", LOG_ALERT}, {"alert", LOG_ALERT},
...@@ -494,6 +514,81 @@ int logInit (void) ...@@ -494,6 +514,81 @@ int logInit (void)
return 0; return 0;
} }
extern int oai_exit;
void * log_mem_write(void)
{
int *fp;
char f_name[1024];
struct timespec slp_tm;
slp_tm.tv_sec = 0;
slp_tm.tv_nsec = 10000;
pthread_setname_np( pthread_self(), "log_mem_write");
while (!oai_exit) {
pthread_mutex_lock(&log_mem_lock);
log_mem_write_flag=0;
pthread_cond_wait(&log_mem_notify, &log_mem_lock);
log_mem_write_flag=1;
pthread_mutex_unlock(&log_mem_lock);
// write!
if(log_mem_d[log_mem_write_side].enable_flag==0){
if(log_mem_file_cnt>1){
log_mem_file_cnt=1;
printf("log over write!!!\n");
}
snprintf(f_name,1024, "%s_%d.log",log_mem_filename,log_mem_file_cnt);
fp=open(f_name, O_WRONLY | O_CREAT, 0666);
write(fp, log_mem_d[log_mem_write_side].buf_p, log_mem_d[log_mem_write_side].buf_index);
close(fp);
log_mem_file_cnt++;
log_mem_d[log_mem_write_side].buf_index=0;
log_mem_d[log_mem_write_side].enable_flag=1;
}else{
printf("If you'd like to write log, you should set enable flag to 0!!!\n");
nanosleep(&slp_tm,NULL);
}
}
}
int logInit_log_mem (void)
{
if(log_mem_flag==1){
if(log_mem_multi==1){
printf("log-mem multi!!!\n");
log_mem_d[0].buf_p = malloc(LOG_MEM_SIZE);
log_mem_d[0].buf_index=0;
log_mem_d[0].enable_flag=1;
log_mem_d[1].buf_p = malloc(LOG_MEM_SIZE);
log_mem_d[1].buf_index=0;
log_mem_d[1].enable_flag=1;
log_mem_side=0;
if ((pthread_mutex_init (&log_mem_lock, NULL) != 0)
|| (pthread_cond_init (&log_mem_notify, NULL) != 0)) {
log_mem_d[1].enable_flag=0;
return;
}
pthread_create(&log_mem_thread, NULL, log_mem_write, (void*)NULL);
}else{
printf("log-mem single!!!\n");
log_mem_d[0].buf_p = malloc(LOG_MEM_SIZE);
log_mem_d[0].buf_index=0;
log_mem_d[0].enable_flag=1;
log_mem_d[1].enable_flag=0;
log_mem_side=0;
}
}else{
log_mem_d[0].buf_p=NULL;
log_mem_d[1].buf_p=NULL;
log_mem_d[0].enable_flag=0;
log_mem_d[1].enable_flag=0;
}
printf("log init done\n");
return 0;
}
void nfapi_log(char *file, char *func, int line, int comp, int level, const char* format, va_list args) void nfapi_log(char *file, char *func, int line, int comp, int level, const char* format, va_list args)
{ {
//logRecord_mt(file,func,line, pthread_self(), comp, level, format, ##args) //logRecord_mt(file,func,line, pthread_self(), comp, level, format, ##args)
...@@ -1295,6 +1390,7 @@ void logRecord_mt(const char *file, const char *func, int line, int comp, ...@@ -1295,6 +1390,7 @@ void logRecord_mt(const char *file, const char *func, int line, int comp,
* big enough so that the buffer is never full. * big enough so that the buffer is never full.
*/ */
char log_buffer[MAX_LOG_TOTAL]; char log_buffer[MAX_LOG_TOTAL];
int temp_index;
/* for no gcc warnings */ /* for no gcc warnings */
(void)log_start; (void)log_start;
...@@ -1392,7 +1488,41 @@ void logRecord_mt(const char *file, const char *func, int line, int comp, ...@@ -1392,7 +1488,41 @@ void logRecord_mt(const char *file, const char *func, int line, int comp,
// OAI printf compatibility // OAI printf compatibility
if ((g_log->onlinelog == 1) && (level != LOG_FILE)) if ((g_log->onlinelog == 1) && (level != LOG_FILE))
if(log_mem_flag==1){
if(log_mem_d[log_mem_side].enable_flag==1){
temp_index=log_mem_d[log_mem_side].buf_index;
if(temp_index+len+1 < LOG_MEM_SIZE){
log_mem_d[log_mem_side].buf_index+=len;
memcpy(&log_mem_d[log_mem_side].buf_p[temp_index],log_buffer,len);
}else{
log_mem_d[log_mem_side].enable_flag=0;
if(log_mem_d[1-log_mem_side].enable_flag==1){
temp_index=log_mem_d[1-log_mem_side].buf_index;
if(temp_index+len+1 < LOG_MEM_SIZE){
log_mem_d[1-log_mem_side].buf_index+=len;
log_mem_side=1-log_mem_side;
memcpy(&log_mem_d[log_mem_side].buf_p[temp_index],log_buffer,len);
/* write down !*/
if (pthread_mutex_lock(&log_mem_lock) != 0) {
return;
}
if(log_mem_write_flag==0){
log_mem_write_side=1-log_mem_side;
if(pthread_cond_signal(&log_mem_notify) != 0) {
}
}
if(pthread_mutex_unlock(&log_mem_lock) != 0) {
return;
}
}else{
log_mem_d[1-log_mem_side].enable_flag=0;
}
}
}
}
}else{
fwrite(log_buffer, len, 1, stdout); fwrite(log_buffer, len, 1, stdout);
}
if (g_log->syslog) { if (g_log->syslog) {
syslog(g_log->level, "%s", log_buffer); syslog(g_log->level, "%s", log_buffer);
...@@ -1720,6 +1850,39 @@ void log_set_instance_type (log_instance_type_t instance) ...@@ -1720,6 +1850,39 @@ void log_set_instance_type (log_instance_type_t instance)
} }
#endif #endif
void output_log_mem(void){
int cnt,cnt2;
int *fp;
char f_name[1024];
if(log_mem_flag==1){
log_mem_d[0].enable_flag=0;
log_mem_d[1].enable_flag=0;
usleep(10); // wait for log writing
while(log_mem_write_flag==1){
usleep(100);
}
if(log_mem_multi==1){
snprintf(f_name,1024, "%s_%d.log",log_mem_filename,log_mem_file_cnt);
fp=open(f_name, O_WRONLY | O_CREAT, 0666);
write(fp, log_mem_d[0].buf_p, log_mem_d[0].buf_index);
close(fp);
free(log_mem_d[0].buf_p);
snprintf(f_name,1024, "%s_%d.log",log_mem_filename,log_mem_file_cnt);
fp=open(f_name, O_WRONLY | O_CREAT, 0666);
write(fp, log_mem_d[1].buf_p, log_mem_d[1].buf_index);
close(fp);
free(log_mem_d[1].buf_p);
}else{
fp=open(log_mem_filename, O_WRONLY | O_CREAT, 0666);
write(fp, log_mem_d[0].buf_p, log_mem_d[0].buf_index);
close(fp);
free(log_mem_d[0].buf_p);
}
}
}
#ifdef LOG_TEST #ifdef LOG_TEST
int main(int argc, char *argv[]) int main(int argc, char *argv[])
......
...@@ -253,6 +253,10 @@ typedef enum log_instance_type_e { ...@@ -253,6 +253,10 @@ typedef enum log_instance_type_e {
void log_set_instance_type (log_instance_type_t instance); void log_set_instance_type (log_instance_type_t instance);
#endif #endif
#define LOG_MEM_SIZE 100*1024*1024
#define LOG_MEM_FILE "./logmem.log"
int logInit_log_mem(void);
void output_log_mem(void);
/*--- INCLUDES ---------------------------------------------------------------*/ /*--- INCLUDES ---------------------------------------------------------------*/
# include "log_if.h" # include "log_if.h"
......
...@@ -32,3 +32,6 @@ extern int log_shutdown; ...@@ -32,3 +32,6 @@ extern int log_shutdown;
extern mapping log_level_names[]; extern mapping log_level_names[];
extern mapping log_verbosity_names[]; extern mapping log_verbosity_names[];
extern int log_mem_flag;
extern char * log_mem_filename;
...@@ -144,8 +144,7 @@ static char threequarter_fs=0; ...@@ -144,8 +144,7 @@ static char threequarter_fs=0;
uint32_t downlink_frequency[MAX_NUM_CCs][4]; uint32_t downlink_frequency[MAX_NUM_CCs][4];
int32_t uplink_frequency_offset[MAX_NUM_CCs][4]; int32_t uplink_frequency_offset[MAX_NUM_CCs][4];
char logmem_filename[1024] = {0};
#if defined(ENABLE_ITTI) #if defined(ENABLE_ITTI)
static char *itti_dump_file = NULL; static char *itti_dump_file = NULL;
#endif #endif
...@@ -605,6 +604,12 @@ static void get_options(void) { ...@@ -605,6 +604,12 @@ static void get_options(void) {
if (start_telnetsrv) { if (start_telnetsrv) {
load_module_shlib("telnetsrv",NULL,0); load_module_shlib("telnetsrv",NULL,0);
} }
if (strlen(logmem_filename) > 0) {
log_mem_filename = &logmem_filename[0];
log_mem_flag = 1;
printf("Enabling OPT for log save at memory %s\n",log_mem_filename);
logInit_log_mem();
}
if (UE_flag > 0) { if (UE_flag > 0) {
......
...@@ -182,6 +182,7 @@ extern int16_t dlsch_demod_shift; ...@@ -182,6 +182,7 @@ extern int16_t dlsch_demod_shift;
{"g" , CONFIG_HLP_LOGL, 0, uptr:&glog_level, defintval:0, TYPE_UINT, 0}, \ {"g" , CONFIG_HLP_LOGL, 0, uptr:&glog_level, defintval:0, TYPE_UINT, 0}, \
{"G" , CONFIG_HLP_LOGV, 0, uptr:&glog_verbosity, defintval:0, TYPE_UINT16, 0}, \ {"G" , CONFIG_HLP_LOGV, 0, uptr:&glog_verbosity, defintval:0, TYPE_UINT16, 0}, \
{"telnetsrv", CONFIG_HLP_TELN, PARAMFLAG_BOOL, uptr:&start_telnetsrv, defintval:0, TYPE_UINT, 0}, \ {"telnetsrv", CONFIG_HLP_TELN, PARAMFLAG_BOOL, uptr:&start_telnetsrv, defintval:0, TYPE_UINT, 0}, \
{"log-mem", NULL, 0, strptr:(char **)&logmem_filename, defstrval:"./logmem.log", TYPE_STRING, sizeof(logmem_filename)}, \
} }
#define CMDLINE_ONLINELOG_IDX 0 #define CMDLINE_ONLINELOG_IDX 0
#define CMDLINE_GLOGLEVEL_IDX 1 #define CMDLINE_GLOGLEVEL_IDX 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment