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