1 /* Copyright (c) 2010, 2021, 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-1335  USA */
22 
23 #ifndef MYSQL_STAGE_H
24 #define MYSQL_STAGE_H
25 
26 /**
27   @file mysql/psi/mysql_stage.h
28   Instrumentation helpers for stages.
29 */
30 
31 #include "mysql/psi/psi.h"
32 
33 #ifndef PSI_STAGE_CALL
34 #define PSI_STAGE_CALL(M) PSI_DYNAMIC_CALL(M)
35 #endif
36 
37 /**
38   @defgroup Stage_instrumentation Stage Instrumentation
39   @ingroup Instrumentation_interface
40   @{
41 */
42 
43 /**
44   @def mysql_stage_register(P1, P2, P3)
45   Stage registration.
46 */
47 #ifdef HAVE_PSI_STAGE_INTERFACE
48 #define mysql_stage_register(P1, P2, P3) \
49   inline_mysql_stage_register(P1, P2, P3)
50 #else
51 #define mysql_stage_register(P1, P2, P3) \
52   do {} while (0)
53 #endif
54 
55 /**
56   @def MYSQL_SET_STAGE
57   Set the current stage.
58   Use this API when the file and line
59   is passed from the caller.
60   @param K the stage key
61   @param F the source file name
62   @param L the source file line
63   @return the current stage progress
64 */
65 #ifdef HAVE_PSI_STAGE_INTERFACE
66   #define MYSQL_SET_STAGE(K, F, L) \
67     inline_mysql_set_stage(K, F, L)
68 #else
69   #define MYSQL_SET_STAGE(K, F, L) \
70     NULL
71 #endif
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 #ifdef HAVE_PSI_STAGE_INTERFACE
80   #define mysql_set_stage(K) \
81     inline_mysql_set_stage(K, __FILE__, __LINE__)
82 #else
83   #define mysql_set_stage(K) \
84     NULL
85 #endif
86 
87 /**
88   @def mysql_end_stage
89   End the last stage
90 */
91 #ifdef HAVE_PSI_STAGE_INTERFACE
92   #define mysql_end_stage() \
93     inline_mysql_end_stage()
94 #else
95   #define mysql_end_stage() \
96   do {} while (0)
97 #endif
98 
99 #ifdef HAVE_PSI_STAGE_INTERFACE
inline_mysql_stage_register(const char * category,PSI_stage_info ** info,int count)100 static inline void inline_mysql_stage_register(
101   const char *category, PSI_stage_info **info, int count)
102 {
103   PSI_STAGE_CALL(register_stage)(category, info, count);
104 }
105 #endif
106 
107 #ifdef HAVE_PSI_STAGE_INTERFACE
108 static inline PSI_stage_progress*
inline_mysql_set_stage(PSI_stage_key key,const char * src_file,int src_line)109 inline_mysql_set_stage(PSI_stage_key key,
110                        const char *src_file, int src_line)
111 {
112   return PSI_STAGE_CALL(start_stage)(key, src_file, src_line);
113 }
114 #endif
115 
116 #ifdef HAVE_PSI_STAGE_INTERFACE
117 static inline void
inline_mysql_end_stage()118 inline_mysql_end_stage()
119 {
120   PSI_STAGE_CALL(end_stage)();
121 }
122 #endif
123 
124 #ifdef HAVE_PSI_STAGE_INTERFACE
125 #define mysql_stage_set_work_completed(P1, P2) \
126   inline_mysql_stage_set_work_completed(P1, P2)
127 
128 #define mysql_stage_get_work_completed(P1) \
129   inline_mysql_stage_get_work_completed(P1)
130 #else
131 #define mysql_stage_set_work_completed(P1, P2) \
132   do {} while (0)
133 
134 #define mysql_stage_get_work_completed(P1) \
135   do {} while (0)
136 #endif
137 
138 #ifdef HAVE_PSI_STAGE_INTERFACE
139 #define mysql_stage_inc_work_completed(P1, P2) \
140   inline_mysql_stage_inc_work_completed(P1, P2)
141 #else
142 #define mysql_stage_inc_work_completed(P1, P2) \
143   do {} while (0)
144 #endif
145 
146 #ifdef HAVE_PSI_STAGE_INTERFACE
147 #define mysql_stage_set_work_estimated(P1, P2) \
148   inline_mysql_stage_set_work_estimated(P1, P2)
149 
150 #define mysql_stage_get_work_estimated(P1) \
151   inline_mysql_stage_get_work_estimated(P1)
152 #else
153 #define mysql_stage_set_work_estimated(P1, P2) \
154   do {} while (0)
155 
156 #define mysql_stage_get_work_estimated(P1) \
157   do {} while (0)
158 #endif
159 
160 #ifdef HAVE_PSI_STAGE_INTERFACE
161 static inline void
inline_mysql_stage_set_work_completed(PSI_stage_progress * progress,ulonglong val)162 inline_mysql_stage_set_work_completed(PSI_stage_progress *progress,
163                                       ulonglong val)
164 {
165   if (progress != NULL)
166     progress->m_work_completed= val;
167 }
168 
169 static inline ulonglong
inline_mysql_stage_get_work_completed(PSI_stage_progress * progress)170 inline_mysql_stage_get_work_completed(PSI_stage_progress *progress)
171 {
172   return progress->m_work_completed;
173 }
174 #endif
175 
176 #ifdef HAVE_PSI_STAGE_INTERFACE
177 static inline void
inline_mysql_stage_inc_work_completed(PSI_stage_progress * progress,ulonglong val)178 inline_mysql_stage_inc_work_completed(PSI_stage_progress *progress,
179                                       ulonglong val)
180 {
181   if (progress != NULL)
182     progress->m_work_completed+= val;
183 }
184 #endif
185 
186 #ifdef HAVE_PSI_STAGE_INTERFACE
187 static inline void
inline_mysql_stage_set_work_estimated(PSI_stage_progress * progress,ulonglong val)188 inline_mysql_stage_set_work_estimated(PSI_stage_progress *progress,
189                                       ulonglong val)
190 {
191   if (progress != NULL)
192     progress->m_work_estimated= val;
193 }
194 
195 static inline ulonglong
inline_mysql_stage_get_work_estimated(PSI_stage_progress * progress)196 inline_mysql_stage_get_work_estimated(PSI_stage_progress *progress)
197 {
198   return progress->m_work_estimated;
199 }
200 #endif
201 
202 /** @} (end of group Stage_instrumentation) */
203 
204 #endif
205 
206