Skip to content

Commit c907330

Browse files
committed
WL#4896 PERFORMANCE SCHEMA NET IO
Added instrumentation for IDLE events.
1 parent 8cf80c2 commit c907330

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+622
-95
lines changed

include/mysql/psi/mysql_idle.h

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
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 as published by
5+
the Free Software Foundation; version 2 of the License.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with this program; if not, write to the Free Software Foundation,
14+
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15+
16+
#ifndef MYSQL_IDLE_H
17+
#define MYSQL_IDLE_H
18+
19+
/**
20+
@file mysql/psi/mysql_idle.h
21+
Instrumentation helpers for idle waits.
22+
*/
23+
24+
#include "mysql/psi/psi.h"
25+
26+
/**
27+
@defgroup Idle_instrumentation Idle Instrumentation
28+
@ingroup Instrumentation_interface
29+
@{
30+
*/
31+
32+
/**
33+
@def MYSQL_IDLE_WAIT_VARIABLES
34+
Instrumentation helper for idle waits.
35+
This instrumentation declares local variables.
36+
Do not use a ';' after this macro
37+
@param LOCKER the locker
38+
@param STATE the locker state
39+
@sa MYSQL_START_IDLE_WAIT
40+
@sa MYSQL_END_IDLE_WAIT
41+
*/
42+
#ifdef HAVE_PSI_INTERFACE
43+
#define MYSQL_IDLE_WAIT_VARIABLES(LOCKER, STATE) \
44+
struct PSI_idle_locker* LOCKER; \
45+
PSI_idle_locker_state STATE;
46+
#else
47+
#define MYSQL_IDLE_WAIT_VARIABLES(LOCKER, STATE)
48+
#endif
49+
50+
/**
51+
@def MYSQL_START_IDLE_WAIT
52+
Instrumentation helper for table io_waits.
53+
This instrumentation marks the start of a wait event.
54+
@param LOCKER the locker
55+
@param STATE the locker state
56+
@sa MYSQL_END_IDLE_WAIT.
57+
*/
58+
#ifdef HAVE_PSI_INTERFACE
59+
#define MYSQL_START_IDLE_WAIT(LOCKER, STATE) \
60+
LOCKER= inline_mysql_start_idle_wait(STATE, __FILE__, __LINE__)
61+
#else
62+
#define MYSQL_START_IDLE_WAIT(LOCKER, STATE) \
63+
do {} while (0)
64+
#endif
65+
66+
/**
67+
@def MYSQL_END_IDLE_WAIT
68+
Instrumentation helper for idle waits.
69+
This instrumentation marks the end of a wait event.
70+
@param LOCKER the locker
71+
@sa MYSQL_START_IDLE_WAIT.
72+
*/
73+
#ifdef HAVE_PSI_INTERFACE
74+
#define MYSQL_END_IDLE_WAIT(LOCKER) \
75+
inline_mysql_end_idle_wait(LOCKER)
76+
#else
77+
#define MYSQL_END_IDLE_WAIT(LOCKER) \
78+
do {} while (0)
79+
#endif
80+
81+
#ifdef HAVE_PSI_INTERFACE
82+
/**
83+
Instrumentation calls for MYSQL_START_IDLE_WAIT.
84+
@sa MYSQL_END_IDLE_WAIT.
85+
*/
86+
static inline struct PSI_idle_locker *
87+
inline_mysql_start_idle_wait(PSI_idle_locker_state *state,
88+
const char *src_file, int src_line)
89+
{
90+
struct PSI_idle_locker *locker= NULL;
91+
if (likely(PSI_server != NULL))
92+
{
93+
locker= PSI_server->start_idle_wait(state, src_file, src_line);
94+
}
95+
return locker;
96+
}
97+
98+
/**
99+
Instrumentation calls for MYSQL_END_IDLE_WAIT.
100+
@sa MYSQL_START_IDLE_WAIT.
101+
*/
102+
static inline void
103+
inline_mysql_end_idle_wait(struct PSI_idle_locker *locker)
104+
{
105+
if (likely(locker != NULL))
106+
PSI_server->end_idle_wait(locker);
107+
}
108+
#endif
109+
110+
/** @} (end of group Idle_instrumentation) */
111+
112+
#endif
113+

include/mysql/psi/mysql_socket.h

+16
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,22 @@ mysql_socket_invalid()
8686
MYSQL_SOCKET mysql_socket= {INVALID_SOCKET, NULL};
8787
return mysql_socket;
8888
}
89+
90+
/**
91+
Set the state (IDLE, ACTIVE) of an instrumented socket.
92+
@param socket the instrumented socket
93+
@param state the new state
94+
@sa PSI_socket_state
95+
*/
96+
static inline void
97+
mysql_socket_set_state(MYSQL_SOCKET socket, enum PSI_socket_state state)
98+
{
99+
#ifdef HAVE_PSI_INTERFACE
100+
if ((PSI_server != NULL) && (socket.m_psi != NULL))
101+
PSI_server->set_socket_state(socket.m_psi, state);
102+
#endif
103+
}
104+
89105
/**
90106
@def mysql_socket_getfd
91107
MYSQL_SOCKET helper. Get socket descriptor.

include/mysql/psi/psi.h

+67-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -142,6 +142,12 @@ struct PSI_bootstrap
142142
#endif
143143
#endif
144144

145+
/**
146+
Interface for an instrumented idle operation.
147+
This is an opaque structure.
148+
*/
149+
struct PSI_idle_locker;
150+
145151
/**
146152
Interface for an instrumented mutex operation.
147153
This is an opaque structure.
@@ -265,6 +271,15 @@ enum PSI_table_lock_operation
265271
PSI_TABLE_EXTERNAL_LOCK= 1
266272
};
267273

274+
/** State of an instrumented socket. */
275+
enum PSI_socket_state
276+
{
277+
/** Idle, waiting for the next command. */
278+
PSI_SOCKET_STATE_IDLE= 0,
279+
/** Active, executing a command. */
280+
PSI_SOCKET_STATE_ACTIVE= 1
281+
};
282+
268283
/** Operation performed on an instrumented socket. */
269284
enum PSI_socket_operation
270285
{
@@ -514,6 +529,29 @@ struct PSI_socket_info_v1
514529
int m_flags;
515530
};
516531

532+
/**
533+
State data storage for @c start_idle_wait_v1_t.
534+
This structure provide temporary storage to an idle locker.
535+
The content of this structure is considered opaque,
536+
the fields are only hints of what an implementation
537+
of the psi interface can use.
538+
This memory is provided by the instrumented code for performance reasons.
539+
@sa start_idle_wait_v1_t.
540+
*/
541+
struct PSI_idle_locker_state_v1
542+
{
543+
/** Internal state. */
544+
uint m_flags;
545+
/** Current thread. */
546+
struct PSI_thread *m_thread;
547+
/** Timer start. */
548+
ulonglong m_timer_start;
549+
/** Timer function. */
550+
ulonglong (*m_timer)(void);
551+
/** Internal data. */
552+
void *m_wait;
553+
};
554+
517555
/**
518556
State data storage for @c get_thread_mutex_locker_v1_t.
519557
This structure provide temporary storage to a mutex locker.
@@ -1126,6 +1164,12 @@ typedef void (*signal_cond_v1_t)
11261164
typedef void (*broadcast_cond_v1_t)
11271165
(struct PSI_cond *cond);
11281166

1167+
typedef struct PSI_idle_locker* (*start_idle_wait_v1_t)
1168+
(struct PSI_idle_locker_state_v1 *state, const char *src_file, uint src_line);
1169+
1170+
typedef void (*end_idle_wait_v1_t)
1171+
(struct PSI_idle_locker *locker);
1172+
11291173
/**
11301174
Record a mutex instrumentation wait start event.
11311175
@param locker a thread locker for the running thread
@@ -1296,6 +1340,14 @@ typedef void (*start_socket_wait_v1_t)
12961340
typedef void (*end_socket_wait_v1_t)
12971341
(struct PSI_socket_locker *locker, size_t count);
12981342

1343+
/**
1344+
Set the socket state for an instrumented socket.
1345+
@param socket the instrumented socket
1346+
@param state socket state
1347+
*/
1348+
typedef void (*set_socket_state_v1_t)(struct PSI_socket *socket,
1349+
enum PSI_socket_state state);
1350+
12991351
/**
13001352
Set the socket descriptor for an instrumented socket.
13011353
@param socket the instrumented socket
@@ -1434,6 +1486,10 @@ struct PSI_v1
14341486
signal_cond_v1_t signal_cond;
14351487
/** @sa broadcast_cond_v1_t. */
14361488
broadcast_cond_v1_t broadcast_cond;
1489+
/** @sa start_idle_wait_v1_t. */
1490+
start_idle_wait_v1_t start_idle_wait;
1491+
/** @sa end_idle_wait_v1_t. */
1492+
end_idle_wait_v1_t end_idle_wait;
14371493
/** @sa start_mutex_wait_v1_t. */
14381494
start_mutex_wait_v1_t start_mutex_wait;
14391495
/** @sa end_mutex_wait_v1_t. */
@@ -1473,6 +1529,8 @@ struct PSI_v1
14731529
start_socket_wait_v1_t start_socket_wait;
14741530
/** @sa end_socket_wait_v1_t. */
14751531
end_socket_wait_v1_t end_socket_wait;
1532+
/** @sa set_socket_state_v1_t. */
1533+
set_socket_state_v1_t set_socket_state;
14761534
/** @sa set_socket_descriptor_v1_t. */
14771535
set_socket_descriptor_v1_t set_socket_descriptor;
14781536
/** @sa set_socket_address_v1_t. */
@@ -1546,6 +1604,12 @@ struct PSI_file_info_v2
15461604
int placeholder;
15471605
};
15481606

1607+
struct PSI_idle_locker_state_v2
1608+
{
1609+
/** Placeholder */
1610+
int placeholder;
1611+
};
1612+
15491613
struct PSI_mutex_locker_state_v2
15501614
{
15511615
/** Placeholder */
@@ -1626,6 +1690,7 @@ typedef struct PSI_cond_info_v1 PSI_cond_info;
16261690
typedef struct PSI_thread_info_v1 PSI_thread_info;
16271691
typedef struct PSI_file_info_v1 PSI_file_info;
16281692
typedef struct PSI_socket_info_v1 PSI_socket_info;
1693+
typedef struct PSI_idle_locker_state_v1 PSI_idle_locker_state;
16291694
typedef struct PSI_mutex_locker_state_v1 PSI_mutex_locker_state;
16301695
typedef struct PSI_rwlock_locker_state_v1 PSI_rwlock_locker_state;
16311696
typedef struct PSI_cond_locker_state_v1 PSI_cond_locker_state;
@@ -1642,6 +1707,7 @@ typedef struct PSI_cond_info_v2 PSI_cond_info;
16421707
typedef struct PSI_thread_info_v2 PSI_thread_info;
16431708
typedef struct PSI_file_info_v2 PSI_file_info;
16441709
typedef struct PSI_socket_info_v2 PSI_socket_info;
1710+
typedef struct PSI_idle_locker_state_v2 PSI_idle_locker_state;
16451711
typedef struct PSI_mutex_locker_state_v2 PSI_mutex_locker_state;
16461712
typedef struct PSI_rwlock_locker_state_v2 PSI_rwlock_locker_state;
16471713
typedef struct PSI_cond_locker_state_v2 PSI_cond_locker_state;

include/mysql/psi/psi_abi_v1.h.pp

+24
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
{
1515
void* (*get_interface)(int version);
1616
};
17+
struct PSI_idle_locker;
1718
struct PSI_mutex_locker;
1819
struct PSI_rwlock_locker;
1920
struct PSI_cond_locker;
@@ -67,6 +68,11 @@
6768
PSI_TABLE_LOCK= 0,
6869
PSI_TABLE_EXTERNAL_LOCK= 1
6970
};
71+
enum PSI_socket_state
72+
{
73+
PSI_SOCKET_STATE_IDLE= 0,
74+
PSI_SOCKET_STATE_ACTIVE= 1
75+
};
7076
enum PSI_socket_operation
7177
{
7278
PSI_SOCKET_CREATE= 0,
@@ -126,6 +132,14 @@
126132
const char *m_name;
127133
int m_flags;
128134
};
135+
struct PSI_idle_locker_state_v1
136+
{
137+
uint m_flags;
138+
struct PSI_thread *m_thread;
139+
ulonglong m_timer_start;
140+
ulonglong (*m_timer)(void);
141+
void *m_wait;
142+
};
129143
struct PSI_mutex_locker_state_v1
130144
{
131145
uint m_flags;
@@ -297,6 +311,10 @@
297311
(struct PSI_cond *cond);
298312
typedef void (*broadcast_cond_v1_t)
299313
(struct PSI_cond *cond);
314+
typedef struct PSI_idle_locker* (*start_idle_wait_v1_t)
315+
(struct PSI_idle_locker_state_v1 *state, const char *src_file, uint src_line);
316+
typedef void (*end_idle_wait_v1_t)
317+
(struct PSI_idle_locker *locker);
300318
typedef void (*start_mutex_wait_v1_t)
301319
(struct PSI_mutex_locker *locker, const char *src_file, uint src_line);
302320
typedef void (*end_mutex_wait_v1_t)
@@ -334,6 +352,8 @@
334352
const char *src_file, uint src_line);
335353
typedef void (*end_socket_wait_v1_t)
336354
(struct PSI_socket_locker *locker, size_t count);
355+
typedef void (*set_socket_state_v1_t)(struct PSI_socket *socket,
356+
enum PSI_socket_state state);
337357
typedef void (*set_socket_descriptor_v1_t)(struct PSI_socket *socket,
338358
uint fd);
339359
typedef void (*set_socket_address_v1_t)(struct PSI_socket *socket,
@@ -394,6 +414,8 @@
394414
unlock_rwlock_v1_t unlock_rwlock;
395415
signal_cond_v1_t signal_cond;
396416
broadcast_cond_v1_t broadcast_cond;
417+
start_idle_wait_v1_t start_idle_wait;
418+
end_idle_wait_v1_t end_idle_wait;
397419
start_mutex_wait_v1_t start_mutex_wait;
398420
end_mutex_wait_v1_t end_mutex_wait;
399421
start_rwlock_rdwait_v1_t start_rwlock_rdwait;
@@ -414,6 +436,7 @@
414436
end_file_wait_v1_t end_file_wait;
415437
start_socket_wait_v1_t start_socket_wait;
416438
end_socket_wait_v1_t end_socket_wait;
439+
set_socket_state_v1_t set_socket_state;
417440
set_socket_descriptor_v1_t set_socket_descriptor;
418441
set_socket_address_v1_t set_socket_address;
419442
set_socket_info_v1_t set_socket_info;
@@ -426,6 +449,7 @@
426449
typedef struct PSI_thread_info_v1 PSI_thread_info;
427450
typedef struct PSI_file_info_v1 PSI_file_info;
428451
typedef struct PSI_socket_info_v1 PSI_socket_info;
452+
typedef struct PSI_idle_locker_state_v1 PSI_idle_locker_state;
429453
typedef struct PSI_mutex_locker_state_v1 PSI_mutex_locker_state;
430454
typedef struct PSI_rwlock_locker_state_v1 PSI_rwlock_locker_state;
431455
typedef struct PSI_cond_locker_state_v1 PSI_cond_locker_state;

include/mysql/psi/psi_abi_v2.h.pp

+11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
{
1515
void* (*get_interface)(int version);
1616
};
17+
struct PSI_idle_locker;
1718
struct PSI_mutex_locker;
1819
struct PSI_rwlock_locker;
1920
struct PSI_cond_locker;
@@ -67,6 +68,11 @@
6768
PSI_TABLE_LOCK= 0,
6869
PSI_TABLE_EXTERNAL_LOCK= 1
6970
};
71+
enum PSI_socket_state
72+
{
73+
PSI_SOCKET_STATE_IDLE= 0,
74+
PSI_SOCKET_STATE_ACTIVE= 1
75+
};
7076
enum PSI_socket_operation
7177
{
7278
PSI_SOCKET_CREATE= 0,
@@ -114,6 +120,10 @@
114120
{
115121
int placeholder;
116122
};
123+
struct PSI_idle_locker_state_v2
124+
{
125+
int placeholder;
126+
};
117127
struct PSI_mutex_locker_state_v2
118128
{
119129
int placeholder;
@@ -145,6 +155,7 @@
145155
typedef struct PSI_thread_info_v2 PSI_thread_info;
146156
typedef struct PSI_file_info_v2 PSI_file_info;
147157
typedef struct PSI_socket_info_v2 PSI_socket_info;
158+
typedef struct PSI_idle_locker_state_v2 PSI_idle_locker_state;
148159
typedef struct PSI_mutex_locker_state_v2 PSI_mutex_locker_state;
149160
typedef struct PSI_rwlock_locker_state_v2 PSI_rwlock_locker_state;
150161
typedef struct PSI_cond_locker_state_v2 PSI_cond_locker_state;

0 commit comments

Comments
 (0)