1# Tests for PERFORMANCE_SCHEMA 2# Verify the orthogonality of iterators (table*::rnd_next()), 3# for every table and instruments. 4 5--source include/not_embedded.inc 6--source include/no_valgrind_without_big.inc 7--source include/have_perfschema.inc 8 9--disable_warnings 10drop procedure if exists check_instrument; 11--enable_warnings 12 13# Print known global memory instruments (PSI_FLAG_GLOBAL), 14# see maintenance of count_global_expected below. 15 16# --echo "Known PSI_FLAG_GLOBAL memory instruments" 17# select name from performance_schema.setup_instruments 18# where (name like "memory/%") 19# and (name not like "memory/performance_schema/%") 20# and (name not in 21# (select event_name from 22# performance_schema.memory_summary_by_account_by_event_name)); 23 24delimiter $; 25create procedure check_instrument(in instr_name varchar(128)) 26begin 27 declare save_count_expected integer; 28 declare count_expected integer; 29 declare count_builtin_expected integer; 30 declare count_global_expected integer; 31 declare is_wait integer; 32 declare is_wait_file integer; 33 declare is_wait_socket integer; 34 declare is_stage integer; 35 declare is_statement integer; 36 declare is_transaction integer; 37 declare is_memory integer; 38 declare is_wait_table integer; 39 declare is_wait_file_table integer; 40 declare is_wait_socket_table integer; 41 declare is_stage_table integer; 42 declare is_statement_table integer; 43 declare is_transaction_table integer; 44 declare is_memory_table integer; 45 declare is_memory_global_table integer; 46 declare pfs_table_name varchar(64); 47 declare msg varchar(512); 48 declare msg_detail varchar(512); 49 declare cmd_1 varchar(512); 50 declare cmd_2 varchar(512); 51 declare done integer default 0; 52 declare debug integer default 0; 53 54 declare pfs_cursor CURSOR FOR 55 select table_name from information_schema.tables 56 where table_schema= 'performance_schema' 57 and table_name like "%_by_event_name%"; 58 59 declare continue handler for sqlstate '02000' 60 set done = 1; 61 62 select (instr_name like "wait/%") or (instr_name like "idle") into is_wait; 63 select (instr_name like "wait/io/file/%") into is_wait_file; 64 select (instr_name like "wait/io/socket/%") into is_wait_socket; 65 select (instr_name like "stage/%") into is_stage; 66 select (instr_name like "statement/%") into is_statement; 67 select (instr_name like "memory/%") into is_memory; 68 select (instr_name like "transaction") into is_transaction; 69 70 select instr_name, is_wait, is_wait_file, is_wait_socket, is_stage, is_statement, is_memory, is_transaction; 71 72 select count(name) 73 from performance_schema.setup_instruments 74 where (name like (concat(instr_name, "%"))) 75 and (not name like "%/abstract/%") 76 and (not name like "memory/performance_schema/%") 77 into save_count_expected; 78 79 select count(name) 80 from performance_schema.setup_instruments 81 where (name like (concat(instr_name, "%"))) 82 and (name like "memory/performance_schema/%") 83 into count_builtin_expected; 84 85 select count(name) 86 from performance_schema.setup_instruments 87 where (name like (concat(instr_name, "%"))) 88 and (name in ( 89 "memory/sql/buffered_logs", 90 "memory/sql/sql_acl_mem", 91 "memory/sql/sql_acl_memex", 92 "memory/sql/acl_cache", 93 "memory/sql/TABLE_SHARE::mem_root", 94 "memory/sql/TABLE", 95 "memory/sql/Query_cache", 96 "memory/sql/native_functions", 97 "memory/sql/Event_basic::mem_root", 98 "memory/sql/root", 99 "memory/sql/load_env_plugins", 100 "memory/sql/plugin_ref", 101 "memory/sql/plugin_mem_root", 102 "memory/sql/plugin_bookmark", 103 "memory/csv/TINA_SHARE", 104 "memory/sql/tz_storage", 105 "memory/sql/servers_cache", 106 "memory/sql/udf_mem" 107 )) 108 into count_global_expected; 109 110 set cmd_1= "select count(*) from (select distinct event_name from performance_schema."; 111 set cmd_2= concat(" where event_name like \"", 112 instr_name, 113 "%\") t into @count_actual"); 114 115 open pfs_cursor; 116 repeat 117 fetch pfs_cursor into pfs_table_name; 118 if not done then 119 select (pfs_table_name like "%waits%") into is_wait_table; 120 select (pfs_table_name like "file_summary%") into is_wait_file_table; 121 select (pfs_table_name like "socket_summary%") into is_wait_socket_table; 122 select (pfs_table_name like "%stages%") into is_stage_table; 123 select (pfs_table_name like "%statements%") into is_statement_table; 124 select (pfs_table_name like "%memory%") into is_memory_table; 125 select (pfs_table_name like "memory_summary_global_by_event_name") into is_memory_global_table; 126 select (pfs_table_name like "%transaction%") into is_transaction_table; 127 128 set count_expected = save_count_expected; 129 130 if is_memory_global_table 131 then 132 set count_expected = save_count_expected + count_builtin_expected; 133 end if; 134 135 if is_memory_table = 1 and is_memory_global_table = 0 136 then 137 set count_expected = save_count_expected - count_global_expected; 138 end if; 139 140 select concat("Checking table ", pfs_table_name, " ...") as status; 141 select concat(cmd_1, pfs_table_name, cmd_2) into @cmd; 142 if debug = 1 143 then 144 select @cmd; 145 end if; 146 prepare stmt from @cmd; 147 execute stmt; 148 drop prepare stmt; 149 set msg_detail= concat("table ", pfs_table_name, 150 ", instruments ", count_expected, 151 ", found ", @count_actual); 152 153 if is_wait = 1 154 then 155 if is_wait_table = 1 and @count_actual <> count_expected 156 then 157 set msg= concat("Missing wait events: ", msg_detail); 158 signal sqlstate '05000' set message_text= msg; 159 end if; 160 161 if is_wait_table = 0 162 and is_wait_file_table = 0 163 and is_wait_socket_table = 0 164 and @count_actual <> 0 165 then 166 set msg= concat("Unexpected wait events: ", msg_detail); 167 signal sqlstate '05000' set message_text= msg; 168 end if; 169 end if; 170 171 if is_wait_file = 1 172 then 173 if is_wait_file_table = 1 and @count_actual <> count_expected 174 then 175 set msg= concat("Missing wait/io/file events: ", msg_detail); 176 signal sqlstate '05000' set message_text= msg; 177 end if; 178 179 if is_wait_table = 0 and is_wait_file_table = 0 and @count_actual <> 0 180 then 181 set msg= concat("Unexpected wait/io/file events: ", msg_detail); 182 signal sqlstate '05000' set message_text= msg; 183 end if; 184 end if; 185 186 if is_wait_socket = 1 187 then 188 if is_wait_socket_table = 1 and @count_actual <> count_expected 189 then 190 set msg= concat("Missing wait/io/socket events: ", msg_detail); 191 signal sqlstate '05000' set message_text= msg; 192 end if; 193 194 if is_wait_table = 0 and is_wait_socket_table = 0 and @count_actual <> 0 195 then 196 set msg= concat("Unexpected wait/io/socket events: ", msg_detail); 197 signal sqlstate '05000' set message_text= msg; 198 end if; 199 end if; 200 201 if is_stage = 1 202 then 203 if is_stage_table = 1 and @count_actual <> count_expected 204 then 205 set msg= concat("Missing stage events: ", msg_detail); 206 signal sqlstate '05000' set message_text= msg; 207 end if; 208 209 if is_stage_table = 0 and @count_actual <> 0 210 then 211 set msg= concat("Unexpected stage events: ", msg_detail); 212 signal sqlstate '05000' set message_text= msg; 213 end if; 214 end if; 215 216 if is_statement = 1 217 then 218 if is_statement_table = 1 and @count_actual <> count_expected 219 then 220 set msg= concat("Missing statement events: ", msg_detail); 221 signal sqlstate '05000' set message_text= msg; 222 end if; 223 224 if is_statement_table = 0 and @count_actual <> 0 225 then 226 set msg= concat("Unexpected statement events: ", msg_detail); 227 signal sqlstate '05000' set message_text= msg; 228 end if; 229 end if; 230 231 if is_memory = 1 232 then 233 if is_memory_table = 1 and @count_actual <> count_expected 234 then 235 set msg= concat("Missing memory events: ", msg_detail); 236 signal sqlstate '05000' set message_text= msg; 237 end if; 238 239 if is_memory_table = 0 and @count_actual <> 0 240 then 241 set msg= concat("Unexpected memory events: ", msg_detail); 242 signal sqlstate '05000' set message_text= msg; 243 end if; 244 end if; 245 246 if is_transaction = 1 247 then 248 if is_transaction_table = 1 and @count_actual <> count_expected 249 then 250 set msg= concat("Missing transaction events: ", msg_detail); 251 signal sqlstate '05000' set message_text= msg; 252 end if; 253 254 if is_transaction_table = 0 and @count_actual <> 0 255 then 256 set msg= concat("Unexpected transaction events: ", msg_detail); 257 signal sqlstate '05000' set message_text= msg; 258 end if; 259 end if; 260 261 end if; 262 until done 263 end repeat; 264 close pfs_cursor; 265 266 -- Dont want to return a 02000 NOT FOUND, there should be a better way 267 signal sqlstate '01000' set message_text='Done', mysql_errno=12000; 268end 269$ 270delimiter ;$ 271 272# Check the configuration is ok 273show global variables where 274 `Variable_name` != "performance_schema_max_statement_classes" and 275 `Variable_name` like "performance_schema%"; 276 277call check_instrument("wait/synch/mutex/"); 278call check_instrument("wait/synch/rwlock/"); 279call check_instrument("wait/synch/sxlock/"); 280call check_instrument("wait/synch/cond/"); 281call check_instrument("wait/synch/"); 282call check_instrument("wait/io/file/"); 283call check_instrument("wait/io/socket/"); 284call check_instrument("wait/io/table/"); 285call check_instrument("wait/io/"); 286call check_instrument("wait/lock/table/"); 287call check_instrument("wait/lock/"); 288call check_instrument("wait/"); 289call check_instrument("stage/"); 290call check_instrument("statement/com/"); 291call check_instrument("statement/sql/"); 292call check_instrument("statement/abstract/"); 293call check_instrument("statement/"); 294call check_instrument("idle"); 295call check_instrument("memory/"); 296call check_instrument("memory/performance_schema/"); 297call check_instrument("transaction"); 298 299drop procedure check_instrument; 300 301