Skip to content

Commit 96f9b31

Browse files
committed
Bug#12981100 PERFORMANCE_SCHEMA NET IO IDLE AND RECV EVENTS NEST WITHIN THE WRONG STATEMENT
This bug is caused by the lack of integration between: - the IDLE instrumentation - the SOCKET instrumentation - the STATEMENT instrumentation - the STAGE instrumentation in the server. While each instrumentation taken individually works, the overall result is events that do not properly relate to each others. The fix consist of several parts. 1) Define a network call back interface for the NET structure, so that the network layer can notify events when a packet header is seen. This part is critical to isolate all the SQL layer performance schema related instrumentation from the NET code. 2) Use this call back interface internally in mysqld, to call the IDLE / SOCKET / STATEMENT / STAGE instrumentation in a coherent way, respecting the logical order or events. 3) IDLE instrumentation: - IDLE events are generated with a NULL NESTING_EVENT_ID parent - HAVE_PSI_IDLE_INTERFACE was missing and has been added, to facilitate building without the IDLE instrumentation. 4) STATEMENT instrumentation: Statements are now created (MYSQL_START_STATEMENT) much sooner, when a new packet header is seen. As a result, a new statement instrument "statement/com/", has been defined to represent a statement just started. Also, in release builds only, a spurious "statement/sql/" statement existed, due to a bug related to SHOW PROCEDURE CODE and SHOW FUNCTION CODE, for which no statement name was defined in release builds. This has been fixed. 4) SOCKET instrumentation: no changes in the code itself. SOCKET events are now properly recorded as childrens of a statement, due to the reordering of MYSQL_START_STATEMENT. 5) STAGES instrumentation no changes in the code itself. The first stage ("stage/sql/init") is now started right after a statement starts. 6) Existing test cases tests events_aggregates* were missing instrumentation for "statement/com/Query", so that SQL statements that were intended to be recorded were not. This has been fixed in the tests. Tests outputs have been adjusted, as there is a new statement class. A new test, nesting.test, shows precise events dependencies between all events.
1 parent 10e4351 commit 96f9b31

File tree

93 files changed

+2977
-1984
lines changed

Some content is hidden

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

93 files changed

+2977
-1984
lines changed

include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ SET(HEADERS
5454
m_ctype.h
5555
my_attribute.h
5656
my_compiler.h
57+
mysql_com_server.h
5758
${HEADERS_GEN_CONFIGURE}
5859
)
5960

include/mysql.h.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
unsigned int *return_status;
2828
unsigned char reading_or_writing;
2929
char save_char;
30-
my_bool mysql_socket_idle;
30+
my_bool unused1;
3131
my_bool unused2;
3232
my_bool compress;
3333
my_bool unused3;

include/mysql/psi/mysql_idle.h

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,6 @@
2929
@{
3030
*/
3131

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-
5032
/**
5133
@def MYSQL_START_IDLE_WAIT
5234
Instrumentation helper for table io_waits.
@@ -55,7 +37,7 @@
5537
@param STATE the locker state
5638
@sa MYSQL_END_IDLE_WAIT.
5739
*/
58-
#ifdef HAVE_PSI_INTERFACE
40+
#ifdef HAVE_PSI_IDLE_INTERFACE
5941
#define MYSQL_START_IDLE_WAIT(LOCKER, STATE) \
6042
LOCKER= inline_mysql_start_idle_wait(STATE, __FILE__, __LINE__)
6143
#else
@@ -70,15 +52,15 @@
7052
@param LOCKER the locker
7153
@sa MYSQL_START_IDLE_WAIT.
7254
*/
73-
#ifdef HAVE_PSI_INTERFACE
55+
#ifdef HAVE_PSI_IDLE_INTERFACE
7456
#define MYSQL_END_IDLE_WAIT(LOCKER) \
7557
inline_mysql_end_idle_wait(LOCKER)
7658
#else
7759
#define MYSQL_END_IDLE_WAIT(LOCKER) \
7860
do {} while (0)
7961
#endif
8062

81-
#ifdef HAVE_PSI_INTERFACE
63+
#ifdef HAVE_PSI_IDLE_INTERFACE
8264
/**
8365
Instrumentation calls for MYSQL_START_IDLE_WAIT.
8466
@sa MYSQL_END_IDLE_WAIT.

include/mysql/psi/psi.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ struct PSI_bootstrap
136136
@sa DISABLE_PSI_TABLE
137137
@sa DISABLE_PSI_STAGE
138138
@sa DISABLE_PSI_STATEMENT
139+
@sa DISABLE_PSI_SOCKET
140+
@sa DISABLE_PSI_IDLE
139141
*/
140142

141143
#ifndef DISABLE_PSI_MUTEX
@@ -221,6 +223,16 @@ struct PSI_bootstrap
221223
#define HAVE_PSI_SOCKET_INTERFACE
222224
#endif
223225

226+
/**
227+
@def DISABLE_PSI_IDLE
228+
Compiling option to disable the idle instrumentation.
229+
@sa DISABLE_PSI_MUTEX
230+
*/
231+
232+
#ifndef DISABLE_PSI_IDLE
233+
#define HAVE_PSI_IDLE_INTERFACE
234+
#endif
235+
224236
/**
225237
@def PSI_VERSION_1
226238
Performance Schema Interface number for version 1.

include/mysql_com.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ typedef struct st_net {
302302
unsigned int *return_status;
303303
unsigned char reading_or_writing;
304304
char save_char;
305-
my_bool mysql_socket_idle; /* Perfschema: True when socket state is IDLE */
305+
my_bool unused1; /* Please remove with the next incompatible ABI change */
306306
my_bool unused2; /* Please remove with the next incompatible ABI change */
307307
my_bool compress;
308308
my_bool unused3; /* Please remove with the next incompatible ABI change. */
@@ -323,6 +323,14 @@ typedef struct st_net {
323323
char last_error[MYSQL_ERRMSG_SIZE];
324324
/** Client library sqlstate buffer. Set along with the error message. */
325325
char sqlstate[SQLSTATE_LENGTH+1];
326+
/**
327+
Extension pointer, for the caller private use.
328+
Any program linking with the networking library can use this pointer,
329+
which is handy when private connection specific data needs to be
330+
maintained.
331+
The mysqld server process uses this pointer internally,
332+
to maintain the server internal instrumentation for the connection.
333+
*/
326334
void *extension;
327335
} NET;
328336

include/mysql_com_server.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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
14+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15+
16+
/*
17+
Definitions private to the server,
18+
used in the networking layer to notify specific events.
19+
*/
20+
21+
#ifndef _mysql_com_server_h
22+
#define _mysql_com_server_h
23+
24+
struct st_net_server;
25+
26+
typedef void (*before_header_callback_fn)
27+
(struct st_net *net, void *user_data, size_t count);
28+
29+
typedef void (*after_header_callback_fn)
30+
(struct st_net *net, void *user_data, size_t count, my_bool rc);
31+
32+
struct st_net_server
33+
{
34+
before_header_callback_fn m_before_header;
35+
after_header_callback_fn m_after_header;
36+
void *m_user_data;
37+
};
38+
39+
typedef struct st_net_server NET_SERVER;
40+
41+
#endif

mysql-test/suite/perfschema/include/event_aggregate_setup.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ update performance_schema.setup_instruments set enabled='YES', timed='YES'
122122
update performance_schema.setup_instruments set enabled='YES', timed='YES'
123123
where name in ('statement/sql/select',
124124
'statement/sql/insert',
125+
'statement/com/',
126+
'statement/com/Query',
125127
'statement/com/Quit',
126128
'statement/com/error');
127129

0 commit comments

Comments
 (0)