diff options
author | Sergey Vojtovich <svoj@mariadb.org> | 2015-04-15 11:29:01 +0400 |
---|---|---|
committer | Sergey Vojtovich <svoj@mariadb.org> | 2015-05-13 10:43:13 +0400 |
commit | 55d5af733d97808a1479b185c029ac0121c0f158 (patch) | |
tree | b8cf068171645ffda853e03e631d8d1602047053 | |
parent | c8ad5b2f1223d8bb6edcdcb56317172206c9fd8e (diff) | |
download | mariadb-git-55d5af733d97808a1479b185c029ac0121c0f158.tar.gz |
MDEV-7945 - THD::enter_stage() takes 0.48% in OLTP RO
THD::enter_stage() optimizations:
- stage backup code moved to THD::backup_stage(), saves one condition
- moved check for "new_stage" out to callers that actually need it
- remnants of enter_stage() moved to sql_class.h so it can be inlined
THD::enter_stage() overhead dropped 0.48% -> 0.07%.
PROFILING::status_change() optimizations:
- "status_arg" is now checked by QUERY_PROFILE::new_status()
- no need to check "enabled": !enabled && current is impossible
- remnants of status_change() moved to sql_profile.h so it can be inlined
PROFILING::status_change() overhead dropped 0.1% -> out of radar.
-rw-r--r-- | sql/lock.cc | 4 | ||||
-rw-r--r-- | sql/sql_class.cc | 37 | ||||
-rw-r--r-- | sql/sql_class.h | 32 | ||||
-rw-r--r-- | sql/sql_profile.cc | 29 | ||||
-rw-r--r-- | sql/sql_profile.h | 9 | ||||
-rw-r--r-- | sql/sql_show.cc | 6 |
6 files changed, 46 insertions, 71 deletions
diff --git a/sql/lock.cc b/sql/lock.cc index c241e635e6b..a2f7df04de5 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -306,8 +306,8 @@ bool mysql_lock_tables(THD *thd, MYSQL_LOCK *sql_lock, uint flags) PSI_stage_info org_stage; DBUG_ENTER("mysql_lock_tables(sql_lock)"); - thd->enter_stage(&stage_system_lock, &org_stage, __func__, __FILE__, - __LINE__); + thd->backup_stage(&org_stage); + THD_STAGE_INFO(thd, stage_system_lock); if (sql_lock->table_count && lock_external(thd, sql_lock->table, sql_lock->table_count)) goto end; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 7de565d3cc8..a32cfdb9f3a 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -557,40 +557,11 @@ void set_thd_stage_info(void *thd_arg, if (thd == NULL) thd= current_thd; - thd->enter_stage(new_stage, old_stage, calling_func, calling_file, - calling_line); -} - -void THD::enter_stage(const PSI_stage_info *new_stage, - PSI_stage_info *old_stage, - const char *calling_func, - const char *calling_file, - const unsigned int calling_line) -{ - DBUG_PRINT("THD::enter_stage", ("%s:%d", calling_file, calling_line)); - - if (old_stage != NULL) - { - old_stage->m_key= m_current_stage_key; - old_stage->m_name= proc_info; - } - - if (new_stage != NULL) - { - const char *msg= new_stage->m_name; + if (old_stage) + thd->backup_stage(old_stage); -#if defined(ENABLED_PROFILING) - profiling.status_change(msg, calling_func, calling_file, calling_line); -#endif - - m_current_stage_key= new_stage->m_key; - proc_info= msg; - -#ifdef HAVE_PSI_THREAD_INTERFACE - MYSQL_SET_STAGE(m_current_stage_key, calling_file, calling_line); -#endif - } - return; + if (new_stage) + thd->enter_stage(new_stage, calling_func, calling_file, calling_line); } void thd_enter_cond(MYSQL_THD thd, mysql_cond_t *cond, mysql_mutex_t *mutex, diff --git a/sql/sql_class.h b/sql/sql_class.h index acb8777d980..fb563281d88 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -53,7 +53,7 @@ void set_thd_stage_info(void *thd, const unsigned int calling_line); #define THD_STAGE_INFO(thd, stage) \ - (thd)->enter_stage(& stage, NULL, __func__, __FILE__, __LINE__) + (thd)->enter_stage(&stage, __func__, __FILE__, __LINE__) #include "my_apc.h" #include "rpl_gtid.h" @@ -1989,10 +1989,28 @@ private: public: void enter_stage(const PSI_stage_info *stage, - PSI_stage_info *old_stage, const char *calling_func, const char *calling_file, - const unsigned int calling_line); + const unsigned int calling_line) + { + DBUG_PRINT("THD::enter_stage", ("%s:%d", calling_file, calling_line)); + DBUG_ASSERT(stage); + m_current_stage_key= stage->m_key; + proc_info= stage->m_name; +#if defined(ENABLED_PROFILING) + profiling.status_change(stage->m_name, calling_func, calling_file, + calling_line); +#endif +#ifdef HAVE_PSI_THREAD_INTERFACE + MYSQL_SET_STAGE(m_current_stage_key, calling_file, calling_line); +#endif + } + + void backup_stage(PSI_stage_info *stage) + { + stage->m_key= m_current_stage_key; + stage->m_name= proc_info; + } const char *get_proc_info() const { return proc_info; } @@ -2915,7 +2933,10 @@ public: mysql_mutex_assert_owner(mutex); mysys_var->current_mutex = mutex; mysys_var->current_cond = cond; - enter_stage(stage, old_stage, src_function, src_file, src_line); + if (old_stage) + backup_stage(old_stage); + if (stage) + enter_stage(stage, src_function, src_file, src_line); } inline void exit_cond(const PSI_stage_info *stage, const char *src_function, const char *src_file, @@ -2931,7 +2952,8 @@ public: mysql_mutex_lock(&mysys_var->mutex); mysys_var->current_mutex = 0; mysys_var->current_cond = 0; - enter_stage(stage, NULL, src_function, src_file, src_line); + if (stage) + enter_stage(stage, src_function, src_file, src_line); mysql_mutex_unlock(&mysys_var->mutex); return; } diff --git a/sql/sql_profile.cc b/sql/sql_profile.cc index 26d515842ed..2eaaea41f18 100644 --- a/sql/sql_profile.cc +++ b/sql/sql_profile.cc @@ -302,7 +302,8 @@ void QUERY_PROFILE::new_status(const char *status_arg, PROF_MEASUREMENT *prof; DBUG_ENTER("QUERY_PROFILE::status"); - DBUG_ASSERT(status_arg != NULL); + if (!status_arg) + DBUG_VOID_RETURN; if ((function_arg != NULL) && (file_arg != NULL)) prof= new PROF_MEASUREMENT(this, status_arg, function_arg, base_name(file_arg), line_arg); @@ -336,32 +337,6 @@ PROFILING::~PROFILING() delete current; } -/** - A new state is given, and that signals the profiler to start a new - timed step for the current query's profile. - - @param status_arg name of this step - @param function_arg calling function (usually supplied from compiler) - @param function_arg calling file (usually supplied from compiler) - @param function_arg calling line number (usually supplied from compiler) -*/ -void PROFILING::status_change(const char *status_arg, - const char *function_arg, - const char *file_arg, unsigned int line_arg) -{ - DBUG_ENTER("PROFILING::status_change"); - - if (status_arg == NULL) /* We don't know how to handle that */ - DBUG_VOID_RETURN; - - if (current == NULL) /* This profile was already discarded. */ - DBUG_VOID_RETURN; - - if (unlikely(enabled)) - current->new_status(status_arg, function_arg, file_arg, line_arg); - - DBUG_VOID_RETURN; -} /** Prepare to start processing a new query. It is an error to do this diff --git a/sql/sql_profile.h b/sql/sql_profile.h index f8970bb162a..52eaba49181 100644 --- a/sql/sql_profile.h +++ b/sql/sql_profile.h @@ -278,7 +278,14 @@ public: void status_change(const char *status_arg, const char *function_arg, - const char *file_arg, unsigned int line_arg); + const char *file_arg, unsigned int line_arg) + { + if (unlikely(current)) + { + DBUG_ASSERT(enabled); + current->new_status(status_arg, function_arg, file_arg, line_arg); + } + } inline void set_thd(THD *thd_arg) { thd= thd_arg; }; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index d4d259be6bb..0a051f60e9c 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -7891,9 +7891,9 @@ bool get_schema_tables_result(JOIN *join, Warnings_only_error_handler err_handler; thd->push_internal_handler(&err_handler); - thd->enter_stage(&stage_filling_schema_table, &org_stage, __func__, __FILE__, - __LINE__); - + thd->backup_stage(&org_stage); + THD_STAGE_INFO(thd, stage_filling_schema_table); + JOIN_TAB *tab; for (tab= first_linear_tab(join, WITHOUT_BUSH_ROOTS, WITH_CONST_TABLES); tab; |