Commit 55d5af73 authored by Sergey Vojtovich's avatar Sergey Vojtovich

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.
parent c8ad5b2f
......@@ -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;
......
......@@ -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 (old_stage)
thd->backup_stage(old_stage);
if (new_stage != NULL)
{
const char *msg= new_stage->m_name;
#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,
......
......@@ -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 @@ class THD :public Statement,
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 @@ class THD :public Statement,
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 @@ class THD :public Statement,
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;
}
......
......@@ -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
......
......@@ -278,7 +278,14 @@ class PROFILING
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; };
......
......@@ -7891,8 +7891,8 @@ 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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment