#include "proxysql.h" #include #ifdef DEBUG #ifdef DEBUG_EXTERN #undef DEBUG_EXTERN #endif /* DEBUG_EXTERN */ #endif /* DEBUG */ //extern debug_level *gdbg_lvl; //extern int gdbg; void crash_handler(int sig) { #ifdef DEBUG //g_mem_profile(); malloc_stats_print(NULL, NULL, ""); #endif void *arr[20]; size_t s; s = backtrace(arr, 20); fprintf(stderr, "Error: signal %d:\n", sig); backtrace_symbols_fd(arr, s, STDERR_FILENO); exit(EXIT_FAILURE); } /* void proxy_debug_func(enum debug_module module, int verbosity, const char *fmt, ...) { assert(module=10) { void *arr[20]; char **strings; int s; s = backtrace(arr, 20); //backtrace_symbols_fd(arr, s, STDERR_FILENO); strings=backtrace_symbols(arr,s); if (strings == NULL) { perror("backtrace_symbols"); exit(EXIT_FAILURE); } for (int i=0; iglock); //dbg_msg_t *dbg_msg=g_malloc(sizeof(dbg_msg_t)); dbg_msg_t *dbg_msg=__l_alloc(glo_debug->sfp,sizeof(dbg_msg_t)); SPIN_UNLOCK(glo_debug->glock); gettimeofday(&dbg_msg->tv, NULL); dbg_msg->thr=thr; //dbg_msg->file=g_strdup(__file); dbg_msg->module=module; dbg_msg->file=(char *)__file; dbg_msg->line=__line; //dbg_msg->func=g_strdup(__func); dbg_msg->func=(char *)__func; dbg_msg->verb=verbosity; while (__sync_fetch_and_add(&glo_debug->msg_count,0)>9000) {usleep(10000); } SPIN_LOCK(glo_debug->glock); __sync_fetch_and_add(&glo_debug->msg_count,1); dbg_msg->msg=__l_alloc(glo_debug->sfp,DEBUG_MSG_MAXSIZE); SPIN_UNLOCK(glo_debug->glock); va_list ap; va_start(ap, fmt); //vfprintf(stderr, fmt, ap); vsnprintf(dbg_msg->msg,DEBUG_MSG_MAXSIZE,fmt,ap); va_end(ap); //memcpy(dbg_msg->msg,debugbuff,DEBUG_MSG_MAXSIZE); //dbg_msg->msg=g_strdup(debugbuff); g_async_queue_push(glo_debug->async_queue,dbg_msg); */ }; #endif void proxy_error_func(const char *fmt, ...) { va_list ap; va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); }; #ifdef DEBUG void init_debug_struct() { int i; GloVars.global.gdbg_lvl= (debug_level *) malloc(PROXY_DEBUG_UNKNOWN*sizeof(debug_level)); for (i=0;iasync_queue,1000000); if (dbg_msg) { // char __buffer[25]; // char __buffer2[35]; // struct timeval tv; // gettimeofday(&tv, NULL); // struct tm *__tm_info=localtime(&dbg_msg->tv.tv_sec); // strftime(__buffer, 25, "%Y-%m-%d %H:%M:%S", __tm_info); // sprintf(__buffer2, "%s:06%d", __buffer, (int)dbg_msg->tv.tv_usec); // sqlite3_exec_exit_on_failure(db,"BEGIN TRANSACTION"); __sqlite3_debugdb__flush_debugs(statement, dbg_msg); // sqlite3_exec_exit_on_failure(db,"COMMIT"); // fprintf(debugfile, "%s:%06d %d:%s:%d:%s(): LVL#%d : %s" , __buffer, (int)dbg_msg->tv.tv_usec, dbg_msg->thr, dbg_msg->file, dbg_msg->line, dbg_msg->func, dbg_msg->verb, dbg_msg->msg); if (dbg_msg->tv.tv_sec > lt + 4) { lt=dbg_msg->tv.tv_sec; fflush(debugfile); sqlite3_exec_exit_on_failure(db,"COMMIT"); sqlite3_exec_exit_on_failure(db,"BEGIN TRANSACTION"); } //g_free(dbg_msg->file); //g_free(dbg_msg->func); SPIN_LOCK(glo_debug->glock); __l_free(glo_debug->sfp,DEBUG_MSG_MAXSIZE, dbg_msg->msg); __sync_fetch_and_sub(&glo_debug->msg_count,1); __l_free(glo_debug->sfp, sizeof(dbg_msg_t), dbg_msg); //g_free(dbg_msg); SPIN_UNLOCK(glo_debug->glock); // g_free(dbg_msg->msg); //g_slice_free1(sizeof(dbg_msg_t *),dbg_msg); } else { //sqlite3_exec_exit_on_failure(db,"COMMIT"); } } return NULL; } #endif */