summaryrefslogtreecommitdiff
path: root/mysql-test/suite/perfschema/t/func_mutex.test
blob: 652d53bf17e45e348b8b15894f5c493b8df2e042 (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
##
## WL#4818, 4.1.3 MUTEXES, RW-LOCKS, ...
##
## Functional testing of mutexes and RW-locks
##

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

UPDATE performance_schema.setup_instruments SET enabled = 'NO', timed = 'YES';

UPDATE performance_schema.setup_instruments SET enabled = 'YES'
WHERE name LIKE 'wait/synch/mutex/%'
   OR name LIKE 'wait/synch/rwlock/%';

--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings

#
# TODO: Change to InnoDB when it gets instrumentation
#

CREATE TABLE t1 (id INT PRIMARY KEY, b CHAR(100) DEFAULT 'initial value')
ENGINE=MyISAM;

INSERT INTO t1 (id) VALUES (1), (2), (3), (4), (5), (6), (7), (8);

#
# FM1: Count for mutex should increase with instrumentation enabled and
# FM2: Count for mutex should not increase with instrumentation disabled
#

TRUNCATE TABLE performance_schema.events_waits_history_long;
TRUNCATE TABLE performance_schema.events_waits_history;
TRUNCATE TABLE performance_schema.events_waits_current;

SELECT * FROM t1 WHERE id = 1;

SET @before_count = (SELECT SUM(TIMER_WAIT)
                     FROM performance_schema.events_waits_history_long
                     WHERE (EVENT_NAME = 'wait/synch/mutex/sql/LOCK_open'));

SELECT * FROM t1;

SET @after_count = (SELECT SUM(TIMER_WAIT)
                    FROM performance_schema.events_waits_history_long
                    WHERE (EVENT_NAME = 'wait/synch/mutex/sql/LOCK_open'));

SELECT IF((@after_count - @before_count) > 0, 'Success', 'Failure') test_fm1_timed;

UPDATE performance_schema.setup_instruments SET enabled = 'NO'
WHERE NAME = 'wait/synch/mutex/sql/LOCK_open';

TRUNCATE TABLE performance_schema.events_waits_history_long;
TRUNCATE TABLE performance_schema.events_waits_history;
TRUNCATE TABLE performance_schema.events_waits_current;

SELECT * FROM t1 WHERE id = 1;

SET @before_count = (SELECT SUM(TIMER_WAIT)
                     FROM performance_schema.events_waits_history_long
                     WHERE (EVENT_NAME = 'wait/synch/mutex/sql/LOCK_open'));

SELECT * FROM t1;

SET @after_count = (SELECT SUM(TIMER_WAIT)
                    FROM performance_schema.events_waits_history_long
                    WHERE (EVENT_NAME = 'wait/synch/mutex/sql/LOCK_open'));

SELECT IF((COALESCE(@after_count, 0) - COALESCE(@before_count, 0)) = 0, 'Success', 'Failure') test_fm2_timed;

#
# Repeat for RW-lock
#

TRUNCATE TABLE performance_schema.events_waits_history_long;
TRUNCATE TABLE performance_schema.events_waits_history;
TRUNCATE TABLE performance_schema.events_waits_current;

SELECT * FROM t1 WHERE id = 1;

SET @before_count = (SELECT SUM(TIMER_WAIT)
                     FROM performance_schema.events_waits_history_long
                     WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_grant'));

SELECT * FROM t1;

SET @after_count = (SELECT SUM(TIMER_WAIT)
                    FROM performance_schema.events_waits_history_long
                    WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_grant'));

SELECT IF((@after_count - @before_count) > 0, 'Success', 'Failure') test_fm1_rw_timed;

UPDATE performance_schema.setup_instruments SET enabled = 'NO'
WHERE NAME = 'wait/synch/rwlock/sql/LOCK_grant';

TRUNCATE TABLE performance_schema.events_waits_history_long;
TRUNCATE TABLE performance_schema.events_waits_history;
TRUNCATE TABLE performance_schema.events_waits_current;

SELECT * FROM t1 WHERE id = 1;

SET @before_count = (SELECT SUM(TIMER_WAIT)
                     FROM performance_schema.events_waits_history_long
                     WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_grant'));

SELECT * FROM t1;

SET @after_count = (SELECT SUM(TIMER_WAIT)
                    FROM performance_schema.events_waits_history_long
                    WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_grant'));

SELECT IF((COALESCE(@after_count, 0) - COALESCE(@before_count, 0)) = 0, 'Success', 'Failure') test_fm2_rw_timed;

# Clean-up.
UPDATE performance_schema.setup_instruments SET enabled = 'YES';
DROP TABLE t1;

UPDATE performance_schema.setup_instruments SET enabled = 'YES', timed = 'YES';