Commit bc6d1ad4 authored by Laurent THOMAS's avatar Laurent THOMAS

reduce the hot memory for LOG_x decision from 1.2MB to less than one mem page (4KB)

parent d1002cc7
...@@ -416,8 +416,8 @@ int register_log_component(char *name, ...@@ -416,8 +416,8 @@ int register_log_component(char *name,
g_log->log_component[computed_compidx].name = strdup(name); g_log->log_component[computed_compidx].name = strdup(name);
g_log->log_component[computed_compidx].stream = stdout; g_log->log_component[computed_compidx].stream = stdout;
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_rarely_used[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_rarely_used[computed_compidx].filelog_name, "/tmp/%s.%s", name, fext);
} else { } else {
fprintf(stderr,"{LOG} %s %d Couldn't register component %s\n",__FILE__,__LINE__,name); fprintf(stderr,"{LOG} %s %d Couldn't register component %s\n",__FILE__,__LINE__,name);
} }
...@@ -427,11 +427,13 @@ int register_log_component(char *name, ...@@ -427,11 +427,13 @@ int register_log_component(char *name,
static void unregister_all_log_components(void) static void unregister_all_log_components(void)
{ {
log_component_t* lc = &g_log->log_component[0]; log_component_t *lc = g_log->log_component;
log_component_back_t *lb = g_log->log_rarely_used;
while (lc->name) { while (lc->name) {
free((char *)lc->name); // defined as const, but assigned through strdup() free((char *)lc->name); // defined as const, but assigned through strdup()
free(lc->filelog_name); free(lb->filelog_name);
lc++; lc++;
lb++;
} }
} }
...@@ -545,7 +547,7 @@ static inline int log_header(log_component_t *c, ...@@ -545,7 +547,7 @@ static inline int log_header(log_component_t *c,
int line, int line,
int level) int level)
{ {
int flag= g_log->flag | c->flag; int flag = g_log->flag; // | c->flag;
char threadname[64]; char threadname[64];
if (flag & FLAG_THREAD ) { if (flag & FLAG_THREAD ) {
...@@ -635,8 +637,8 @@ void log_dump(int component, ...@@ -635,8 +637,8 @@ void log_dump(int component,
va_list args; va_list args;
char *wbuf; char *wbuf;
log_component_t *c = &g_log->log_component[component]; log_component_t *c = &g_log->log_component[component];
int flag= g_log->flag | c->flag; int flag = g_log->flag; // | c->flag;
switch(datatype) { switch(datatype) {
case LOG_DUMP_DOUBLE: case LOG_DUMP_DOUBLE:
wbuf=malloc((buffsize * 10) + 64 + MAX_LOG_TOTAL); wbuf=malloc((buffsize * 10) + 64 + MAX_LOG_TOTAL);
...@@ -685,7 +687,7 @@ int set_log(int component, ...@@ -685,7 +687,7 @@ int set_log(int component,
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_rarely_used[component].savedlevel = g_log->log_component[component].level;
g_log->log_component[component].level = level; g_log->log_component[component].level = level;
return 0; return 0;
...@@ -704,7 +706,7 @@ void set_glog_onlinelog(int enable) ...@@ -704,7 +706,7 @@ void set_glog_onlinelog(int enable)
{ {
for (int c=0; c< MAX_LOG_COMPONENTS; c++ ) { for (int c=0; c< MAX_LOG_COMPONENTS; c++ ) {
if ( enable ) { if ( enable ) {
g_log->log_component[c].level = g_log->log_component[c].savedlevel; g_log->log_component[c].level = g_log->log_rarely_used[c].savedlevel;
g_log->log_component[c].vprint = vfprintf; g_log->log_component[c].vprint = vfprintf;
g_log->log_component[c].print = fprintf; g_log->log_component[c].print = fprintf;
g_log->log_component[c].stream = stdout; g_log->log_component[c].stream = stdout;
...@@ -741,7 +743,7 @@ void set_glog_filelog(int enable) ...@@ -741,7 +743,7 @@ void set_glog_filelog(int enable)
void set_component_filelog(int comp) void set_component_filelog(int comp)
{ {
if (g_log->log_component[comp].stream == NULL || g_log->log_component[comp].stream == stdout) { if (g_log->log_component[comp].stream == NULL || g_log->log_component[comp].stream == stdout) {
g_log->log_component[comp].stream = fopen(g_log->log_component[comp].filelog_name,"w"); g_log->log_component[comp].stream = fopen(g_log->log_rarely_used[comp].filelog_name, "w");
} }
g_log->log_component[comp].vprint = vfprintf; g_log->log_component[comp].vprint = vfprintf;
...@@ -892,7 +894,7 @@ static void log_output_memory(log_component_t *c, const char *file, const char * ...@@ -892,7 +894,7 @@ static void log_output_memory(log_component_t *c, const char *file, const char *
len = MAX_LOG_TOTAL; len = MAX_LOG_TOTAL;
} }
} }
if ( !((g_log->flag | c->flag) & FLAG_NOCOLOR) ) { if (!((g_log->flag /*| c->flag*/) & FLAG_NOCOLOR)) {
int n = snprintf(log_buffer+len, MAX_LOG_TOTAL-len, "%s", log_level_highlight_end[level]); int n = snprintf(log_buffer+len, MAX_LOG_TOTAL-len, "%s", log_level_highlight_end[level]);
if (n > 0) { if (n > 0) {
len += n; len += n;
......
...@@ -235,23 +235,24 @@ typedef struct { ...@@ -235,23 +235,24 @@ typedef struct {
typedef int(*log_vprint_func_t)(FILE *stream, const char *format, va_list ap ); typedef int(*log_vprint_func_t)(FILE *stream, const char *format, va_list ap );
typedef int(*log_print_func_t)(FILE *stream, const char *format, ... ); typedef int(*log_print_func_t)(FILE *stream, const char *format, ... );
typedef struct {
int savedlevel;
char *filelog_name;
} log_component_back_t;
typedef struct { typedef struct {
const char *name; const char *name;
int level; int level;
int savedlevel; int filelog;
int flag;
int filelog;
char *filelog_name;
FILE *stream; FILE *stream;
log_vprint_func_t vprint; log_vprint_func_t vprint;
log_print_func_t print; log_print_func_t print;
/* SR: make the log buffer component relative */
// char log_buffer[MAX_LOG_TOTAL];
} log_component_t; } log_component_t;
typedef struct { typedef struct {
log_component_t log_component[MAX_LOG_COMPONENTS]; log_component_t log_component[MAX_LOG_COMPONENTS];
log_component_back_t log_rarely_used[MAX_LOG_COMPONENTS];
char level2string[NUM_LOG_LEVEL]; char level2string[NUM_LOG_LEVEL];
int flag; int flag;
char *filelog_name; char *filelog_name;
......
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