summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicențiu Ciorbaru <cvicentiu@gmail.com>2023-02-03 15:00:49 +0200
committerVicențiu Ciorbaru <cvicentiu@gmail.com>2023-02-03 16:27:16 +0200
commit9f16d153579eb30639b5f7e8a827d65f44475979 (patch)
tree473c5be8a3e51a9b556a173d2280069033b9acf9
parent2a08b2c15c22fe1019aea00ba160f5ca7e56e231 (diff)
downloadmariadb-git-9f16d153579eb30639b5f7e8a827d65f44475979.tar.gz
debug_sync: Print all current active signals within the trace file during wait
When running with DBUG trace enabled, print all current active signals. The output looks like this with the signals present in curr: T@6 ... debug_sync_exec: wait for 'nothing' at: 'now', curr: 'something,from_function,from_myvar'
-rw-r--r--sql/debug_sync.cc55
1 files changed, 50 insertions, 5 deletions
diff --git a/sql/debug_sync.cc b/sql/debug_sync.cc
index b7090efa01b..aa6956060b4 100644
--- a/sql/debug_sync.cc
+++ b/sql/debug_sync.cc
@@ -18,6 +18,7 @@
#include "mariadb.h"
#include "debug_sync.h"
+#include <cstring>
#if defined(ENABLED_DEBUG_SYNC)
@@ -352,6 +353,40 @@ void debug_sync_init_thread(THD *thd)
/**
+ Returns an allocated buffer containing a comma-separated C string of all
+ active signals.
+
+ Buffer must be freed by the caller.
+*/
+static const char *get_signal_set_as_string()
+{
+ mysql_mutex_assert_owner(&debug_sync_global.ds_mutex);
+ size_t req_size= 1; // In case of empty set for the end '\0' char.
+
+ for (size_t i= 0; i < debug_sync_global.ds_signal_set.size(); i++)
+ req_size+= debug_sync_global.ds_signal_set.at(i)->length + 1;
+
+ char *buf= (char *) my_malloc(PSI_NOT_INSTRUMENTED, req_size, MYF(0));
+ if (!buf)
+ return nullptr;
+ memset(buf, '\0', req_size);
+
+ char *cur_pos= buf;
+ for (size_t i= 0; i < debug_sync_global.ds_signal_set.size(); i++)
+ {
+ const LEX_CSTRING *signal= debug_sync_global.ds_signal_set.at(i);
+ memcpy(cur_pos, signal->str, signal->length);
+ if (i != debug_sync_global.ds_signal_set.size() - 1)
+ cur_pos[signal->length]= ',';
+ else
+ cur_pos[signal->length] = '\0';
+ cur_pos+= signal->length + 1;
+ }
+ return buf;
+}
+
+
+/**
End the debug sync facility at thread end.
@param[in] thd thread handle
@@ -1581,12 +1616,22 @@ static void debug_sync_execute(THD *thd, st_debug_sync_action *action)
restore_current_mutex = false;
set_timespec(abstime, action->timeout);
- // TODO turn this into a for loop printing.
DBUG_EXECUTE("debug_sync_exec", {
- /* Functions as DBUG_PRINT args can change keyword and line nr. */
- DBUG_PRINT("debug_sync_exec",
- ("wait for '%s' at: '%s'",
- sig_wait, dsp_name));});
+ const char *signal_set= get_signal_set_as_string();
+ if (!signal_set)
+ {
+ DBUG_PRINT("debug_sync_exec",
+ ("Out of memory when fetching signal set"));
+ }
+ else
+ {
+ /* Functions as DBUG_PRINT args can change keyword and line nr. */
+ DBUG_PRINT("debug_sync_exec",
+ ("wait for '%s' at: '%s', curr: '%s'",
+ sig_wait, dsp_name, signal_set));
+ my_free((void *)signal_set);
+ }});
+
/*
Wait until global signal string matches the wait_for string.