add fsctl debug sql

This commit is contained in:
Anthony Minessale 2012-04-02 12:58:40 -05:00
parent b80a3a3439
commit d655ceecf8
4 changed files with 39 additions and 19 deletions

View File

@ -314,7 +314,8 @@ typedef enum {
SCF_CLEAR_SQL = (1 << 17),
SCF_THREADED_SYSTEM_EXEC = (1 << 18),
SCF_SYNC_CLOCK_REQUESTED = (1 << 19),
SCF_CORE_ODBC_REQ = (1 << 20)
SCF_CORE_ODBC_REQ = (1 << 20),
SCF_DEBUG_SQL = (1 << 21)
} switch_core_flag_enum_t;
typedef uint32_t switch_core_flag_t;
@ -1743,7 +1744,8 @@ typedef enum {
SCSC_PAUSE_CHECK,
SCSC_READY_CHECK,
SCSC_THREADED_SYSTEM_EXEC,
SCSC_SYNC_CLOCK_WHEN_IDLE
SCSC_SYNC_CLOCK_WHEN_IDLE,
SCSC_DEBUG_SQL,
} switch_session_ctl_t;
typedef enum {

View File

@ -1908,6 +1908,12 @@ SWITCH_STANDARD_API(ctl_function)
}
switch_core_session_ctl(command, &arg);
stream->write_function(stream, "+OK\n");
} else if (!strcasecmp(argv[0], "debug_sql")) {
int x = 0;
switch_core_session_ctl(SCSC_DEBUG_SQL, &x);
stream->write_function(stream, "+OK SQL DEBUG [%s]\n", x ? "on" : "off");
} else if (!strcasecmp(argv[0], "reclaim_mem")) {
switch_core_session_ctl(SCSC_RECLAIM, &arg);
stream->write_function(stream, "+OK\n");
@ -5461,6 +5467,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
switch_console_set_complete("add complete del");
switch_console_set_complete("add db_cache status");
switch_console_set_complete("add fsctl debug_level");
switch_console_set_complete("add fsctl debug_sql");
switch_console_set_complete("add fsctl last_sps");
switch_console_set_complete("add fsctl default_dtmf_duration");
switch_console_set_complete("add fsctl hupall");

View File

@ -2014,6 +2014,17 @@ SWITCH_DECLARE(int32_t) switch_core_session_ctl(switch_session_ctl_t cmd, void *
}
switch (cmd) {
case SCSC_DEBUG_SQL:
{
if (switch_test_flag((&runtime), SCF_DEBUG_SQL)) {
switch_clear_flag((&runtime), SCF_DEBUG_SQL);
newintval = 0;
} else {
switch_set_flag((&runtime), SCF_DEBUG_SQL);
newintval = 1;
}
}
break;
case SCSC_VERBOSE_EVENTS:
if (intval) {
if (oldintval > -1) {

View File

@ -34,7 +34,7 @@
#include <switch.h>
#include "private/switch_core_pvt.h"
//#define DEBUG_SQL 1
#define SWITCH_SQL_QUEUE_LEN 100000
#define SWITCH_SQL_QUEUE_PAUSE_LEN 90000
@ -1019,11 +1019,11 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
if (new_mlen < runtime.max_sql_buffer_len) {
sql_len = new_mlen;
#ifdef DEBUG_SQL
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"REALLOC %ld %d %d\n", (long int)sql_len, switch_queue_size(sql_manager.sql_queue[0]),
switch_queue_size(sql_manager.sql_queue[1]));
#endif
if (switch_test_flag((&runtime), SCF_DEBUG_SQL)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"REALLOC %ld %d %d\n", (long int)sql_len, switch_queue_size(sql_manager.sql_queue[0]),
switch_queue_size(sql_manager.sql_queue[1]));
}
if (!(tmp = realloc(sqlbuf, sql_len))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL thread ending on mem err\n");
abort();
@ -1031,10 +1031,10 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
}
sqlbuf = tmp;
} else {
#ifdef DEBUG_SQL
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"SAVE %d %d\n", switch_queue_size(sql_manager.sql_queue[0]), switch_queue_size(sql_manager.sql_queue[1]));
#endif
if (switch_test_flag((&runtime), SCF_DEBUG_SQL)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"SAVE %d %d\n", switch_queue_size(sql_manager.sql_queue[0]), switch_queue_size(sql_manager.sql_queue[1]));
}
save_sql = sql;
sql = NULL;
lc = 0;
@ -1077,16 +1077,16 @@ static void *SWITCH_THREAD_FUNC switch_core_sql_thread(switch_thread_t *thread,
wrote = 0;
if (trans && iterations && (iterations > target || !lc)) {
#ifdef DEBUG_SQL
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"RUN %d %d %d\n", switch_queue_size(sql_manager.sql_queue[0]), switch_queue_size(sql_manager.sql_queue[1]), iterations);
#endif
if (switch_test_flag((&runtime), SCF_DEBUG_SQL)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"RUN %d %d %d\n", switch_queue_size(sql_manager.sql_queue[0]), switch_queue_size(sql_manager.sql_queue[1]), iterations);
}
if (switch_cache_db_persistant_execute_trans(sql_manager.event_db, sqlbuf, 1) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL thread unable to commit transaction, records lost!\n");
}
#ifdef DEBUG_SQL
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "DONE\n");
#endif
if (switch_test_flag((&runtime), SCF_DEBUG_SQL)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "DONE\n");
}
iterations = 0;