MySQL 8.0.41
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Resource group service

Introduction

The Performance Schema Resource Group service provides methods to:

  • assign a resource group name to a foreground (user) and background (system) threads
  • query the system attributes of a given thread, such as thread id, user name, host name, etc.

Once assigned, the resource group name is visible in the PERFORMANCE_SCHEMA.THREADS table.

Setting a group name

A group name can be assigned to the current thread or to another thread identified by either a thread id or a pointer to thread instrumentation.

User-defined data can also be assigned to the thread.

To assign a group name to the current thread, use:

int set_thread_resource_group(const char* group_name,
int group_name_len,
void *user_data)
int set_thread_resource_group(PFS_thread *pfs, const char *group_name, int group_name_len, void *user_data)
Set the resource group name for a given thread.
Definition: pfs.cc:3427

where

  • group_name is the resource group name string
  • group_name_len is the length of resource group name string
  • user_data is an optional user-defined context

To assign a group name and user data to another thread, use:

int set_thread_resource_group_by_id(PSI_thread *psi_thread,
unsigned long long thread_id,
const char* group_name,
int group_name_len,
void *user_data)
struct PSI_thread PSI_thread
Definition: psi_thread_bits.h:82
static my_thread_id thread_id
Definition: my_thr_init.cc:63

where

  • psi_thread is the target thread instrumentation. Ignored if NULL.
  • thread_id is the thread id of the target thread (THREADS.THREAD_ID). Only used if thread is NULL.
  • group_name is the resource group name string
  • group_name_len is the length of resource group name string
  • user_data is the optional user-defined context

Both functions return 0 if successful, or 1 otherwise.

The group name is limited to 64 characters, UTF8. Names longer than 64 characters will be truncated. user_data is an optional user-defined context associated with thread_id that will be returned to the callback function in the thread attributes structure.

Getting thread attributes

To get the system and security attributes for the current thread, use:

int get_thread_system_attrs(PSI_thread_attrs *thread_attrs)
Performance Schema thread type: user/foreground or system/background.
Definition: psi_thread_bits.h:470

where

  • thread_attrs is a pointer to a thread attribute structure PSI_thread_attrs

To get the system and security attributes for another thread identified either by a thread id or by the thread instrumentation, use:

int get_thread_system_attrs_by_id(PSI_thread *psi_thread,
unsigned long long thread_id,
PSI_thread_attrs *thread_attrs)

where psi_thread is the target thread instrumentation. Ignored if NULL. thread_id is the thread id of the target thread (THREADS.THREAD_ID). Only used if psi_thread is NULL. thread_attrs is a pointer to thread attribute structure, PSI_thread_attrs

Both function return 0 if successful or 1 otherwise.