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
|
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP PROCEDURE IF EXISTS ps_statement_avg_latency_histogram;
DELIMITER $$
CREATE DEFINER='mariadb.sys'@'localhost' PROCEDURE ps_statement_avg_latency_histogram ()
COMMENT '
Description
-----------
Outputs a textual histogram graph of the average latency values
across all normalized queries tracked within the Performance Schema
events_statements_summary_by_digest table.
Can be used to show a very high level picture of what kind of
latency distribution statements running within this instance have.
Parameters
-----------
None.
Example
-----------
mysql> CALL sys.ps_statement_avg_latency_histogram()\\G
*************************** 1. row ***************************
Performance Schema Statement Digest Average Latency Histogram:
. = 1 unit
* = 2 units
# = 3 units
(0 - 38ms) 240 | ################################################################################
(38 - 77ms) 38 | ......................................
(77 - 115ms) 3 | ...
(115 - 154ms) 62 | *******************************
(154 - 192ms) 3 | ...
(192 - 231ms) 0 |
(231 - 269ms) 0 |
(269 - 307ms) 0 |
(307 - 346ms) 0 |
(346 - 384ms) 1 | .
(384 - 423ms) 1 | .
(423 - 461ms) 0 |
(461 - 499ms) 0 |
(499 - 538ms) 0 |
(538 - 576ms) 0 |
(576 - 615ms) 1 | .
Total Statements: 350; Buckets: 16; Bucket Size: 38 ms;
'
SQL SECURITY INVOKER
NOT DETERMINISTIC
READS SQL DATA
BEGIN
SELECT CONCAT('\n',
'\n . = 1 unit',
'\n * = 2 units',
'\n # = 3 units\n',
@label := CONCAT(@label_inner := CONCAT('\n(0 - ',
ROUND((@bucket_size := (SELECT ROUND((MAX(avg_us) - MIN(avg_us)) / (@buckets := 16)) AS size
FROM sys.x$ps_digest_avg_latency_distribution)) / (@unit_div := 1000)),
(@unit := 'ms'), ')'),
REPEAT(' ', (@max_label_size := ((1 + LENGTH(ROUND((@bucket_size * 15) / @unit_div)) + 3 + LENGTH(ROUND(@bucket_size * 16) / @unit_div)) + 1)) - LENGTH(@label_inner)),
@count_in_bucket := IFNULL((SELECT SUM(cnt)
FROM sys.x$ps_digest_avg_latency_distribution AS b1
WHERE b1.avg_us <= @bucket_size), 0)),
REPEAT(' ', (@max_label_len := (@max_label_size + LENGTH((@total_queries := (SELECT SUM(cnt) FROM sys.x$ps_digest_avg_latency_distribution)))) + 1) - LENGTH(@label)), '| ',
IFNULL(REPEAT(IF(@count_in_bucket < (@one_unit := 40), '.', IF(@count_in_bucket < (@two_unit := 80), '*', '#')),
IF(@count_in_bucket < @one_unit, @count_in_bucket,
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND(@bucket_size / @unit_div), ' - ', ROUND((@bucket_size * 2) / @unit_div), @unit, ')'),
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
@count_in_bucket := IFNULL((SELECT SUM(cnt)
FROM sys.x$ps_digest_avg_latency_distribution AS b1
WHERE b1.avg_us > @bucket_size AND b1.avg_us <= @bucket_size * 2), 0)),
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
IF(@count_in_bucket < @one_unit, @count_in_bucket,
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 2) / @unit_div), ' - ', ROUND((@bucket_size * 3) / @unit_div), @unit, ')'),
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
@count_in_bucket := IFNULL((SELECT SUM(cnt)
FROM sys.x$ps_digest_avg_latency_distribution AS b1
WHERE b1.avg_us > @bucket_size * 2 AND b1.avg_us <= @bucket_size * 3), 0)),
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
IF(@count_in_bucket < @one_unit, @count_in_bucket,
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 3) / @unit_div), ' - ', ROUND((@bucket_size * 4) / @unit_div), @unit, ')'),
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
@count_in_bucket := IFNULL((SELECT SUM(cnt)
FROM sys.x$ps_digest_avg_latency_distribution AS b1
WHERE b1.avg_us > @bucket_size * 3 AND b1.avg_us <= @bucket_size * 4), 0)),
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
IF(@count_in_bucket < @one_unit, @count_in_bucket,
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 4) / @unit_div), ' - ', ROUND((@bucket_size * 5) / @unit_div), @unit, ')'),
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
@count_in_bucket := IFNULL((SELECT SUM(cnt)
FROM sys.x$ps_digest_avg_latency_distribution AS b1
WHERE b1.avg_us > @bucket_size * 4 AND b1.avg_us <= @bucket_size * 5), 0)),
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
IF(@count_in_bucket < @one_unit, @count_in_bucket,
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 5) / @unit_div), ' - ', ROUND((@bucket_size * 6) / @unit_div), @unit, ')'),
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
@count_in_bucket := IFNULL((SELECT SUM(cnt)
FROM sys.x$ps_digest_avg_latency_distribution AS b1
WHERE b1.avg_us > @bucket_size * 5 AND b1.avg_us <= @bucket_size * 6), 0)),
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
IF(@count_in_bucket < @one_unit, @count_in_bucket,
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 6) / @unit_div), ' - ', ROUND((@bucket_size * 7) / @unit_div), @unit, ')'),
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
@count_in_bucket := IFNULL((SELECT SUM(cnt)
FROM sys.x$ps_digest_avg_latency_distribution AS b1
WHERE b1.avg_us > @bucket_size * 6 AND b1.avg_us <= @bucket_size * 7), 0)),
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
IF(@count_in_bucket < @one_unit, @count_in_bucket,
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 7) / @unit_div), ' - ', ROUND((@bucket_size * 8) / @unit_div), @unit, ')'),
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
@count_in_bucket := IFNULL((SELECT SUM(cnt)
FROM sys.x$ps_digest_avg_latency_distribution AS b1
WHERE b1.avg_us > @bucket_size * 7 AND b1.avg_us <= @bucket_size * 8), 0)),
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
IF(@count_in_bucket < @one_unit, @count_in_bucket,
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 8) / @unit_div), ' - ', ROUND((@bucket_size * 9) / @unit_div), @unit, ')'),
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
@count_in_bucket := IFNULL((SELECT SUM(cnt)
FROM sys.x$ps_digest_avg_latency_distribution AS b1
WHERE b1.avg_us > @bucket_size * 8 AND b1.avg_us <= @bucket_size * 9), 0)),
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
IF(@count_in_bucket < @one_unit, @count_in_bucket,
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 9) / @unit_div), ' - ', ROUND((@bucket_size * 10) / @unit_div), @unit, ')'),
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
@count_in_bucket := IFNULL((SELECT SUM(cnt)
FROM sys.x$ps_digest_avg_latency_distribution AS b1
WHERE b1.avg_us > @bucket_size * 9 AND b1.avg_us <= @bucket_size * 10), 0)),
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
IF(@count_in_bucket < @one_unit, @count_in_bucket,
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 10) / @unit_div), ' - ', ROUND((@bucket_size * 11) / @unit_div), @unit, ')'),
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
@count_in_bucket := IFNULL((SELECT SUM(cnt)
FROM sys.x$ps_digest_avg_latency_distribution AS b1
WHERE b1.avg_us > @bucket_size * 10 AND b1.avg_us <= @bucket_size * 11), 0)),
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
IF(@count_in_bucket < @one_unit, @count_in_bucket,
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 11) / @unit_div), ' - ', ROUND((@bucket_size * 12) / @unit_div), @unit, ')'),
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
@count_in_bucket := IFNULL((SELECT SUM(cnt)
FROM sys.x$ps_digest_avg_latency_distribution AS b1
WHERE b1.avg_us > @bucket_size * 11 AND b1.avg_us <= @bucket_size * 12), 0)),
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
IF(@count_in_bucket < @one_unit, @count_in_bucket,
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 12) / @unit_div), ' - ', ROUND((@bucket_size * 13) / @unit_div), @unit, ')'),
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
@count_in_bucket := IFNULL((SELECT SUM(cnt)
FROM sys.x$ps_digest_avg_latency_distribution AS b1
WHERE b1.avg_us > @bucket_size * 12 AND b1.avg_us <= @bucket_size * 13), 0)),
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
IF(@count_in_bucket < @one_unit, @count_in_bucket,
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 13) / @unit_div), ' - ', ROUND((@bucket_size * 14) / @unit_div), @unit, ')'),
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
@count_in_bucket := IFNULL((SELECT SUM(cnt)
FROM sys.x$ps_digest_avg_latency_distribution AS b1
WHERE b1.avg_us > @bucket_size * 13 AND b1.avg_us <= @bucket_size * 14), 0)),
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
IF(@count_in_bucket < @one_unit, @count_in_bucket,
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 14) / @unit_div), ' - ', ROUND((@bucket_size * 15) / @unit_div), @unit, ')'),
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
@count_in_bucket := IFNULL((SELECT SUM(cnt)
FROM sys.x$ps_digest_avg_latency_distribution AS b1
WHERE b1.avg_us > @bucket_size * 14 AND b1.avg_us <= @bucket_size * 15), 0)),
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
IF(@count_in_bucket < @one_unit, @count_in_bucket,
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
@label := CONCAT(@label_inner := CONCAT('\n(', ROUND((@bucket_size * 15) / @unit_div), ' - ', ROUND((@bucket_size * 16) / @unit_div), @unit, ')'),
REPEAT(' ', @max_label_size - LENGTH(@label_inner)),
@count_in_bucket := IFNULL((SELECT SUM(cnt)
FROM sys.x$ps_digest_avg_latency_distribution AS b1
WHERE b1.avg_us > @bucket_size * 15 AND b1.avg_us <= @bucket_size * 16), 0)),
REPEAT(' ', @max_label_len - LENGTH(@label)), '| ',
IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')),
IF(@count_in_bucket < @one_unit, @count_in_bucket,
IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''),
'\n\n Total Statements: ', @total_queries, '; Buckets: ', @buckets , '; Bucket Size: ', ROUND(@bucket_size / @unit_div) , ' ', @unit, ';\n'
) AS `Performance Schema Statement Digest Average Latency Histogram`;
END $$
DELIMITER ;
|