|
| 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 | +# Tests for the performance schema |
| 17 | + |
| 18 | +# ============= |
| 19 | +# DOCUMENTATION |
| 20 | +# ============= |
| 21 | + |
| 22 | +# Verify critical stages of a statement |
| 23 | +# |
| 24 | +# The tests are written with the following helpers: |
| 25 | +# - include/stage_setup.inc |
| 26 | +# - include/stage_cleanup.inc |
| 27 | +# |
| 28 | +# Helpers are intended to be used as follows. |
| 29 | +# |
| 30 | +# A Typical test t/stage_xxx.test will consist of: |
| 31 | +# --source ../include/stage_setup.inc |
| 32 | +# ... test specific payload ... |
| 33 | +# --source ../include/stage_cleanup.inc |
| 34 | +# and a t/stage_xxx-master.opt file |
| 35 | +# |
| 36 | +# ============================== |
| 37 | +# HELPER include/stage_setup.inc |
| 38 | +# ============================== |
| 39 | + |
| 40 | +--source include/not_embedded.inc |
| 41 | +--source include/have_perfschema.inc |
| 42 | + |
| 43 | +# The file with expected results fits only to a run without |
| 44 | +# ps-protocol/sp-protocol/cursor-protocol/view-protocol. |
| 45 | +if (`SELECT $PS_PROTOCOL + $SP_PROTOCOL + $CURSOR_PROTOCOL |
| 46 | + + $VIEW_PROTOCOL > 0`) |
| 47 | +{ |
| 48 | + --skip Test requires: ps-protocol/sp-protocol/cursor-protocol/view-protocol disabled |
| 49 | +} |
| 50 | + |
| 51 | +--disable_query_log |
| 52 | + |
| 53 | +grant ALL on *.* to user1@localhost; |
| 54 | +grant ALL on *.* to user2@localhost; |
| 55 | +grant ALL on *.* to user3@localhost; |
| 56 | +grant ALL on *.* to user4@localhost; |
| 57 | + |
| 58 | +flush privileges; |
| 59 | + |
| 60 | +# Save the setup |
| 61 | + |
| 62 | +--disable_warnings |
| 63 | +drop table if exists test.setup_actors; |
| 64 | +drop table if exists test.t1; |
| 65 | +--enable_warnings |
| 66 | + |
| 67 | +create table test.t1(a varchar(64)); |
| 68 | + |
| 69 | +create table test.setup_actors as |
| 70 | + select * from performance_schema.setup_actors; |
| 71 | + |
| 72 | +# Only instrument the user connections |
| 73 | +truncate table performance_schema.setup_actors; |
| 74 | +insert into performance_schema.setup_actors |
| 75 | + set host= 'localhost', user= 'user1', role= '%'; |
| 76 | +insert into performance_schema.setup_actors |
| 77 | + set host= 'localhost', user= 'user2', role= '%'; |
| 78 | +insert into performance_schema.setup_actors |
| 79 | + set host= 'localhost', user= 'user3', role= '%'; |
| 80 | +insert into performance_schema.setup_actors |
| 81 | + set host= 'localhost', user= 'user4', role= '%'; |
| 82 | + |
| 83 | +update performance_schema.threads set instrumented='NO'; |
| 84 | + |
| 85 | +# Only instrument a few events of each kind |
| 86 | +update performance_schema.setup_instruments set enabled='YES', timed='YES'; |
| 87 | + |
| 88 | +# Start from a known clean state, to avoid noise from previous tests |
| 89 | +flush tables; |
| 90 | +flush status; |
| 91 | +truncate performance_schema.events_stages_summary_by_thread_by_event_name; |
| 92 | +truncate performance_schema.events_stages_summary_global_by_event_name; |
| 93 | +truncate performance_schema.events_stages_history; |
| 94 | +truncate performance_schema.events_stages_history_long; |
| 95 | +truncate performance_schema.events_statements_summary_by_thread_by_event_name; |
| 96 | +truncate performance_schema.events_statements_summary_global_by_event_name; |
| 97 | +truncate performance_schema.events_statements_history; |
| 98 | +truncate performance_schema.events_statements_history_long; |
| 99 | + |
| 100 | +--disable_warnings |
| 101 | +drop procedure if exists dump_thread; |
| 102 | +drop procedure if exists dump_one_thread; |
| 103 | +--enable_warnings |
| 104 | + |
| 105 | +delimiter $$; |
| 106 | + |
| 107 | +create procedure dump_thread() |
| 108 | +begin |
| 109 | + call dump_one_thread('user1'); |
| 110 | + call dump_one_thread('user2'); |
| 111 | + call dump_one_thread('user3'); |
| 112 | + call dump_one_thread('user4'); |
| 113 | +end |
| 114 | +$$ |
| 115 | + |
| 116 | +create procedure dump_one_thread(in username varchar(64)) |
| 117 | +begin |
| 118 | + declare my_thread_id int; |
| 119 | + declare my_statement_id int; |
| 120 | + |
| 121 | + set my_thread_id = (select thread_id from performance_schema.threads |
| 122 | + where processlist_user=username); |
| 123 | + |
| 124 | + if (my_thread_id is not null) then |
| 125 | + begin |
| 126 | + # Dump the current statement for this thread |
| 127 | + select username, event_name, sql_text |
| 128 | + from performance_schema.events_statements_current |
| 129 | + where thread_id = my_thread_id; |
| 130 | + |
| 131 | + # Get the current statement |
| 132 | + set my_statement_id = (select event_id from |
| 133 | + performance_schema.events_statements_current |
| 134 | + where thread_id = my_thread_id); |
| 135 | + |
| 136 | + # Dump the stages for this statement |
| 137 | + select username, event_name, nesting_event_type |
| 138 | + from performance_schema.events_stages_current |
| 139 | + where thread_id = my_thread_id |
| 140 | + and nesting_event_id = my_statement_id |
| 141 | + order by event_id asc; |
| 142 | + select username, event_name, nesting_event_type |
| 143 | + from performance_schema.events_stages_history |
| 144 | + where thread_id = my_thread_id |
| 145 | + and nesting_event_id = my_statement_id |
| 146 | + order by event_id asc; |
| 147 | + end; |
| 148 | + else |
| 149 | + select username, "not found" as status; |
| 150 | + end if; |
| 151 | +end |
| 152 | +$$ |
| 153 | + |
| 154 | +delimiter ;$$ |
| 155 | + |
| 156 | +--enable_query_log |
0 commit comments