Merge lp:~sergei.glushchenko/percona-server/5.6-ps-blueprint-scalability-metrics into lp:percona-server/5.6
- 5.6-ps-blueprint-scalability-metrics
- Merge into 5.6
Proposed by
Sergei Glushchenko
| Status: | Merged |
|---|---|
| Approved by: | Alexey Kopytov |
| Approved revision: | no longer in the source branch. |
| Merged at revision: | 559 |
| Proposed branch: | lp:~sergei.glushchenko/percona-server/5.6-ps-blueprint-scalability-metrics |
| Merge into: | lp:percona-server/5.6 |
| Diff against target: |
656 lines (+607/-0) 8 files modified
mysql-test/include/have_scalability_metrics_plugin.inc (+21/-0) mysql-test/include/plugin.defs (+1/-0) mysql-test/r/scalability_metrics.result (+46/-0) mysql-test/t/scalability_metrics-master.opt (+1/-0) mysql-test/t/scalability_metrics.test (+68/-0) plugin/scalability_metrics/CMakeLists.txt (+17/-0) plugin/scalability_metrics/scalability_metrics.c (+451/-0) sql/item_func.cc (+2/-0) |
| To merge this branch: | bzr merge lp:~sergei.glushchenko/percona-server/5.6-ps-blueprint-scalability-metrics |
| Related bugs: | |
| Related blueprints: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Alexey Kopytov (community) | Approve | ||
|
Review via email:
|
|||
Commit message
Description of the change
Merge scalability metrics from 5.5
http://
To post a comment you must log in.
Revision history for this message
| Sergei Glushchenko (sergei.glushchenko) wrote : | # |
Revision history for this message
| Alexey Kopytov (akopytov) wrote : | # |
Same comments as in the 5.5 MP.
review:
Needs Fixing
Revision history for this message
| Sergei Glushchenko (sergei.glushchenko) wrote : | # |
Updated with 5.5 changes
Revision history for this message
| Alexey Kopytov (akopytov) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
| 1 | === added file 'mysql-test/include/have_scalability_metrics_plugin.inc' |
| 2 | --- mysql-test/include/have_scalability_metrics_plugin.inc 1970-01-01 00:00:00 +0000 |
| 3 | +++ mysql-test/include/have_scalability_metrics_plugin.inc 2014-02-10 13:58:36 +0000 |
| 4 | @@ -0,0 +1,21 @@ |
| 5 | +# |
| 6 | +# Check if server has support for loading plugins |
| 7 | +# |
| 8 | +if (`SELECT @@have_dynamic_loading != 'YES'`) { |
| 9 | + --skip Example plugin requires dynamic loading |
| 10 | +} |
| 11 | + |
| 12 | +# |
| 13 | +# Check if the variable SCALABILITY_METRICS is set |
| 14 | +# |
| 15 | +if (!$SCALABILITY_METRICS) { |
| 16 | + --skip Example plugin requires the environment variable \$SCALABILITY_METRICS to be set (normally done by mtr) |
| 17 | +} |
| 18 | + |
| 19 | +# |
| 20 | +# Check if --plugin-dir was setup for exampledb |
| 21 | +# |
| 22 | +if (`SELECT CONCAT('--plugin-dir=', REPLACE(@@plugin_dir, '\\\\', '/')) != '$SCALABILITY_METRICS_OPT/'`) { |
| 23 | + --skip Example plugin requires that --plugin-dir is set to the example plugin dir (either the .opt file does not contain \$SCALABILITY_METRICS_OPT or another plugin is in use) |
| 24 | +} |
| 25 | +enable_query_log; |
| 26 | |
| 27 | === modified file 'mysql-test/include/plugin.defs' |
| 28 | --- mysql-test/include/plugin.defs 2013-01-18 04:53:12 +0000 |
| 29 | +++ mysql-test/include/plugin.defs 2014-02-10 13:58:36 +0000 |
| 30 | @@ -45,3 +45,4 @@ |
| 31 | libmemcached plugin/innodb_memcached/daemon_memcached DAEMON_MEMCACHED daemon_memcached |
| 32 | innodb_engine plugin/innodb_memcached/innodb_memcache INNODB_ENGINE |
| 33 | validate_password plugin/password_validation VALIDATE_PASSWORD validate_password |
| 34 | +scalability_metrics plugin/scalability_metrics SCALABILITY_METRICS |
| 35 | |
| 36 | === added file 'mysql-test/r/scalability_metrics.result' |
| 37 | --- mysql-test/r/scalability_metrics.result 1970-01-01 00:00:00 +0000 |
| 38 | +++ mysql-test/r/scalability_metrics.result 2014-02-10 13:58:36 +0000 |
| 39 | @@ -0,0 +1,46 @@ |
| 40 | +set debug_sync= 'RESET'; |
| 41 | +INSTALL PLUGIN scalability_metrics SONAME 'scalability_metrics.so'; |
| 42 | +SHOW STATUS LIKE 'scalability_metrics%'; |
| 43 | +Variable_name Value |
| 44 | +scalability_metrics_busytime 0 |
| 45 | +scalability_metrics_concurrency 0 |
| 46 | +scalability_metrics_elapsedtime 0 |
| 47 | +scalability_metrics_queries 0 |
| 48 | +scalability_metrics_totaltime 0 |
| 49 | +SET GLOBAL scalability_metrics_control = ON; |
| 50 | +SHOW STATUS LIKE 'scalability_metrics_concurrency'; |
| 51 | +Variable_name Value |
| 52 | +scalability_metrics_concurrency 1 |
| 53 | +SHOW STATUS LIKE 'scalability_metrics_queries'; |
| 54 | +Variable_name Value |
| 55 | +scalability_metrics_queries 1 |
| 56 | +SET DEBUG_SYNC="func_sleep_before_sleep SIGNAL sleep1"; |
| 57 | +SELECT SLEEP(100); |
| 58 | +SET DEBUG_SYNC= 'now WAIT_FOR sleep1'; |
| 59 | +SHOW STATUS LIKE 'scalability_metrics_concurrency'; |
| 60 | +Variable_name Value |
| 61 | +scalability_metrics_concurrency 2 |
| 62 | +SHOW STATUS LIKE 'scalability_metrics_queries'; |
| 63 | +Variable_name Value |
| 64 | +scalability_metrics_queries 8 |
| 65 | +KILL CONNECTION @id; |
| 66 | +ERROR HY000: Lost connection to MySQL server during query |
| 67 | +SET GLOBAL scalability_metrics_control = OFF; |
| 68 | +SHOW STATUS LIKE 'scalability_metrics_concurrency'; |
| 69 | +Variable_name Value |
| 70 | +scalability_metrics_concurrency 1 |
| 71 | +SHOW STATUS LIKE 'scalability_metrics_queries'; |
| 72 | +Variable_name Value |
| 73 | +scalability_metrics_queries 0 |
| 74 | +SET GLOBAL scalability_metrics_control = OFF; |
| 75 | +SHOW STATUS LIKE 'scalability_metrics%'; |
| 76 | +Variable_name Value |
| 77 | +scalability_metrics_busytime 0 |
| 78 | +scalability_metrics_concurrency 1 |
| 79 | +scalability_metrics_elapsedtime 0 |
| 80 | +scalability_metrics_queries 0 |
| 81 | +scalability_metrics_totaltime 0 |
| 82 | +UNINSTALL PLUGIN scalability_metrics; |
| 83 | +Warnings: |
| 84 | +Warning 1620 Plugin is busy and will be uninstalled on shutdown |
| 85 | +set debug_sync= 'RESET'; |
| 86 | |
| 87 | === added file 'mysql-test/t/scalability_metrics-master.opt' |
| 88 | --- mysql-test/t/scalability_metrics-master.opt 1970-01-01 00:00:00 +0000 |
| 89 | +++ mysql-test/t/scalability_metrics-master.opt 2014-02-10 13:58:36 +0000 |
| 90 | @@ -0,0 +1,1 @@ |
| 91 | +$SCALABILITY_METRICS_OPT |
| 92 | |
| 93 | === added file 'mysql-test/t/scalability_metrics.test' |
| 94 | --- mysql-test/t/scalability_metrics.test 1970-01-01 00:00:00 +0000 |
| 95 | +++ mysql-test/t/scalability_metrics.test 2014-02-10 13:58:36 +0000 |
| 96 | @@ -0,0 +1,68 @@ |
| 97 | +################################################################################ |
| 98 | +# Test for plugin scalability_metrics |
| 99 | +################################################################################ |
| 100 | + |
| 101 | +--source include/have_scalability_metrics_plugin.inc |
| 102 | +--source include/have_debug_sync.inc |
| 103 | + |
| 104 | +set debug_sync= 'RESET'; |
| 105 | + |
| 106 | +INSTALL PLUGIN scalability_metrics SONAME 'scalability_metrics.so'; |
| 107 | + |
| 108 | +SHOW STATUS LIKE 'scalability_metrics%'; |
| 109 | +SET GLOBAL scalability_metrics_control = ON; |
| 110 | + |
| 111 | +SHOW STATUS LIKE 'scalability_metrics_concurrency'; |
| 112 | +SHOW STATUS LIKE 'scalability_metrics_queries'; |
| 113 | + |
| 114 | +--source include/count_sessions.inc |
| 115 | + |
| 116 | +connect (con1,localhost,root,,); |
| 117 | + |
| 118 | +# test concurrency |
| 119 | + |
| 120 | +let $ID= `SELECT @id := CONNECTION_ID()`; |
| 121 | + |
| 122 | +SET DEBUG_SYNC="func_sleep_before_sleep SIGNAL sleep1"; |
| 123 | + |
| 124 | +send SELECT SLEEP(100); |
| 125 | + |
| 126 | +connection default; |
| 127 | + |
| 128 | +SET DEBUG_SYNC= 'now WAIT_FOR sleep1'; |
| 129 | + |
| 130 | +let $ignore= `SELECT @id := $ID`; |
| 131 | + |
| 132 | +SHOW STATUS LIKE 'scalability_metrics_concurrency'; |
| 133 | +SHOW STATUS LIKE 'scalability_metrics_queries'; |
| 134 | + |
| 135 | +KILL CONNECTION @id; |
| 136 | + |
| 137 | +--source include/wait_until_count_sessions.inc |
| 138 | + |
| 139 | +connection default; |
| 140 | + |
| 141 | +connection con1; |
| 142 | +--error 2013 |
| 143 | +reap; |
| 144 | + |
| 145 | +--enable_reconnect |
| 146 | +--source include/wait_until_connected_again.inc |
| 147 | + |
| 148 | +connection default; |
| 149 | + |
| 150 | +# test reset |
| 151 | + |
| 152 | +SET GLOBAL scalability_metrics_control = OFF; |
| 153 | + |
| 154 | +SHOW STATUS LIKE 'scalability_metrics_concurrency'; |
| 155 | +SHOW STATUS LIKE 'scalability_metrics_queries'; |
| 156 | + |
| 157 | +disconnect con1; |
| 158 | + |
| 159 | +SET GLOBAL scalability_metrics_control = OFF; |
| 160 | +SHOW STATUS LIKE 'scalability_metrics%'; |
| 161 | + |
| 162 | +UNINSTALL PLUGIN scalability_metrics; |
| 163 | + |
| 164 | +set debug_sync= 'RESET'; |
| 165 | |
| 166 | === added directory 'plugin/scalability_metrics' |
| 167 | === added file 'plugin/scalability_metrics/CMakeLists.txt' |
| 168 | --- plugin/scalability_metrics/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
| 169 | +++ plugin/scalability_metrics/CMakeLists.txt 2014-02-10 13:58:36 +0000 |
| 170 | @@ -0,0 +1,17 @@ |
| 171 | +# Copyright (c) 2014 Percona LLC and/or its affiliates. All rights reserved. |
| 172 | +# |
| 173 | +# This program is free software; you can redistribute it and/or modify |
| 174 | +# it under the terms of the GNU General Public License as published by |
| 175 | +# the Free Software Foundation; version 2 of the License. |
| 176 | +# |
| 177 | +# This program is distributed in the hope that it will be useful, |
| 178 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 179 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 180 | +# GNU General Public License for more details. |
| 181 | +# |
| 182 | +# You should have received a copy of the GNU General Public License |
| 183 | +# along with this program; if not, write to the Free Software |
| 184 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 185 | + |
| 186 | +MYSQL_ADD_PLUGIN(scalability_metrics scalability_metrics.c |
| 187 | + MODULE_ONLY MODULE_OUTPUT_NAME "scalability_metrics") |
| 188 | |
| 189 | === added file 'plugin/scalability_metrics/scalability_metrics.c' |
| 190 | --- plugin/scalability_metrics/scalability_metrics.c 1970-01-01 00:00:00 +0000 |
| 191 | +++ plugin/scalability_metrics/scalability_metrics.c 2014-02-10 13:58:36 +0000 |
| 192 | @@ -0,0 +1,451 @@ |
| 193 | +/* Copyright (c) 2014 Percona LLC and/or its affiliates. All rights reserved. |
| 194 | + |
| 195 | + This program is free software; you can redistribute it and/or |
| 196 | + modify it under the terms of the GNU General Public License |
| 197 | + as published by the Free Software Foundation; version 2 of |
| 198 | + the License. |
| 199 | + |
| 200 | + This program is distributed in the hope that it will be useful, |
| 201 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 202 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 203 | + GNU General Public License for more details. |
| 204 | + |
| 205 | + You should have received a copy of the GNU General Public License |
| 206 | + along with this program; if not, write to the Free Software |
| 207 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 208 | + |
| 209 | +#include <mysql/plugin.h> |
| 210 | +#include <mysql/plugin_audit.h> |
| 211 | +#include <my_global.h> |
| 212 | +#include <my_sys.h> |
| 213 | +#include <my_list.h> |
| 214 | +#include <my_pthread.h> |
| 215 | +#include <typelib.h> |
| 216 | +#include <limits.h> |
| 217 | +#include <string.h> |
| 218 | + |
| 219 | +static volatile ulonglong starttime= 0; |
| 220 | +static volatile ulonglong concurrency= 0; |
| 221 | +static volatile ulonglong busystart= 0; |
| 222 | +static volatile ulonglong busytime= 0; |
| 223 | +static volatile ulonglong totaltime= 0; |
| 224 | +static volatile ulonglong queries= 0; |
| 225 | + |
| 226 | +#ifdef HAVE_PSI_INTERFACE |
| 227 | +PSI_mutex_key key_thd_list_mutex; |
| 228 | +#endif |
| 229 | +mysql_mutex_t thd_list_mutex; |
| 230 | + |
| 231 | +LIST *thd_list_root= NULL; |
| 232 | + |
| 233 | +typedef struct sm_thd_data_struct { |
| 234 | + ulonglong start; |
| 235 | + ulonglong duration; |
| 236 | + ulonglong queries; |
| 237 | + LIST *backref; |
| 238 | +} sm_thd_data_t; |
| 239 | + |
| 240 | +typedef enum { CTL_ON= 0, CTL_OFF= 1, CTL_RESET= 2 } sm_ctl_t; |
| 241 | +static const char* sm_ctl_names[]= { "ON", "OFF", "RESET", NullS }; |
| 242 | +static TYPELIB sm_ctl_typelib= { |
| 243 | + array_elements(sm_ctl_names) - 1, |
| 244 | + "", |
| 245 | + sm_ctl_names, |
| 246 | + NULL |
| 247 | +}; |
| 248 | + |
| 249 | +static |
| 250 | +void sm_ctl_update(MYSQL_THD thd, struct st_mysql_sys_var *var, |
| 251 | + void *var_ptr, const void *save); |
| 252 | + |
| 253 | +static ulong sm_ctl= CTL_OFF; |
| 254 | + |
| 255 | +static |
| 256 | +MYSQL_THDVAR_ULONGLONG(thd_data, |
| 257 | + PLUGIN_VAR_READONLY | PLUGIN_VAR_NOSYSVAR | PLUGIN_VAR_NOCMDOPT, |
| 258 | + "scalability metrics data", NULL, NULL, 0, 0, ULONGLONG_MAX, 0); |
| 259 | + |
| 260 | + |
| 261 | +static MYSQL_SYSVAR_ENUM( |
| 262 | + control, /* name */ |
| 263 | + sm_ctl, /* var */ |
| 264 | + PLUGIN_VAR_RQCMDARG, |
| 265 | + "Control the scalability metrics. Use this to turn ON/OFF or RESET metrics.", |
| 266 | + NULL, /* check func. */ |
| 267 | + sm_ctl_update, /* update func. */ |
| 268 | + CTL_OFF, /* default */ |
| 269 | + &sm_ctl_typelib /* typelib */ |
| 270 | +); |
| 271 | + |
| 272 | +static |
| 273 | +ulonglong sm_clock_time_get() |
| 274 | +{ |
| 275 | +#if (defined HAVE_CLOCK_GETTIME) |
| 276 | + struct timespec ts; |
| 277 | +#ifdef CLOCK_MONOTONIC_RAW |
| 278 | + clock_gettime(CLOCK_MONOTONIC_RAW, &ts); |
| 279 | +#else |
| 280 | + clock_gettime(CLOCK_MONOTONIC, &ts); |
| 281 | +#endif |
| 282 | + return((ulonglong) ts.tv_sec * 1000000000 + ts.tv_nsec); |
| 283 | +#else |
| 284 | + /* since output values measured in microseconds anyway, |
| 285 | + 100 nanoseconds precision should be enough here */ |
| 286 | + return(my_getsystime() * 100); |
| 287 | +#endif |
| 288 | +} |
| 289 | + |
| 290 | + |
| 291 | +/* Get duration in microseconds */ |
| 292 | +static |
| 293 | +ulonglong sm_clock_time_duration(ulonglong beg, ulonglong end) |
| 294 | +{ |
| 295 | + return((end - beg) / 1000); |
| 296 | +} |
| 297 | + |
| 298 | +static |
| 299 | +sm_thd_data_t *sm_thd_data_get(MYSQL_THD thd) |
| 300 | +{ |
| 301 | + sm_thd_data_t *thd_data = (sm_thd_data_t *) (intptr) THDVAR(thd, thd_data); |
| 302 | + if (unlikely(thd_data == NULL)) |
| 303 | + { |
| 304 | + thd_data= calloc(sizeof(sm_thd_data_t), 1); |
| 305 | + mysql_mutex_lock(&thd_list_mutex); |
| 306 | + thd_data->backref= list_push(thd_list_root, thd_data); |
| 307 | + mysql_mutex_unlock(&thd_list_mutex); |
| 308 | + THDVAR(thd, thd_data)= (ulonglong) (intptr) thd_data; |
| 309 | + } |
| 310 | + return thd_data; |
| 311 | +} |
| 312 | + |
| 313 | + |
| 314 | +static |
| 315 | +void sm_thd_data_release(MYSQL_THD thd) |
| 316 | +{ |
| 317 | + sm_thd_data_t *thd_data = (sm_thd_data_t *) (intptr) THDVAR(thd, thd_data); |
| 318 | + if (likely(thd_data != NULL && thd_data->backref != NULL)) |
| 319 | + { |
| 320 | + (void) __sync_add_and_fetch(&queries, thd_data->queries); |
| 321 | + (void) __sync_add_and_fetch(&totaltime, thd_data->duration); |
| 322 | + mysql_mutex_lock(&thd_list_mutex); |
| 323 | + thd_list_root= list_delete(thd_list_root, thd_data->backref); |
| 324 | + mysql_mutex_unlock(&thd_list_mutex); |
| 325 | + free(thd_data->backref); |
| 326 | + free(thd_data); |
| 327 | + THDVAR(thd, thd_data)= 0; |
| 328 | + } |
| 329 | +} |
| 330 | + |
| 331 | +static |
| 332 | +int sm_reset_one(void *data, void *argument __attribute__((unused))) |
| 333 | +{ |
| 334 | + sm_thd_data_t *thd_data= (sm_thd_data_t *) data; |
| 335 | + thd_data->queries= 0; |
| 336 | + thd_data->duration= 0; |
| 337 | + return(0); |
| 338 | +} |
| 339 | + |
| 340 | +static |
| 341 | +void sm_reset() |
| 342 | +{ |
| 343 | + starttime= sm_clock_time_get(); |
| 344 | + busytime= totaltime= queries= 0; |
| 345 | + mysql_mutex_lock(&thd_list_mutex); |
| 346 | + list_walk(thd_list_root, sm_reset_one, NULL); |
| 347 | + mysql_mutex_unlock(&thd_list_mutex); |
| 348 | +} |
| 349 | + |
| 350 | + |
| 351 | +static |
| 352 | +void sm_ctl_update(MYSQL_THD thd __attribute__((unused)), |
| 353 | + struct st_mysql_sys_var *var __attribute__((unused)), |
| 354 | + void *var_ptr __attribute__((unused)), |
| 355 | + const void *save) { |
| 356 | + ulong new_val= *((sm_ctl_t*) save); |
| 357 | + |
| 358 | + if (new_val != sm_ctl) |
| 359 | + sm_reset(); |
| 360 | + |
| 361 | + if (new_val != CTL_RESET) |
| 362 | + { |
| 363 | + sm_ctl= new_val; |
| 364 | + |
| 365 | + if (new_val == CTL_OFF) |
| 366 | + { |
| 367 | + mysql_mutex_lock(&thd_list_mutex); |
| 368 | + list_free(thd_list_root, FALSE); |
| 369 | + thd_list_root= NULL; |
| 370 | + mysql_mutex_unlock(&thd_list_mutex); |
| 371 | + } |
| 372 | + } |
| 373 | + |
| 374 | +} |
| 375 | + |
| 376 | + |
| 377 | +static |
| 378 | +int sm_plugin_init(void *arg __attribute__((unused))) |
| 379 | +{ |
| 380 | + mysql_mutex_init(key_thd_list_mutex, &thd_list_mutex, MY_MUTEX_INIT_FAST); |
| 381 | + |
| 382 | + sm_reset(); |
| 383 | + |
| 384 | + return(0); |
| 385 | +} |
| 386 | + |
| 387 | + |
| 388 | +static |
| 389 | +int sm_plugin_deinit(void *arg __attribute__((unused))) |
| 390 | +{ |
| 391 | + list_free(thd_list_root, FALSE); |
| 392 | + thd_list_root= NULL; |
| 393 | + |
| 394 | + mysql_mutex_destroy(&thd_list_mutex); |
| 395 | + |
| 396 | + return(0); |
| 397 | +} |
| 398 | + |
| 399 | +static |
| 400 | +void sm_query_started(MYSQL_THD thd, |
| 401 | + const char* query __attribute__((unused))) { |
| 402 | + |
| 403 | + sm_thd_data_t *thd_data= sm_thd_data_get(thd); |
| 404 | + |
| 405 | + if (__sync_bool_compare_and_swap(&concurrency, 0, 1)) |
| 406 | + { |
| 407 | + thd_data->start= sm_clock_time_get(); |
| 408 | + busystart= thd_data->start; |
| 409 | + } |
| 410 | + else |
| 411 | + { |
| 412 | + thd_data->start= sm_clock_time_get(); |
| 413 | + (void) __sync_add_and_fetch(&concurrency, 1); |
| 414 | + } |
| 415 | +} |
| 416 | + |
| 417 | +static |
| 418 | +void sm_query_finished(MYSQL_THD thd, |
| 419 | + const char* query __attribute__((unused))) { |
| 420 | + |
| 421 | + sm_thd_data_t *thd_data= sm_thd_data_get(thd); |
| 422 | + ulonglong end, save_busystart; |
| 423 | + |
| 424 | + if (thd_data->start != 0) |
| 425 | + { |
| 426 | + save_busystart= busystart; |
| 427 | + if (__sync_sub_and_fetch(&concurrency, 1) == 0) |
| 428 | + { |
| 429 | + end= sm_clock_time_get(); |
| 430 | + (void) __sync_add_and_fetch(&busytime, |
| 431 | + sm_clock_time_duration(save_busystart, end)); |
| 432 | + } |
| 433 | + else |
| 434 | + { |
| 435 | + end= sm_clock_time_get(); |
| 436 | + } |
| 437 | + |
| 438 | + thd_data->duration+= sm_clock_time_duration(thd_data->start, end); |
| 439 | + thd_data->queries++; |
| 440 | + } |
| 441 | +} |
| 442 | + |
| 443 | +static |
| 444 | +void sm_query_failed(MYSQL_THD thd, |
| 445 | + const char* query, |
| 446 | + int err __attribute__((unused))) { |
| 447 | + |
| 448 | + /* currently there is no difference between success and failure */ |
| 449 | + |
| 450 | + sm_query_finished(thd, query); |
| 451 | + |
| 452 | +} |
| 453 | + |
| 454 | + |
| 455 | +static |
| 456 | +int sm_elapsedtime(MYSQL_THD thd __attribute__((unused)), |
| 457 | + struct st_mysql_show_var* var, |
| 458 | + char *buff) |
| 459 | +{ |
| 460 | + *((ulonglong*)buff)= (sm_ctl == CTL_ON) ? |
| 461 | + sm_clock_time_duration(starttime, sm_clock_time_get()) : |
| 462 | + 0; |
| 463 | + var->type= SHOW_LONGLONG; |
| 464 | + var->value= buff; |
| 465 | + return(0); |
| 466 | +} |
| 467 | + |
| 468 | + |
| 469 | +static |
| 470 | +int sm_sum_queries(void *data, void *argument) |
| 471 | +{ |
| 472 | + sm_thd_data_t *thd_data= (sm_thd_data_t *) data; |
| 473 | + *((ulonglong *) argument)+= thd_data->queries; |
| 474 | + return(0); |
| 475 | +} |
| 476 | + |
| 477 | + |
| 478 | +static |
| 479 | +int sm_queries(MYSQL_THD thd __attribute__((unused)), |
| 480 | + struct st_mysql_show_var* var, |
| 481 | + char *buff) |
| 482 | +{ |
| 483 | + ulonglong sum_queries= 0; |
| 484 | + |
| 485 | + if (sm_ctl == CTL_ON) |
| 486 | + { |
| 487 | + mysql_mutex_lock(&thd_list_mutex); |
| 488 | + list_walk(thd_list_root, sm_sum_queries, (unsigned char *) &sum_queries); |
| 489 | + mysql_mutex_unlock(&thd_list_mutex); |
| 490 | + } |
| 491 | + *((ulonglong *) buff)= queries + sum_queries; |
| 492 | + var->type= SHOW_LONGLONG; |
| 493 | + var->value= buff; |
| 494 | + return(0); |
| 495 | +} |
| 496 | + |
| 497 | + |
| 498 | +static |
| 499 | +int sm_sum_totaltime(void *data, void *argument) |
| 500 | +{ |
| 501 | + sm_thd_data_t *thd_data= (sm_thd_data_t *) data; |
| 502 | + *((ulonglong *) argument)+= thd_data->duration; |
| 503 | + return(0); |
| 504 | +} |
| 505 | + |
| 506 | + |
| 507 | +static |
| 508 | +int sm_totaltime(MYSQL_THD thd __attribute__((unused)), |
| 509 | + struct st_mysql_show_var* var, |
| 510 | + char *buff) |
| 511 | +{ |
| 512 | + ulonglong sum_totaltime= 0; |
| 513 | + |
| 514 | + if (sm_ctl == CTL_ON) |
| 515 | + { |
| 516 | + mysql_mutex_lock(&thd_list_mutex); |
| 517 | + list_walk(thd_list_root, sm_sum_totaltime, |
| 518 | + (unsigned char *) &sum_totaltime); |
| 519 | + mysql_mutex_unlock(&thd_list_mutex); |
| 520 | + } |
| 521 | + *((ulonglong *) buff)= totaltime + sum_totaltime; |
| 522 | + var->type= SHOW_LONGLONG; |
| 523 | + var->value= buff; |
| 524 | + return(0); |
| 525 | +} |
| 526 | + |
| 527 | + |
| 528 | +static void sm_notify(MYSQL_THD thd, unsigned int event_class, |
| 529 | + const void *event) |
| 530 | +{ |
| 531 | + |
| 532 | + if (event_class == MYSQL_AUDIT_GENERAL_CLASS) |
| 533 | + { |
| 534 | + const struct mysql_event_general *event_general= |
| 535 | + (const struct mysql_event_general *) event; |
| 536 | + |
| 537 | + if (sm_ctl != CTL_ON) |
| 538 | + { |
| 539 | + return; |
| 540 | + } |
| 541 | + |
| 542 | + if (event_general->general_command && |
| 543 | + event_general->event_subclass == MYSQL_AUDIT_GENERAL_LOG && |
| 544 | + strcmp(event_general->general_command, "Query") == 0) |
| 545 | + { |
| 546 | + sm_query_started(thd, event_general->general_query); |
| 547 | + } |
| 548 | + else if (event_general->general_command && |
| 549 | + event_general->event_subclass == MYSQL_AUDIT_GENERAL_LOG && |
| 550 | + strcmp(event_general->general_command, "Execute") == 0) |
| 551 | + { |
| 552 | + sm_query_started(thd, event_general->general_query); |
| 553 | + } |
| 554 | + else if (event_general->general_query && |
| 555 | + event_general->event_subclass == MYSQL_AUDIT_GENERAL_RESULT) |
| 556 | + { |
| 557 | + sm_query_finished(thd, event_general->general_query); |
| 558 | + } |
| 559 | + else if (event_general->general_query && |
| 560 | + event_general->event_subclass == MYSQL_AUDIT_GENERAL_ERROR) |
| 561 | + { |
| 562 | + sm_query_failed(thd, event_general->general_query, |
| 563 | + event_general->general_error_code); |
| 564 | + } |
| 565 | + |
| 566 | + } |
| 567 | + else if (event_class == MYSQL_AUDIT_CONNECTION_CLASS) |
| 568 | + { |
| 569 | + const struct mysql_event_connection *event_connection= |
| 570 | + (const struct mysql_event_connection *) event; |
| 571 | + switch (event_connection->event_subclass) |
| 572 | + { |
| 573 | + case MYSQL_AUDIT_CONNECTION_CONNECT: |
| 574 | + sm_thd_data_get(thd); |
| 575 | + break; |
| 576 | + case MYSQL_AUDIT_CONNECTION_DISCONNECT: |
| 577 | + sm_thd_data_release(thd); |
| 578 | + break; |
| 579 | + default: |
| 580 | + break; |
| 581 | + } |
| 582 | + } |
| 583 | +} |
| 584 | + |
| 585 | +/* |
| 586 | + * Plugin system vars |
| 587 | + */ |
| 588 | +static struct st_mysql_sys_var* scalability_metrics_system_variables[] = |
| 589 | +{ |
| 590 | + MYSQL_SYSVAR(thd_data), |
| 591 | + MYSQL_SYSVAR(control), |
| 592 | + NULL |
| 593 | +}; |
| 594 | + |
| 595 | +/* |
| 596 | + Plugin type-specific descriptor |
| 597 | +*/ |
| 598 | +static struct st_mysql_audit scalability_metrics_descriptor= |
| 599 | +{ |
| 600 | + MYSQL_AUDIT_INTERFACE_VERSION, /* interface version */ |
| 601 | + NULL, /* release_thd function */ |
| 602 | + sm_notify, /* notify function */ |
| 603 | + { MYSQL_AUDIT_GENERAL_CLASSMASK | |
| 604 | + MYSQL_AUDIT_CONNECTION_CLASSMASK } /* class mask */ |
| 605 | +}; |
| 606 | + |
| 607 | +/* |
| 608 | + Plugin status variables for SHOW STATUS |
| 609 | +*/ |
| 610 | + |
| 611 | +static struct st_mysql_show_var simple_status[]= |
| 612 | +{ |
| 613 | + { "scalability_metrics_elapsedtime", (char *) &sm_elapsedtime, SHOW_FUNC }, |
| 614 | + { "scalability_metrics_queries", (char *) &sm_queries, SHOW_FUNC }, |
| 615 | + { "scalability_metrics_concurrency", (char *) &concurrency, SHOW_LONGLONG }, |
| 616 | + { "scalability_metrics_totaltime", (char *) &sm_totaltime, SHOW_FUNC }, |
| 617 | + { "scalability_metrics_busytime", (char *) &busytime, SHOW_LONGLONG }, |
| 618 | + { 0, 0, 0} |
| 619 | +}; |
| 620 | + |
| 621 | + |
| 622 | +/* |
| 623 | + Plugin library descriptor |
| 624 | +*/ |
| 625 | + |
| 626 | +mysql_declare_plugin(scalability_metrics) |
| 627 | +{ |
| 628 | + MYSQL_AUDIT_PLUGIN, /* type */ |
| 629 | + &scalability_metrics_descriptor, /* descriptor */ |
| 630 | + "scalability_metrics", /* name */ |
| 631 | + "Percona LLC and/or its affiliates", /* author */ |
| 632 | + "Scalability metrics", /* description */ |
| 633 | + PLUGIN_LICENSE_GPL, |
| 634 | + sm_plugin_init, /* init function (when loaded) */ |
| 635 | + sm_plugin_deinit, /* deinit function (when unloaded) */ |
| 636 | + 0x0001, /* version */ |
| 637 | + simple_status, /* status variables */ |
| 638 | + scalability_metrics_system_variables, /* system variables */ |
| 639 | + NULL, |
| 640 | + 0, |
| 641 | +} |
| 642 | +mysql_declare_plugin_end; |
| 643 | + |
| 644 | |
| 645 | === modified file 'sql/item_func.cc' |
| 646 | --- sql/item_func.cc 2013-12-05 17:23:10 +0000 |
| 647 | +++ sql/item_func.cc 2014-02-10 13:58:36 +0000 |
| 648 | @@ -4537,6 +4537,8 @@ |
| 649 | thd->mysys_var->current_mutex= &LOCK_user_locks; |
| 650 | thd->mysys_var->current_cond= &cond; |
| 651 | |
| 652 | + DEBUG_SYNC(current_thd, "func_sleep_before_sleep"); |
| 653 | + |
| 654 | error= 0; |
| 655 | thd_wait_begin(thd, THD_WAIT_SLEEP); |
| 656 | while (!thd->killed) |
Same comments as in the 5.5 MP.