Changeset: 9acdf458f9b4 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9acdf458f9b4 Modified Files: gdk/gdk_tracer.c gdk/gdk_tracer.h monetdb5/modules/mal/tracer.c monetdb5/modules/mal/tracer.h monetdb5/modules/mal/tracer.mal sql/scripts/81_tracer.sql sql/storage/store.c Branch: default Log Message:
Disabled function logging.showinfo() && report message in case GDKtracer fails to write logs for whatever reason diffs (263 lines): diff --git a/gdk/gdk_tracer.c b/gdk/gdk_tracer.c --- a/gdk/gdk_tracer.c +++ b/gdk/gdk_tracer.c @@ -16,22 +16,13 @@ static gdk_tracer *active_tracer = &trac MT_Lock lock = MT_LOCK_INITIALIZER("GDKtracer_1"); static FILE *output_file; -static bool USE_STREAM = true; +static ATOMIC_TYPE CUR_ADAPTER = ATOMIC_VAR_INIT(DEFAULT_ADAPTER); static bool INIT_BASIC_ADAPTER = false; - -static ATOMIC_TYPE CUR_ADAPTER = ATOMIC_VAR_INIT(DEFAULT_ADAPTER); +static bool LOG_EXC_REP = false; static LOG_LEVEL CUR_FLUSH_LEVEL = DEFAULT_FLUSH_LEVEL; static bool GDK_TRACER_STOP = false; -static const char *LAYER_STR[] = { - FOREACH_LAYER(GENERATE_STRING) -}; - -static const char *ADAPTER_STR[] = { - FOREACH_ADPTR(GENERATE_STRING) -}; - LOG_LEVEL LVL_PER_COMPONENT[] = { FOREACH_COMP(GENERATE_LOG_LEVEL) }; @@ -47,10 +38,13 @@ static gdk_return snprintf(file_name, sizeof(file_name), "%s%c%s%c%s%s", GDKgetenv("gdk_dbpath"), DIR_SEP, FILE_NAME, NAME_SEP, GDKtracer_get_timestamp("%Y%m%d_%H%M%S"), ".log"); output_file = fopen(file_name, "w"); + + // Even if creating the file failed, the adapter has + // still tried to initialize and we shouldn't retry it INIT_BASIC_ADAPTER = true; if (!output_file) { - GDK_TRACER_EXCEPTION("Failed to initialize BASIC adapter. Could not open file: %s\n", file_name); + GDK_TRACER_EXCEPTION(BASIC_INIT_FAILED ": %s\n", file_name); return GDK_FAIL; } @@ -356,22 +350,22 @@ GDKtracer_log(LOG_LEVEL level, const cha MT_lock_unset(&lock); // Failed to write to the buffer - bytes_written < 0 - // Fallback logging mechanism - va_list va; - va_start(va, fmt); - GDK_TRACER_OSTREAM(fmt, va); - va_end(va); + if(!LOG_EXC_REP) + { + GDK_TRACER_EXCEPTION(GDKTRACER_FAILED "\n"); + LOG_EXC_REP = true; + } } } } else { MT_lock_unset(&lock); // Failed to write to the buffer - bytes_written < 0 - // Fallback logging mechanism - va_list va; - va_start(va, fmt); - GDK_TRACER_OSTREAM(fmt, va); - va_end(va); + if(!LOG_EXC_REP) + { + GDK_TRACER_EXCEPTION(GDKTRACER_FAILED "\n"); + LOG_EXC_REP = true; + } } // Flush the current buffer in case the event is @@ -411,15 +405,16 @@ GDKtracer_flush_buffer(void) size_t nitems = 1; size_t w = fwrite(&active_tracer->buffer, active_tracer->allocated_size, nitems, output_file); - if (w == nitems) { - USE_STREAM = false; + if (w == nitems) fflush(output_file); - } + else + // fwrite failed for whatever reason (e.g: disk is full) + if(!LOG_EXC_REP) + { + GDK_TRACER_EXCEPTION(GDKTRACER_FAILED "\n"); + LOG_EXC_REP = true; + } } - // fwrite failed for whatever reason - // (e.g: disk is full) fallback to stream - if (USE_STREAM) - GDK_TRACER_OSTREAM("%s", active_tracer->buffer); // Reset buffer memset(active_tracer->buffer, 0, BUFFER_SIZE); @@ -432,7 +427,7 @@ GDKtracer_flush_buffer(void) active_tracer->allocated_size = 0; MT_lock_unset(&lock); - GDK_TRACER_OSTREAM("Using adapter: %s\n", ADAPTER_STR[(int) ATOMIC_GET(&CUR_ADAPTER)]); + // Here we are supposed to send the logs to the profiler } // The file is kept open no matter the adapter @@ -446,38 +441,9 @@ GDKtracer_flush_buffer(void) gdk_return -GDKtracer_show_info(void) +GDKtracer_show_comp_info(void) { - int i = 0; - size_t max_width = 0; - int space = 0; - - // Find max width from components - for (i = 0; i < COMPONENTS_COUNT; i++) { - size_t comp_width = strlen(COMPONENT_STR[i]); - if (comp_width > max_width) - max_width = comp_width; - } + // "# (%d) %s %*s\n", i, COMPONENT_STR[i], 1, LEVEL_STR[LVL_PER_COMPONENT[i]]; - GDK_TRACER_OSTREAM("\n###############################################################\n"); - GDK_TRACER_OSTREAM("# Available logging levels\n"); - for (i = 0; i < LOG_LEVELS_COUNT; i++) { - GDK_TRACER_OSTREAM("# (%d) %s\n", i, LEVEL_STR[i]); - } - - GDK_TRACER_OSTREAM("\n# You can use one of the following layers to massively set the LOG level\n"); - for (i = 0; i < LAYERS_COUNT; i++) { - GDK_TRACER_OSTREAM("# (%d) %s\n", i, LAYER_STR[i]); - } - - GDK_TRACER_OSTREAM("\n# LOG level per component\n"); - for (i = 0; i < COMPONENTS_COUNT; i++) { - space = (int) (max_width - strlen(COMPONENT_STR[i]) + 30); - if (i < 10) - GDK_TRACER_OSTREAM("# (%d) %s %*s\n", i, COMPONENT_STR[i], space, LEVEL_STR[LVL_PER_COMPONENT[i]]); - else - GDK_TRACER_OSTREAM("# (%d) %s %*s\n", i, COMPONENT_STR[i], space, LEVEL_STR[LVL_PER_COMPONENT[i]]); - } - GDK_TRACER_OSTREAM("###############################################################\n"); return GDK_SUCCEED; } diff --git a/gdk/gdk_tracer.h b/gdk/gdk_tracer.h --- a/gdk/gdk_tracer.h +++ b/gdk/gdk_tracer.h @@ -44,10 +44,12 @@ #define NEW_LINE '\n' #define MXW "20" +#define BASIC_INIT_FAILED "Failed to initialize BASIC adapter" +#define GDKTRACER_FAILED "Failed to write logs" + #define AS_STR(x) #x #define STR(x) AS_STR(x) -//#define __FILENAME__ (__builtin_strrchr(__FILE__, DIR_SEP) ? __builtin_strrchr(__FILE__, DIR_SEP) + 1 : __FILE__) #define __FILENAME__ __FILE__ #define GENERATE_ENUM(ENUM) ENUM, @@ -89,13 +91,13 @@ static const char *LEVEL_STR[] = { // LAYERS -#define FOREACH_LAYER(LAYER) \ +#define FOREACH_LAYER(LAYER) \ LAYER( MDB_ALL ) \ LAYER( SQL_ALL ) \ LAYER( MAL_ALL ) \ LAYER( GDK_ALL ) \ - \ - LAYER( LAYERS_COUNT ) \ + \ + LAYER( LAYERS_COUNT ) \ typedef enum { FOREACH_LAYER(GENERATE_ENUM) @@ -366,6 +368,6 @@ gdk_export gdk_return GDKtracer_log(LOG_ gdk_export gdk_return GDKtracer_flush_buffer(void); -gdk_export gdk_return GDKtracer_show_info(void); +gdk_export gdk_return GDKtracer_show_comp_info(void); #endif /* _GDK_TRACER_H_ */ diff --git a/monetdb5/modules/mal/tracer.c b/monetdb5/modules/mal/tracer.c --- a/monetdb5/modules/mal/tracer.c +++ b/monetdb5/modules/mal/tracer.c @@ -114,9 +114,9 @@ TRACERreset_adapter(void *ret) str -TRACERshow_info(void *ret) +TRACERshow_comp_info(void *ret) { (void) ret; - GDKtracer_show_info(); + GDKtracer_show_comp_info(); return MAL_SUCCEED; } diff --git a/monetdb5/modules/mal/tracer.h b/monetdb5/modules/mal/tracer.h --- a/monetdb5/modules/mal/tracer.h +++ b/monetdb5/modules/mal/tracer.h @@ -25,7 +25,7 @@ mal_export str TRACERset_flush_level(voi mal_export str TRACERreset_flush_level(void *ret); mal_export str TRACERset_adapter(void *ret, int *adapter_id); mal_export str TRACERreset_adapter(void *ret); -mal_export str TRACERshow_info(void *ret); +mal_export str TRACERshow_comp_info(void *ret); #endif /* _TRACER_H */ diff --git a/monetdb5/modules/mal/tracer.mal b/monetdb5/modules/mal/tracer.mal --- a/monetdb5/modules/mal/tracer.mal +++ b/monetdb5/modules/mal/tracer.mal @@ -42,7 +42,7 @@ command resetadapter() :void address TRACERreset_adapter comment "Resets the adapter back to the default"; -command showinfo() :void -address TRACERshow_info -comment "Dumps to the console all the available logging levels, layers and the components -along with their current logging level being set"; +command showcompinfo() :void +address TRACERshow_comp_info +comment "Returns in the form of a SQL result-set all the components along with their ID +and the their current logging level being set"; diff --git a/sql/scripts/81_tracer.sql b/sql/scripts/81_tracer.sql --- a/sql/scripts/81_tracer.sql +++ b/sql/scripts/81_tracer.sql @@ -42,8 +42,8 @@ CREATE PROCEDURE logging.setadapter(adap CREATE PROCEDURE logging.resetadapter() EXTERNAL NAME logging.resetadapter; --- Dumps to the console all the available logging levels, --- layers and the components along with their current logging --- level being set -CREATE PROCEDURE logging.showinfo() - EXTERNAL NAME logging.showinfo; +-- Returns in the form of a SQL result-set all the +-- components along with their ID the their current +-- logging level being set +CREATE PROCEDURE logging.showcompinfo() + EXTERNAL NAME logging.showcompinfo; diff --git a/sql/storage/store.c b/sql/storage/store.c --- a/sql/storage/store.c +++ b/sql/storage/store.c @@ -4617,7 +4617,7 @@ static int reset_trans(sql_trans *tr, sql_trans *ptr) { int res = reset_changeset(tr, &tr->schemas, &ptr->schemas, (sql_base *)tr->parent, (resetf) &reset_schema, (dupfunc) &schema_dup); - TRC_DEBUG(SQL_STORE, "Reset transaction: %d", tr->wtime); + TRC_DEBUG(SQL_STORE, "Reset transaction: %d\n", tr->wtime); return res; } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list