MySQL 8.4.2
Source Code Documentation
mysql_stage.h
Go to the documentation of this file.
1/* Copyright (c) 2010, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef MYSQL_STAGE_H
25#define MYSQL_STAGE_H
26
27/**
28 @file include/mysql/psi/mysql_stage.h
29 Instrumentation helpers for stages.
30*/
31
32#include "my_compiler.h"
33
34/* HAVE_PSI_*_INTERFACE */
35#include "my_psi_config.h" // IWYU pragma: keep
36
37#include "mysql/psi/psi_stage.h"
38
39#include "my_inttypes.h"
40
41#if defined(MYSQL_SERVER) || defined(PFS_DIRECT_CALL)
42/* PSI_STAGE_CALL() as direct call. */
43#include "pfs_stage_provider.h" // IWYU pragma: keep
44#endif
45
46#ifndef PSI_STAGE_CALL
47#define PSI_STAGE_CALL(M) psi_stage_service->M
48#endif
49
50/**
51 @defgroup psi_api_stage Stage Instrumentation (API)
52 @ingroup psi_api
53 @{
54*/
55
56/**
57 @def mysql_stage_register(P1, P2, P3)
58 Stage registration.
59*/
60#define mysql_stage_register(P1, P2, P3) inline_mysql_stage_register(P1, P2, P3)
61
62/**
63 @def MYSQL_SET_STAGE
64 Set the current stage.
65 Use this API when the file and line
66 is passed from the caller.
67 @param K the stage key
68 @param F the source file name
69 @param L the source file line
70 @return the current stage progress
71*/
72#define MYSQL_SET_STAGE(K, F, L) inline_mysql_set_stage(K, F, L)
73
74/**
75 @def mysql_set_stage
76 Set the current stage.
77 @param K the stage key
78 @return the current stage progress
79*/
80#define mysql_set_stage(K) inline_mysql_set_stage(K, __FILE__, __LINE__)
81
82/**
83 @def mysql_end_stage
84 End the last stage
85*/
86#define mysql_end_stage inline_mysql_end_stage
87
88static inline void inline_mysql_stage_register(const char *category
89 [[maybe_unused]],
90 PSI_stage_info **info
91 [[maybe_unused]],
92 int count [[maybe_unused]]) {
93#ifdef HAVE_PSI_STAGE_INTERFACE
94 PSI_STAGE_CALL(register_stage)(category, info, count);
95#endif
96}
97
99 PSI_stage_key key [[maybe_unused]], const char *src_file [[maybe_unused]],
100 int src_line [[maybe_unused]]) {
101#ifdef HAVE_PSI_STAGE_INTERFACE
102 return PSI_STAGE_CALL(start_stage)(key, src_file, src_line);
103#else
104 return nullptr;
105#endif
106}
107
108static inline void inline_mysql_end_stage() {
109#ifdef HAVE_PSI_STAGE_INTERFACE
110 PSI_STAGE_CALL(end_stage)();
111#endif
112}
113
114#ifdef HAVE_PSI_STAGE_INTERFACE
115#define mysql_stage_set_work_completed(P1, P2) \
116 inline_mysql_stage_set_work_completed(P1, P2)
117
118#define mysql_stage_get_work_completed(P1) \
119 inline_mysql_stage_get_work_completed(P1)
120#else
121#define mysql_stage_set_work_completed(P1, P2) \
122 do { \
123 } while (0)
124
125#define mysql_stage_get_work_completed(P1) \
126 do { \
127 } while (0)
128#endif
129
130#ifdef HAVE_PSI_STAGE_INTERFACE
131#define mysql_stage_inc_work_completed(P1, P2) \
132 inline_mysql_stage_inc_work_completed(P1, P2)
133#else
134#define mysql_stage_inc_work_completed(P1, P2) \
135 do { \
136 } while (0)
137#endif
138
139#ifdef HAVE_PSI_STAGE_INTERFACE
140#define mysql_stage_set_work_estimated(P1, P2) \
141 inline_mysql_stage_set_work_estimated(P1, P2)
142
143#define mysql_stage_get_work_estimated(P1) \
144 inline_mysql_stage_get_work_estimated(P1)
145#else
146#define mysql_stage_set_work_estimated(P1, P2) \
147 do { \
148 } while (0)
149
150#define mysql_stage_get_work_estimated(P1) \
151 do { \
152 } while (0)
153#endif
154
155#ifdef HAVE_PSI_STAGE_INTERFACE
157 PSI_stage_progress *progress, ulonglong val) {
158 if (progress != nullptr) {
159 progress->m_work_completed = val;
160 }
161}
162
164 PSI_stage_progress *progress) {
165 return progress->m_work_completed;
166}
167#endif
168
169#ifdef HAVE_PSI_STAGE_INTERFACE
171 PSI_stage_progress *progress, ulonglong val) {
172 if (progress != nullptr) {
173 progress->m_work_completed += val;
174 }
175}
176#endif
177
178#ifdef HAVE_PSI_STAGE_INTERFACE
180 PSI_stage_progress *progress, ulonglong val) {
181 if (progress != nullptr) {
182 progress->m_work_estimated = val;
183 }
184}
185
187 PSI_stage_progress *progress) {
188 return progress->m_work_estimated;
189}
190#endif
191
192/** @} (end of group psi_api_stage) */
193
194#endif
#define PSI_STAGE_CALL(M)
Definition: psi_stage.h:36
unsigned int PSI_stage_key
Instrumented stage key.
Definition: psi_stage_bits.h:43
static void inline_mysql_stage_set_work_completed(PSI_stage_progress *progress, ulonglong val)
Definition: mysql_stage.h:156
static void inline_mysql_end_stage()
Definition: mysql_stage.h:108
static ulonglong inline_mysql_stage_get_work_completed(PSI_stage_progress *progress)
Definition: mysql_stage.h:163
static void inline_mysql_stage_inc_work_completed(PSI_stage_progress *progress, ulonglong val)
Definition: mysql_stage.h:170
static PSI_stage_progress * inline_mysql_set_stage(PSI_stage_key key, const char *src_file, int src_line)
Definition: mysql_stage.h:98
static void inline_mysql_stage_register(const char *category, PSI_stage_info **info, int count)
Definition: mysql_stage.h:88
static void inline_mysql_stage_set_work_estimated(PSI_stage_progress *progress, ulonglong val)
Definition: mysql_stage.h:179
static ulonglong inline_mysql_stage_get_work_estimated(PSI_stage_progress *progress)
Definition: mysql_stage.h:186
Header for compiler-dependent features.
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
static int count
Definition: myisam_ftdump.cc:45
static const char * category
Definition: sha2_password.cc:170
Performance schema instrumentation (declarations).
Performance schema instrumentation interface.
required string key
Definition: replication_asynchronous_connection_failover.proto:60
Stage instrument information.
Definition: psi_stage_bits.h:74
Interface for an instrumented stage progress.
Definition: psi_stage_bits.h:63
unsigned long long m_work_estimated
Definition: psi_stage_bits.h:65
unsigned long long m_work_completed
Definition: psi_stage_bits.h:64