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 diff -ruN a/storage/innodb_plugin/buf/buf0buf.c b/storage/innodb_plugin/buf/buf0buf.c
9 --- a/storage/innodb_plugin/buf/buf0buf.c 2010-08-27 16:13:11.061058561 +0900
10 +++ b/storage/innodb_plugin/buf/buf0buf.c 2010-08-27 16:30:47.341987400 +0900
12 #include "dict0dict.h"
17 +/* prototypes for new functions added to ha_innodb.cc */
18 +trx_t* innobase_get_trx();
20 +inline void _increment_page_get_statistics(buf_block_t* block, trx_t* trx)
23 + ulint block_hash_byte;
24 + byte block_hash_offset;
28 + if (!innobase_get_slow_log() || !trx || !trx->take_stats)
31 + if (!trx->distinct_page_access_hash) {
32 + trx->distinct_page_access_hash = mem_alloc(DPAH_SIZE);
33 + memset(trx->distinct_page_access_hash, 0, DPAH_SIZE);
36 + block_hash = ut_hash_ulint((block->page.space << 20) + block->page.space +
37 + block->page.offset, DPAH_SIZE << 3);
38 + block_hash_byte = block_hash >> 3;
39 + block_hash_offset = (byte) block_hash & 0x07;
40 + if (block_hash_byte < 0 || block_hash_byte >= DPAH_SIZE)
41 + fprintf(stderr, "!!! block_hash_byte = %lu block_hash_offset = %d !!!\n", block_hash_byte, block_hash_offset);
42 + if (block_hash_offset < 0 || block_hash_offset > 7)
43 + fprintf(stderr, "!!! block_hash_byte = %lu block_hash_offset = %d !!!\n", block_hash_byte, block_hash_offset);
44 + if ((trx->distinct_page_access_hash[block_hash_byte] & ((byte) 0x01 << block_hash_offset)) == 0)
45 + trx->distinct_page_access++;
46 + trx->distinct_page_access_hash[block_hash_byte] |= (byte) 0x01 << block_hash_offset;
51 IMPLEMENTATION OF THE BUFFER POOL
52 @@ -1726,10 +1760,18 @@
59 + ib_uint64_t start_time;
60 + ib_uint64_t finish_time;
62 #ifndef UNIV_LOG_DEBUG
63 ut_ad(!ibuf_inside());
65 + if (innobase_get_slow_log()) {
66 + trx = innobase_get_trx();
68 buf_pool->stat.n_page_gets++;
72 //buf_pool_mutex_exit();
73 rw_lock_s_unlock(&page_hash_latch);
75 - buf_read_page(space, zip_size, offset);
76 + buf_read_page(space, zip_size, offset, trx);
78 #if defined UNIV_DEBUG || defined UNIV_BUF_DEBUG
79 ut_a(++buf_dbg_counter % 37 || buf_validate());
80 @@ -1822,6 +1864,13 @@
81 /* Let us wait until the read operation
84 + if (innobase_get_slow_log() && trx && trx->take_stats)
86 + ut_usectime(&sec, &ms);
87 + start_time = (ib_uint64_t)sec * 1000000 + ms;
92 enum buf_io_fix io_fix;
94 @@ -1836,6 +1885,12 @@
98 + if (innobase_get_slow_log() && trx && trx->take_stats && start_time)
100 + ut_usectime(&sec, &ms);
101 + finish_time = (ib_uint64_t)sec * 1000000 + ms;
102 + trx->io_reads_wait_timer += (ulint)(finish_time - start_time);
106 #ifdef UNIV_IBUF_COUNT_DEBUG
107 @@ -2092,6 +2147,11 @@
110 mutex_t* block_mutex;
114 + ib_uint64_t start_time;
115 + ib_uint64_t finish_time;
118 ut_ad(mtr->state == MTR_ACTIVE);
119 @@ -2106,6 +2166,9 @@
120 #ifndef UNIV_LOG_DEBUG
121 ut_ad(!ibuf_inside() || ibuf_page(space, zip_size, offset, NULL));
123 + if (innobase_get_slow_log()) {
124 + trx = innobase_get_trx();
126 buf_pool->stat.n_page_gets++;
129 @@ -2159,7 +2222,7 @@
133 - if (buf_read_page(space, zip_size, offset)) {
134 + if (buf_read_page(space, zip_size, offset, trx)) {
136 } else if (retries < BUF_PAGE_READ_MAX_RETRIES) {
138 @@ -2444,6 +2507,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 @@ -2458,6 +2528,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 @@ -2483,13 +2559,17 @@
166 /* In the case of a first access, try to apply linear
169 - buf_read_ahead_linear(space, zip_size, offset);
170 + buf_read_ahead_linear(space, zip_size, offset, 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 @@ -2512,6 +2592,7 @@
185 unsigned access_time;
192 @@ -2589,13 +2670,17 @@
193 #ifdef UNIV_DEBUG_FILE_ACCESSES
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
204 buf_read_ahead_linear(buf_block_get_space(block),
205 buf_block_get_zip_size(block),
206 - buf_block_get_page_no(block));
207 + buf_block_get_page_no(block), trx);
210 #ifdef UNIV_IBUF_COUNT_DEBUG
211 @@ -2604,6 +2689,9 @@
213 buf_pool->stat.n_page_gets++;
215 + if (innobase_get_slow_log()) {
216 + _increment_page_get_statistics(block, trx);
221 @@ -2625,6 +2713,7 @@
228 ut_ad(mtr->state == MTR_ACTIVE);
229 @@ -2709,6 +2798,11 @@
231 buf_pool->stat.n_page_gets++;
233 + if (innobase_get_slow_log()) {
234 + trx = innobase_get_trx();
235 + _increment_page_get_statistics(block, trx);
241 diff -ruN a/storage/innodb_plugin/buf/buf0rea.c b/storage/innodb_plugin/buf/buf0rea.c
242 --- a/storage/innodb_plugin/buf/buf0rea.c 2010-08-27 16:23:31.014020792 +0900
243 +++ b/storage/innodb_plugin/buf/buf0rea.c 2010-08-27 16:30:47.342987531 +0900
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 @@ -176,15 +177,15 @@
255 ut_ad(buf_page_in_file(bpage));
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);
272 ut_a(*err == DB_SUCCESS);
276 ulint space, /*!< in: space id */
277 ulint zip_size,/*!< in: compressed page size in bytes, or 0 */
278 - ulint offset) /*!< in: page number */
279 + ulint offset, /*!< in: page number */
282 ib_int64_t tablespace_version;
286 count = buf_read_page_low(&err, TRUE, BUF_READ_ANY_PAGE, space,
288 - tablespace_version, offset);
289 + tablespace_version, offset, trx);
290 srv_buf_pool_reads += count;
291 if (err == DB_TABLESPACE_DELETED) {
292 ut_print_timestamp(stderr);
294 /*==================*/
295 ulint space, /*!< in: space id */
296 ulint zip_size,/*!< in: compressed page size in bytes, or 0 */
297 - ulint offset) /*!< in: page number of a page; NOTE: the current thread
298 + ulint offset, /*!< in: page number of a page; NOTE: the current thread
299 must want access to this page (see NOTE 3 above) */
302 ib_int64_t tablespace_version;
305 count += buf_read_page_low(
307 ibuf_mode | OS_AIO_SIMULATED_WAKE_LATER,
308 - space, zip_size, FALSE, tablespace_version, i);
309 + space, zip_size, FALSE, tablespace_version, i, trx);
310 if (err == DB_TABLESPACE_DELETED) {
311 ut_print_timestamp(stderr);
314 buf_read_page_low(&err, sync && (i + 1 == n_stored),
315 BUF_READ_ANY_PAGE, space_ids[i],
316 zip_size, TRUE, space_versions[i],
318 + page_nos[i], NULL);
320 if (UNIV_UNLIKELY(err == DB_TABLESPACE_DELETED)) {
322 @@ -728,12 +731,12 @@
323 if ((i + 1 == n_stored) && sync) {
324 buf_read_page_low(&err, TRUE, BUF_READ_ANY_PAGE, space,
325 zip_size, TRUE, tablespace_version,
327 + page_nos[i], NULL);
329 buf_read_page_low(&err, FALSE, BUF_READ_ANY_PAGE
330 | OS_AIO_SIMULATED_WAKE_LATER,
331 space, zip_size, TRUE,
332 - tablespace_version, page_nos[i]);
333 + tablespace_version, page_nos[i], NULL);
337 diff -ruN a/storage/innodb_plugin/fil/fil0fil.c b/storage/innodb_plugin/fil/fil0fil.c
338 --- a/storage/innodb_plugin/fil/fil0fil.c 2010-08-27 16:15:55.187400372 +0900
339 +++ b/storage/innodb_plugin/fil/fil0fil.c 2010-08-27 16:30:47.346992376 +0900
340 @@ -4325,7 +4325,7 @@
341 node->name, node->handle, buf,
342 offset_low, offset_high,
348 node->size += n_pages;
349 @@ -4652,7 +4652,7 @@
350 i/o on a tablespace which does not exist */
356 ulint type, /*!< in: OS_FILE_READ or OS_FILE_WRITE,
357 ORed to OS_FILE_LOG, if a log i/o
358 @@ -4677,8 +4677,9 @@
359 void* buf, /*!< in/out: buffer where to store read data
360 or from where to write; in aio this must be
361 appropriately aligned */
362 - void* message) /*!< in: message for aio handler if non-sync
363 + void* message, /*!< in: message for aio handler if non-sync
364 aio used, else ignored */
369 @@ -4848,7 +4849,7 @@
371 /* Queue the aio request */
372 ret = os_aio(type, mode | wake_later, node->name, node->handle, buf,
373 - offset_low, offset_high, len, node, message);
374 + offset_low, offset_high, len, node, message, trx);
378 diff -ruN a/storage/innodb_plugin/handler/ha_innodb.cc b/storage/innodb_plugin/handler/ha_innodb.cc
379 --- a/storage/innodb_plugin/handler/ha_innodb.cc 2010-08-27 16:30:34.589021493 +0900
380 +++ b/storage/innodb_plugin/handler/ha_innodb.cc 2010-08-27 16:30:47.356987871 +0900
381 @@ -1372,6 +1372,16 @@
382 trx->check_unique_secondary = !thd_test_options(
383 thd, OPTION_RELAXED_UNIQUE_CHECKS);
385 +#ifdef EXTENDED_SLOWLOG
386 + if (thd_log_slow_verbosity(thd) & SLOG_V_INNODB) {
387 + trx->take_stats = TRUE;
389 + trx->take_stats = FALSE;
392 + trx->take_stats = FALSE;
398 @@ -1427,6 +1437,32 @@
402 +/*************************************************************************
403 +Gets current trx. */
408 + THD *thd=current_thd;
409 + if (likely(thd != 0)) {
410 + trx_t*& trx = thd_to_trx(thd);
419 +innobase_get_slow_log()
421 +#ifdef EXTENDED_SLOWLOG
422 + return((ibool) thd_opt_slow_log());
428 /*********************************************************************//**
429 Construct ha_innobase handler. */
431 @@ -8940,6 +8976,25 @@
432 statement has ended */
434 if (trx->n_mysql_tables_in_use == 0) {
435 +#ifdef EXTENDED_SLOWLOG
436 + increment_thd_innodb_stats(thd,
437 + (unsigned long long) ut_conv_dulint_to_longlong(trx->id),
440 + trx->io_reads_wait_timer,
441 + trx->lock_que_wait_timer,
442 + trx->innodb_que_wait_timer,
443 + trx->distinct_page_access);
447 + trx->io_reads_wait_timer = 0;
448 + trx->lock_que_wait_timer = 0;
449 + trx->innodb_que_wait_timer = 0;
450 + trx->distinct_page_access = 0;
451 + if (trx->distinct_page_access_hash)
452 + memset(trx->distinct_page_access_hash, 0, DPAH_SIZE);
455 trx->mysql_n_tables_locked = 0;
456 prebuilt->used_in_HANDLER = FALSE;
457 diff -ruN a/storage/innodb_plugin/handler/innodb_patch_info.h b/storage/innodb_plugin/handler/innodb_patch_info.h
458 --- a/storage/innodb_plugin/handler/innodb_patch_info.h 2010-08-27 16:30:34.590004526 +0900
459 +++ b/storage/innodb_plugin/handler/innodb_patch_info.h 2010-08-27 16:30:47.361987777 +0900
461 {"innodb_purge_thread","Enable to use purge devoted thread","","http://www.percona.com/docs/wiki/percona-xtradb"},
462 {"innodb_admin_command_base","XtraDB specific command interface through i_s","","http://www.percona.com/docs/wiki/percona-xtradb"},
463 {"innodb_show_lock_name","Show mutex/lock name instead of crated file/line","","http://www.percona.com/docs/wiki/percona-xtradb"},
464 +{"innodb_extend_slow","Extended statistics in slow.log","It is InnoDB-part only. It needs to patch also to mysqld.","http://www.percona.com/docs/wiki/percona-xtradb"},
465 {NULL, NULL, NULL, NULL}
467 diff -ruN a/storage/innodb_plugin/include/buf0rea.h b/storage/innodb_plugin/include/buf0rea.h
468 --- a/storage/innodb_plugin/include/buf0rea.h 2010-08-27 15:54:18.078987755 +0900
469 +++ b/storage/innodb_plugin/include/buf0rea.h 2010-08-27 16:30:47.363031394 +0900
474 +#include "trx0types.h"
475 #include "buf0types.h"
477 /********************************************************************//**
480 ulint space, /*!< in: space id */
481 ulint zip_size,/*!< in: compressed page size in bytes, or 0 */
482 - ulint offset);/*!< in: page number */
483 + ulint offset, /*!< in: page number */
485 /********************************************************************//**
486 Applies linear read-ahead if in the buf_pool the page is a border page of
487 a linear read-ahead area and all the pages in the area have been accessed.
489 /*==================*/
490 ulint space, /*!< in: space id */
491 ulint zip_size,/*!< in: compressed page size in bytes, or 0 */
492 - ulint offset);/*!< in: page number of a page; NOTE: the current thread
493 + ulint offset, /*!< in: page number of a page; NOTE: the current thread
494 must want access to this page (see NOTE 3 above) */
496 /********************************************************************//**
497 Issues read requests for pages which the ibuf module wants to read in, in
498 order to contract the insert buffer tree. Technically, this function is like
499 diff -ruN a/storage/innodb_plugin/include/fil0fil.h b/storage/innodb_plugin/include/fil0fil.h
500 --- a/storage/innodb_plugin/include/fil0fil.h 2010-08-27 15:52:14.325059269 +0900
501 +++ b/storage/innodb_plugin/include/fil0fil.h 2010-08-27 16:30:47.365059512 +0900
503 Reads or writes data. This operation is asynchronous (aio).
504 @return DB_SUCCESS, or DB_TABLESPACE_DELETED if we are trying to do
505 i/o on a tablespace which does not exist */
506 +#define fil_io(type, sync, space_id, zip_size, block_offset, byte_offset, len, buf, message) \
507 + _fil_io(type, sync, space_id, zip_size, block_offset, byte_offset, len, buf, message, NULL)
514 ulint type, /*!< in: OS_FILE_READ or OS_FILE_WRITE,
515 ORed to OS_FILE_LOG, if a log i/o
517 void* buf, /*!< in/out: buffer where to store read data
518 or from where to write; in aio this must be
519 appropriately aligned */
520 - void* message); /*!< in: message for aio handler if non-sync
521 + void* message, /*!< in: message for aio handler if non-sync
522 aio used, else ignored */
524 /**********************************************************************//**
525 Waits for an aio operation to complete. This function is used to write the
526 handler for completed requests. The aio array of pending requests is divided
527 diff -ruN a/storage/innodb_plugin/include/os0file.h b/storage/innodb_plugin/include/os0file.h
528 --- a/storage/innodb_plugin/include/os0file.h 2010-08-04 02:24:19.000000000 +0900
529 +++ b/storage/innodb_plugin/include/os0file.h 2010-08-27 16:30:47.366987560 +0900
534 +#include "trx0types.h"
539 /*******************************************************************//**
540 Requests a synchronous read operation.
541 @return TRUE if request was successful, FALSE if fail */
542 +#define os_file_read(file, buf, offset, offset_high, n) \
543 + _os_file_read(file, buf, offset, offset_high, n, NULL)
550 os_file_t file, /*!< in: handle to a file */
551 void* buf, /*!< in: buffer where to read */
553 offset where to read */
554 ulint offset_high,/*!< in: most significant 32 bits of
556 - ulint n); /*!< in: number of bytes to read */
557 + ulint n, /*!< in: number of bytes to read */
559 /*******************************************************************//**
560 Rewind file to its start, read at most size - 1 bytes from it to str, and
561 NUL-terminate str. All errors are silently ignored. This function is
562 @@ -646,10 +651,11 @@
563 (can be used to identify a completed
564 aio operation); ignored if mode is
566 - void* message2);/*!< in: message for the aio handler
567 + void* message2,/*!< in: message for the aio handler
568 (can be used to identify a completed
569 aio operation); ignored if mode is
572 /************************************************************************//**
573 Wakes up all async i/o threads so that they know to exit themselves in
575 diff -ruN a/storage/innodb_plugin/include/srv0srv.h b/storage/innodb_plugin/include/srv0srv.h
576 --- a/storage/innodb_plugin/include/srv0srv.h 2010-08-27 16:27:30.225055856 +0900
577 +++ b/storage/innodb_plugin/include/srv0srv.h 2010-08-27 16:30:47.367988259 +0900
579 #define SRV_AUTO_EXTEND_INCREMENT \
580 (srv_auto_extend_increment * ((1024 * 1024) / UNIV_PAGE_SIZE))
582 +/* prototypes for new functions added to ha_innodb.cc */
583 +ibool innobase_get_slow_log();
585 /* This is set to TRUE if the MySQL user has set it in MySQL */
586 extern ibool srv_lower_case_table_names;
588 diff -ruN a/storage/innodb_plugin/include/trx0trx.h b/storage/innodb_plugin/include/trx0trx.h
589 --- a/storage/innodb_plugin/include/trx0trx.h 2010-08-27 16:08:45.301058614 +0900
590 +++ b/storage/innodb_plugin/include/trx0trx.h 2010-08-27 16:30:47.369989369 +0900
592 /*------------------------------*/
593 char detailed_error[256]; /*!< detailed error message for last
595 + /*------------------------------*/
597 + ib_uint64_t io_read;
598 + ulint io_reads_wait_timer;
599 + ib_uint64_t lock_que_wait_ustarted;
600 + ulint lock_que_wait_timer;
601 + ulint innodb_que_wait_timer;
602 + ulint distinct_page_access;
603 +#define DPAH_SIZE 8192
604 + byte* distinct_page_access_hash;
608 #define TRX_MAX_N_THREADS 32 /* maximum number of
609 diff -ruN a/storage/innodb_plugin/lock/lock0lock.c b/storage/innodb_plugin/lock/lock0lock.c
610 --- a/storage/innodb_plugin/lock/lock0lock.c 2010-08-27 15:52:14.332058513 +0900
611 +++ b/storage/innodb_plugin/lock/lock0lock.c 2010-08-27 16:30:47.374058285 +0900
612 @@ -1757,6 +1757,8 @@
619 ut_ad(mutex_own(&kernel_mutex));
621 @@ -1815,6 +1817,10 @@
622 trx->que_state = TRX_QUE_LOCK_WAIT;
623 trx->was_chosen_as_deadlock_victim = FALSE;
624 trx->wait_started = time(NULL);
625 + if (innobase_get_slow_log() && trx->take_stats) {
626 + ut_usectime(&sec, &ms);
627 + trx->lock_que_wait_ustarted = (ib_uint64_t)sec * 1000000 + ms;
630 ut_a(que_thr_stop(thr));
632 @@ -3695,6 +3701,8 @@
639 ut_ad(mutex_own(&kernel_mutex));
641 @@ -3750,6 +3758,10 @@
645 + if (innobase_get_slow_log() && trx->take_stats) {
646 + ut_usectime(&sec, &ms);
647 + trx->lock_que_wait_ustarted = (ib_uint64_t)sec * 1000000 + ms;
649 trx->que_state = TRX_QUE_LOCK_WAIT;
650 trx->was_chosen_as_deadlock_victim = FALSE;
651 trx->wait_started = time(NULL);
652 diff -ruN a/storage/innodb_plugin/os/os0file.c b/storage/innodb_plugin/os/os0file.c
653 --- a/storage/innodb_plugin/os/os0file.c 2010-08-27 16:23:31.038058669 +0900
654 +++ b/storage/innodb_plugin/os/os0file.c 2010-08-27 16:30:47.380058815 +0900
656 #include "srv0start.h"
659 +#include "trx0sys.h"
660 +#include "trx0trx.h"
661 #include "log0recv.h"
662 #ifndef UNIV_HOTBACKUP
663 # include "os0sync.h"
664 @@ -2087,22 +2089,30 @@
665 /*******************************************************************//**
666 Does a synchronous read operation in Posix.
667 @return number of bytes read, -1 if error */
668 +#define os_file_pread(file, buf, n, offset, offset_high) \
669 + _os_file_pread(file, buf, n, offset, offset_high, NULL);
676 os_file_t file, /*!< in: handle to a file */
677 void* buf, /*!< in: buffer where to read */
678 ulint n, /*!< in: number of bytes to read */
679 ulint offset, /*!< in: least significant 32 bits of file
680 offset from where to read */
681 - ulint offset_high) /*!< in: most significant 32 bits of
682 + ulint offset_high, /*!< in: most significant 32 bits of
687 #if defined(HAVE_PREAD) && !defined(HAVE_BROKEN_PREAD)
689 #endif /* HAVE_PREAD && !HAVE_BROKEN_PREAD */
692 + ib_uint64_t start_time;
693 + ib_uint64_t finish_time;
695 ut_a((offset & 0xFFFFFFFFUL) == offset);
697 @@ -2123,6 +2133,15 @@
701 + if (innobase_get_slow_log() && trx && trx->take_stats)
705 + ut_usectime(&sec, &ms);
706 + start_time = (ib_uint64_t)sec * 1000000 + ms;
710 #if defined(HAVE_PREAD) && !defined(HAVE_BROKEN_PREAD)
711 os_mutex_enter(os_file_count_mutex);
712 os_file_n_pending_preads++;
713 @@ -2136,6 +2155,13 @@
714 os_n_pending_reads--;
715 os_mutex_exit(os_file_count_mutex);
717 + if (innobase_get_slow_log() && trx && trx->take_stats && start_time)
719 + ut_usectime(&sec, &ms);
720 + finish_time = (ib_uint64_t)sec * 1000000 + ms;
721 + trx->io_reads_wait_timer += (ulint)(finish_time - start_time);
727 @@ -2172,6 +2198,13 @@
728 os_n_pending_reads--;
729 os_mutex_exit(os_file_count_mutex);
731 + if (innobase_get_slow_log() && trx && trx->take_stats && start_time)
733 + ut_usectime(&sec, &ms);
734 + finish_time = (ib_uint64_t)sec * 1000000 + ms;
735 + trx->io_reads_wait_timer += (ulint)(finish_time - start_time);
741 @@ -2302,7 +2335,7 @@
742 @return TRUE if request was successful, FALSE if fail */
748 os_file_t file, /*!< in: handle to a file */
749 void* buf, /*!< in: buffer where to read */
750 @@ -2310,7 +2343,8 @@
751 offset where to read */
752 ulint offset_high, /*!< in: most significant 32 bits of
754 - ulint n) /*!< in: number of bytes to read */
755 + ulint n, /*!< in: number of bytes to read */
760 @@ -2385,7 +2419,7 @@
761 os_bytes_read_since_printout += n;
764 - ret = os_file_pread(file, buf, n, offset, offset_high);
765 + ret = _os_file_pread(file, buf, n, offset, offset_high, trx);
767 if ((ulint)ret == n) {
769 @@ -3356,7 +3390,8 @@
771 ulint offset_high, /*!< in: most significant 32 bits of
773 - ulint len) /*!< in: length of the block to read or write */
774 + ulint len, /*!< in: length of the block to read or write */
779 @@ -3642,10 +3677,11 @@
780 (can be used to identify a completed
781 aio operation); ignored if mode is
783 - void* message2)/*!< in: message for the aio handler
784 + void* message2,/*!< in: message for the aio handler
785 (can be used to identify a completed
786 aio operation); ignored if mode is
790 os_aio_array_t* array;
792 @@ -3687,8 +3723,8 @@
793 wait in the Windows case. */
795 if (type == OS_FILE_READ) {
796 - return(os_file_read(file, buf, offset,
798 + return(_os_file_read(file, buf, offset,
799 + offset_high, n, trx));
802 ut_a(type == OS_FILE_WRITE);
803 @@ -3721,8 +3757,13 @@
807 + if (trx && type == OS_FILE_READ)
812 slot = os_aio_array_reserve_slot(type, array, message1, message2, file,
813 - name, buf, offset, offset_high, n);
814 + name, buf, offset, offset_high, n, trx);
815 if (type == OS_FILE_READ) {
816 if (os_aio_use_native_aio) {
818 diff -ruN a/storage/innodb_plugin/srv/srv0srv.c b/storage/innodb_plugin/srv/srv0srv.c
819 --- a/storage/innodb_plugin/srv/srv0srv.c 2010-08-27 16:27:30.233022109 +0900
820 +++ b/storage/innodb_plugin/srv/srv0srv.c 2010-08-27 16:30:47.384058509 +0900
823 #include "os0sync.h" /* for HAVE_ATOMIC_BUILTINS */
825 +/* prototypes for new functions added to ha_innodb.cc */
826 +ibool innobase_get_slow_log();
828 /* This is set to TRUE if the MySQL user has set it in MySQL; currently
829 affects only FOREIGN KEY definition parsing */
830 UNIV_INTERN ibool srv_lower_case_table_names = FALSE;
831 @@ -1155,6 +1158,10 @@
832 ibool has_slept = FALSE;
833 srv_conc_slot_t* slot = NULL;
835 + ib_uint64_t start_time = 0L;
836 + ib_uint64_t finish_time = 0L;
840 if (trx->mysql_thd != NULL
841 && thd_is_replication_slave_thread(trx->mysql_thd)) {
842 @@ -1231,6 +1238,7 @@
844 if (SRV_THREAD_SLEEP_DELAY > 0) {
845 os_thread_sleep(SRV_THREAD_SLEEP_DELAY);
846 + trx->innodb_que_wait_timer += SRV_THREAD_SLEEP_DELAY;
850 @@ -1286,12 +1294,25 @@
851 /* Go to wait for the event; when a thread leaves InnoDB it will
852 release this thread */
854 + if (innobase_get_slow_log() && trx->take_stats) {
855 + ut_usectime(&sec, &ms);
856 + start_time = (ib_uint64_t)sec * 1000000 + ms;
861 trx->op_info = "waiting in InnoDB queue";
863 os_event_wait(slot->event);
867 + if (innobase_get_slow_log() && trx->take_stats && start_time) {
868 + ut_usectime(&sec, &ms);
869 + finish_time = (ib_uint64_t)sec * 1000000 + ms;
870 + trx->innodb_que_wait_timer += (ulint)(finish_time - start_time);
873 os_fast_mutex_lock(&srv_conc_mutex);
875 srv_conc_n_waiting_threads--;
876 diff -ruN a/storage/innodb_plugin/trx/trx0trx.c b/storage/innodb_plugin/trx/trx0trx.c
877 --- a/storage/innodb_plugin/trx/trx0trx.c 2010-08-27 16:08:45.306058896 +0900
878 +++ b/storage/innodb_plugin/trx/trx0trx.c 2010-08-27 16:30:47.387058330 +0900
880 trx->global_read_view = NULL;
881 trx->read_view = NULL;
885 + trx->io_reads_wait_timer = 0;
886 + trx->lock_que_wait_timer = 0;
887 + trx->innodb_que_wait_timer = 0;
888 + trx->distinct_page_access = 0;
889 + trx->distinct_page_access_hash = NULL;
890 + trx->take_stats = FALSE;
892 /* Set X/Open XA transaction identification to NULL */
893 memset(&trx->xid, 0, sizeof(trx->xid));
894 trx->xid.formatID = -1;
897 trx->mysql_process_no = os_proc_get_number();
899 + if (innobase_get_slow_log() && trx->take_stats) {
900 + trx->distinct_page_access_hash = mem_alloc(DPAH_SIZE);
901 + memset(trx->distinct_page_access_hash, 0, DPAH_SIZE);
909 trx_t* trx) /*!< in, own: trx object */
911 + if (trx->distinct_page_access_hash)
913 + mem_free(trx->distinct_page_access_hash);
914 + trx->distinct_page_access_hash= NULL;
917 mutex_enter(&kernel_mutex);
919 UT_LIST_REMOVE(mysql_trx_list, trx_sys->mysql_trx_list, trx);
921 /*====================*/
922 trx_t* trx) /*!< in, own: trx object */
924 + if (trx->distinct_page_access_hash)
926 + mem_free(trx->distinct_page_access_hash);
927 + trx->distinct_page_access_hash= NULL;
930 mutex_enter(&kernel_mutex);
933 @@ -1093,6 +1119,9 @@
934 trx_t* trx) /*!< in: transaction */
941 ut_ad(mutex_own(&kernel_mutex));
942 ut_ad(trx->que_state == TRX_QUE_LOCK_WAIT);
943 @@ -1107,6 +1136,11 @@
944 thr = UT_LIST_GET_FIRST(trx->wait_thrs);
947 + if (innobase_get_slow_log() && trx->take_stats) {
948 + ut_usectime(&sec, &ms);
949 + now = (ib_uint64_t)sec * 1000000 + ms;
950 + trx->lock_que_wait_timer += (ulint)(now - trx->lock_que_wait_ustarted);
952 trx->que_state = TRX_QUE_RUNNING;
955 @@ -1120,6 +1154,9 @@
956 trx_t* trx) /*!< in: transaction in the TRX_QUE_LOCK_WAIT state */
963 ut_ad(mutex_own(&kernel_mutex));
964 ut_ad(trx->que_state == TRX_QUE_LOCK_WAIT);
965 @@ -1134,6 +1171,11 @@
966 thr = UT_LIST_GET_FIRST(trx->wait_thrs);
969 + if (innobase_get_slow_log() && trx->take_stats) {
970 + ut_usectime(&sec, &ms);
971 + now = (ib_uint64_t)sec * 1000000 + ms;
972 + trx->lock_que_wait_timer += (ulint)(now - trx->lock_que_wait_ustarted);
974 trx->que_state = TRX_QUE_RUNNING;