MySQL 8.0.37
Source Code Documentation
pfs_resource_group.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2024, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef PFS_RESOURCE_GROUP_H
25#define PFS_RESOURCE_GROUP_H
26
29
30/**
31 @page PAGE_PFS_RESOURCE_GROUP_SERVICE Resource group service
32
33 @section PFS_RESOURCE_GROUP_INTRO Introduction
34 The Performance Schema Resource Group service provides methods to:
35 - assign a resource group name to a foreground (user) and background (system)
36 threads
37 - query the system attributes of a given thread, such as thread id, user name,
38 host name, etc.
39
40 Once assigned, the resource group name is visible in the
41 PERFORMANCE_SCHEMA.THREADS table.
42
43 @section PFS_RESOURCE_GROUP_SET Setting a group name
44
45 A group name can be assigned to the current thread or to another thread
46 identified by either a thread id or a pointer to thread instrumentation.
47
48 User-defined data can also be assigned to the thread.
49
50 To assign a group name to the current thread, use:
51
52 @code
53 int set_thread_resource_group(const char* group_name,
54 int group_name_len,
55 void *user_data)
56 @endcode
57
58 where
59 - @c group_name is the resource group name string
60 - @c group_name_len is the length of resource group name string
61 - @c user_data is an optional user-defined context
62
63 To assign a group name and user data to another thread, use:
64
65 @code
66 int set_thread_resource_group_by_id(PSI_thread *psi_thread,
67 unsigned long long thread_id,
68 const char* group_name,
69 int group_name_len,
70 void *user_data)
71 @endcode
72
73 where
74 - @c psi_thread is the target thread instrumentation. Ignored if NULL.
75 - @c thread_id is the thread id of the target thread (THREADS.THREAD_ID). Only
76 used if thread is NULL.
77 - @c group_name is the resource group name string
78 - @c group_name_len is the length of resource group name string
79 - @c user_data is the optional user-defined context
80
81 Both functions return 0 if successful, or 1 otherwise.
82
83 The group name is limited to 64 characters, UTF8. Names longer than 64
84 characters will be truncated. user_data is an optional user-defined context
85 associated with thread_id that will be returned to the callback function in
86 the thread attributes structure.
87
88 @section PFS_RESOURCE_GROUP_GET Getting thread attributes
89
90 To get the system and security attributes for the current thread, use:
91
92 @code
93 int get_thread_system_attrs(PSI_thread_attrs *thread_attrs)
94 @endcode
95
96 where
97 - @c thread_attrs is a pointer to a thread attribute structure
98 #PSI_thread_attrs
99
100 To get the system and security attributes for another thread identified either
101 by a thread id or by the thread instrumentation, use:
102
103 @code
104 int get_thread_system_attrs_by_id(PSI_thread *psi_thread,
105 unsigned long long thread_id,
106 PSI_thread_attrs *thread_attrs)
107 @endcode
108
109 where
110 @c psi_thread is the target thread instrumentation. Ignored if NULL.
111 @c thread_id is the thread id of the target thread (THREADS.THREAD_ID). Only
112 used if psi_thread is NULL.
113 @c thread_attrs is a pointer to thread attribute structure, #PSI_thread_attrs
114
115 Both function return 0 if successful or 1 otherwise.
116
117*/
118
119/*
120 SERVICE_DEFINITION(pfs_resource_group)
121 Introduced in MySQL 8.0.2
122 Removed in MySQL 8.0.17
123 Status: Removed, use version 3 instead.
124*/
125
126/*
127 Version 3.
128 Introduced in MySQL 8.0.17
129 Status: active
130*/
131
132BEGIN_SERVICE_DEFINITION(pfs_resource_group_v3)
134set_thread_resource_group_by_id_v1_t set_thread_resource_group_by_id;
135get_thread_system_attrs_v3_t get_thread_system_attrs;
136get_thread_system_attrs_by_id_v3_t get_thread_system_attrs_by_id;
137END_SERVICE_DEFINITION(pfs_resource_group_v3)
138
139#define REQUIRES_PFS_RESOURCE_GROUP_SERVICE \
140 REQUIRES_SERVICE(pfs_resource_group_v3)
141
142#endif
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.
Definition: psi_thread_bits.h:372
int(* get_thread_system_attrs_v3_t)(PSI_thread_attrs_v3 *thread_attrs)
Get system attributes for the current thread.
Definition: psi_thread_bits.h:539
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 ...
Definition: psi_thread_bits.h:550
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 instrumentati...
Definition: psi_thread_bits.h:387
Instrumentation helpers for mysys threads.
#define END_SERVICE_DEFINITION(name)
A macro to end the last Service definition started with the BEGIN_SERVICE_DEFINITION macro.
Definition: service.h:91
#define BEGIN_SERVICE_DEFINITION(name)
Declares a new Service.
Definition: service.h:86
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:3414