MySQL 8.4.2
Source Code Documentation
Collaboration diagram for Thread Instrumentation (ABI):

Classes

struct  PSI_thread_info_v1
 Thread instrument information. More...
 
struct  PSI_thread_info_v5
 Thread instrument information. More...
 
struct  PSI_thread_attrs_v3
 Performance Schema thread type: user/foreground or system/background. More...
 
struct  PSI_notification_v3
 Registration structure for the pfs_notification service. More...
 
struct  PSI_thread_bootstrap
 Entry point for the performance schema interface. More...
 
struct  PSI_thread_service_v4
 Performance Schema Thread Interface, version 4. More...
 
struct  PSI_thread_service_v5
 Performance Schema Thread Interface, version 5. More...
 
struct  PSI_thread_service_v6
 Performance Schema Thread Interface, version 6. More...
 
struct  PSI_thread_service_v7
 Performance Schema Thread Interface, version 7. More...
 

Macros

#define PSI_USERNAME_LENGTH   (32 * 3)
 
#define PSI_NAME_LEN   (64 * 3)
 
#define PSI_HOSTNAME_LENGTH   (255)
 
#define PSI_THREAD_VERSION_1   1
 Performance Schema Thread Interface number for version 1. More...
 
#define PSI_THREAD_VERSION_2   2
 Performance Schema Thread Interface number for version 2. More...
 
#define PSI_THREAD_VERSION_3   3
 Performance Schema Thread Interface number for version 3. More...
 
#define PSI_THREAD_VERSION_4   4
 Performance Schema Thread Interface number for version 4. More...
 
#define PSI_THREAD_VERSION_5   5
 Performance Schema Thread Interface number for version 5. More...
 
#define PSI_THREAD_VERSION_6   6
 Performance Schema Thread Interface number for version 6. More...
 
#define PSI_THREAD_VERSION_7   7
 Performance Schema Thread Interface number for version 7. More...
 
#define PSI_CURRENT_THREAD_VERSION   7
 Performance Schema Thread Interface number for the most recent version. More...
 

Typedefs

typedef unsigned int PSI_thread_key
 Instrumented thread key. More...
 
typedef unsigned int PSI_thread_seqnum
 Instrumented thread sequence number. More...
 
typedef int opaque_vio_type
 
typedef struct PSI_thread PSI_thread
 
typedef struct PSI_thread_info_v1 PSI_thread_info_v1
 
typedef struct PSI_thread_info_v5 PSI_thread_info_v5
 
typedef void(* register_thread_v1_t) (const char *category, struct PSI_thread_info_v1 *info, int count)
 Thread registration API. More...
 
typedef void(* register_thread_v5_t) (const char *category, struct PSI_thread_info_v5 *info, int count)
 Thread registration API. More...
 
typedef int(* spawn_thread_v1_t) (PSI_thread_key key, my_thread_handle *thread, const my_thread_attr_t *attr, void *(*start_routine) (void *), void *arg)
 Spawn a thread. More...
 
typedef int(* spawn_thread_v5_t) (PSI_thread_key key, PSI_thread_seqnum seqnum, my_thread_handle *thread, const my_thread_attr_t *attr, void *(*start_routine) (void *), void *arg)
 
typedef struct PSI_thread *(* new_thread_v1_t) (PSI_thread_key key, const void *identity, unsigned long long thread_id)
 Create instrumentation for a thread. More...
 
typedef struct PSI_thread *(* new_thread_v5_t) (PSI_thread_key key, PSI_thread_seqnum seqnum, const void *identity, unsigned long long thread_id)
 
typedef void(* set_thread_THD_v1_t) (struct PSI_thread *thread, THD *thd)
 Assign a THD to an instrumented thread. More...
 
typedef void(* set_thread_id_v1_t) (struct PSI_thread *thread, unsigned long long id)
 Assign an id to an instrumented thread. More...
 
typedef unsigned long long(* get_current_thread_internal_id_v2_t) ()
 Read the THREAD_ID of the current thread. More...
 
typedef unsigned long long(* get_thread_internal_id_v2_t) (struct PSI_thread *thread)
 Read the THREAD_ID of an instrumented thread. More...
 
typedef struct PSI_thread *(* get_thread_by_id_v2_t) (unsigned long long processlist_id)
 Get the instrumentation for the thread of given PROCESSLIST_ID. More...
 
typedef void(* set_thread_os_id_v1_t) (struct PSI_thread *thread)
 Assign the current operating system thread id to an instrumented thread. More...
 
typedef struct PSI_thread *(* get_thread_v1_t) (void)
 Get the instrumentation for the running thread. More...
 
typedef void(* set_thread_user_v1_t) (const char *user, int user_len)
 Assign a user name to the instrumented thread. More...
 
typedef void(* set_thread_account_v1_t) (const char *user, int user_len, const char *host, int host_len)
 Assign a user name and host name to the instrumented thread. More...
 
typedef void(* set_thread_db_v1_t) (const char *db, int db_len)
 Assign a current database to the instrumented thread. More...
 
typedef void(* set_thread_command_v1_t) (int command)
 Assign a current command to the instrumented thread. More...
 
typedef void(* set_connection_type_v1_t) (opaque_vio_type conn_type)
 Assign a connection type to the instrumented thread. More...
 
typedef void(* set_thread_start_time_v1_t) (time_t start_time)
 Assign a start time to the instrumented thread. More...
 
typedef void(* set_thread_state_v1_t) (const char *state)
 Assign a state to the instrumented thread. More...
 
typedef void(* set_thread_info_v1_t) (const char *info, unsigned int info_len)
 Assign a process info to the instrumented thread. More...
 
typedef void(* set_thread_secondary_engine_v6_t) (bool secondary)
 Set a thread EXECUTION_ENGINE attribute. More...
 
typedef int(* set_thread_resource_group_v1_t) (const char *group_name, int group_name_len, void *user_data)
 Assign a resource group name to the current thread. More...
 
typedef int(* set_thread_resource_group_by_id_v1_t) (PSI_thread *thread, unsigned long long thread_id, const char *group_name, int group_name_len, void *user_data)
 Assign a resource group name to an instrumented thread, identified either by the thread instrumentation or Performance Schema thread id. More...
 
typedef void(* set_thread_v1_t) (struct PSI_thread *thread)
 Attach a thread instrumentation to the running thread. More...
 
typedef void(* set_thread_peer_port_v4_t) (PSI_thread *thread, unsigned int port)
 Assign the remote (peer) port to the instrumented thread. More...
 
typedef void(* aggregate_thread_status_v2_t) (struct PSI_thread *thread)
 Aggregate the thread status variables. More...
 
typedef void(* delete_current_thread_v1_t) (void)
 Delete the current thread instrumentation. More...
 
typedef void(* delete_thread_v1_t) (struct PSI_thread *thread)
 Delete a thread instrumentation. More...
 
typedef int(* set_thread_connect_attrs_v1_t) (const char *buffer, unsigned int length, const void *from_cs)
 Stores an array of connection attributes. More...
 
typedef void(* get_current_thread_event_id_v2_t) (unsigned long long *thread_internal_id, unsigned long long *event_id)
 Get the current thread current event. More...
 
typedef void(* get_thread_event_id_v1_t) (unsigned long long *thread_internal_id, unsigned long long *event_id)
 Get the thread current event. More...
 
typedef void(* get_thread_event_id_v2_t) (struct PSI_thread *psi, unsigned long long *thread_internal_id, unsigned long long *event_id)
 Get the thread current event. More...
 
typedef struct PSI_thread_attrs_v3 PSI_thread_attrs
 
typedef void(* PSI_notification_cb_v3) (const PSI_thread_attrs_v3 *thread_attrs)
 Callback for the pfs_notification service. More...
 
typedef struct PSI_notification_v3 PSI_notification
 
typedef int(* get_thread_system_attrs_v3_t) (PSI_thread_attrs_v3 *thread_attrs)
 Get system attributes for the current thread. More...
 
typedef int(* get_thread_system_attrs_by_id_v3_t) (PSI_thread *thread, unsigned long long thread_id, PSI_thread_attrs_v3 *thread_attrs)
 Get system attributes for an instrumented thread, identified either by the thread instrumentation or Performance Schema thread id. More...
 
typedef int(* register_notification_v3_t) (const PSI_notification_v3 *callbacks, bool with_ref_count)
 Register callback functions for the Notification service. More...
 
typedef int(* unregister_notification_v1_t) (int handle)
 Unregister callback functions for the Notification service. More...
 
typedef void(* notify_session_connect_v1_t) (PSI_thread *thread)
 Invoke the callback function registered for a session connect event. More...
 
typedef void(* notify_session_disconnect_v1_t) (PSI_thread *thread)
 Invoke the callback function registered for a session disconnect event. More...
 
typedef void(* notify_session_change_user_v1_t) (PSI_thread *thread)
 Invoke the callback function registered for a change user event. More...
 
typedef struct PSI_thread_info_v5 PSI_thread_info
 
typedef void(* thread_detect_telemetry_v7_t) (PSI_thread *thread)
 
typedef void(* thread_abort_telemetry_v7_t) (PSI_thread *thread)
 
typedef struct PSI_thread_bootstrap PSI_thread_bootstrap
 
typedef void(* set_mem_cnt_THD_v1_t) (THD *thd, THD **backup_thd)
 Set instrumented thread used for memory counting. More...
 
typedef struct PSI_thread_service_v7 PSI_thread_service_t
 

Variables

MYSQL_PLUGIN_IMPORT PSI_thread_service_tpsi_thread_service
 

Detailed Description

Macro Definition Documentation

◆ PSI_CURRENT_THREAD_VERSION

#define PSI_CURRENT_THREAD_VERSION   7

Performance Schema Thread Interface number for the most recent version.

The most current version is PSI_THREAD_VERSION_7

◆ PSI_HOSTNAME_LENGTH

#define PSI_HOSTNAME_LENGTH   (255)

◆ PSI_NAME_LEN

#define PSI_NAME_LEN   (64 * 3)

◆ PSI_THREAD_VERSION_1

#define PSI_THREAD_VERSION_1   1

Performance Schema Thread Interface number for version 1.

This version is obsolete.

◆ PSI_THREAD_VERSION_2

#define PSI_THREAD_VERSION_2   2

Performance Schema Thread Interface number for version 2.

This version is obsolete.

◆ PSI_THREAD_VERSION_3

#define PSI_THREAD_VERSION_3   3

Performance Schema Thread Interface number for version 3.

This version is obsolete.

◆ PSI_THREAD_VERSION_4

#define PSI_THREAD_VERSION_4   4

Performance Schema Thread Interface number for version 4.

This version is supported.

◆ PSI_THREAD_VERSION_5

#define PSI_THREAD_VERSION_5   5

Performance Schema Thread Interface number for version 5.

This version is supported.

◆ PSI_THREAD_VERSION_6

#define PSI_THREAD_VERSION_6   6

Performance Schema Thread Interface number for version 6.

This version is supported.

◆ PSI_THREAD_VERSION_7

#define PSI_THREAD_VERSION_7   7

Performance Schema Thread Interface number for version 7.

This version is supported.

◆ PSI_USERNAME_LENGTH

#define PSI_USERNAME_LENGTH   (32 * 3)

Typedef Documentation

◆ aggregate_thread_status_v2_t

typedef void(* aggregate_thread_status_v2_t) (struct PSI_thread *thread)

Aggregate the thread status variables.

◆ delete_current_thread_v1_t

typedef void(* delete_current_thread_v1_t) (void)

Delete the current thread instrumentation.

◆ delete_thread_v1_t

typedef void(* delete_thread_v1_t) (struct PSI_thread *thread)

Delete a thread instrumentation.

◆ get_current_thread_event_id_v2_t

typedef void(* get_current_thread_event_id_v2_t) (unsigned long long *thread_internal_id, unsigned long long *event_id)

Get the current thread current event.

Parameters
[out]thread_internal_idThe thread internal id
[out]event_idThe per thread event id.

◆ get_current_thread_internal_id_v2_t

typedef unsigned long long(* get_current_thread_internal_id_v2_t) ()

Read the THREAD_ID of the current thread.

Returns
the id of the instrumented thread

◆ get_thread_by_id_v2_t

typedef struct PSI_thread *(* get_thread_by_id_v2_t) (unsigned long long processlist_id)

Get the instrumentation for the thread of given PROCESSLIST_ID.

Parameters
processlist_idthe thread id
Returns
the instrumented thread

◆ get_thread_event_id_v1_t

typedef void(* get_thread_event_id_v1_t) (unsigned long long *thread_internal_id, unsigned long long *event_id)

Get the thread current event.

Deprecated:
Parameters
[out]thread_internal_idThe thread internal id
[out]event_idThe per thread event id.

◆ get_thread_event_id_v2_t

typedef void(* get_thread_event_id_v2_t) (struct PSI_thread *psi, unsigned long long *thread_internal_id, unsigned long long *event_id)

Get the thread current event.

Parameters
psithe instrumented thread
[out]thread_internal_idThe thread internal id
[out]event_idThe per thread event id.

◆ get_thread_internal_id_v2_t

typedef unsigned long long(* get_thread_internal_id_v2_t) (struct PSI_thread *thread)

Read the THREAD_ID of an instrumented thread.

Parameters
threadthe instrumented thread
Returns
the id of the instrumented thread

◆ get_thread_system_attrs_by_id_v3_t

typedef int(* get_thread_system_attrs_by_id_v3_t) (PSI_thread *thread, unsigned long long thread_id, PSI_thread_attrs_v3 *thread_attrs)

Get system attributes for an instrumented thread, identified either by the thread instrumentation or Performance Schema thread id.

Parameters
threadpointer to the thread instrumentation. Ignored if NULL.
thread_idthread id of the target thread. Only used if thread is NULL.
thread_attrspointer to pfs_thread_attr struct
Returns
0 if successful, 1 otherwise

◆ get_thread_system_attrs_v3_t

typedef int(* get_thread_system_attrs_v3_t) (PSI_thread_attrs_v3 *thread_attrs)

Get system attributes for the current thread.

Parameters
thread_attrspointer to pfs_thread_attr struct
Returns
0 if successful, 1 otherwise

◆ get_thread_v1_t

typedef struct PSI_thread *(* get_thread_v1_t) (void)

Get the instrumentation for the running thread.

For this function to return a result, the thread instrumentation must have been attached to the running thread using set_thread()

Returns
the instrumentation for the running thread

◆ new_thread_v1_t

typedef struct PSI_thread *(* new_thread_v1_t) (PSI_thread_key key, const void *identity, unsigned long long thread_id)

Create instrumentation for a thread.

Parameters
keythe registered key
identityan address typical of the thread
thread_idPROCESSLIST_ID of the thread
Returns
an instrumented thread

◆ new_thread_v5_t

typedef struct PSI_thread *(* new_thread_v5_t) (PSI_thread_key key, PSI_thread_seqnum seqnum, const void *identity, unsigned long long thread_id)

◆ notify_session_change_user_v1_t

typedef void(* notify_session_change_user_v1_t) (PSI_thread *thread)

Invoke the callback function registered for a change user event.

Parameters
threadthe thread instrumentation

◆ notify_session_connect_v1_t

typedef void(* notify_session_connect_v1_t) (PSI_thread *thread)

Invoke the callback function registered for a session connect event.

Parameters
threadthe thread instrumentation

◆ notify_session_disconnect_v1_t

typedef void(* notify_session_disconnect_v1_t) (PSI_thread *thread)

Invoke the callback function registered for a session disconnect event.

Parameters
threadthe thread instrumentation

◆ opaque_vio_type

typedef int opaque_vio_type
See also
enum_vio_type.

◆ PSI_notification

◆ PSI_notification_cb_v3

typedef void(* PSI_notification_cb_v3) (const PSI_thread_attrs_v3 *thread_attrs)

Callback for the pfs_notification service.

Parameters
thread_attrssystem attributes of the current thread.

◆ PSI_thread

typedef struct PSI_thread PSI_thread

◆ PSI_thread_attrs

◆ PSI_thread_bootstrap

◆ PSI_thread_info

◆ PSI_thread_info_v1

◆ PSI_thread_info_v5

◆ PSI_thread_key

typedef unsigned int PSI_thread_key

Instrumented thread key.

To instrument a thread, a thread key must be obtained using register_thread. Using a zero key always disable the instrumentation.

◆ PSI_thread_seqnum

typedef unsigned int PSI_thread_seqnum

Instrumented thread sequence number.

This sequence number is used in conjunction with foo, to print names like "foo-NN" in ps/top/debuggers ...

See also
my_thread_self_setname().

◆ PSI_thread_service_t

◆ register_notification_v3_t

typedef int(* register_notification_v3_t) (const PSI_notification_v3 *callbacks, bool with_ref_count)

Register callback functions for the Notification service.

For best performance, set with_ref_count = false.

Parameters
callbacksstructure of user-defined callback functions
with_ref_counttrue if callbacks can be unregistered
See also
unregister_notification
Returns
registration handle on success, 0 if failure

◆ register_thread_v1_t

typedef void(* register_thread_v1_t) (const char *category, struct PSI_thread_info_v1 *info, int count)

Thread registration API.

Parameters
categorya category name (typically a plugin name)
infoan array of thread info to register
countthe size of the info array

◆ register_thread_v5_t

typedef void(* register_thread_v5_t) (const char *category, struct PSI_thread_info_v5 *info, int count)

Thread registration API.

Parameters
categorya category name (typically a plugin name)
infoan array of thread info to register
countthe size of the info array

◆ set_connection_type_v1_t

typedef void(* set_connection_type_v1_t) (opaque_vio_type conn_type)

Assign a connection type to the instrumented thread.

Parameters
conn_typethe connection type

◆ set_mem_cnt_THD_v1_t

typedef void(* set_mem_cnt_THD_v1_t) (THD *thd, THD **backup_thd)

Set instrumented thread used for memory counting.

Parameters
[in]thdthe instrumented thread
[out]backup_thdthe backup thread

◆ set_thread_account_v1_t

typedef void(* set_thread_account_v1_t) (const char *user, int user_len, const char *host, int host_len)

Assign a user name and host name to the instrumented thread.

Parameters
userthe user name
user_lenthe user name length
hostthe host name
host_lenthe host name length

◆ set_thread_command_v1_t

typedef void(* set_thread_command_v1_t) (int command)

Assign a current command to the instrumented thread.

Parameters
commandthe current command

◆ set_thread_connect_attrs_v1_t

typedef int(* set_thread_connect_attrs_v1_t) (const char *buffer, unsigned int length, const void *from_cs)

Stores an array of connection attributes.

Parameters
bufferchar array of length encoded connection attributes in network format
lengthlength of the data in buffer
from_cscharset in which buffer is encoded
Returns
state
Return values
non_0attributes truncated
0stored the attribute

◆ set_thread_db_v1_t

typedef void(* set_thread_db_v1_t) (const char *db, int db_len)

Assign a current database to the instrumented thread.

Parameters
dbthe database name
db_lenthe database name length

◆ set_thread_id_v1_t

typedef void(* set_thread_id_v1_t) (struct PSI_thread *thread, unsigned long long id)

Assign an id to an instrumented thread.

Parameters
threadthe instrumented thread
idthe PROCESSLIST_ID to assign

◆ set_thread_info_v1_t

typedef void(* set_thread_info_v1_t) (const char *info, unsigned int info_len)

Assign a process info to the instrumented thread.

Parameters
infothe process into string
info_lenthe process into string length

◆ set_thread_os_id_v1_t

typedef void(* set_thread_os_id_v1_t) (struct PSI_thread *thread)

Assign the current operating system thread id to an instrumented thread.

The operating system task id is obtained from gettid()

Parameters
threadthe instrumented thread

◆ set_thread_peer_port_v4_t

typedef void(* set_thread_peer_port_v4_t) (PSI_thread *thread, unsigned int port)

Assign the remote (peer) port to the instrumented thread.

Parameters
threadpointer to the thread instrumentation
portthe remote port

◆ set_thread_resource_group_by_id_v1_t

typedef int(* set_thread_resource_group_by_id_v1_t) (PSI_thread *thread, unsigned long long thread_id, const char *group_name, int group_name_len, void *user_data)

Assign a resource group name to an instrumented thread, identified either by the thread instrumentation or Performance Schema thread id.

Parameters
threadpointer to the thread instrumentation. Ignored if NULL.
thread_idthread id of the target thread. Only used if thread is NULL.
group_nameresource group name string
group_name_lenresource group name string length
user_datauser-defined data return 0 if successful, 1 otherwise

◆ set_thread_resource_group_v1_t

typedef int(* set_thread_resource_group_v1_t) (const char *group_name, int group_name_len, void *user_data)

Assign a resource group name to the current thread.

Parameters
group_nameresource group name string
group_name_lenresource group name string length
user_datauser-defined data return 0 if successful, 1 otherwise

◆ set_thread_secondary_engine_v6_t

typedef void(* set_thread_secondary_engine_v6_t) (bool secondary)

Set a thread EXECUTION_ENGINE attribute.

Parameters
secondaryTrue for SECONDARY, false for PRIMARY.

◆ set_thread_start_time_v1_t

typedef void(* set_thread_start_time_v1_t) (time_t start_time)

Assign a start time to the instrumented thread.

Parameters
start_timethe thread start time

◆ set_thread_state_v1_t

typedef void(* set_thread_state_v1_t) (const char *state)

Assign a state to the instrumented thread.

Parameters
statethe thread state

◆ set_thread_THD_v1_t

typedef void(* set_thread_THD_v1_t) (struct PSI_thread *thread, THD *thd)

Assign a THD to an instrumented thread.

Parameters
threadthe instrumented thread
thdthe sql layer THD to assign

◆ set_thread_user_v1_t

typedef void(* set_thread_user_v1_t) (const char *user, int user_len)

Assign a user name to the instrumented thread.

Parameters
userthe user name
user_lenthe user name length

◆ set_thread_v1_t

typedef void(* set_thread_v1_t) (struct PSI_thread *thread)

Attach a thread instrumentation to the running thread.

In case of thread pools, this method should be called when a worker thread picks a work item and runs it. Also, this method should be called if the instrumented code does not keep the pointer returned by new_thread() and relies on get_thread() instead.

Parameters
threadthe thread instrumentation

◆ spawn_thread_v1_t

typedef int(* spawn_thread_v1_t) (PSI_thread_key key, my_thread_handle *thread, const my_thread_attr_t *attr, void *(*start_routine)(void *), void *arg)

Spawn a thread.

This method creates a new thread, with instrumentation.

Parameters
keythe instrumentation key for this thread
threadthe resulting thread
attrthe thread attributes
start_routinethe thread start routine
argthe thread start routine argument

◆ spawn_thread_v5_t

typedef int(* spawn_thread_v5_t) (PSI_thread_key key, PSI_thread_seqnum seqnum, my_thread_handle *thread, const my_thread_attr_t *attr, void *(*start_routine)(void *), void *arg)

◆ thread_abort_telemetry_v7_t

typedef void(* thread_abort_telemetry_v7_t) (PSI_thread *thread)

◆ thread_detect_telemetry_v7_t

typedef void(* thread_detect_telemetry_v7_t) (PSI_thread *thread)

◆ unregister_notification_v1_t

typedef int(* unregister_notification_v1_t) (int handle)

Unregister callback functions for the Notification service.

Parameters
handleregistration handle returned by register_notification()
See also
register_notification
Returns
0 if successful, non-zero otherwise

Variable Documentation

◆ psi_thread_service

MYSQL_PLUGIN_IMPORT PSI_thread_service_t* psi_thread_service
extern