1##
2## WL#4818, 4.1.3 MUTEXES, RW-LOCKS, ...
3##
4## Functional testing of mutexes and RW-locks
5##
6
7--source include/not_embedded.inc
8--source include/have_perfschema.inc
9
10UPDATE performance_schema.setup_instruments SET enabled = 'NO', timed = 'YES';
11
12UPDATE performance_schema.setup_instruments SET enabled = 'YES'
13WHERE name LIKE 'wait/synch/mutex/%'
14   OR name LIKE 'wait/synch/rwlock/%';
15
16# reset lost counters
17truncate table performance_schema.events_statements_summary_by_digest;
18flush status;
19
20# Make sure objects are instrumented
21select NAME from performance_schema.mutex_instances
22  where NAME = 'wait/synch/mutex/sql/LOCK_open';
23select NAME from performance_schema.rwlock_instances
24  where NAME = 'wait/synch/rwlock/sql/LOCK_grant' limit 1;
25
26--disable_warnings
27DROP TABLE IF EXISTS t1;
28--enable_warnings
29
30#
31# TODO: Change to InnoDB when it gets instrumentation
32#
33
34CREATE TABLE t1 (id INT PRIMARY KEY, b CHAR(100) DEFAULT 'initial value')
35ENGINE=MyISAM;
36
37INSERT INTO t1 (id) VALUES (1), (2), (3), (4), (5), (6), (7), (8);
38
39#
40# FM1: Count for mutex should increase with instrumentation enabled and
41# FM2: Count for mutex should not increase with instrumentation disabled
42#
43
44TRUNCATE TABLE performance_schema.events_waits_history_long;
45TRUNCATE TABLE performance_schema.events_waits_history;
46TRUNCATE TABLE performance_schema.events_waits_current;
47
48SELECT * FROM t1 WHERE id = 1;
49
50SET @before_count = (SELECT SUM(TIMER_WAIT)
51                     FROM performance_schema.events_waits_history_long
52                     WHERE (EVENT_NAME = 'wait/synch/mutex/sql/LOCK_table_cache'));
53
54SELECT * FROM t1;
55
56SET @after_count = (SELECT SUM(TIMER_WAIT)
57                    FROM performance_schema.events_waits_history_long
58                    WHERE (EVENT_NAME = 'wait/synch/mutex/sql/LOCK_table_cache'));
59
60SELECT IF((@after_count - @before_count) > 0, 'Success', 'Failure') test_fm1_timed;
61
62UPDATE performance_schema.setup_instruments SET enabled = 'NO'
63WHERE NAME = 'wait/synch/mutex/sql/LOCK_table_cache';
64
65TRUNCATE TABLE performance_schema.events_waits_history_long;
66TRUNCATE TABLE performance_schema.events_waits_history;
67TRUNCATE TABLE performance_schema.events_waits_current;
68
69SELECT * FROM t1 WHERE id = 1;
70
71SET @before_count = (SELECT SUM(TIMER_WAIT)
72                     FROM performance_schema.events_waits_history_long
73                     WHERE (EVENT_NAME = 'wait/synch/mutex/sql/LOCK_table_cache'));
74
75SELECT * FROM t1;
76
77SET @after_count = (SELECT SUM(TIMER_WAIT)
78                    FROM performance_schema.events_waits_history_long
79                    WHERE (EVENT_NAME = 'wait/synch/mutex/sql/LOCK_table_cache'));
80
81SELECT IF((COALESCE(@after_count, 0) - COALESCE(@before_count, 0)) = 0, 'Success', 'Failure') test_fm2_timed;
82
83#
84# Repeat for RW-lock
85#
86
87TRUNCATE TABLE performance_schema.events_waits_history_long;
88TRUNCATE TABLE performance_schema.events_waits_history;
89TRUNCATE TABLE performance_schema.events_waits_current;
90
91SELECT * FROM t1 WHERE id = 1;
92
93SET @before_count = (SELECT SUM(TIMER_WAIT)
94                     FROM performance_schema.events_waits_history_long
95                     WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_grant'));
96
97SELECT * FROM t1;
98
99SET @after_count = (SELECT SUM(TIMER_WAIT)
100                    FROM performance_schema.events_waits_history_long
101                    WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_grant'));
102
103SELECT IF((@after_count - @before_count) > 0, 'Success', 'Failure') test_fm1_rw_timed;
104
105UPDATE performance_schema.setup_instruments SET enabled = 'NO'
106WHERE NAME = 'wait/synch/rwlock/sql/LOCK_grant';
107
108TRUNCATE TABLE performance_schema.events_waits_history_long;
109TRUNCATE TABLE performance_schema.events_waits_history;
110TRUNCATE TABLE performance_schema.events_waits_current;
111
112SELECT * FROM t1 WHERE id = 1;
113
114SET @before_count = (SELECT SUM(TIMER_WAIT)
115                     FROM performance_schema.events_waits_history_long
116                     WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_grant'));
117
118SELECT * FROM t1;
119
120SET @after_count = (SELECT SUM(TIMER_WAIT)
121                    FROM performance_schema.events_waits_history_long
122                    WHERE (EVENT_NAME = 'wait/synch/rwlock/sql/LOCK_grant'));
123
124SELECT IF((COALESCE(@after_count, 0) - COALESCE(@before_count, 0)) = 0, 'Success', 'Failure') test_fm2_rw_timed;
125
126# Clean-up.
127UPDATE performance_schema.setup_instruments SET enabled = 'YES';
128DROP TABLE t1;
129
130UPDATE performance_schema.setup_instruments SET enabled = 'YES', timed = 'YES';
131
132# In case of failure, will indicate the root cause
133show global status like "performance_schema%";
134
135