1 # name : innodb_extend_slow.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 --- a/storage/innobase/buf/buf0buf.c
9 +++ b/storage/innobase/buf/buf0buf.c
11 #include "dict0dict.h"
16 +/* prototypes for new functions added to ha_innodb.cc */
17 +trx_t* innobase_get_trx();
19 +inline void _increment_page_get_statistics(buf_block_t* block, trx_t* trx)
22 + ulint block_hash_byte;
23 + byte block_hash_offset;
27 + if (!innobase_get_slow_log() || !trx || !trx->take_stats)
30 + if (!trx->distinct_page_access_hash) {
31 + trx->distinct_page_access_hash = mem_alloc(DPAH_SIZE);
32 + memset(trx->distinct_page_access_hash, 0, DPAH_SIZE);
35 + block_hash = ut_hash_ulint((block->page.space << 20) + block->page.space +
36 + block->page.offset, DPAH_SIZE << 3);
37 + block_hash_byte = block_hash >> 3;
38 + block_hash_offset = (byte) block_hash & 0x07;
39 + if (block_hash_byte >= DPAH_SIZE)
40 + fprintf(stderr, "!!! block_hash_byte = %lu block_hash_offset = %d !!!\n", block_hash_byte, block_hash_offset);
41 + if (block_hash_offset > 7)
42 + fprintf(stderr, "!!! block_hash_byte = %lu block_hash_offset = %d !!!\n", block_hash_byte, block_hash_offset);
43 + if ((trx->distinct_page_access_hash[block_hash_byte] & ((byte) 0x01 << block_hash_offset)) == 0)
44 + trx->distinct_page_access++;
45 + trx->distinct_page_access_hash[block_hash_byte] |= (byte) 0x01 << block_hash_offset;
50 IMPLEMENTATION OF THE BUFFER POOL
51 @@ -1871,8 +1905,16 @@
58 + ib_uint64_t start_time;
59 + ib_uint64_t finish_time;
60 buf_pool_t* buf_pool = buf_pool_get(space, offset);
62 + if (innobase_get_slow_log()) {
63 + trx = innobase_get_trx();
65 buf_pool->stat.n_page_gets++;
69 //buf_pool_mutex_exit(buf_pool);
70 rw_lock_s_unlock(&buf_pool->page_hash_latch);
72 - buf_read_page(space, zip_size, offset);
73 + buf_read_page(space, zip_size, offset, trx);
75 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
76 ut_a(++buf_dbg_counter % 37 || buf_validate());
77 @@ -1986,6 +2028,13 @@
78 /* Let us wait until the read operation
81 + if (innobase_get_slow_log() && trx && trx->take_stats)
83 + ut_usectime(&sec, &ms);
84 + start_time = (ib_uint64_t)sec * 1000000 + ms;
89 enum buf_io_fix io_fix;
91 @@ -2000,6 +2049,12 @@
95 + if (innobase_get_slow_log() && trx && trx->take_stats && start_time)
97 + ut_usectime(&sec, &ms);
98 + finish_time = (ib_uint64_t)sec * 1000000 + ms;
99 + trx->io_reads_wait_timer += (ulint)(finish_time - start_time);
103 #ifdef UNIV_IBUF_COUNT_DEBUG
104 @@ -2314,6 +2369,11 @@
107 mutex_t* block_mutex = NULL;
111 + ib_uint64_t start_time;
112 + ib_uint64_t finish_time;
113 buf_pool_t* buf_pool = buf_pool_get(space, offset);
116 @@ -2343,6 +2403,9 @@
117 || ibuf_page_low(space, zip_size, offset,
118 FALSE, file, line, NULL));
120 + if (innobase_get_slow_log()) {
121 + trx = innobase_get_trx();
123 buf_pool->stat.n_page_gets++;
124 fold = buf_page_address_fold(space, offset);
126 @@ -2413,9 +2476,9 @@
130 - if (buf_read_page(space, zip_size, offset)) {
131 + if (buf_read_page(space, zip_size, offset, trx)) {
132 buf_read_ahead_random(space, zip_size, offset,
134 + ibuf_inside(mtr), trx);
137 } else if (retries < BUF_PAGE_READ_MAX_RETRIES) {
138 @@ -2725,6 +2788,13 @@
139 /* Let us wait until the read operation
142 + if (innobase_get_slow_log() && trx && trx->take_stats)
144 + ut_usectime(&sec, &ms);
145 + start_time = (ib_uint64_t)sec * 1000000 + ms;
150 enum buf_io_fix io_fix;
152 @@ -2739,6 +2809,12 @@
156 + if (innobase_get_slow_log() && trx && trx->take_stats && start_time)
158 + ut_usectime(&sec, &ms);
159 + finish_time = (ib_uint64_t)sec * 1000000 + ms;
160 + trx->io_reads_wait_timer += (ulint)(finish_time - start_time);
164 fix_type = MTR_MEMO_BUF_FIX;
165 @@ -2765,13 +2841,17 @@
168 buf_read_ahead_linear(space, zip_size, offset,
170 + ibuf_inside(mtr), trx);
173 #ifdef UNIV_IBUF_COUNT_DEBUG
174 ut_a(ibuf_count_get(buf_block_get_space(block),
175 buf_block_get_page_no(block)) == 0);
177 + if (innobase_get_slow_log()) {
178 + _increment_page_get_statistics(block, trx);
184 @@ -2795,6 +2875,7 @@
185 unsigned access_time;
192 @@ -2872,6 +2953,10 @@
193 #if defined UNIV_DEBUG_FILE_ACCESSES || defined UNIV_DEBUG
194 ut_a(block->page.file_page_was_freed == FALSE);
196 + if (innobase_get_slow_log()) {
197 + trx = innobase_get_trx();
200 if (UNIV_UNLIKELY(!access_time)) {
201 /* In the case of a first access, try to apply linear
203 @@ -2879,7 +2964,7 @@
204 buf_read_ahead_linear(buf_block_get_space(block),
205 buf_block_get_zip_size(block),
206 buf_block_get_page_no(block),
208 + ibuf_inside(mtr), trx);
211 #ifdef UNIV_IBUF_COUNT_DEBUG
212 @@ -2889,6 +2974,9 @@
213 buf_pool = buf_pool_from_block(block);
214 buf_pool->stat.n_page_gets++;
216 + if (innobase_get_slow_log()) {
217 + _increment_page_get_statistics(block, trx);
222 @@ -2911,6 +2999,7 @@
223 buf_pool_t* buf_pool;
229 ut_ad(mtr->state == MTR_ACTIVE);
230 @@ -2997,6 +3086,11 @@
232 buf_pool->stat.n_page_gets++;
234 + if (innobase_get_slow_log()) {
235 + trx = innobase_get_trx();
236 + _increment_page_get_statistics(block, trx);
242 --- a/storage/innobase/buf/buf0rea.c
243 +++ b/storage/innobase/buf/buf0rea.c
245 treat the tablespace as dropped; this is a timestamp we
246 use to stop dangling page reads from a tablespace
247 which we have DISCARDed + IMPORTed back */
248 - ulint offset) /*!< in: page number */
249 + ulint offset, /*!< in: page number */
254 @@ -181,15 +182,15 @@
256 thd_wait_begin(NULL, THD_WAIT_DISKIO);
258 - *err = fil_io(OS_FILE_READ | wake_later,
259 + *err = _fil_io(OS_FILE_READ | wake_later,
260 sync, space, zip_size, offset, 0, zip_size,
261 - bpage->zip.data, bpage);
262 + bpage->zip.data, bpage, trx);
264 ut_a(buf_page_get_state(bpage) == BUF_BLOCK_FILE_PAGE);
266 - *err = fil_io(OS_FILE_READ | wake_later,
267 + *err = _fil_io(OS_FILE_READ | wake_later,
268 sync, space, 0, offset, 0, UNIV_PAGE_SIZE,
269 - ((buf_block_t*) bpage)->frame, bpage);
270 + ((buf_block_t*) bpage)->frame, bpage, trx);
273 ut_a(*err == DB_SUCCESS);
276 ulint offset, /*!< in: page number of a page which
277 the current thread wants to access */
278 - ibool inside_ibuf) /*!< in: TRUE if we are inside ibuf
279 + ibool inside_ibuf, /*!< in: TRUE if we are inside ibuf
283 buf_pool_t* buf_pool = buf_pool_get(space, offset);
284 ib_int64_t tablespace_version;
287 ibuf_mode | OS_AIO_SIMULATED_WAKE_LATER,
288 space, zip_size, FALSE,
289 - tablespace_version, i);
290 + tablespace_version, i, trx);
291 if (err == DB_TABLESPACE_DELETED) {
292 ut_print_timestamp(stderr);
296 ulint space, /*!< in: space id */
297 ulint zip_size,/*!< in: compressed page size in bytes, or 0 */
298 - ulint offset) /*!< in: page number */
299 + ulint offset, /*!< in: page number */
302 buf_pool_t* buf_pool = buf_pool_get(space, offset);
303 ib_int64_t tablespace_version;
306 count = buf_read_page_low(&err, TRUE, BUF_READ_ANY_PAGE, space,
308 - tablespace_version, offset);
309 + tablespace_version, offset, trx);
310 srv_buf_pool_reads += count;
311 if (err == DB_TABLESPACE_DELETED) {
312 ut_print_timestamp(stderr);
314 ulint space, /*!< in: space id */
315 ulint zip_size, /*!< in: compressed page size in bytes, or 0 */
316 ulint offset, /*!< in: page number; see NOTE 3 above */
317 - ibool inside_ibuf) /*!< in: TRUE if we are inside ibuf routine */
318 + ibool inside_ibuf, /*!< in: TRUE if we are inside ibuf routine */
321 buf_pool_t* buf_pool = buf_pool_get(space, offset);
322 ib_int64_t tablespace_version;
324 count += buf_read_page_low(
327 - space, zip_size, FALSE, tablespace_version, i);
328 + space, zip_size, FALSE, tablespace_version, i, trx);
329 if (err == DB_TABLESPACE_DELETED) {
330 ut_print_timestamp(stderr);
333 buf_read_page_low(&err, sync && (i + 1 == n_stored),
334 BUF_READ_ANY_PAGE, space_ids[i],
335 zip_size, TRUE, space_versions[i],
337 + page_nos[i], NULL);
339 if (UNIV_UNLIKELY(err == DB_TABLESPACE_DELETED)) {
341 @@ -900,12 +904,12 @@
342 if ((i + 1 == n_stored) && sync) {
343 buf_read_page_low(&err, TRUE, BUF_READ_ANY_PAGE, space,
344 zip_size, TRUE, tablespace_version,
346 + page_nos[i], NULL);
348 buf_read_page_low(&err, FALSE, BUF_READ_ANY_PAGE
349 | OS_AIO_SIMULATED_WAKE_LATER,
350 space, zip_size, TRUE,
351 - tablespace_version, page_nos[i]);
352 + tablespace_version, page_nos[i], NULL);
356 --- a/storage/innobase/fil/fil0fil.c
357 +++ b/storage/innobase/fil/fil0fil.c
358 @@ -4765,7 +4765,7 @@
359 node->name, node->handle, buf,
360 offset_low, offset_high,
366 node->size += n_pages;
367 @@ -5092,7 +5092,7 @@
368 i/o on a tablespace which does not exist */
374 ulint type, /*!< in: OS_FILE_READ or OS_FILE_WRITE,
375 ORed to OS_FILE_LOG, if a log i/o
376 @@ -5117,8 +5117,9 @@
377 void* buf, /*!< in/out: buffer where to store read data
378 or from where to write; in aio this must be
379 appropriately aligned */
380 - void* message) /*!< in: message for aio handler if non-sync
381 + void* message, /*!< in: message for aio handler if non-sync
382 aio used, else ignored */
387 @@ -5286,7 +5287,7 @@
389 /* Queue the aio request */
390 ret = os_aio(type, mode | wake_later, node->name, node->handle, buf,
391 - offset_low, offset_high, len, node, message);
392 + offset_low, offset_high, len, node, message, trx);
396 --- a/storage/innobase/handler/ha_innodb.cc
397 +++ b/storage/innobase/handler/ha_innodb.cc
398 @@ -1584,6 +1584,16 @@
399 trx->check_unique_secondary = !thd_test_options(
400 thd, OPTION_RELAXED_UNIQUE_CHECKS);
402 +#ifdef EXTENDED_SLOWLOG
403 + if (thd_log_slow_verbosity(thd) & SLOG_V_INNODB) {
404 + trx->take_stats = TRUE;
406 + trx->take_stats = FALSE;
409 + trx->take_stats = FALSE;
415 @@ -1638,6 +1648,32 @@
419 +/*************************************************************************
420 +Gets current trx. */
425 + THD *thd=current_thd;
426 + if (likely(thd != 0)) {
427 + trx_t*& trx = thd_to_trx(thd);
436 +innobase_get_slow_log()
438 +#ifdef EXTENDED_SLOWLOG
439 + return((ibool) thd_opt_slow_log());
445 /*********************************************************************//**
446 Note that a transaction has been registered with MySQL.
447 @return true if transaction is registered with MySQL 2PC coordinator */
448 @@ -9417,6 +9453,25 @@
449 statement has ended */
451 if (trx->n_mysql_tables_in_use == 0) {
452 +#ifdef EXTENDED_SLOWLOG
453 + increment_thd_innodb_stats(thd,
454 + (unsigned long long) trx->id,
457 + trx->io_reads_wait_timer,
458 + trx->lock_que_wait_timer,
459 + trx->innodb_que_wait_timer,
460 + trx->distinct_page_access);
464 + trx->io_reads_wait_timer = 0;
465 + trx->lock_que_wait_timer = 0;
466 + trx->innodb_que_wait_timer = 0;
467 + trx->distinct_page_access = 0;
468 + if (trx->distinct_page_access_hash)
469 + memset(trx->distinct_page_access_hash, 0, DPAH_SIZE);
472 trx->mysql_n_tables_locked = 0;
473 prebuilt->used_in_HANDLER = FALSE;
474 --- a/storage/innobase/include/buf0rea.h
475 +++ b/storage/innobase/include/buf0rea.h
480 +#include "trx0types.h"
481 #include "buf0types.h"
483 /********************************************************************//**
486 ulint space, /*!< in: space id */
487 ulint zip_size,/*!< in: compressed page size in bytes, or 0 */
488 - ulint offset);/*!< in: page number */
489 + ulint offset, /*!< in: page number */
491 /********************************************************************//**
492 Applies a random read-ahead in buf_pool if there are at least a threshold
493 value of accessed pages from the random read-ahead area. Does not read any
496 ulint offset, /*!< in: page number of a page which
497 the current thread wants to access */
498 - ibool inside_ibuf); /*!< in: TRUE if we are inside ibuf
499 + ibool inside_ibuf, /*!< in: TRUE if we are inside ibuf
502 /********************************************************************//**
503 Applies linear read-ahead if in the buf_pool the page is a border page of
504 a linear read-ahead area and all the pages in the area have been accessed.
506 ulint space, /*!< in: space id */
507 ulint zip_size, /*!< in: compressed page size in bytes, or 0 */
508 ulint offset, /*!< in: page number; see NOTE 3 above */
509 - ibool inside_ibuf); /*!< in: TRUE if we are inside ibuf routine */
510 + ibool inside_ibuf, /*!< in: TRUE if we are inside ibuf routine */
512 /********************************************************************//**
513 Issues read requests for pages which the ibuf module wants to read in, in
514 order to contract the insert buffer tree. Technically, this function is like
515 --- a/storage/innobase/include/fil0fil.h
516 +++ b/storage/innobase/include/fil0fil.h
518 Reads or writes data. This operation is asynchronous (aio).
519 @return DB_SUCCESS, or DB_TABLESPACE_DELETED if we are trying to do
520 i/o on a tablespace which does not exist */
521 +#define fil_io(type, sync, space_id, zip_size, block_offset, byte_offset, len, buf, message) \
522 + _fil_io(type, sync, space_id, zip_size, block_offset, byte_offset, len, buf, message, NULL)
529 ulint type, /*!< in: OS_FILE_READ or OS_FILE_WRITE,
530 ORed to OS_FILE_LOG, if a log i/o
532 void* buf, /*!< in/out: buffer where to store read data
533 or from where to write; in aio this must be
534 appropriately aligned */
535 - void* message); /*!< in: message for aio handler if non-sync
536 + void* message, /*!< in: message for aio handler if non-sync
537 aio used, else ignored */
539 /**********************************************************************//**
540 Waits for an aio operation to complete. This function is used to write the
541 handler for completed requests. The aio array of pending requests is divided
542 --- a/storage/innobase/include/os0file.h
543 +++ b/storage/innobase/include/os0file.h
548 +#include "trx0types.h"
552 @@ -277,13 +278,17 @@
553 pfs_os_file_close_func(file, __FILE__, __LINE__)
555 # define os_aio(type, mode, name, file, buf, offset, offset_high, \
556 - n, message1, message2) \
557 + n, message1, message2, trx) \
558 pfs_os_aio_func(type, mode, name, file, buf, offset, \
559 - offset_high, n, message1, message2, \
560 + offset_high, n, message1, message2, trx, \
563 # define os_file_read(file, buf, offset, offset_high, n) \
564 - pfs_os_file_read_func(file, buf, offset, offset_high, n, \
565 + pfs_os_file_read_func(file, buf, offset, offset_high, n, NULL, \
566 + __FILE__, __LINE__)
568 +# define os_file_read_trx(file, buf, offset, offset_high, n, trx) \
569 + pfs_os_file_read_func(file, buf, offset, offset_high, n, trx, \
572 # define os_file_read_no_error_handling(file, buf, offset, \
573 @@ -319,12 +324,15 @@
574 # define os_file_close(file) os_file_close_func(file)
576 # define os_aio(type, mode, name, file, buf, offset, offset_high, \
577 - n, message1, message2) \
578 + n, message1, message2, trx) \
579 os_aio_func(type, mode, name, file, buf, offset, offset_high, n,\
580 - message1, message2)
581 + message1, message2, trx)
583 # define os_file_read(file, buf, offset, offset_high, n) \
584 - os_file_read_func(file, buf, offset, offset_high, n)
585 + os_file_read_func(file, buf, offset, offset_high, n, NULL)
587 +# define os_file_read_trx(file, buf, offset, offset_high, n, trx) \
588 + os_file_read_func(file, buf, offset, offset_high, n, trx)
590 # define os_file_read_no_error_handling(file, buf, offset, \
593 ulint offset_high,/*!< in: most significant 32 bits of
595 ulint n, /*!< in: number of bytes to read */
597 const char* src_file,/*!< in: file name where func invoked */
598 ulint src_line);/*!< in: line where the func invoked */
601 (can be used to identify a completed
602 aio operation); ignored if mode is
605 const char* src_file,/*!< in: file name where func invoked */
606 ulint src_line);/*!< in: line where the func invoked */
607 /*******************************************************************//**
609 offset where to read */
610 ulint offset_high,/*!< in: most significant 32 bits of
612 - ulint n); /*!< in: number of bytes to read */
613 + ulint n, /*!< in: number of bytes to read */
615 /*******************************************************************//**
616 Rewind file to its start, read at most size - 1 bytes from it to str, and
617 NUL-terminate str. All errors are silently ignored. This function is
618 @@ -1048,10 +1059,11 @@
619 (can be used to identify a completed
620 aio operation); ignored if mode is
622 - void* message2);/*!< in: message for the aio handler
623 + void* message2,/*!< in: message for the aio handler
624 (can be used to identify a completed
625 aio operation); ignored if mode is
628 /************************************************************************//**
629 Wakes up all async i/o threads so that they know to exit themselves in
631 --- a/storage/innobase/include/os0file.ic
632 +++ b/storage/innobase/include/os0file.ic
634 (can be used to identify a completed
635 aio operation); ignored if mode is
638 const char* src_file,/*!< in: file name where func invoked */
639 ulint src_line)/*!< in: line where the func invoked */
644 result = os_aio_func(type, mode, name, file, buf, offset, offset_high,
645 - n, message1, message2);
646 + n, message1, message2, trx);
648 register_pfs_file_io_end(locker, n);
651 ulint offset_high,/*!< in: most significant 32 bits of
653 ulint n, /*!< in: number of bytes to read */
655 const char* src_file,/*!< in: file name where func invoked */
656 ulint src_line)/*!< in: line where the func invoked */
659 register_pfs_file_io_begin(&state, locker, file, n, PSI_FILE_READ,
662 - result = os_file_read_func(file, buf, offset, offset_high, n);
663 + result = os_file_read_func(file, buf, offset, offset_high, n, trx);
665 register_pfs_file_io_end(locker, n);
667 --- a/storage/innobase/include/srv0srv.h
668 +++ b/storage/innobase/include/srv0srv.h
670 #define SRV_AUTO_EXTEND_INCREMENT \
671 (srv_auto_extend_increment * ((1024 * 1024) / UNIV_PAGE_SIZE))
673 +/* prototypes for new functions added to ha_innodb.cc */
674 +ibool innobase_get_slow_log();
676 /* Mutex for locking srv_monitor_file */
677 extern mutex_t srv_monitor_file_mutex;
678 /* Temporary file for innodb monitor output */
679 --- a/storage/innobase/include/trx0trx.h
680 +++ b/storage/innobase/include/trx0trx.h
682 /*------------------------------*/
683 char detailed_error[256]; /*!< detailed error message for last
685 + /*------------------------------*/
687 + ib_uint64_t io_read;
688 + ulint io_reads_wait_timer;
689 + ib_uint64_t lock_que_wait_ustarted;
690 + ulint lock_que_wait_timer;
691 + ulint innodb_que_wait_timer;
692 + ulint distinct_page_access;
693 +#define DPAH_SIZE 8192
694 + byte* distinct_page_access_hash;
698 #define TRX_MAX_N_THREADS 32 /* maximum number of
699 --- a/storage/innobase/lock/lock0lock.c
700 +++ b/storage/innobase/lock/lock0lock.c
701 @@ -1765,6 +1765,8 @@
708 ut_ad(mutex_own(&kernel_mutex));
710 @@ -1823,6 +1825,10 @@
711 trx->que_state = TRX_QUE_LOCK_WAIT;
712 trx->was_chosen_as_deadlock_victim = FALSE;
713 trx->wait_started = time(NULL);
714 + if (innobase_get_slow_log() && trx->take_stats) {
715 + ut_usectime(&sec, &ms);
716 + trx->lock_que_wait_ustarted = (ib_uint64_t)sec * 1000000 + ms;
719 ut_a(que_thr_stop(thr));
721 @@ -3766,6 +3772,8 @@
728 ut_ad(mutex_own(&kernel_mutex));
730 @@ -3821,6 +3829,10 @@
734 + if (innobase_get_slow_log() && trx->take_stats) {
735 + ut_usectime(&sec, &ms);
736 + trx->lock_que_wait_ustarted = (ib_uint64_t)sec * 1000000 + ms;
738 trx->que_state = TRX_QUE_LOCK_WAIT;
739 trx->was_chosen_as_deadlock_victim = FALSE;
740 trx->wait_started = time(NULL);
741 --- a/storage/innobase/os/os0file.c
742 +++ b/storage/innobase/os/os0file.c
744 #include "srv0start.h"
747 +#include "trx0sys.h"
748 +#include "trx0trx.h"
749 #include "log0recv.h"
750 #ifndef UNIV_HOTBACKUP
751 # include "os0sync.h"
752 @@ -2213,13 +2215,18 @@
753 ulint n, /*!< in: number of bytes to read */
754 ulint offset, /*!< in: least significant 32 bits of file
755 offset from where to read */
756 - ulint offset_high) /*!< in: most significant 32 bits of
757 + ulint offset_high, /*!< in: most significant 32 bits of
762 #if defined(HAVE_PREAD) && !defined(HAVE_BROKEN_PREAD)
764 #endif /* HAVE_PREAD && !HAVE_BROKEN_PREAD */
767 + ib_uint64_t start_time;
768 + ib_uint64_t finish_time;
770 ut_a((offset & 0xFFFFFFFFUL) == offset);
772 @@ -2240,6 +2247,15 @@
776 + if (innobase_get_slow_log() && trx && trx->take_stats)
780 + ut_usectime(&sec, &ms);
781 + start_time = (ib_uint64_t)sec * 1000000 + ms;
785 #if defined(HAVE_PREAD) && !defined(HAVE_BROKEN_PREAD)
786 os_mutex_enter(os_file_count_mutex);
787 os_file_n_pending_preads++;
788 @@ -2253,6 +2269,13 @@
789 os_n_pending_reads--;
790 os_mutex_exit(os_file_count_mutex);
792 + if (innobase_get_slow_log() && trx && trx->take_stats && start_time)
794 + ut_usectime(&sec, &ms);
795 + finish_time = (ib_uint64_t)sec * 1000000 + ms;
796 + trx->io_reads_wait_timer += (ulint)(finish_time - start_time);
802 @@ -2289,6 +2312,13 @@
803 os_n_pending_reads--;
804 os_mutex_exit(os_file_count_mutex);
806 + if (innobase_get_slow_log() && trx && trx->take_stats && start_time)
808 + ut_usectime(&sec, &ms);
809 + finish_time = (ib_uint64_t)sec * 1000000 + ms;
810 + trx->io_reads_wait_timer += (ulint)(finish_time - start_time);
816 @@ -2429,7 +2459,8 @@
817 offset where to read */
818 ulint offset_high, /*!< in: most significant 32 bits of
820 - ulint n) /*!< in: number of bytes to read */
821 + ulint n, /*!< in: number of bytes to read */
826 @@ -2504,7 +2535,7 @@
827 os_bytes_read_since_printout += n;
830 - ret = os_file_pread(file, buf, n, offset, offset_high);
831 + ret = os_file_pread(file, buf, n, offset, offset_high, trx);
833 if ((ulint)ret == n) {
835 @@ -2633,7 +2664,7 @@
836 os_bytes_read_since_printout += n;
839 - ret = os_file_pread(file, buf, n, offset, offset_high);
840 + ret = os_file_pread(file, buf, n, offset, offset_high, NULL);
842 if ((ulint)ret == n) {
844 @@ -4027,10 +4058,11 @@
845 (can be used to identify a completed
846 aio operation); ignored if mode is
848 - void* message2)/*!< in: message for the aio handler
849 + void* message2,/*!< in: message for the aio handler
850 (can be used to identify a completed
851 aio operation); ignored if mode is
855 os_aio_array_t* array;
857 @@ -4078,7 +4110,7 @@
859 if (type == OS_FILE_READ) {
860 return(os_file_read_func(file, buf, offset,
862 + offset_high, n, trx));
865 ut_a(type == OS_FILE_WRITE);
866 @@ -4119,6 +4151,11 @@
867 array = NULL; /* Eliminate compiler warning */
870 + if (trx && type == OS_FILE_READ)
875 slot = os_aio_array_reserve_slot(type, array, message1, message2, file,
876 name, buf, offset, offset_high, n);
877 if (type == OS_FILE_READ) {
878 --- a/storage/innobase/srv/srv0srv.c
879 +++ b/storage/innobase/srv/srv0srv.c
881 #include "mysql/plugin.h"
882 #include "mysql/service_thd_wait.h"
884 +/* prototypes for new functions added to ha_innodb.cc */
885 +ibool innobase_get_slow_log();
887 /* The following counter is incremented whenever there is some user activity
889 UNIV_INTERN ulint srv_activity_count = 0;
890 @@ -1237,6 +1240,10 @@
891 ibool has_slept = FALSE;
892 srv_conc_slot_t* slot = NULL;
894 + ib_uint64_t start_time = 0L;
895 + ib_uint64_t finish_time = 0L;
899 #ifdef UNIV_SYNC_DEBUG
900 ut_ad(!sync_thread_levels_nonempty_trx(trx->has_search_latch));
901 @@ -1317,6 +1324,7 @@
903 if (SRV_THREAD_SLEEP_DELAY > 0) {
904 os_thread_sleep(SRV_THREAD_SLEEP_DELAY);
905 + trx->innodb_que_wait_timer += SRV_THREAD_SLEEP_DELAY;
909 @@ -1376,6 +1384,14 @@
910 #ifdef UNIV_SYNC_DEBUG
911 ut_ad(!sync_thread_levels_nonempty_trx(trx->has_search_latch));
912 #endif /* UNIV_SYNC_DEBUG */
914 + if (innobase_get_slow_log() && trx->take_stats) {
915 + ut_usectime(&sec, &ms);
916 + start_time = (ib_uint64_t)sec * 1000000 + ms;
921 trx->op_info = "waiting in InnoDB queue";
923 thd_wait_begin(trx->mysql_thd, THD_WAIT_USER_LOCK);
924 @@ -1384,6 +1400,12 @@
928 + if (innobase_get_slow_log() && trx->take_stats && start_time) {
929 + ut_usectime(&sec, &ms);
930 + finish_time = (ib_uint64_t)sec * 1000000 + ms;
931 + trx->innodb_que_wait_timer += (ulint)(finish_time - start_time);
934 os_fast_mutex_lock(&srv_conc_mutex);
936 srv_conc_n_waiting_threads--;
937 --- a/storage/innobase/trx/trx0trx.c
938 +++ b/storage/innobase/trx/trx0trx.c
940 trx->global_read_view = NULL;
941 trx->read_view = NULL;
945 + trx->io_reads_wait_timer = 0;
946 + trx->lock_que_wait_timer = 0;
947 + trx->innodb_que_wait_timer = 0;
948 + trx->distinct_page_access = 0;
949 + trx->distinct_page_access_hash = NULL;
950 + trx->take_stats = FALSE;
952 /* Set X/Open XA transaction identification to NULL */
953 memset(&trx->xid, 0, sizeof(trx->xid));
954 trx->xid.formatID = -1;
957 mutex_exit(&kernel_mutex);
959 + if (innobase_get_slow_log() && trx->take_stats) {
960 + trx->distinct_page_access_hash = mem_alloc(DPAH_SIZE);
961 + memset(trx->distinct_page_access_hash, 0, DPAH_SIZE);
969 trx_t* trx) /*!< in, own: trx object */
971 + if (trx->distinct_page_access_hash)
973 + mem_free(trx->distinct_page_access_hash);
974 + trx->distinct_page_access_hash= NULL;
977 mutex_enter(&kernel_mutex);
979 UT_LIST_REMOVE(mysql_trx_list, trx_sys->mysql_trx_list, trx);
981 /*====================*/
982 trx_t* trx) /*!< in, own: trx object */
984 + if (trx->distinct_page_access_hash)
986 + mem_free(trx->distinct_page_access_hash);
987 + trx->distinct_page_access_hash= NULL;
990 mutex_enter(&kernel_mutex);
993 @@ -1212,6 +1238,9 @@
994 trx_t* trx) /*!< in: transaction */
1001 ut_ad(mutex_own(&kernel_mutex));
1002 ut_ad(trx->que_state == TRX_QUE_LOCK_WAIT);
1003 @@ -1226,6 +1255,11 @@
1004 thr = UT_LIST_GET_FIRST(trx->wait_thrs);
1007 + if (innobase_get_slow_log() && trx->take_stats) {
1008 + ut_usectime(&sec, &ms);
1009 + now = (ib_uint64_t)sec * 1000000 + ms;
1010 + trx->lock_que_wait_timer += (ulint)(now - trx->lock_que_wait_ustarted);
1012 trx->que_state = TRX_QUE_RUNNING;
1015 @@ -1239,6 +1273,9 @@
1016 trx_t* trx) /*!< in: transaction in the TRX_QUE_LOCK_WAIT state */
1023 ut_ad(mutex_own(&kernel_mutex));
1024 ut_ad(trx->que_state == TRX_QUE_LOCK_WAIT);
1025 @@ -1253,6 +1290,11 @@
1026 thr = UT_LIST_GET_FIRST(trx->wait_thrs);
1029 + if (innobase_get_slow_log() && trx->take_stats) {
1030 + ut_usectime(&sec, &ms);
1031 + now = (ib_uint64_t)sec * 1000000 + ms;
1032 + trx->lock_que_wait_timer += (ulint)(now - trx->lock_que_wait_ustarted);
1034 trx->que_state = TRX_QUE_RUNNING;