MySQL 8.0.31
Source Code Documentation
psi_socket_bits.h
Go to the documentation of this file.
1/* Copyright (c) 2008, 2022, 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 COMPONENTS_SERVICES_BITS_PSI_SOCKET_BITS_H
24#define COMPONENTS_SERVICES_BITS_PSI_SOCKET_BITS_H
25
26#ifndef MYSQL_ABI_CHECK
27#include <stddef.h> /* size_t */
28#endif
29
30#include <mysql/components/services/bits/my_io_bits.h> /* socklen_t */
32
33/**
34 @file mysql/components/services/bits/psi_socket_bits.h
35 Performance schema instrumentation interface.
36
37 @defgroup psi_abi_socket Socket Instrumentation (ABI)
38 @ingroup psi_abi
39 @{
40*/
41
42/**
43 Instrumented socket key.
44 To instrument a socket, a socket key must be obtained using @c
45 register_socket.
46 Using a zero key always disable the instrumentation.
47*/
48typedef unsigned int PSI_socket_key;
49
50/**
51 @def PSI_SOCKET_VERSION_1
52 Performance Schema Socket Interface number for version 1.
53 This version is supported.
54*/
55#define PSI_SOCKET_VERSION_1 1
56
57/**
58 @def PSI_CURRENT_SOCKET_VERSION
59 Performance Schema Socket Interface number for the most recent version.
60 The most current version is @c PSI_SOCKET_VERSION_1
61*/
62#define PSI_CURRENT_SOCKET_VERSION 1
63
64/**
65 Interface for an instrumented socket descriptor.
66 This is an opaque structure.
67*/
69typedef struct PSI_socket PSI_socket;
70
71/**
72 Interface for an instrumented socket operation.
73 This is an opaque structure.
74*/
77
78/** State of an instrumented socket. */
80 /** Idle, waiting for the next command. */
82 /** Active, executing a command. */
84};
86
87/** Operation performed on an instrumented socket. */
89 /** Socket creation, as in @c socket() or @c socketpair(). */
91 /** Socket connection, as in @c connect(), @c listen() and @c accept(). */
93 /** Socket bind, as in @c bind(), @c getsockname() and @c getpeername(). */
95 /** Socket close, as in @c shutdown(). */
97 /** Socket send, @c send(). */
99 /** Socket receive, @c recv(). */
101 /** Socket send, @c sendto(). */
103 /** Socket receive, @c recvfrom). */
105 /** Socket send, @c sendmsg(). */
107 /** Socket receive, @c recvmsg(). */
109 /** Socket seek, such as @c fseek() or @c seek(). */
111 /** Socket options, as in @c getsockopt() and @c setsockopt(). */
113 /** Socket status, as in @c sockatmark() and @c isfdtype(). */
115 /** Socket shutdown, as in @c shutdown(). */
117 /** Socket select, as in @c select() and @c poll(). */
121
122/**
123 Socket instrument information.
124 @since PSI_SOCKET_VERSION_1
125 This structure is used to register an instrumented socket.
126*/
128 /**
129 Pointer to the key assigned to the registered socket.
130 */
132 /**
133 The name of the socket instrument to register.
134 */
135 const char *m_name;
136 /**
137 The flags of the socket instrument to register.
138 @sa PSI_FLAG_SINGLETON
139 */
140 unsigned int m_flags;
141 /** Volatility index. */
143 /** Documentation. */
144 const char *m_documentation;
145};
147
148/**
149 State data storage for @c start_socket_wait_v1_t.
150 This structure provide temporary storage to a socket locker.
151 The content of this structure is considered opaque,
152 the fields are only hints of what an implementation
153 of the psi interface can use.
154 This memory is provided by the instrumented code for performance reasons.
155 @sa start_socket_wait_v1_t
156*/
158 /** Internal state. */
159 unsigned int m_flags;
160 /** Current socket. */
162 /** Current thread. */
164 /** Operation number of bytes. */
166 /** Timer start. */
167 unsigned long long m_timer_start{0};
168 /** Timer function. */
169 unsigned long long (*m_timer)(void);
170 /** Current operation. */
172 /** Source file. */
173 const char *m_src_file;
174 /** Source line number. */
176 /** Internal data. */
177 void *m_wait;
178};
180
181/**
182 Socket registration API.
183 @param category a category name (typically a plugin name)
184 @param info an array of socket info to register
185 @param count the size of the info array
186*/
187typedef void (*register_socket_v1_t)(const char *category,
188 struct PSI_socket_info_v1 *info,
189 int count);
190
191/**
192 Socket instrumentation initialisation API.
193 @param key the registered socket key
194 @param fd socket file descriptor
195 @param addr the socket ip address
196 @param addr_len length of socket ip address
197 @return an instrumented socket
198*/
199typedef struct PSI_socket *(*init_socket_v1_t)(PSI_socket_key key,
200 const my_socket *fd,
201 const struct sockaddr *addr,
202 socklen_t addr_len);
203
204/**
205 socket instrumentation destruction API.
206 @param socket the socket to destroy
207*/
208typedef void (*destroy_socket_v1_t)(struct PSI_socket *socket);
209
210/**
211 Record a socket instrumentation start event.
212 @param state data storage for the locker
213 @param socket the instrumented socket
214 @param op socket operation to be performed
215 @param count the number of bytes requested, or 0 if not applicable
216 @param src_file the source file name
217 @param src_line the source line number
218 @return a socket locker, or NULL
219*/
220typedef struct PSI_socket_locker *(*start_socket_wait_v1_t)(
221 struct PSI_socket_locker_state_v1 *state, struct PSI_socket *socket,
222 enum PSI_socket_operation op, size_t count, const char *src_file,
223 unsigned int src_line);
224
225/**
226 Record a socket instrumentation end event.
227 Note that for socket close operations, the instrumented socket handle
228 associated with the socket (which was provided to obtain a locker)
229 is invalid after this call.
230 @param locker a socket locker for the running thread
231 @param count the number of bytes actually used in the operation,
232 or 0 if not applicable, or -1 if the operation failed
233 @sa get_thread_socket_locker
234*/
235typedef void (*end_socket_wait_v1_t)(struct PSI_socket_locker *locker,
236 size_t count);
237
238/**
239 Set the socket state for an instrumented socket.
240 @param socket the instrumented socket
241 @param state socket state
242*/
244 enum PSI_socket_state state);
245
246/**
247 Set the socket info for an instrumented socket.
248 @param socket the instrumented socket
249 @param fd the socket descriptor
250 @param addr the socket ip address
251 @param addr_len length of socket ip address
252*/
253typedef void (*set_socket_info_v1_t)(struct PSI_socket *socket,
254 const my_socket *fd,
255 const struct sockaddr *addr,
256 socklen_t addr_len);
257
258/**
259 Bind a socket to the thread that owns it.
260 @param socket instrumented socket
261*/
263
266
267/** @} (end of group psi_abi_socket) */
268
269#endif /* COMPONENTS_SERVICES_BITS_PSI_SOCKET_BITS_H */
void(* register_socket_v1_t)(const char *category, struct PSI_socket_info_v1 *info, int count)
Socket registration API.
Definition: psi_socket_bits.h:187
PSI_socket_operation
Operation performed on an instrumented socket.
Definition: psi_socket_bits.h:88
struct PSI_socket_locker PSI_socket_locker
Definition: psi_socket_bits.h:76
PSI_socket_state
State of an instrumented socket.
Definition: psi_socket_bits.h:79
void(* set_socket_state_v1_t)(struct PSI_socket *socket, enum PSI_socket_state state)
Set the socket state for an instrumented socket.
Definition: psi_socket_bits.h:243
void(* set_socket_info_v1_t)(struct PSI_socket *socket, const my_socket *fd, const struct sockaddr *addr, socklen_t addr_len)
Set the socket info for an instrumented socket.
Definition: psi_socket_bits.h:253
void(* destroy_socket_v1_t)(struct PSI_socket *socket)
socket instrumentation destruction API.
Definition: psi_socket_bits.h:208
unsigned int PSI_socket_key
Instrumented socket key.
Definition: psi_socket_bits.h:48
void(* set_socket_thread_owner_v1_t)(struct PSI_socket *socket)
Bind a socket to the thread that owns it.
Definition: psi_socket_bits.h:262
void(* end_socket_wait_v1_t)(struct PSI_socket_locker *locker, size_t count)
Record a socket instrumentation end event.
Definition: psi_socket_bits.h:235
@ PSI_SOCKET_CLOSE
Socket close, as in shutdown().
Definition: psi_socket_bits.h:96
@ PSI_SOCKET_RECVMSG
Socket receive, recvmsg().
Definition: psi_socket_bits.h:108
@ PSI_SOCKET_STAT
Socket status, as in sockatmark() and isfdtype().
Definition: psi_socket_bits.h:114
@ PSI_SOCKET_SEND
Socket send, send().
Definition: psi_socket_bits.h:98
@ PSI_SOCKET_SENDMSG
Socket send, sendmsg().
Definition: psi_socket_bits.h:106
@ PSI_SOCKET_RECV
Socket receive, recv().
Definition: psi_socket_bits.h:100
@ PSI_SOCKET_BIND
Socket bind, as in bind(), getsockname() and getpeername().
Definition: psi_socket_bits.h:94
@ PSI_SOCKET_SEEK
Socket seek, such as fseek() or seek().
Definition: psi_socket_bits.h:110
@ PSI_SOCKET_CREATE
Socket creation, as in socket() or socketpair().
Definition: psi_socket_bits.h:90
@ PSI_SOCKET_CONNECT
Socket connection, as in connect(), listen() and accept().
Definition: psi_socket_bits.h:92
@ PSI_SOCKET_SENDTO
Socket send, sendto().
Definition: psi_socket_bits.h:102
@ PSI_SOCKET_SHUTDOWN
Socket shutdown, as in shutdown().
Definition: psi_socket_bits.h:116
@ PSI_SOCKET_RECVFROM
Socket receive, recvfrom).
Definition: psi_socket_bits.h:104
@ PSI_SOCKET_SELECT
Socket select, as in select() and poll().
Definition: psi_socket_bits.h:118
@ PSI_SOCKET_OPT
Socket options, as in getsockopt() and setsockopt().
Definition: psi_socket_bits.h:112
@ PSI_SOCKET_STATE_ACTIVE
Active, executing a command.
Definition: psi_socket_bits.h:83
@ PSI_SOCKET_STATE_IDLE
Idle, waiting for the next command.
Definition: psi_socket_bits.h:81
struct PSI_thread PSI_thread
Definition: psi_thread_bits.h:81
Types to make file and socket I/O compatible.
static int count
Definition: myisam_ftdump.cc:42
int my_socket
Definition: mysql.h:64
Log info(cout, "NOTE")
stdx::expected< native_handle_type, error_type > socket(int family, int sock_type, int protocol)
Definition: socket.h:56
static const char * category
Definition: sha2_password.cc:169
Performance schema instrumentation interface.
required string key
Definition: replication_asynchronous_connection_failover.proto:59
struct sockaddr sockaddr
Definition: sock_probe_win32.h:62
Instrumented artifact.
Definition: psi_bits.h:166
Socket instrument information.
Definition: psi_socket_bits.h:127
int m_volatility
Volatility index.
Definition: psi_socket_bits.h:142
PSI_socket_key * m_key
Pointer to the key assigned to the registered socket.
Definition: psi_socket_bits.h:131
const char * m_documentation
Documentation.
Definition: psi_socket_bits.h:144
const char * m_name
The name of the socket instrument to register.
Definition: psi_socket_bits.h:135
unsigned int m_flags
The flags of the socket instrument to register.
Definition: psi_socket_bits.h:140
State data storage for start_socket_wait_v1_t.
Definition: psi_socket_bits.h:157
unsigned long long m_timer_start
Timer start.
Definition: psi_socket_bits.h:167
enum PSI_socket_operation m_operation
Current operation.
Definition: psi_socket_bits.h:171
unsigned int m_flags
Internal state.
Definition: psi_socket_bits.h:159
struct PSI_socket * m_socket
Current socket.
Definition: psi_socket_bits.h:161
struct PSI_thread * m_thread
Current thread.
Definition: psi_socket_bits.h:163
const char * m_src_file
Source file.
Definition: psi_socket_bits.h:173
size_t m_number_of_bytes
Operation number of bytes.
Definition: psi_socket_bits.h:165
int m_src_line
Source line number.
Definition: psi_socket_bits.h:175
unsigned long long(* m_timer)(void)
Timer function.
Definition: psi_socket_bits.h:169
void * m_wait
Internal data.
Definition: psi_socket_bits.h:177
Interface for an instrumented socket descriptor.
Definition: psi_socket_bits.h:68