| 1 |
# |
| 2 |
# Expected test structure: |
| 3 |
# |
| 4 |
# 1) |
| 5 |
# |
| 6 |
# update table performance_schema.setup_instruments, |
| 7 |
# to set enabled and controlled memory instruments |
| 8 |
# to use for the payload. |
| 9 |
# |
| 10 |
# 2) |
| 11 |
# |
| 12 |
# --source ../include/controlled_memory_setup.inc |
| 13 |
# |
| 14 |
# Optional: |
| 15 |
# |
| 16 |
# let $ctrl_mem_debug = TRUE; |
| 17 |
# |
| 18 |
# 3) (multiple sections) |
| 19 |
# |
| 20 |
# --connection con1 |
| 21 |
# |
| 22 |
# <test payload> |
| 23 |
# |
| 24 |
# --connection con2 |
| 25 |
# |
| 26 |
# <test payload> |
| 27 |
# |
| 28 |
# --source ../include/controlled_memory_dump.inc |
| 29 |
# |
| 30 |
# 4) |
| 31 |
# --source ../include/controlled_memory_cleanup.inc |
| 32 |
# |
| 33 |
# Tests performed: |
| 34 |
# |
| 35 |
# - check that per thread stats are consistent with thread summaries |
| 36 |
# - check that per statements stats are consistent with thread stats |
| 37 |
# - check that digest summaries are consistent with statements |
| 38 |
|
| 39 |
--disable_query_log |
| 40 |
|
| 41 |
# To debug a test, override this default in the .test file |
| 42 |
let $ctrl_mem_debug = FALSE; |
| 43 |
|
| 44 |
CREATE TABLE test.enforced AS |
| 45 |
SELECT NAME FROM performance_schema.setup_instruments |
| 46 |
WHERE (find_in_set('controlled', FLAGS)); |
| 47 |
|
| 48 |
delimiter $$; |
| 49 |
|
| 50 |
CREATE PROCEDURE test.verify_thread( |
| 51 |
inspect_tid BIGINT UNSIGNED, |
| 52 |
con_name varchar(10), |
| 53 |
debug BOOLEAN) |
| 54 |
BEGIN |
| 55 |
DECLARE expected_ctrl_size bigint; |
| 56 |
DECLARE expected_ctrl_max bigint; |
| 57 |
DECLARE expected_total_size bigint; |
| 58 |
DECLARE expected_total_max bigint; |
| 59 |
DECLARE thread_ctrl_size bigint; |
| 60 |
DECLARE thread_ctrl_max bigint; |
| 61 |
DECLARE thread_total_size bigint; |
| 62 |
DECLARE thread_total_max bigint; |
| 63 |
DECLARE stmt_ctrl_max bigint; |
| 64 |
DECLARE stmt_total_max bigint; |
| 65 |
declare msg varchar(512); |
| 66 |
|
| 67 |
SELECT SUM(CURRENT_NUMBER_OF_BYTES_USED), SUM(HIGH_NUMBER_OF_BYTES_USED) |
| 68 |
FROM performance_schema.memory_summary_by_thread_by_event_name |
| 69 |
WHERE THREAD_ID = inspect_tid |
| 70 |
AND EVENT_NAME IN (SELECT * FROM test.enforced) |
| 71 |
INTO expected_ctrl_size, expected_ctrl_max; |
| 72 |
|
| 73 |
/* For empty test.enforced */ |
| 74 |
IF (expected_ctrl_size is null) |
| 75 |
THEN |
| 76 |
SET expected_ctrl_size = 0; |
| 77 |
END IF; |
| 78 |
|
| 79 |
IF (expected_ctrl_max is null) |
| 80 |
THEN |
| 81 |
SET expected_ctrl_max = 0; |
| 82 |
END IF; |
| 83 |
|
| 84 |
SELECT SUM(CURRENT_NUMBER_OF_BYTES_USED), SUM(HIGH_NUMBER_OF_BYTES_USED) |
| 85 |
FROM performance_schema.memory_summary_by_thread_by_event_name |
| 86 |
WHERE THREAD_ID = inspect_tid |
| 87 |
INTO expected_total_size, expected_total_max; |
| 88 |
|
| 89 |
IF (debug) |
| 90 |
THEN |
| 91 |
SELECT THREAD_ID, EVENT_NAME, CURRENT_NUMBER_OF_BYTES_USED, HIGH_NUMBER_OF_BYTES_USED |
| 92 |
FROM performance_schema.memory_summary_by_thread_by_event_name |
| 93 |
WHERE THREAD_ID = inspect_tid |
| 94 |
AND HIGH_NUMBER_OF_BYTES_USED > 0; |
| 95 |
END IF; |
| 96 |
|
| 97 |
SELECT CONTROLLED_MEMORY, MAX_CONTROLLED_MEMORY, TOTAL_MEMORY, MAX_TOTAL_MEMORY |
| 98 |
FROM performance_schema.threads |
| 99 |
WHERE THREAD_ID = inspect_tid |
| 100 |
INTO thread_ctrl_size, thread_ctrl_max, thread_total_size, thread_total_max; |
| 101 |
|
| 102 |
IF (debug) |
| 103 |
THEN |
| 104 |
SELECT con_name as connection, |
| 105 |
expected_ctrl_size, thread_ctrl_size, |
| 106 |
expected_ctrl_max, thread_ctrl_max, |
| 107 |
expected_total_size, thread_total_size, |
| 108 |
expected_total_max, thread_total_max; |
| 109 |
END IF; |
| 110 |
|
| 111 |
IF (thread_ctrl_size <> expected_ctrl_size) |
| 112 |
THEN |
| 113 |
SET msg = concat("CTRL SIZE: expected ", expected_ctrl_size, " actual ", thread_ctrl_size); |
| 114 |
SIGNAL sqlstate '05000' set message_text= msg; |
| 115 |
END IF; |
| 116 |
|
| 117 |
/* MAX(SUM(Xi)) <= SUM(MAX(Xi)) */ |
| 118 |
IF (thread_ctrl_max > expected_ctrl_max) |
| 119 |
THEN |
| 120 |
SET msg = concat("CTRL MAX: expected ", expected_ctrl_max, " actual ", thread_ctrl_max); |
| 121 |
SIGNAL sqlstate '05000' set message_text= msg; |
| 122 |
END IF; |
| 123 |
|
| 124 |
IF (thread_total_size <> expected_total_size) |
| 125 |
THEN |
| 126 |
SET msg = concat("TOTAL SIZE: expected ", expected_total_size, " actual ", thread_total_size); |
| 127 |
SIGNAL sqlstate '05000' set message_text= msg; |
| 128 |
END IF; |
| 129 |
|
| 130 |
/* MAX(SUM(Xi)) <= SUM(MAX(Xi)) */ |
| 131 |
IF (thread_total_max > expected_total_max) |
| 132 |
THEN |
| 133 |
SET msg = concat("TOTAL MAX: expected ", expected_total_max, " actual ", thread_total_max); |
| 134 |
SIGNAL sqlstate '05000' set message_text= msg; |
| 135 |
END IF; |
| 136 |
|
| 137 |
SELECT con_name as connection, "threads PASSED" as check_status; |
| 138 |
|
| 139 |
SELECT MAX(MAX_CONTROLLED_MEMORY), MAX(MAX_TOTAL_MEMORY) |
| 140 |
from performance_schema.events_statements_history_long |
| 141 |
WHERE THREAD_ID = inspect_tid |
| 142 |
into stmt_ctrl_max, stmt_total_max; |
| 143 |
|
| 144 |
if (debug) |
| 145 |
then |
| 146 |
SELECT con_name as connection, |
| 147 |
stmt_ctrl_max, thread_ctrl_max, |
| 148 |
stmt_total_max, thread_total_max; |
| 149 |
end if; |
| 150 |
|
| 151 |
IF (stmt_ctrl_max > thread_ctrl_max) |
| 152 |
THEN |
| 153 |
SET msg = concat("STMT CTRL MAX: expected ", thread_ctrl_max, " actual ", stmt_ctrl_max); |
| 154 |
SIGNAL sqlstate '05000' set message_text= msg; |
| 155 |
END IF; |
| 156 |
|
| 157 |
IF (stmt_total_max > thread_total_max) |
| 158 |
THEN |
| 159 |
SET msg = concat("STMT TOTAL MAX: expected ", thread_total_max, " actual ", stmt_total_max); |
| 160 |
SIGNAL sqlstate '05000' set message_text= msg; |
| 161 |
END IF; |
| 162 |
|
| 163 |
SELECT con_name as connection, "statement history PASSED" as check_status; |
| 164 |
|
| 165 |
SELECT now() as offending_ctrl_digests, |
| 166 |
d.DIGEST_TEXT, d.MAX_CONTROLLED_MEMORY, h.max_ctrl |
| 167 |
FROM performance_schema.events_statements_summary_by_digest d |
| 168 |
JOIN ( |
| 169 |
SELECT DIGEST, MAX(MAX_CONTROLLED_MEMORY) as max_ctrl |
| 170 |
FROM performance_schema.events_statements_history_long |
| 171 |
WHERE THREAD_ID = inspect_tid |
| 172 |
GROUP BY DIGEST |
| 173 |
) as h |
| 174 |
ON d.DIGEST = h.DIGEST |
| 175 |
WHERE (d.MAX_CONTROLLED_MEMORY < h.max_ctrl); |
| 176 |
|
| 177 |
SELECT now() as offending_total_digests, |
| 178 |
d.DIGEST_TEXT, d.MAX_TOTAL_MEMORY, h.max_total |
| 179 |
FROM performance_schema.events_statements_summary_by_digest d |
| 180 |
JOIN ( |
| 181 |
SELECT DIGEST, MAX(MAX_TOTAL_MEMORY) as max_total |
| 182 |
FROM performance_schema.events_statements_history_long |
| 183 |
WHERE THREAD_ID = inspect_tid |
| 184 |
GROUP BY DIGEST |
| 185 |
) as h |
| 186 |
ON d.DIGEST = h.DIGEST |
| 187 |
WHERE (d.MAX_TOTAL_MEMORY < h.max_total); |
| 188 |
END |
| 189 |
$$ |
| 190 |
|
| 191 |
delimiter ;$$ |
| 192 |
|
| 193 |
--enable_query_log |
| 194 |
|
| 195 |
--echo # Switch to (con1, localhost, root, , ) |
| 196 |
connect (con1, localhost, root, , ); |
| 197 |
|
| 198 |
let $con1_thread_id= `select THREAD_ID from performance_schema.threads |
| 199 |
where PROCESSLIST_ID = connection_id()`; |
| 200 |
|
| 201 |
--echo # Switch to (con2, localhost, root, , ) |
| 202 |
connect (con2, localhost, root, , ); |
| 203 |
|
| 204 |
let $con2_thread_id= `select THREAD_ID from performance_schema.threads |
| 205 |
where PROCESSLIST_ID = connection_id()`; |
| 206 |
|
| 207 |
--connection default |
| 208 |
|
| 209 |
--disable_query_log |
| 210 |
|
| 211 |
UPDATE performance_schema.setup_threads SET ENABLED = 'NO'; |
| 212 |
UPDATE performance_schema.threads SET INSTRUMENTED = 'NO'; |
| 213 |
|
| 214 |
--eval UPDATE performance_schema.threads SET INSTRUMENTED = 'YES' WHERE THREAD_ID IN ($con1_thread_id, $con2_thread_id); |
| 215 |
|
| 216 |
TRUNCATE TABLE performance_schema.events_statements_history_long; |
| 217 |
TRUNCATE TABLE performance_schema.events_statements_summary_by_digest; |
| 218 |
TRUNCATE TABLE performance_schema.events_statements_summary_by_thread_by_event_name; |
| 219 |
|
| 220 |
--enable_query_log |