Commit f6656c69 authored by laurent's avatar laurent

enhance log system

parent c4fdf44d
...@@ -68,6 +68,10 @@ mapping log_options[] = { ...@@ -68,6 +68,10 @@ mapping log_options[] = {
{NULL,-1} {NULL,-1}
}; };
#define COMP_NAME(CoMP) #CoMP,
static const char *predef_names[]={
FOREACH_COMP(COMP_NAME)
};
mapping log_maskmap[] = LOG_MASKMAP_INIT; mapping log_maskmap[] = LOG_MASKMAP_INIT;
...@@ -248,12 +252,7 @@ void log_getconfig(log_t *g_log) { ...@@ -248,12 +252,7 @@ void log_getconfig(log_t *g_log) {
memset(logparams_logfile, 0, sizeof(paramdef_t)*MAX_LOG_PREDEF_COMPONENTS); memset(logparams_logfile, 0, sizeof(paramdef_t)*MAX_LOG_PREDEF_COMPONENTS);
for (int i=MIN_LOG_COMPONENTS; i < MAX_LOG_PREDEF_COMPONENTS; i++) { for (int i=MIN_LOG_COMPONENTS; i < MAX_LOG_PREDEF_COMPONENTS; i++) {
if(g_log->log_component[i].name == NULL) { AssertFatal(g_log->log_component[i].name, "Must have been intialized before\n");
g_log->log_component[i].name = malloc(16);
sprintf((char *)g_log->log_component[i].name,"comp%i?",i);
logparams_logfile[i].paramflags = PARAMFLAG_DONOTREAD;
logparams_level[i].paramflags = PARAMFLAG_DONOTREAD;
}
sprintf(logparams_level[i].optname, LOG_CONFIG_LEVEL_FORMAT, g_log->log_component[i].name); sprintf(logparams_level[i].optname, LOG_CONFIG_LEVEL_FORMAT, g_log->log_component[i].name);
sprintf(logparams_logfile[i].optname, LOG_CONFIG_LOGFILE_FORMAT, g_log->log_component[i].name); sprintf(logparams_logfile[i].optname, LOG_CONFIG_LOGFILE_FORMAT, g_log->log_component[i].name);
...@@ -282,8 +281,8 @@ void log_getconfig(log_t *g_log) { ...@@ -282,8 +281,8 @@ void log_getconfig(log_t *g_log) {
/* now set the log levels and infile option, according to what we read */ /* now set the log levels and infile option, according to what we read */
for (int i=MIN_LOG_COMPONENTS; i < MAX_LOG_PREDEF_COMPONENTS; i++) { for (int i=MIN_LOG_COMPONENTS; i < MAX_LOG_PREDEF_COMPONENTS; i++) {
g_log->log_component[i].level = map_str_to_int(log_level_names, *(logparams_level[i].strptr)); int level = map_str_nocase_to_int(log_level_names, *(logparams_level[i].strptr));
set_log(i, g_log->log_component[i].level); set_log(i, level);
if (*(logparams_logfile[i].uptr) == 1) if (*(logparams_logfile[i].uptr) == 1)
set_component_filelog(i); set_component_filelog(i);
...@@ -323,7 +322,7 @@ void log_getconfig(log_t *g_log) { ...@@ -323,7 +322,7 @@ void log_getconfig(log_t *g_log) {
set_glog_onlinelog(consolelog); set_glog_onlinelog(consolelog);
} }
int register_log_component(char *name, char *fext, int compidx) { int register_log_component(const char *name, char *fext, const int compidx) {
int computed_compidx=compidx; int computed_compidx=compidx;
if (strlen(fext) > 3) { if (strlen(fext) > 3) {
...@@ -345,6 +344,7 @@ int register_log_component(char *name, char *fext, int compidx) { ...@@ -345,6 +344,7 @@ int register_log_component(char *name, char *fext, int compidx) {
g_log->log_component[computed_compidx].filelog = 0; g_log->log_component[computed_compidx].filelog = 0;
g_log->log_component[computed_compidx].filelog_name = malloc(strlen(name)+16);/* /tmp/<name>.%s */ g_log->log_component[computed_compidx].filelog_name = malloc(strlen(name)+16);/* /tmp/<name>.%s */
sprintf(g_log->log_component[computed_compidx].filelog_name,"/tmp/%s.%s",name,fext); sprintf(g_log->log_component[computed_compidx].filelog_name,"/tmp/%s.%s",name,fext);
set_log(computed_compidx, OAILOG_ERR);
} else { } else {
fprintf(stderr,"{LOG} %s %d Couldn't register componemt %s\n",__FILE__,__LINE__,name); fprintf(stderr,"{LOG} %s %d Couldn't register componemt %s\n",__FILE__,__LINE__,name);
} }
...@@ -362,45 +362,18 @@ int logInit (void) { ...@@ -362,45 +362,18 @@ int logInit (void) {
} }
memset(g_log,0,sizeof(log_t)); memset(g_log,0,sizeof(log_t));
register_log_component("PHY","log",PHY); for (int i=MIN_LOG_COMPONENTS; i < MAX_LOG_PREDEF_COMPONENTS; i++) {
register_log_component("MAC","log",MAC); register_log_component(predef_names[i], "log", i+MIN_LOG_COMPONENTS);
register_log_component("OPT","log",OPT); }
register_log_component("RLC","log",RLC);
register_log_component("PDCP","log",PDCP);
register_log_component("RRC","log",RRC);
register_log_component("OMG","csv",OMG); register_log_component("OMG","csv",OMG);
register_log_component("OTG","log",OTG);
register_log_component("OTG_LATENCY","dat",OTG_LATENCY); register_log_component("OTG_LATENCY","dat",OTG_LATENCY);
register_log_component("OTG_LATENCY_BG","dat",OTG_LATENCY_BG); register_log_component("OTG_LATENCY_BG","dat",OTG_LATENCY_BG);
register_log_component("OTG_GP","dat",OTG_GP); register_log_component("OTG_GP","dat",OTG_GP);
register_log_component("OTG_GP_BG","dat",OTG_GP_BG); register_log_component("OTG_GP_BG","dat",OTG_GP_BG);
register_log_component("OTG_JITTER","dat",OTG_JITTER); register_log_component("OTG_JITTER","dat",OTG_JITTER);
register_log_component("OCG","",OCG);
register_log_component("PERF","",PERF);
register_log_component("OIP","",OIP);
register_log_component("CLI","",CLI);
register_log_component("MSC","log",MSC);
register_log_component("OCM","log",OCM);
register_log_component("HW","",HW);
register_log_component("OSA","",OSA);
register_log_component("eRAL","",RAL_ENB);
register_log_component("mRAL","",RAL_UE);
register_log_component("ENB_APP","log",ENB_APP);
register_log_component("FLEXRAN_AGENT","log",FLEXRAN_AGENT);
register_log_component("TMR","",TMR);
register_log_component("USIM","txt",USIM); register_log_component("USIM","txt",USIM);
register_log_component("SIM","txt",SIM); register_log_component("SIM","txt",SIM);
/* following log component are used for the localization*/
register_log_component("LOCALIZE","log",LOCALIZE);
register_log_component("NAS","log",NAS);
register_log_component("UDP","",UDP_);
register_log_component("GTPV1U","",GTPU);
register_log_component("S1AP","",S1AP);
register_log_component("X2AP","",X2AP);
register_log_component("SCTP","",SCTP);
register_log_component("X2AP","",X2AP);
register_log_component("LOADER","log",LOADER);
register_log_component("ASN","log",ASN);
for (int i=0 ; log_level_names[i].name != NULL ; i++) for (int i=0 ; log_level_names[i].name != NULL ; i++)
g_log->level2string[i] = toupper(log_level_names[i].name[0]); // uppercased first letter of level name g_log->level2string[i] = toupper(log_level_names[i].name[0]); // uppercased first letter of level name
...@@ -497,10 +470,8 @@ int set_log(int component, int level) { ...@@ -497,10 +470,8 @@ int set_log(int component, int level) {
component, MIN_LOG_COMPONENTS, MAX_LOG_COMPONENTS); component, MIN_LOG_COMPONENTS, MAX_LOG_COMPONENTS);
DevCheck((level < NUM_LOG_LEVEL) && (level >= OAILOG_DISABLE), level, NUM_LOG_LEVEL, DevCheck((level < NUM_LOG_LEVEL) && (level >= OAILOG_DISABLE), level, NUM_LOG_LEVEL,
OAILOG_ERR); OAILOG_ERR);
if ( g_log->log_component[component].level != OAILOG_DISABLE ) if ( g_log->log_component[component].level != OAILOG_DISABLE )
g_log->log_component[component].savedlevel = g_log->log_component[component].level; g_log->log_component[component].savedlevel = level;
g_log->log_component[component].level = level; g_log->log_component[component].level = level;
return 0; return 0;
} }
...@@ -588,6 +559,20 @@ int map_str_to_int(mapping *map, const char *str) { ...@@ -588,6 +559,20 @@ int map_str_to_int(mapping *map, const char *str) {
map++; map++;
} }
} }
int map_str_nocase_to_int(mapping *map, const char *str) {
while (1) {
if (map->name == NULL) {
return(-1);
}
printf("cmp: %s, %s, res %d\n", map->name, str, strcasecmp(map->name, str));
if (!strcasecmp(map->name, str)) {
printf ("found \n");
return(map->value);
}
map++;
}
}
/* map an int to a string. Takes a mapping array and a value */ /* map an int to a string. Takes a mapping array and a value */
char *map_int_to_str(mapping *map, int val) { char *map_int_to_str(mapping *map, int val) {
......
...@@ -176,56 +176,57 @@ extern "C" { ...@@ -176,56 +176,57 @@ extern "C" {
#define SET_LOG_DUMP(B) g_log->dump_mask = (g_log->dump_mask | B) #define SET_LOG_DUMP(B) g_log->dump_mask = (g_log->dump_mask | B)
#define CLEAR_LOG_DUMP(B) g_log->dump_mask = (g_log->dump_mask & (~B)) #define CLEAR_LOG_DUMP(B) g_log->dump_mask = (g_log->dump_mask & (~B))
#define FOREACH_COMP(COMP) \
COMP(PHY) \
COMP(MAC) \
COMP(EMU) \
COMP(SIM) \
COMP(OCG) \
COMP(OMG) \
COMP(OPT) \
COMP(OTG) \
COMP(OTG_LATENCY) \
COMP(OTG_LATENCY_BG) \
COMP(OTG_GP) \
COMP(OTG_GP_BG) \
COMP(OTG_JITTER) \
COMP(RLC) \
COMP(PDCP) \
COMP(RRC) \
COMP(NAS) \
COMP( PERF) \
COMP(OIP) \
COMP(CLI) \
COMP(MSC) \
COMP(OCM) \
COMP(UDP_) \
COMP(GTPU) \
COMP(SPGW) \
COMP(S1AP) \
COMP(SCTP) \
COMP(HW) \
COMP(OSA) \
COMP(RAL_ENB) \
COMP(RAL_UE) \
COMP(ENB_APP) \
COMP(FLEXRAN_AGENT) \
COMP(TMR) \
COMP(USIM) \
COMP(LOCALIZE) \
COMP(X2AP) \
COMP(GNB_APP) \
COMP(NR_RRC) \
COMP(NR_MAC) \
COMP(NR_PHY) \
COMP(LOADER) \
COMP(ASN)
#define COMP_ENUM(CoMP) CoMP,
#define MIN_LOG_COMPONENTS 0
typedef enum { typedef enum {
MIN_LOG_COMPONENTS = 0, FOREACH_COMP(COMP_ENUM)
PHY = MIN_LOG_COMPONENTS, MAX_LOG_PREDEF_COMPONENTS
MAC, } comp_name_t;
EMU,
SIM,
OCG,
OMG,
OPT,
OTG,
OTG_LATENCY,
OTG_LATENCY_BG,
OTG_GP,
OTG_GP_BG,
OTG_JITTER,
RLC,
PDCP,
RRC,
NAS,
PERF,
OIP,
CLI,
MSC,
OCM,
UDP_,
GTPU,
SPGW,
S1AP,
SCTP,
HW,
OSA,
RAL_ENB,
RAL_UE,
ENB_APP,
FLEXRAN_AGENT,
TMR,
USIM,
LOCALIZE,
X2AP,
GNB_APP,
NR_RRC,
NR_MAC,
NR_PHY,
LOADER,
ASN,
MAX_LOG_PREDEF_COMPONENTS,
}
comp_name_t;
#define MAX_LOG_DYNALLOC_COMPONENTS 20 #define MAX_LOG_DYNALLOC_COMPONENTS 20
#define MAX_LOG_COMPONENTS (MAX_LOG_PREDEF_COMPONENTS + MAX_LOG_DYNALLOC_COMPONENTS) #define MAX_LOG_COMPONENTS (MAX_LOG_PREDEF_COMPONENTS + MAX_LOG_DYNALLOC_COMPONENTS)
...@@ -300,11 +301,12 @@ void set_component_filelog(int comp); ...@@ -300,11 +301,12 @@ void set_component_filelog(int comp);
void close_component_filelog(int comp); void close_component_filelog(int comp);
void set_component_consolelog(int comp); void set_component_consolelog(int comp);
int map_str_to_int(mapping *map, const char *str); int map_str_to_int(mapping *map, const char *str);
int map_str_nocase_to_int(mapping *map, const char *str);
char *map_int_to_str(mapping *map, int val); char *map_int_to_str(mapping *map, int val);
void logClean (void); void logClean (void);
int is_newline( char *str, int size); int is_newline( char *str, int size);
int register_log_component(char *name, char *fext, int compidx); int register_log_component(const char *name, char *fext, const int compidx);
/* @}*/ /* @}*/
...@@ -360,7 +362,9 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int ...@@ -360,7 +362,9 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int
#define LOG_DUMP_DOUBLE 1 #define LOG_DUMP_DOUBLE 1
// debugging macros // debugging macros
#define LOG_F LOG_I /* because LOG_F was originaly to dump a message or buffer but is also used as a regular level...., to dump use LOG_DUMPMSG */ #define LOG_F LOG_I /* because LOG_F was originaly to dump a message or buffer but is also used as a regular level...., to dump use LOG_DUMPMSG */
# if T_TRACER # ifndef T_TRACER
#define T_stdout 1
#endif
/* per component, level dependant macros */ /* per component, level dependant macros */
# define LOG_E(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_ERR ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_ERR, x) ;} else { T(T_LEGACY_ ## c ## _ERROR, T_PRINTF(x)) ;}} while (0) # define LOG_E(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_ERR ) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_ERR, x) ;} else { T(T_LEGACY_ ## c ## _ERROR, T_PRINTF(x)) ;}} while (0)
# define LOG_W(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_WARNING) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_WARNING, x) ;} else { T(T_LEGACY_ ## c ## _WARNING, T_PRINTF(x)) ;}} while (0) # define LOG_W(c, x...) do { if (T_stdout) { if( g_log->log_component[c].level >= OAILOG_WARNING) logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_WARNING, x) ;} else { T(T_LEGACY_ ## c ## _WARNING, T_PRINTF(x)) ;}} while (0)
...@@ -377,21 +381,7 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int ...@@ -377,21 +381,7 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int
# define LOG_DUMPFLAG(D) (g_log->dump_mask & D) # define LOG_DUMPFLAG(D) (g_log->dump_mask & D)
# define LOG_M(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0)/* */ # define LOG_M(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0)/* */
/* define variable only used in LOG macro's */ /* define variable only used in LOG macro's */
# define LOG_VAR(A,B) A B
# else /* T_TRACER: remove all debugging and tracing messages, except errors */
# define LOG_I(c, x...) do {logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x) ; } while(0)/* */
# define LOG_W(c, x...) do {logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_WARNING, x) ; } while(0)/* */
# define LOG_E(c, x...) do {logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_ERR, x) ; } while(0)/* */
# define LOG_D(c, x...) do {logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_DEBUG, x) ; } while(0)/* */
# define LOG_T(c, x...) /* */
# define LOG_DUMPMSG(c, b, s, x...) /* */
# define nfapi_log(FILE, FNC, LN, COMP, LVL, FMT...)
# define LOG_DEBUGFLAG(D) ( 0 )
# define LOG_DUMPFLAG(D) ( 0 )
# define LOG_M(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format);} while(0)
# define LOG_VAR(A,B)
# endif /* T_TRACER */
/* avoid warnings for variables only used in LOG macro's but set outside debug section */ /* avoid warnings for variables only used in LOG macro's but set outside debug section */
#define GCC_NOTUSED __attribute__((unused)) #define GCC_NOTUSED __attribute__((unused))
#define LOG_USEDINLOG_VAR(A,B) GCC_NOTUSED A B #define LOG_USEDINLOG_VAR(A,B) GCC_NOTUSED A B
......
...@@ -197,7 +197,8 @@ void start_background_system(void) { ...@@ -197,7 +197,8 @@ void start_background_system(void) {
} }
void threadCreate(pthread_t* t, void * (*func)(void*), void * param, char* name, int affinity, int priority){ void threadCreate_impl(pthread_t* t, void * (*func)(void*), void * param, char* name, int affinity, int priority, const char *functionName){
LOG_I(TMR, "creating thread: %s, for function %s, priotity %d\n", name, functionName, priority);
pthread_attr_t attr; pthread_attr_t attr;
pthread_attr_init(&attr); pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
......
...@@ -45,7 +45,10 @@ void start_background_system(void); ...@@ -45,7 +45,10 @@ void start_background_system(void);
void set_latency_target(void); void set_latency_target(void);
void configure_linux(void); void configure_linux(void);
void threadCreate(pthread_t* t, void * (*func)(void*), void * param, char* name, int affinity, int priority); void threadCreate_impl(pthread_t* t, void * (*func)(void*), void * param, char* name, int affinity, int priority, const char * funcName);
#define threadCreate(t, f, p, n , a, prio) threadCreate_impl(t, f, p, n , a, prio, #f)
#define OAI_PRIORITY_RT_LOW sched_get_priority_min(SCHED_FIFO) #define OAI_PRIORITY_RT_LOW sched_get_priority_min(SCHED_FIFO)
#define OAI_PRIORITY_RT sched_get_priority_max(SCHED_FIFO)-10 #define OAI_PRIORITY_RT sched_get_priority_max(SCHED_FIFO)-10
#define OAI_PRIORITY_RT_MAX sched_get_priority_max(SCHED_FIFO) #define OAI_PRIORITY_RT_MAX sched_get_priority_max(SCHED_FIFO)
......
...@@ -1265,11 +1265,11 @@ void init_RU(const char *rf_config_file) { ...@@ -1265,11 +1265,11 @@ void init_RU(const char *rf_config_file) {
} }
int main( int argc, char **argv ) { int main( int argc, char **argv ) {
start_background_system();
AssertFatal(load_configmodule(argc,argv) != NULL, ""); AssertFatal(load_configmodule(argc,argv) != NULL, "");
logInit();
start_background_system();
mode = normal_txrx; mode = normal_txrx;
configure_linux(); configure_linux();
logInit();
printf("Reading in command-line options\n"); printf("Reading in command-line options\n");
get_options (); get_options ();
set_taus_seed (0); set_taus_seed (0);
......
...@@ -358,7 +358,7 @@ int esm_proc_pdn_connectivity_accept(nas_user_t *user, int pti, esm_proc_pdn_typ ...@@ -358,7 +358,7 @@ int esm_proc_pdn_connectivity_accept(nas_user_t *user, int pti, esm_proc_pdn_typ
int pid = RETURNerror; int pid = RETURNerror;
char apn_first_char[4]; char apn_first_char[4];
LOG_VAR(char, str[128]); LOG_USEDINLOG_VAR(char, str[128]);
if (isprint(apn->value[0])) { if (isprint(apn->value[0])) {
apn_first_char[0] = '\0'; apn_first_char[0] = '\0';
......
...@@ -284,7 +284,7 @@ NETWORK_CONTROLLER : ...@@ -284,7 +284,7 @@ NETWORK_CONTROLLER :
global_log_verbosity ="medium"; global_log_verbosity ="medium";
hw_log_level ="info"; hw_log_level ="info";
hw_log_verbosity ="medium"; hw_log_verbosity ="medium";
phy_log_level ="info"; phy_log_level ="debug";
phy_log_verbosity ="medium"; phy_log_verbosity ="medium";
mac_log_level ="info"; mac_log_level ="info";
mac_log_verbosity ="high"; mac_log_verbosity ="high";
......
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