summaryrefslogtreecommitdiff
path: root/sql/sp_head.cc
diff options
context:
space:
mode:
authorunknown <cmiller@zippy.cornsilk.net>2007-11-13 09:46:17 -0500
committerunknown <cmiller@zippy.cornsilk.net>2007-11-13 09:46:17 -0500
commit7eb9aac77e69e0bce9234958b50dde38140007a8 (patch)
treea965c70fa22a2751eacbcde6ec95b4fb00f7d2a8 /sql/sp_head.cc
parentac180f8272f9be0cf2621c11e03e313b891c4417 (diff)
downloadmariadb-git-7eb9aac77e69e0bce9234958b50dde38140007a8.tar.gz
Insert profiling instructions into s-p code to make each statement
be profiled separately. Expand the time formats in i_s.profiling to wide enough for larger numbers. mysql-test/r/profiling.result: Show that each query inside a procedure is profiled separately. mysql-test/t/profiling.test: Show that each query inside a procedure is profiled separately. sql/sp_head.cc: Poke profiling into stored-procedure code. For statement parts only of routines, process them as profilable discrete queries. sql/sql_profile.cc: Encode decimal size correctly.
Diffstat (limited to 'sql/sp_head.cc')
-rw-r--r--sql/sp_head.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 09ae572152f..3becfd6bcf4 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -1162,15 +1162,36 @@ sp_head::execute(THD *thd)
*/
thd->spcont->callers_arena= &backup_arena;
+#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
+ /* Discard the initial part of executing routines. */
+ thd->profiling.discard_current_query();
+#endif
do
{
sp_instr *i;
uint hip; // Handler ip
+#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
+ /*
+ Treat each "instr" of a routine as discrete unit that could be profiled.
+ Profiling only records information for segments of code that set the
+ source of the query, and almost all kinds of instructions in s-p do not.
+ */
+ thd->profiling.finish_current_query();
+ thd->profiling.start_new_query("continuing inside routine");
+#endif
+
i = get_instr(ip); // Returns NULL when we're done.
if (i == NULL)
+ {
+#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
+ thd->profiling.discard_current_query();
+#endif
break;
+ }
+
DBUG_PRINT("execute", ("Instruction %u", ip));
+
/* Don't change NOW() in FUNCTION or TRIGGER */
if (!thd->in_sub_stmt)
thd->set_time(); // Make current_time() et al work
@@ -1248,6 +1269,11 @@ sp_head::execute(THD *thd)
}
} while (!err_status && !thd->killed);
+#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
+ thd->profiling.finish_current_query();
+ thd->profiling.start_new_query("tail end of routine");
+#endif
+
/* Restore query context. */
m_creation_ctx->restore_env(thd, saved_creation_ctx);
@@ -2725,6 +2751,10 @@ sp_instr_stmt::execute(THD *thd, uint *nextp)
query= thd->query;
query_length= thd->query_length;
+#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
+ /* This s-p instr is profilable and will be captured. */
+ thd->profiling.set_query_source(m_query.str, m_query.length);
+#endif
if (!(res= alloc_query(thd, m_query.str, m_query.length)) &&
!(res=subst_spvars(thd, this, &m_query)))
{