1 # name : innodb_show_status.patch
2 # introduced : 11 or before
3 # maintainer : Yasufumi
6 # Any small change to this file in the main branch
7 # should be done or reviewed by the maintainer!
8 diff -ruN a/storage/innobase/buf/buf0buf.c b/storage/innobase/buf/buf0buf.c
9 --- a/storage/innobase/buf/buf0buf.c 2010-11-03 07:01:13.000000000 +0900
10 +++ b/storage/innobase/buf/buf0buf.c 2010-12-03 15:07:31.786968193 +0900
14 total_info->pool_size += pool_info->pool_size;
15 + total_info->pool_size_bytes += pool_info->pool_size_bytes;
16 total_info->lru_len += pool_info->lru_len;
17 total_info->old_lru_len += pool_info->old_lru_len;
18 total_info->free_list_len += pool_info->free_list_len;
21 pool_info->pool_size = buf_pool->curr_size;
23 + pool_info->pool_size_bytes = buf_pool->curr_pool_size;
25 pool_info->lru_len = UT_LIST_GET_LEN(buf_pool->LRU);
27 pool_info->old_lru_len = buf_pool->LRU_old_len;
28 @@ -4993,14 +4996,16 @@
32 - "Buffer pool size %lu\n"
33 - "Free buffers %lu\n"
34 - "Database pages %lu\n"
35 - "Old database pages %lu\n"
36 - "Modified db pages %lu\n"
37 + "Buffer pool size %lu\n"
38 + "Buffer pool size, bytes %lu\n"
39 + "Free buffers %lu\n"
40 + "Database pages %lu\n"
41 + "Old database pages %lu\n"
42 + "Modified db pages %lu\n"
44 "Pending writes: LRU %lu, flush list %lu, single page %lu\n",
46 + pool_info->pool_size_bytes,
47 pool_info->free_list_len,
49 pool_info->old_lru_len,
50 diff -ruN a/storage/innobase/buf/buf0flu.c b/storage/innobase/buf/buf0flu.c
51 --- a/storage/innobase/buf/buf0flu.c 2010-12-03 20:58:26.000000000 +0300
52 +++ b/storage/innobase/buf/buf0flu.c 2011-01-07 03:37:41.000000000 +0300
54 static buf_flush_stat_t buf_flush_stat_sum;
56 /** Number of pages flushed through non flush_list flushes. */
57 -static ulint buf_lru_flush_page_count = 0;
58 +// static ulint buf_lru_flush_page_count = 0;
62 diff -ruN a/storage/innobase/fil/fil0fil.c b/storage/innobase/fil/fil0fil.c
63 --- a/storage/innobase/fil/fil0fil.c 2010-11-03 07:01:13.000000000 +0900
64 +++ b/storage/innobase/fil/fil0fil.c 2010-12-03 15:07:31.790357112 +0900
65 @@ -4886,3 +4886,30 @@
70 +/*************************************************************************
71 +Return local hash table informations. */
74 +fil_system_hash_cells(void)
75 +/*=======================*/
78 + return (fil_system->spaces->n_cells
79 + + fil_system->name_hash->n_cells);
86 +fil_system_hash_nodes(void)
87 +/*=======================*/
90 + return (UT_LIST_GET_LEN(fil_system->space_list)
91 + * (sizeof(fil_space_t) + MEM_BLOCK_HEADER_SIZE));
96 diff -ruN a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
97 --- a/storage/innobase/handler/ha_innodb.cc 2010-12-03 15:06:58.727955654 +0900
98 +++ b/storage/innobase/handler/ha_innodb.cc 2010-12-03 15:07:31.799376984 +0900
100 (char*) &export_vars.innodb_buffer_pool_pages_dirty, SHOW_LONG},
101 {"buffer_pool_pages_flushed",
102 (char*) &export_vars.innodb_buffer_pool_pages_flushed, SHOW_LONG},
103 + {"buffer_pool_pages_LRU_flushed",
104 + (char*) &export_vars.innodb_buffer_pool_pages_LRU_flushed, SHOW_LONG},
105 {"buffer_pool_pages_free",
106 (char*) &export_vars.innodb_buffer_pool_pages_free, SHOW_LONG},
108 @@ -10977,6 +10979,16 @@
109 "Force InnoDB to not use next-key locking, to use only row-level locking.",
112 +static MYSQL_SYSVAR_ULONG(show_verbose_locks, srv_show_verbose_locks,
113 + PLUGIN_VAR_OPCMDARG,
114 + "Whether to show records locked in SHOW INNODB STATUS.",
115 + NULL, NULL, 0, 0, 1, 0);
117 +static MYSQL_SYSVAR_ULONG(show_locks_held, srv_show_locks_held,
118 + PLUGIN_VAR_RQCMDARG,
119 + "Number of locks held to print for each InnoDB transaction in SHOW INNODB STATUS.",
120 + NULL, NULL, 10, 0, 1000, 0);
122 #ifdef UNIV_LOG_ARCHIVE
123 static MYSQL_SYSVAR_STR(log_arch_dir, innobase_log_arch_dir,
124 PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
125 @@ -11164,7 +11176,7 @@
127 static MYSQL_SYSVAR_STR(version, innodb_version_str,
128 PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_READONLY,
129 - "InnoDB version", NULL, NULL, INNODB_VERSION_STR);
130 + "Percona-InnoDB-plugin version", NULL, NULL, INNODB_VERSION_STR);
132 static MYSQL_SYSVAR_BOOL(use_sys_malloc, srv_use_sys_malloc,
133 PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
134 @@ -11249,6 +11261,8 @@
135 MYSQL_SYSVAR(thread_concurrency),
136 MYSQL_SYSVAR(thread_sleep_delay),
137 MYSQL_SYSVAR(autoinc_lock_mode),
138 + MYSQL_SYSVAR(show_verbose_locks),
139 + MYSQL_SYSVAR(show_locks_held),
140 MYSQL_SYSVAR(version),
141 MYSQL_SYSVAR(use_sys_malloc),
142 MYSQL_SYSVAR(use_native_aio),
143 diff -ruN a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h
144 --- a/storage/innobase/include/buf0buf.h 2011-01-20 07:37:08.000000000 +0900
145 +++ b/storage/innobase/include/buf0buf.h 2011-02-14 15:25:20.859126532 +0900
147 /* General buffer pool info */
148 ulint pool_unique_id; /*!< Buffer Pool ID */
149 ulint pool_size; /*!< Buffer Pool size in pages */
150 + ulint pool_size_bytes;
151 ulint lru_len; /*!< Length of buf_pool->LRU */
152 ulint old_lru_len; /*!< buf_pool->LRU_old_len */
153 ulint free_list_len; /*!< Length of buf_pool->free list */
154 diff -ruN a/storage/innobase/include/fil0fil.h b/storage/innobase/include/fil0fil.h
155 --- a/storage/innobase/include/fil0fil.h 2010-11-03 07:01:13.000000000 +0900
156 +++ b/storage/innobase/include/fil0fil.h 2010-12-03 15:07:31.812028575 +0900
158 /*============================*/
159 ulint id); /*!< in: space id */
161 +/*************************************************************************
162 +Return local hash table informations. */
165 +fil_system_hash_cells(void);
166 +/*========================*/
169 +fil_system_hash_nodes(void);
170 +/*========================*/
172 typedef struct fil_space_struct fil_space_t;
175 diff -ruN a/storage/innobase/include/read0read.h b/storage/innobase/include/read0read.h
176 --- a/storage/innobase/include/read0read.h 2010-12-04 02:58:26.000000000 +0900
177 +++ b/storage/innobase/include/read0read.h 2011-01-21 19:35:44.127631727 +0900
183 const read_view_t* view); /*!< in: read view */
184 /*********************************************************************//**
185 Create a consistent cursor view for mysql to be used in cursors. In this
186 diff -ruN a/storage/innobase/include/srv0srv.h b/storage/innobase/include/srv0srv.h
187 --- a/storage/innobase/include/srv0srv.h 2010-11-03 07:01:13.000000000 +0900
188 +++ b/storage/innobase/include/srv0srv.h 2010-12-03 15:07:31.813958103 +0900
190 extern char srv_adaptive_flushing;
193 +extern ulint srv_show_locks_held;
194 +extern ulint srv_show_verbose_locks;
196 /* The sort order table of the MySQL latin1_swedish_ci character set
198 extern const byte* srv_latin1_ordering;
200 buffer pool to disk */
201 extern ulint srv_buf_pool_flushed;
203 +extern ulint buf_lru_flush_page_count;
205 /** Number of buffer pool reads that led to the
206 reading of a disk page */
207 extern ulint srv_buf_pool_reads;
209 ulint innodb_buffer_pool_reads; /*!< srv_buf_pool_reads */
210 ulint innodb_buffer_pool_wait_free; /*!< srv_buf_pool_wait_free */
211 ulint innodb_buffer_pool_pages_flushed; /*!< srv_buf_pool_flushed */
212 + ulint innodb_buffer_pool_pages_LRU_flushed; /*!< buf_lru_flush_page_count */
213 ulint innodb_buffer_pool_write_requests;/*!< srv_buf_pool_write_requests */
214 ulint innodb_buffer_pool_read_ahead; /*!< srv_read_ahead */
215 ulint innodb_buffer_pool_read_ahead_evicted;/*!< srv_read_ahead evicted*/
216 diff -ruN a/storage/innobase/include/thr0loc.h b/storage/innobase/include/thr0loc.h
217 --- a/storage/innobase/include/thr0loc.h 2010-11-03 07:01:13.000000000 +0900
218 +++ b/storage/innobase/include/thr0loc.h 2010-12-03 15:07:31.815081509 +0900
220 thr_local_get_in_ibuf_field(void);
221 /*=============================*/
223 +/*************************************************************************
224 +Return local hash table informations. */
227 +thr_local_hash_cells(void);
228 +/*=======================*/
231 +thr_local_hash_nodes(void);
232 +/*=======================*/
235 #include "thr0loc.ic"
237 diff -ruN a/storage/innobase/lock/lock0lock.c b/storage/innobase/lock/lock0lock.c
238 --- a/storage/innobase/lock/lock0lock.c 2010-11-03 07:01:13.000000000 +0900
239 +++ b/storage/innobase/lock/lock0lock.c 2010-12-03 15:07:31.819023998 +0900
240 @@ -4374,6 +4374,7 @@
244 + if ( srv_show_verbose_locks ) {
245 block = buf_page_try_get(space, page_no, &mtr);
247 for (i = 0; i < lock_rec_get_n_bits(lock); ++i) {
248 @@ -4400,6 +4401,7 @@
255 if (UNIV_LIKELY_NULL(heap)) {
256 @@ -4583,7 +4585,7 @@
260 - if (!srv_print_innodb_lock_monitor) {
261 + if (!srv_print_innodb_lock_monitor && !srv_show_locks_held) {
265 @@ -4655,8 +4657,8 @@
269 - if (nth_lock >= 10) {
270 - fputs("10 LOCKS PRINTED FOR THIS TRX:"
271 + if (nth_lock >= srv_show_locks_held) {
272 + fputs("TOO MANY LOCKS PRINTED FOR THIS TRX:"
273 " SUPPRESSING FURTHER PRINTS\n",
276 diff -ruN a/storage/innobase/read/read0read.c b/storage/innobase/read/read0read.c
277 --- a/storage/innobase/read/read0read.c 2010-12-04 02:58:26.000000000 +0900
278 +++ b/storage/innobase/read/read0read.c 2011-01-21 19:37:08.292650181 +0900
279 @@ -357,34 +357,35 @@
284 const read_view_t* view) /*!< in: read view */
289 if (view->type == VIEW_HIGH_GRANULARITY) {
292 "High-granularity read view undo_n:o %llu\n",
293 (ullint) view->undo_no);
295 - fprintf(stderr, "Normal read view\n");
296 + fprintf(file, "Normal read view\n");
299 - fprintf(stderr, "Read view low limit trx n:o " TRX_ID_FMT "\n",
300 + fprintf(file, "Read view low limit trx n:o " TRX_ID_FMT "\n",
301 (ullint) view->low_limit_no);
303 - fprintf(stderr, "Read view up limit trx id " TRX_ID_FMT "\n",
304 + fprintf(file, "Read view up limit trx id " TRX_ID_FMT "\n",
305 (ullint) view->up_limit_id);
307 - fprintf(stderr, "Read view low limit trx id " TRX_ID_FMT "\n",
308 + fprintf(file, "Read view low limit trx id " TRX_ID_FMT "\n",
309 (ullint) view->low_limit_id);
311 - fprintf(stderr, "Read view individually stored trx ids:\n");
312 + fprintf(file, "Read view individually stored trx ids:\n");
314 n_ids = view->n_trx_ids;
316 for (i = 0; i < n_ids; i++) {
317 - fprintf(stderr, "Read view trx id " TRX_ID_FMT "\n",
318 + fprintf(file, "Read view trx id " TRX_ID_FMT "\n",
319 (ullint) read_view_get_nth_trx_id(view, i));
322 diff -ruN a/storage/innobase/srv/srv0srv.c b/storage/innobase/srv/srv0srv.c
323 --- a/storage/innobase/srv/srv0srv.c 2010-11-03 07:01:13.000000000 +0900
324 +++ b/storage/innobase/srv/srv0srv.c 2010-12-03 15:07:31.824022673 +0900
326 #include "ha_prototypes.h"
328 #include "os0sync.h" /* for HAVE_ATOMIC_BUILTINS */
329 +#include "read0read.h"
330 #include "mysql/plugin.h"
331 #include "mysql/service_thd_wait.h"
335 UNIV_INTERN char srv_adaptive_flushing = TRUE;
337 +UNIV_INTERN ulint srv_show_locks_held = 10;
338 +UNIV_INTERN ulint srv_show_verbose_locks = 0;
340 /** Maximum number of times allowed to conditionally acquire
341 mutex before switching to blocking wait on the mutex */
342 #define MAX_MUTEX_NOWAIT 20
344 /* variable to count the number of pages that were written from buffer
346 UNIV_INTERN ulint srv_buf_pool_flushed = 0;
347 +UNIV_INTERN ulint buf_lru_flush_page_count = 0;
349 /** Number of buffer pool reads that led to the
350 reading of a disk page */
351 @@ -1821,6 +1826,13 @@
355 + ulint btr_search_sys_subtotal;
356 + ulint lock_sys_subtotal;
357 + ulint recv_sys_subtotal;
362 mutex_enter(&srv_innodb_monitor_mutex);
364 current_time = time(NULL);
365 @@ -1869,31 +1881,6 @@
367 mutex_exit(&dict_foreign_err_mutex);
369 - /* Only if lock_print_info_summary proceeds correctly,
370 - before we call the lock_print_info_all_transactions
371 - to print all the lock information. */
372 - ret = lock_print_info_summary(file, nowait);
376 - long t = ftell(file);
378 - *trx_start = ULINT_UNDEFINED;
380 - *trx_start = (ulint) t;
383 - lock_print_info_all_transactions(file);
385 - long t = ftell(file);
387 - *trx_end = ULINT_UNDEFINED;
389 - *trx_end = (ulint) t;
397 @@ -1924,10 +1911,84 @@
398 "BUFFER POOL AND MEMORY\n"
399 "----------------------\n", file);
401 - "Total memory allocated " ULINTPF
402 - "; in additional pool allocated " ULINTPF "\n",
403 - ut_total_allocated_memory,
404 - mem_pool_get_reserved(mem_comm_pool));
405 + "Total memory allocated " ULINTPF
406 + "; in additional pool allocated " ULINTPF "\n",
407 + ut_total_allocated_memory,
408 + mem_pool_get_reserved(mem_comm_pool));
409 + /* Calcurate reserved memories */
410 + if (btr_search_sys && btr_search_sys->hash_index->heap) {
411 + btr_search_sys_subtotal = mem_heap_get_size(btr_search_sys->hash_index->heap);
413 + btr_search_sys_subtotal = 0;
414 + for (i=0; i < btr_search_sys->hash_index->n_mutexes; i++) {
415 + btr_search_sys_subtotal += mem_heap_get_size(btr_search_sys->hash_index->heaps[i]);
419 + lock_sys_subtotal = 0;
421 + mutex_enter(&kernel_mutex);
422 + trx = UT_LIST_GET_FIRST(trx_sys->mysql_trx_list);
424 + lock_sys_subtotal += ((trx->lock_heap) ? mem_heap_get_size(trx->lock_heap) : 0);
425 + trx = UT_LIST_GET_NEXT(mysql_trx_list, trx);
427 + mutex_exit(&kernel_mutex);
430 + recv_sys_subtotal = ((recv_sys && recv_sys->addr_hash)
431 + ? mem_heap_get_size(recv_sys->heap) : 0);
434 + "Internal hash tables (constant factor + variable factor)\n"
435 + " Adaptive hash index %lu \t(%lu + %lu)\n"
436 + " Page hash %lu (buffer pool 0 only)\n"
437 + " Dictionary cache %lu \t(%lu + %lu)\n"
438 + " File system %lu \t(%lu + %lu)\n"
439 + " Lock system %lu \t(%lu + %lu)\n"
440 + " Recovery system %lu \t(%lu + %lu)\n"
441 + " Threads %lu \t(%lu + %lu)\n",
443 + (ulong) (btr_search_sys
444 + ? (btr_search_sys->hash_index->n_cells * sizeof(hash_cell_t)) : 0)
445 + + btr_search_sys_subtotal,
446 + (ulong) (btr_search_sys
447 + ? (btr_search_sys->hash_index->n_cells * sizeof(hash_cell_t)) : 0),
448 + (ulong) btr_search_sys_subtotal,
450 + (ulong) (buf_pool_from_array(0)->page_hash->n_cells * sizeof(hash_cell_t)),
452 + (ulong) (dict_sys ? ((dict_sys->table_hash->n_cells
453 + + dict_sys->table_id_hash->n_cells
454 + ) * sizeof(hash_cell_t)
455 + + dict_sys->size) : 0),
456 + (ulong) (dict_sys ? ((dict_sys->table_hash->n_cells
457 + + dict_sys->table_id_hash->n_cells
458 + ) * sizeof(hash_cell_t)) : 0),
459 + (ulong) (dict_sys ? (dict_sys->size) : 0),
461 + (ulong) (fil_system_hash_cells() * sizeof(hash_cell_t)
462 + + fil_system_hash_nodes()),
463 + (ulong) (fil_system_hash_cells() * sizeof(hash_cell_t)),
464 + (ulong) fil_system_hash_nodes(),
466 + (ulong) ((lock_sys ? (lock_sys->rec_hash->n_cells * sizeof(hash_cell_t)) : 0)
467 + + lock_sys_subtotal),
468 + (ulong) (lock_sys ? (lock_sys->rec_hash->n_cells * sizeof(hash_cell_t)) : 0),
469 + (ulong) lock_sys_subtotal,
471 + (ulong) (((recv_sys && recv_sys->addr_hash)
472 + ? (recv_sys->addr_hash->n_cells * sizeof(hash_cell_t)) : 0)
473 + + recv_sys_subtotal),
474 + (ulong) ((recv_sys && recv_sys->addr_hash)
475 + ? (recv_sys->addr_hash->n_cells * sizeof(hash_cell_t)) : 0),
476 + (ulong) recv_sys_subtotal,
478 + (ulong) (thr_local_hash_cells() * sizeof(hash_cell_t)
479 + + thr_local_hash_nodes()),
480 + (ulong) (thr_local_hash_cells() * sizeof(hash_cell_t)),
481 + (ulong) thr_local_hash_nodes());
483 fprintf(file, "Dictionary memory allocated " ULINTPF "\n",
486 @@ -1943,6 +2004,16 @@
487 fprintf(file, "%lu read views open inside InnoDB\n",
488 UT_LIST_GET_LEN(trx_sys->view_list));
490 + if (UT_LIST_GET_LEN(trx_sys->view_list)) {
491 + read_view_t* view = UT_LIST_GET_LAST(trx_sys->view_list);
494 + fprintf(file, "---OLDEST VIEW---\n");
495 + read_view_print(file, view);
496 + fprintf(file, "-----------------\n");
500 n_reserved = fil_space_get_n_reserved_extents(0);
501 if (n_reserved > 0) {
503 @@ -1986,6 +2057,31 @@
504 srv_n_rows_deleted_old = srv_n_rows_deleted;
505 srv_n_rows_read_old = srv_n_rows_read;
507 + /* Only if lock_print_info_summary proceeds correctly,
508 + before we call the lock_print_info_all_transactions
509 + to print all the lock information. */
510 + ret = lock_print_info_summary(file, nowait);
514 + long t = ftell(file);
516 + *trx_start = ULINT_UNDEFINED;
518 + *trx_start = (ulint) t;
521 + lock_print_info_all_transactions(file);
523 + long t = ftell(file);
525 + *trx_end = ULINT_UNDEFINED;
527 + *trx_end = (ulint) t;
532 fputs("----------------------------\n"
533 "END OF INNODB MONITOR OUTPUT\n"
534 "============================\n", file);
535 @@ -2029,6 +2125,7 @@
536 = srv_buf_pool_write_requests;
537 export_vars.innodb_buffer_pool_wait_free = srv_buf_pool_wait_free;
538 export_vars.innodb_buffer_pool_pages_flushed = srv_buf_pool_flushed;
539 + export_vars.innodb_buffer_pool_pages_LRU_flushed = buf_lru_flush_page_count;
540 export_vars.innodb_buffer_pool_reads = srv_buf_pool_reads;
541 export_vars.innodb_buffer_pool_read_ahead
542 = stat.n_ra_pages_read;
543 diff -ruN a/storage/innobase/sync/sync0arr.c b/storage/innobase/sync/sync0arr.c
544 --- a/storage/innobase/sync/sync0arr.c 2010-11-03 07:01:13.000000000 +0900
545 +++ b/storage/innobase/sync/sync0arr.c 2010-12-03 15:07:31.826041368 +0900
549 "--Thread %lu has waited at %s line %lu"
550 - " for %.2f seconds the semaphore:\n",
551 + " for %#.5g seconds the semaphore:\n",
552 (ulong) os_thread_pf(cell->thread), cell->file,
554 difftime(time(NULL), cell->reservation_time));
555 diff -ruN a/storage/innobase/thr/thr0loc.c b/storage/innobase/thr/thr0loc.c
556 --- a/storage/innobase/thr/thr0loc.c 2010-11-03 07:01:13.000000000 +0900
557 +++ b/storage/innobase/thr/thr0loc.c 2010-12-03 15:07:31.828023915 +0900
560 /** The hash table. The module is not yet initialized when it is NULL. */
561 static hash_table_t* thr_local_hash = NULL;
562 +ulint thr_local_hash_n_nodes = 0;
564 /** Thread local data */
565 typedef struct thr_local_struct thr_local_t;
567 os_thread_pf(os_thread_get_curr_id()),
570 + thr_local_hash_n_nodes++;
571 mutex_exit(&thr_local_mutex);
576 HASH_DELETE(thr_local_t, hash, thr_local_hash,
577 os_thread_pf(id), local);
578 + thr_local_hash_n_nodes--;
580 mutex_exit(&thr_local_mutex);
583 hash_table_free(thr_local_hash);
584 thr_local_hash = NULL;
587 +/*************************************************************************
588 +Return local hash table informations. */
591 +thr_local_hash_cells(void)
592 +/*======================*/
594 + if (thr_local_hash) {
595 + return (thr_local_hash->n_cells);
602 +thr_local_hash_nodes(void)
603 +/*======================*/
605 + if (thr_local_hash) {
606 + return (thr_local_hash_n_nodes
607 + * (sizeof(thr_local_t) + MEM_BLOCK_HEADER_SIZE));
612 diff -ruN a/storage/innobase/trx/trx0purge.c b/storage/innobase/trx/trx0purge.c
613 --- a/storage/innobase/trx/trx0purge.c 2010-12-04 02:58:26.000000000 +0900
614 +++ b/storage/innobase/trx/trx0purge.c 2011-01-21 19:40:42.086683671 +0900
615 @@ -1201,7 +1201,7 @@
616 /*=====================*/
618 fprintf(stderr, "InnoDB: Purge system view:\n");
619 - read_view_print(purge_sys->view);
620 + read_view_print(stderr, purge_sys->view);
622 fprintf(stderr, "InnoDB: Purge trx n:o " TRX_ID_FMT
623 ", undo n:o " TRX_ID_FMT "\n",