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