MySQL 8.0.39
Source Code Documentation
mysql_trace.cc File Reference
#include "mysql_trace.h"
#include <assert.h>
#include "my_inttypes.h"
#include "my_sys.h"
#include "mysql.h"
#include "mysql/service_mysql_alloc.h"

Macros

#define GET_DATA(TI)   (TI)->trace_plugin_data
 
#define GET_STAGE(TI)   (TI)->stage
 
#define TEST_STAGE(TI, X)   (GET_STAGE(TI) == PROTOCOL_STAGE_##X)
 
#define protocol_stage_get_name(X)
 
#define trace_event_get_name(X)
 

Functions

void mysql_trace_start (MYSQL *m)
 Initialize tracing in a given connection. More...
 
void mysql_trace_trace (MYSQL *m, enum trace_event ev, struct st_trace_event_args args)
 Report a protocol trace event to trace plugin. More...
 
const char * protocol_stage_name (enum protocol_stage stage)
 
const char * trace_event_name (enum trace_event ev)
 

Variables

struct st_mysql_client_plugin_TRACEtrace_plugin = nullptr
 The global trace_plugin pointer. More...
 

Detailed Description


Client-side protocol tracing infrastructure

If a plugin of type MYSQL_CLIENT_TRACE_PLUGIN is loaded into libmysql and its instance is pointed by the global trace_plugin pointer, this plugin is notified of various protocol trace events. See include/mysql/plugin_trace.h for documentation of trace plugin methods and the list of possible trace events.

These trace events are generated with MYSQL_TRACE() macro put in relevant places in libmysql code. The macro calls mysql_trace_trace() function defined here. This function calls trace plugin's trace_event() method, if it is defined.

For each traced connection, the state is kept in st_mysql_trace_info structure (see mysql_trace.h).

To correctly interpret each trace event, trace plugin is informed of the current protocol stage (see include/mysql/plugin_trace.h for list of stages). The current protocol stage is part of the connection tracing state. It is updated with MYSQL_TRACE_STAGE() hooks within libmysql code.

Macro Definition Documentation

◆ GET_DATA

#define GET_DATA (   TI)    (TI)->trace_plugin_data

◆ GET_STAGE

#define GET_STAGE (   TI)    (TI)->stage

◆ protocol_stage_get_name

#define protocol_stage_get_name (   X)
Value:
case PROTOCOL_STAGE_##X: \
return #X;
#define X(b)
Definition: xcom_base.cc:9099

◆ TEST_STAGE

#define TEST_STAGE (   TI,
  X 
)    (GET_STAGE(TI) == PROTOCOL_STAGE_##X)

◆ trace_event_get_name

#define trace_event_get_name (   X)
Value:
case TRACE_EVENT_##X: \
return #X;

Function Documentation

◆ mysql_trace_start()

void mysql_trace_start ( MYSQL m)

Initialize tracing in a given connection.

This function is called from MYSQL_TRACE_STAGE() when the initial CONNECTING stage is reported. It allocates and initializes trace_info structure which is then attached to the connection handle.

◆ mysql_trace_trace()

void mysql_trace_trace ( MYSQL m,
enum trace_event  ev,
struct st_trace_event_args  args 
)

Report a protocol trace event to trace plugin.

Calls plugin's trace_event() method, if it is defined, passing to it the event, the current protocol stage and event arguments (if any).

Terminates tracing of the connection when appropriate.

Parameters
mMYSQL connection handle
evtrace event to be reported
argstrace event arguments

◆ protocol_stage_name()

const char * protocol_stage_name ( enum protocol_stage  stage)

◆ trace_event_name()

const char * trace_event_name ( enum trace_event  ev)

Variable Documentation

◆ trace_plugin

struct st_mysql_client_plugin_TRACE* trace_plugin = nullptr

The global trace_plugin pointer.

If it is not NULL, it points at a loaded trace plugin which should be used to trace all connections made to the server.