summaryrefslogtreecommitdiff
path: root/sql/sql_profile.cc
diff options
context:
space:
mode:
authorSergey Vojtovich <svoj@mariadb.org>2015-04-15 18:12:23 +0400
committerSergey Vojtovich <svoj@mariadb.org>2015-05-13 10:43:13 +0400
commit5cfb6b479efd05fafc77caf94d60240b879d5073 (patch)
treef35853d2a164d3c437e052d49ef2cf23b357cfa6 /sql/sql_profile.cc
parent55d5af733d97808a1479b185c029ac0121c0f158 (diff)
downloadmariadb-git-5cfb6b479efd05fafc77caf94d60240b879d5073.tar.gz
MDEV-7999 - PROFILING routines take 0.2% when profiling disabled
PROFILING::start_new_query() optimizations: - no need to check "current": added assertion instead - "enabled" now means "is enabled currently" instead of "was enabled at query start". Old meaning was useless, new meaning echoes OPTION_PROFILING so that start_new_query() can be defined in sql_profile.h. - remnants of start_new_query() moved to sql_profile.h so it can be inlined PROFILING::start_new_query() overhead dropped 0.08% -> out of radar. PROFILING::set_query_source() optimizations: - no need to check "enabled": !enabled && current is impossible - remnants of set_query_source() moved to sql_profile.h so it can be inlined PROFILING::set_query_source() overhead dropped 0.02% -> out of radar. PROFILING::finish_current_query() optimizations: - moved "current" check out to sql_profile.h so it can be inlined PROFILING::finish_current_query() overhead dropped 0.10% -> out of radar.
Diffstat (limited to 'sql/sql_profile.cc')
-rw-r--r--sql/sql_profile.cc97
1 files changed, 24 insertions, 73 deletions
diff --git a/sql/sql_profile.cc b/sql/sql_profile.cc
index 2eaaea41f18..9fa4d646fa1 100644
--- a/sql/sql_profile.cc
+++ b/sql/sql_profile.cc
@@ -337,36 +337,6 @@ PROFILING::~PROFILING()
delete current;
}
-
-/**
- Prepare to start processing a new query. It is an error to do this
- if there's a query already in process; nesting is not supported.
-
- @param initial_state (optional) name of period before first state change
-*/
-void PROFILING::start_new_query(const char *initial_state)
-{
- DBUG_ENTER("PROFILING::start_new_query");
-
- /* This should never happen unless the server is radically altered. */
- if (unlikely(current != NULL))
- {
- DBUG_PRINT("warning", ("profiling code was asked to start a new query "
- "before the old query was finished. This is "
- "probably a bug."));
- finish_current_query();
- }
-
- enabled= ((thd->variables.option_bits & OPTION_PROFILING) != 0);
-
- if (! enabled) DBUG_VOID_RETURN;
-
- DBUG_ASSERT(current == NULL);
- current= new QUERY_PROFILE(this, initial_state);
-
- DBUG_VOID_RETURN;
-}
-
/**
Throw away the current profile, because it's useless or unwanted
or corrupted.
@@ -386,36 +356,31 @@ void PROFILING::discard_current_query()
saved, and maintain the profile history size. Naturally, this may not
succeed if the profile was previously discarded, and that's expected.
*/
-void PROFILING::finish_current_query()
+void PROFILING::finish_current_query_impl()
{
DBUG_ENTER("PROFILING::finish_current_profile");
- if (current != NULL)
+ DBUG_ASSERT(current);
+
+ /* The last fence-post, so we can support the span before this. */
+ status_change("ending", NULL, NULL, 0);
+
+ if (enabled && /* ON at end? */
+ (current->query_source != NULL) &&
+ (! current->entries.is_empty()))
{
- /* The last fence-post, so we can support the span before this. */
- status_change("ending", NULL, NULL, 0);
+ current->profiling_query_id= next_profile_id(); /* assign an id */
- if ((enabled) && /* ON at start? */
- ((thd->variables.option_bits & OPTION_PROFILING) != 0) && /* and ON at end? */
- (current->query_source != NULL) &&
- (! current->entries.is_empty()))
- {
- current->profiling_query_id= next_profile_id(); /* assign an id */
+ history.push_back(current);
+ last= current; /* never contains something that is not in the history. */
- history.push_back(current);
- last= current; /* never contains something that is not in the history. */
- current= NULL;
- }
- else
- {
- delete current;
- current= NULL;
- }
+ /* Maintain the history size. */
+ while (history.elements > thd->variables.profiling_history_size)
+ delete history.pop();
}
+ else
+ delete current;
- /* Maintain the history size. */
- while (history.elements > thd->variables.profiling_history_size)
- delete history.pop();
-
+ current= NULL;
DBUG_VOID_RETURN;
}
@@ -476,26 +441,6 @@ bool PROFILING::show_profiles()
}
/**
- At a point in execution where we know the query source, save the text
- of it in the query profile.
-
- This must be called exactly once per descrete statement.
-*/
-void PROFILING::set_query_source(char *query_source_arg, uint query_length_arg)
-{
- DBUG_ENTER("PROFILING::set_query_source");
-
- if (! enabled)
- DBUG_VOID_RETURN;
-
- if (current != NULL)
- current->set_query_source(query_source_arg, query_length_arg);
- else
- DBUG_PRINT("info", ("no current profile to send query source to"));
- DBUG_VOID_RETURN;
-}
-
-/**
Fill the information schema table, "query_profile", as defined in show.cc .
There are two ways to get to this function: Selecting from the information
schema, and a SHOW command.
@@ -720,4 +665,10 @@ int PROFILING::fill_statistics_info(THD *thd_arg, TABLE_LIST *tables, Item *cond
DBUG_RETURN(0);
}
+
+
+void PROFILING::reset()
+{
+ enabled= thd->variables.option_bits & OPTION_PROFILING;
+}
#endif /* ENABLED_PROFILING */