]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add fsctl debug sql
authorAnthony Minessale <anthm@freeswitch.org>
Mon, 2 Apr 2012 17:58:40 +0000 (12:58 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Mon, 2 Apr 2012 17:58:40 +0000 (12:58 -0500)
src/include/switch_types.h
src/mod/applications/mod_commands/mod_commands.c
src/switch_core.c
src/switch_core_sqldb.c

index 87577caae14315777423d1218560493c88f5a48b..185fdb64afdf9f0c6a303801bbd5c14a9634e18b 100644 (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 {
index 287afa6d95640d27f0c17d58ef04a9439eb06b34..d82d5eb2d24a4d556b422201a5bedd5b00e7a86d 100644 (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");
index 19de186fc779b9d12c18383085da8c92cfe79a3b..9b876d8458296a1cc1eb52b6ee3cc09bdc5b200b 100644 (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) {
index 0082b7b4ef666eed8a2029878e686282faeebad6..af947f7b11f322a67d72bfaeaf68a295f58f553d 100644 (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;