summaryrefslogtreecommitdiff
path: root/mysql-test/suite/perfschema/t/ortho_iter.test
blob: d577b6dba5bf09f5f148b27430ca19da09579183 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# Tests for PERFORMANCE_SCHEMA
# Verify the orthogonality of iterators (table*::rnd_next()),
# for every table and instruments.

--source include/not_embedded.inc
--source include/no_valgrind_without_big.inc
--source include/have_perfschema.inc

--disable_warnings
drop procedure if exists check_instrument;
--enable_warnings

# reset counters
truncate table performance_schema.events_statements_summary_by_digest;
flush status;

# Print known global memory instruments (PSI_FLAG_GLOBAL),
# see maintenance of count_global_expected below.

# --echo "Known PSI_FLAG_GLOBAL memory instruments"
# select name from performance_schema.setup_instruments
#   where (name like "memory/%")
#   and (name not like "memory/performance_schema/%")
#   and (name not in
#     (select event_name from
#       performance_schema.memory_summary_by_account_by_event_name));

--enable_prepare_warnings

delimiter $;
create procedure check_instrument(in instr_name varchar(128))
begin
  declare save_count_expected integer;
  declare count_expected integer;
  declare count_builtin_expected integer;
  declare count_global_expected integer;
  declare is_wait integer;
  declare is_wait_file integer;
  declare is_wait_socket integer;
  declare is_stage integer;
  declare is_statement integer;
  declare is_transaction integer;
  declare is_memory integer;
  declare is_wait_table integer;
  declare is_wait_file_table integer;
  declare is_wait_socket_table integer;
  declare is_stage_table integer;
  declare is_statement_table integer;
  declare is_transaction_table integer;
  declare is_memory_table integer;
  declare is_memory_global_table integer;
  declare pfs_table_name varchar(64);
  declare msg varchar(512);
  declare msg_detail varchar(512);
  declare cmd_1 varchar(512);
  declare cmd_2 varchar(512);
  declare done integer default 0;
  declare debug integer default 0;

  declare pfs_cursor CURSOR FOR
    select table_name from information_schema.tables
      where table_schema= 'performance_schema'
      and table_name like "%_by_event_name%"
      order by table_name;

  declare continue handler for sqlstate '02000'
    set done = 1;

  select (instr_name like "wait/%") or (instr_name like "idle") into is_wait;
  select (instr_name like "wait/io/file/%") into is_wait_file;
  select (instr_name like "wait/io/socket/%") into is_wait_socket;
  select (instr_name like "stage/%") into is_stage;
  select (instr_name like "statement/%") into is_statement;
  select (instr_name like "memory/%") into is_memory;
  select (instr_name like "transaction") into is_transaction;

  select instr_name, is_wait, is_wait_file, is_wait_socket, is_stage, is_statement, is_memory, is_transaction;

  select count(name)
    from performance_schema.setup_instruments
    where (name like (concat(instr_name, "%")))
    and (not name like "%/abstract/%")
    and (not name like "memory/performance_schema/%")
    into save_count_expected;

  select count(name)
    from performance_schema.setup_instruments
    where (name like (concat(instr_name, "%")))
    and (name like "memory/performance_schema/%")
    into count_builtin_expected;

  select count(name)
    from performance_schema.setup_instruments
    where (name like (concat(instr_name, "%")))
    and (name in (
      "memory/sql/buffered_logs",
      "memory/sql/sql_acl_mem",
      "memory/sql/sql_acl_memex",
      "memory/sql/acl_cache",
      "memory/sql/TABLE_SHARE::mem_root",
      "memory/sql/TABLE",
      "memory/sql/Query_cache",
      "memory/sql/native_functions",
      "memory/sql/Event_basic::mem_root",
      "memory/sql/root",
      "memory/sql/load_env_plugins",
      "memory/sql/plugin_ref",
      "memory/sql/plugin_mem_root",
      "memory/sql/plugin_bookmark",
      "memory/csv/TINA_SHARE",
      "memory/sql/tz_storage",
      "memory/sql/servers_cache",
      "memory/sql/udf_mem"
    ))
  into count_global_expected;

  set cmd_1= "select count(*) from (select distinct event_name from performance_schema.";
  set cmd_2= concat(" where event_name like \"",
                    instr_name,
                    "%\") t into @count_actual");

  open pfs_cursor;
  repeat
    fetch pfs_cursor into pfs_table_name;
    if not done then
      select (pfs_table_name like "%waits%") into is_wait_table;
      select (pfs_table_name like "file_summary%") into is_wait_file_table;
      select (pfs_table_name like "socket_summary%") into is_wait_socket_table;
      select (pfs_table_name like "%stages%") into is_stage_table;
      select (pfs_table_name like "%statements%") into is_statement_table;
      select (pfs_table_name like "%memory%") into is_memory_table;
      select (pfs_table_name like "memory_summary_global_by_event_name") into is_memory_global_table;
      select (pfs_table_name like "%transaction%") into is_transaction_table;

      set count_expected = save_count_expected;

      if is_memory_global_table
      then
        set count_expected = save_count_expected + count_builtin_expected;
      end if;

      if is_memory_table = 1 and is_memory_global_table = 0
      then
        set count_expected = save_count_expected - count_global_expected;
      end if;

      select concat("Checking table ", pfs_table_name, " ...") as status;
      select concat(cmd_1, pfs_table_name, cmd_2) into @cmd;
      if debug = 1
      then
        select @cmd;
      end if;
      prepare stmt from @cmd;
      execute stmt;
      drop prepare stmt;
      set msg_detail= concat("table ", pfs_table_name,
                             ", instruments ", count_expected,
                             ", found ", @count_actual);

      if is_wait = 1
      then
        if is_wait_table = 1 and @count_actual <> count_expected
        then
          set msg= concat("Missing wait events: ", msg_detail);
          signal sqlstate '05000' set message_text= msg;
        end if;

        if is_wait_table = 0
           and is_wait_file_table = 0
           and is_wait_socket_table = 0
           and @count_actual <> 0
        then
          set msg= concat("Unexpected wait events: ", msg_detail);
          signal sqlstate '05000' set message_text= msg;
        end if;
      end if;

      if is_wait_file = 1
      then
        if is_wait_file_table = 1 and @count_actual <> count_expected
        then
          set msg= concat("Missing wait/io/file events: ", msg_detail);
          signal sqlstate '05000' set message_text= msg;
        end if;

        if is_wait_table = 0 and is_wait_file_table = 0 and @count_actual <> 0
        then
          set msg= concat("Unexpected wait/io/file events: ", msg_detail);
          signal sqlstate '05000' set message_text= msg;
        end if;
      end if;

      if is_wait_socket = 1
      then
        if is_wait_socket_table = 1 and @count_actual <> count_expected
        then
          set msg= concat("Missing wait/io/socket events: ", msg_detail);
          signal sqlstate '05000' set message_text= msg;
        end if;

        if is_wait_table = 0 and is_wait_socket_table = 0 and @count_actual <> 0
        then
          set msg= concat("Unexpected wait/io/socket events: ", msg_detail);
          signal sqlstate '05000' set message_text= msg;
        end if;
      end if;

      if is_stage = 1
      then
        if is_stage_table = 1 and @count_actual <> count_expected
        then
          set msg= concat("Missing stage events: ", msg_detail);
          signal sqlstate '05000' set message_text= msg;
        end if;

        if is_stage_table = 0 and @count_actual <> 0
        then
          set msg= concat("Unexpected stage events: ", msg_detail);
          signal sqlstate '05000' set message_text= msg;
        end if;
      end if;

      if is_statement = 1
      then
        if is_statement_table = 1 and @count_actual <> count_expected
        then
          set msg= concat("Missing statement events: ", msg_detail);
          signal sqlstate '05000' set message_text= msg;
        end if;

        if is_statement_table = 0 and @count_actual <> 0
        then
          set msg= concat("Unexpected statement events: ", msg_detail);
          signal sqlstate '05000' set message_text= msg;
        end if;
      end if;

      if is_memory = 1
      then
        if is_memory_table = 1 and @count_actual <> count_expected
        then
          set msg= concat("Missing memory events: ", msg_detail);
          signal sqlstate '05000' set message_text= msg;
        end if;

        if is_memory_table = 0 and @count_actual <> 0
        then
          set msg= concat("Unexpected memory events: ", msg_detail);
          signal sqlstate '05000' set message_text= msg;
        end if;
      end if;

      if is_transaction = 1
      then
        if is_transaction_table = 1 and @count_actual <> count_expected
        then
          set msg= concat("Missing transaction events: ", msg_detail);
          signal sqlstate '05000' set message_text= msg;
        end if;

        if is_transaction_table = 0 and @count_actual <> 0
        then
          set msg= concat("Unexpected transaction events: ", msg_detail);
          signal sqlstate '05000' set message_text= msg;
        end if;
      end if;

    end if;
  until done
  end repeat;
  close pfs_cursor;

  -- Dont want to return a 02000 NOT FOUND, there should be a better way
  signal sqlstate '01000' set message_text='Done', mysql_errno=12000;
end
$
delimiter ;$

--disable_prepare_warnings

# Check the configuration is ok
show global variables like "performance_schema%";

call check_instrument("wait/synch/mutex/");
call check_instrument("wait/synch/rwlock/");
call check_instrument("wait/synch/sxlock/");
call check_instrument("wait/synch/cond/");
call check_instrument("wait/synch/");
call check_instrument("wait/io/file/");
call check_instrument("wait/io/socket/");
call check_instrument("wait/io/table/");
call check_instrument("wait/io/");
call check_instrument("wait/lock/table/");
call check_instrument("wait/lock/");
call check_instrument("wait/");
call check_instrument("stage/");
call check_instrument("statement/com/");
call check_instrument("statement/sql/");
call check_instrument("statement/abstract/");
call check_instrument("statement/");
call check_instrument("idle");
call check_instrument("memory/");
call check_instrument("memory/performance_schema/");
call check_instrument("transaction");

drop procedure check_instrument;