From: Marc Alff Date: April 5 2012 5:05pm Subject: bzr push into mysql-trunk-pfs-tuning branch (marc.alff:3491 to 3492) List-Archive: http://lists.mysql.com/commits/143402 Message-Id: <201204051706.q35H65GZ012099@acsmt356.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 3492 Marc Alff 2012-04-05 tuning, in progress modified: storage/perfschema/pfs.cc storage/perfschema/pfs_instr.cc storage/perfschema/pfs_instr.h storage/perfschema/pfs_instr_class.cc storage/perfschema/pfs_instr_class.h 3491 Marc Alff 2012-04-05 incomplete truncate modified: storage/perfschema/table_esgs_global_by_event_name.cc storage/perfschema/table_esms_global_by_event_name.cc === modified file 'storage/perfschema/pfs.cc' --- a/storage/perfschema/pfs.cc 2012-04-05 07:59:23 +0000 +++ b/storage/perfschema/pfs.cc 2012-04-05 17:05:18 +0000 @@ -1594,7 +1594,6 @@ static void unbind_table_v1(PSI_table *t PFS_table *pfs= reinterpret_cast (table); if (likely(pfs != NULL)) { - pfs->aggregate(); pfs->m_thread_owner= NULL; } } @@ -1615,12 +1614,6 @@ rebind_table_v1(PSI_table_share *share, /* The table handle was already instrumented, reuse it for this thread. */ thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); - if (unlikely(thread == NULL)) - { - destroy_table(pfs); - return NULL; - } - if (unlikely(! pfs->m_share->m_enabled)) { destroy_table(pfs); @@ -1660,8 +1653,6 @@ rebind_table_v1(PSI_table_share *share, return NULL; PFS_thread *thread= my_pthread_getspecific_ptr(PFS_thread*, THR_PFS); - if (unlikely(thread == NULL)) - return NULL; PFS_table *pfs_table= create_table(pfs_table_share, thread, identity); return reinterpret_cast (pfs_table); @@ -2478,8 +2469,6 @@ start_table_io_wait_v1(PSI_table_locker_ return NULL; PFS_thread *pfs_thread= pfs_table->m_thread_owner; - if (unlikely(pfs_thread == NULL)) - return NULL; DBUG_ASSERT(pfs_thread == my_pthread_getspecific_ptr(PFS_thread*, THR_PFS)); @@ -2489,6 +2478,8 @@ start_table_io_wait_v1(PSI_table_locker_ if (flag_thread_instrumentation) { + if (pfs_thread == NULL) + return NULL; if (! pfs_thread->m_enabled) return NULL; state->m_thread= reinterpret_cast (pfs_thread); @@ -2538,7 +2529,6 @@ start_table_io_wait_v1(PSI_table_locker_ pfs_thread->m_events_waits_current++; } - /* TODO: consider a shortcut here */ } else { @@ -2585,8 +2575,6 @@ start_table_lock_wait_v1(PSI_table_locke return NULL; PFS_thread *pfs_thread= pfs_table->m_thread_owner; - if (unlikely(pfs_thread == NULL)) - return NULL; DBUG_ASSERT(pfs_thread == my_pthread_getspecific_ptr(PFS_thread*, THR_PFS)); @@ -2619,6 +2607,8 @@ start_table_lock_wait_v1(PSI_table_locke if (flag_thread_instrumentation) { + if (pfs_thread == NULL) + return NULL; if (! pfs_thread->m_enabled) return NULL; state->m_thread= reinterpret_cast (pfs_thread); @@ -2668,7 +2658,6 @@ start_table_lock_wait_v1(PSI_table_locke pfs_thread->m_events_waits_current++; } - /* TODO: consider a shortcut here */ } else { @@ -3352,17 +3341,16 @@ static void end_idle_wait_v1(PSI_idle_lo PFS_thread *thread= reinterpret_cast (state->m_thread); PFS_single_stat *event_name_array; event_name_array= thread->m_instr_class_waits_stats; - uint index= global_idle_class.m_event_name_index; if (flags & STATE_FLAG_TIMED) { /* Aggregate to EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME (timed) */ - event_name_array[index].aggregate_value(wait_time); + event_name_array[GLOBAL_IDLE_EVENT_INDEX].aggregate_value(wait_time); } else { /* Aggregate to EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME (counted) */ - event_name_array[index].aggregate_counted(); + event_name_array[GLOBAL_IDLE_EVENT_INDEX].aggregate_counted(); } if (flags & STATE_FLAG_EVENT) @@ -3723,22 +3711,40 @@ static void end_table_io_wait_v1(PSI_tab stat->aggregate_counted(); } - if (flags & STATE_FLAG_EVENT) + if (flags & STATE_FLAG_THREAD) { - DBUG_ASSERT(flags & STATE_FLAG_THREAD); PFS_thread *thread= reinterpret_cast (state->m_thread); DBUG_ASSERT(thread != NULL); - PFS_events_waits *wait= reinterpret_cast (state->m_wait); - DBUG_ASSERT(wait != NULL); + PFS_single_stat *event_name_array; + event_name_array= thread->m_instr_class_waits_stats; + + /* + Aggregate to EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME + (for wait/io/table/sql/handler) + */ + if (flags & STATE_FLAG_TIMED) + { + event_name_array[GLOBAL_TABLE_IO_EVENT_INDEX].aggregate_value(wait_time); + } + else + { + event_name_array[GLOBAL_TABLE_IO_EVENT_INDEX].aggregate_counted(); + } + + if (flags & STATE_FLAG_EVENT) + { + PFS_events_waits *wait= reinterpret_cast (state->m_wait); + DBUG_ASSERT(wait != NULL); - wait->m_timer_end= timer_end; - wait->m_end_event_id= thread->m_event_id; - if (flag_events_waits_history) - insert_events_waits_history(thread, wait); - if (flag_events_waits_history_long) - insert_events_waits_history_long(wait); - thread->m_events_waits_current--; + wait->m_timer_end= timer_end; + wait->m_end_event_id= thread->m_event_id; + if (flag_events_waits_history) + insert_events_waits_history(thread, wait); + if (flag_events_waits_history_long) + insert_events_waits_history_long(wait); + thread->m_events_waits_current--; + } } table->m_has_io_stats= true; @@ -3774,22 +3780,40 @@ static void end_table_lock_wait_v1(PSI_t stat->aggregate_counted(); } - if (flags & STATE_FLAG_EVENT) + if (flags & STATE_FLAG_THREAD) { - DBUG_ASSERT(flags & STATE_FLAG_THREAD); PFS_thread *thread= reinterpret_cast (state->m_thread); DBUG_ASSERT(thread != NULL); - PFS_events_waits *wait= reinterpret_cast (state->m_wait); - DBUG_ASSERT(wait != NULL); + PFS_single_stat *event_name_array; + event_name_array= thread->m_instr_class_waits_stats; + + /* + Aggregate to EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME + (for wait/lock/table/sql/handler) + */ + if (flags & STATE_FLAG_TIMED) + { + event_name_array[GLOBAL_TABLE_LOCK_EVENT_INDEX].aggregate_value(wait_time); + } + else + { + event_name_array[GLOBAL_TABLE_LOCK_EVENT_INDEX].aggregate_counted(); + } + + if (flags & STATE_FLAG_EVENT) + { + PFS_events_waits *wait= reinterpret_cast (state->m_wait); + DBUG_ASSERT(wait != NULL); - wait->m_timer_end= timer_end; - wait->m_end_event_id= thread->m_event_id; - if (flag_events_waits_history) - insert_events_waits_history(thread, wait); - if (flag_events_waits_history_long) - insert_events_waits_history_long(wait); - thread->m_events_waits_current--; + wait->m_timer_end= timer_end; + wait->m_end_event_id= thread->m_event_id; + if (flag_events_waits_history) + insert_events_waits_history(thread, wait); + if (flag_events_waits_history_long) + insert_events_waits_history_long(wait); + thread->m_events_waits_current--; + } } table->m_has_lock_stats= true; === modified file 'storage/perfschema/pfs_instr.cc' --- a/storage/perfschema/pfs_instr.cc 2012-03-29 07:47:19 +0000 +++ b/storage/perfschema/pfs_instr.cc 2012-04-05 17:05:18 +0000 @@ -1329,23 +1329,22 @@ void PFS_table::sanitized_aggregate(void and not own the table handle. */ PFS_table_share *safe_share= sanitize_table_share(m_share); - PFS_thread *safe_thread= sanitize_thread(m_thread_owner); - if ((safe_share != NULL && safe_thread != NULL)) + if (safe_share != NULL) { if (m_has_io_stats && m_has_lock_stats) { - safe_aggregate(& m_table_stat, safe_share, safe_thread); + safe_aggregate(& m_table_stat, safe_share); m_has_io_stats= false; m_has_lock_stats= false; } else if (m_has_io_stats) { - safe_aggregate_io(& m_table_stat, safe_share, safe_thread); + safe_aggregate_io(& m_table_stat, safe_share); m_has_io_stats= false; } else if (m_has_lock_stats) { - safe_aggregate_lock(& m_table_stat, safe_share, safe_thread); + safe_aggregate_lock(& m_table_stat, safe_share); m_has_lock_stats= false; } } @@ -1354,10 +1353,9 @@ void PFS_table::sanitized_aggregate(void void PFS_table::sanitized_aggregate_io(void) { PFS_table_share *safe_share= sanitize_table_share(m_share); - PFS_thread *safe_thread= sanitize_thread(m_thread_owner); - if (safe_share != NULL && safe_thread != NULL && m_has_io_stats) + if (safe_share != NULL && m_has_io_stats) { - safe_aggregate_io(& m_table_stat, safe_share, safe_thread); + safe_aggregate_io(& m_table_stat, safe_share); m_has_io_stats= false; } } @@ -1365,100 +1363,44 @@ void PFS_table::sanitized_aggregate_io(v void PFS_table::sanitized_aggregate_lock(void) { PFS_table_share *safe_share= sanitize_table_share(m_share); - PFS_thread *safe_thread= sanitize_thread(m_thread_owner); - if (safe_share != NULL && safe_thread != NULL && m_has_lock_stats) + if (safe_share != NULL && m_has_lock_stats) { - safe_aggregate_lock(& m_table_stat, safe_share, safe_thread); + safe_aggregate_lock(& m_table_stat, safe_share); m_has_lock_stats= false; } } void PFS_table::safe_aggregate(PFS_table_stat *table_stat, - PFS_table_share *table_share, - PFS_thread *thread) + PFS_table_share *table_share) { DBUG_ASSERT(table_stat != NULL); DBUG_ASSERT(table_share != NULL); - DBUG_ASSERT(thread != NULL); uint key_count= sanitize_index_count(table_share->m_key_count); - if (flag_thread_instrumentation && thread->m_enabled) - { - PFS_single_stat *event_name_array; - uint index; - event_name_array= thread->m_instr_class_waits_stats; - - /* - Aggregate to EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME - (for wait/io/table/sql/handler) - */ - index= global_table_io_class.m_event_name_index; - table_stat->sum_io(& event_name_array[index], key_count); - - /* - Aggregate to EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME - (for wait/lock/table/sql/handler) - */ - index= global_table_lock_class.m_event_name_index; - table_stat->sum_lock(& event_name_array[index]); - } - /* Aggregate to TABLE_IO_SUMMARY, TABLE_LOCK_SUMMARY */ table_share->m_table_stat.aggregate(table_stat, key_count); table_stat->fast_reset(); } void PFS_table::safe_aggregate_io(PFS_table_stat *table_stat, - PFS_table_share *table_share, - PFS_thread *thread) + PFS_table_share *table_share) { DBUG_ASSERT(table_stat != NULL); DBUG_ASSERT(table_share != NULL); - DBUG_ASSERT(thread != NULL); uint key_count= sanitize_index_count(table_share->m_key_count); - if (flag_thread_instrumentation && thread->m_enabled) - { - PFS_single_stat *event_name_array; - uint index; - event_name_array= thread->m_instr_class_waits_stats; - - /* - Aggregate to EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME - (for wait/io/table/sql/handler) - */ - index= global_table_io_class.m_event_name_index; - table_stat->sum_io(& event_name_array[index], key_count); - } - /* Aggregate to TABLE_IO_SUMMARY */ table_share->m_table_stat.aggregate_io(table_stat, key_count); table_stat->fast_reset_io(); } void PFS_table::safe_aggregate_lock(PFS_table_stat *table_stat, - PFS_table_share *table_share, - PFS_thread *thread) + PFS_table_share *table_share) { DBUG_ASSERT(table_stat != NULL); DBUG_ASSERT(table_share != NULL); - DBUG_ASSERT(thread != NULL); - - if (flag_thread_instrumentation && thread->m_enabled) - { - PFS_single_stat *event_name_array; - uint index; - event_name_array= thread->m_instr_class_waits_stats; - - /* - Aggregate to EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME - (for wait/lock/table/sql/handler) - */ - index= global_table_lock_class.m_event_name_index; - table_stat->sum_lock(& event_name_array[index]); - } /* Aggregate to TABLE_LOCK_SUMMARY */ table_share->m_table_stat.aggregate_lock(table_stat); === modified file 'storage/perfschema/pfs_instr.h' --- a/storage/perfschema/pfs_instr.h 2012-03-28 08:29:33 +0000 +++ b/storage/perfschema/pfs_instr.h 2012-04-05 17:05:18 +0000 @@ -198,24 +198,21 @@ public: */ void aggregate(void) { - if (likely(m_thread_owner != NULL)) + if (m_has_io_stats && m_has_lock_stats) { - if (m_has_io_stats && m_has_lock_stats) - { - safe_aggregate(& m_table_stat, m_share, m_thread_owner); - m_has_io_stats= false; - m_has_lock_stats= false; - } - else if (m_has_io_stats) - { - safe_aggregate_io(& m_table_stat, m_share, m_thread_owner); - m_has_io_stats= false; - } - else if (m_has_lock_stats) - { - safe_aggregate_lock(& m_table_stat, m_share, m_thread_owner); - m_has_lock_stats= false; - } + safe_aggregate(& m_table_stat, m_share); + m_has_io_stats= false; + m_has_lock_stats= false; + } + else if (m_has_io_stats) + { + safe_aggregate_io(& m_table_stat, m_share); + m_has_io_stats= false; + } + else if (m_has_lock_stats) + { + safe_aggregate_lock(& m_table_stat, m_share); + m_has_lock_stats= false; } } @@ -253,14 +250,11 @@ public: private: static void safe_aggregate(PFS_table_stat *stat, - PFS_table_share *safe_share, - PFS_thread *safe_thread); + PFS_table_share *safe_share); static void safe_aggregate_io(PFS_table_stat *stat, - PFS_table_share *safe_share, - PFS_thread *safe_thread); + PFS_table_share *safe_share); static void safe_aggregate_lock(PFS_table_stat *stat, - PFS_table_share *safe_share, - PFS_thread *safe_thread); + PFS_table_share *safe_share); }; /** Instrumented socket implementation. @see PSI_socket. */ === modified file 'storage/perfschema/pfs_instr_class.cc' --- a/storage/perfschema/pfs_instr_class.cc 2012-03-28 10:46:02 +0000 +++ b/storage/perfschema/pfs_instr_class.cc 2012-04-05 17:05:18 +0000 @@ -199,13 +199,13 @@ uint socket_class_start= 0; void init_event_name_sizing(const PFS_global_param *param) { - mutex_class_start= 0; + mutex_class_start= 3; /* global table io, lock, idle */ rwlock_class_start= mutex_class_start + param->m_mutex_class_sizing; cond_class_start= rwlock_class_start + param->m_rwlock_class_sizing; file_class_start= cond_class_start + param->m_cond_class_sizing; socket_class_start= file_class_start + param->m_file_class_sizing; table_class_start= socket_class_start + param->m_socket_class_sizing; - wait_class_max= table_class_start + 3; /* global table io, lock, idle */ + wait_class_max= table_class_start; } void register_global_classes() @@ -213,19 +213,19 @@ void register_global_classes() /* Table IO class */ init_instr_class(&global_table_io_class, "wait/io/table/sql/handler", 25, 0, PFS_CLASS_TABLE_IO); - global_table_io_class.m_event_name_index= table_class_start; + global_table_io_class.m_event_name_index= GLOBAL_TABLE_IO_EVENT_INDEX; configure_instr_class(&global_table_io_class); /* Table lock class */ init_instr_class(&global_table_lock_class, "wait/lock/table/sql/handler", 27, 0, PFS_CLASS_TABLE_LOCK); - global_table_lock_class.m_event_name_index= table_class_start + 1; + global_table_lock_class.m_event_name_index= GLOBAL_TABLE_LOCK_EVENT_INDEX; configure_instr_class(&global_table_lock_class); /* Idle class */ init_instr_class(&global_idle_class, "idle", 4, 0, PFS_CLASS_IDLE); - global_idle_class.m_event_name_index= table_class_start + 2; + global_idle_class.m_event_name_index= GLOBAL_IDLE_EVENT_INDEX; configure_instr_class(&global_idle_class); } === modified file 'storage/perfschema/pfs_instr_class.h' --- a/storage/perfschema/pfs_instr_class.h 2012-03-28 08:29:33 +0000 +++ b/storage/perfschema/pfs_instr_class.h 2012-04-05 17:05:18 +0000 @@ -333,6 +333,10 @@ inline uint sanitize_index_count(uint co return 0; } +#define GLOBAL_TABLE_IO_EVENT_INDEX 0 +#define GLOBAL_TABLE_LOCK_EVENT_INDEX 1 +#define GLOBAL_IDLE_EVENT_INDEX 2 + /** Instrument controlling all table io. This instrument is used with table SETUP_OBJECTS. No bundle (reason: useless for push emails).