summaryrefslogtreecommitdiff
path: root/sql/sql_profile.h
diff options
context:
space:
mode:
authorunknown <cmiller@zippy.cornsilk.net>2007-11-09 14:45:44 -0500
committerunknown <cmiller@zippy.cornsilk.net>2007-11-09 14:45:44 -0500
commit69aee07373c19b5e5615c9a99574c000d0b3c95c (patch)
treee6911122c3704492d4ff6b6c2535ca9f74e23b9d /sql/sql_profile.h
parent6dbc0c5ab18f6c1f69ef91a5b09359c5378d1eee (diff)
downloadmariadb-git-69aee07373c19b5e5615c9a99574c000d0b3c95c.tar.gz
Rewrite profiler code to be easier to maintain and less buggy.
Between 5.0 and 5.1, the step of incrementing the global query id changed, which broke how the profiler noticed when a new query had started. That reset the state list and caused all but the last five (or so) states to be thrown away. Now, don't watch for query_id changes in the lower level. Add a bogus state change at the end of profiling so that the last real state change is timed. Emit source reference for the start of the span of time instead of the end of it. mysql-test/r/profiling.result: Add a test that shows continuation of execution with multi-statement packets. mysql-test/t/profiling.test: Add a test that shows continuation of execution with multi-statement packets. sql/sql_parse.cc: Insert profiling calls at beginnings and ends of each query. Remove the old way of keeping or discarding profiles, and flipping to new query profiles. sql/sql_profile.cc: No longer use the thread's query_id to determine when we flip to a new statement. Some status statements are set to be NULL in the server. We don't log those, as it doesn't fit this style of profiling yet. Rewrite the parser code to be more active and legible. Relying on passive/lazy discovery of new queries was buggy. Add a bogus status change before ending a profile, so that the previous real status has a endpoint. Emit source reference of the start of the span-of-time instead of the end of it. sql/sql_profile.h: Store the server_query_id at instantiation time for a new query. Rewrite the parser code to be more active. Relying on passive/lazy discovery of new queries was buggy. Name first state to more honestly describe the state. We don't really know of initialization that will follow. sql/sql_show.cc: Update comment to note the decidedly weird field_length behavior on Decimal types in information_schema.
Diffstat (limited to 'sql/sql_profile.h')
-rw-r--r--sql/sql_profile.h63
1 files changed, 18 insertions, 45 deletions
diff --git a/sql/sql_profile.h b/sql/sql_profile.h
index 1a6ebcd0b0e..2483cb3cb6a 100644
--- a/sql/sql_profile.h
+++ b/sql/sql_profile.h
@@ -62,7 +62,7 @@ int make_profile_table_for_show(THD *thd, ST_SCHEMA_TABLE *schema_table);
#endif
-class PROFILE_ENTRY;
+class PROF_MEASUREMENT;
class QUERY_PROFILE;
class PROFILING;
@@ -176,7 +176,7 @@ public:
/**
A single entry in a single profile.
*/
-class PROFILE_ENTRY
+class PROF_MEASUREMENT
{
private:
friend class QUERY_PROFILE;
@@ -195,22 +195,22 @@ private:
double time_usecs;
char *allocated_status_memory;
- void set_status(const char *status_arg, const char *function_arg,
+ void set_label(const char *status_arg, const char *function_arg,
const char *file_arg, unsigned int line_arg);
void clean_up();
- PROFILE_ENTRY();
- PROFILE_ENTRY(QUERY_PROFILE *profile_arg, const char *status_arg);
- PROFILE_ENTRY(QUERY_PROFILE *profile_arg, const char *status_arg,
+ PROF_MEASUREMENT();
+ PROF_MEASUREMENT(QUERY_PROFILE *profile_arg, const char *status_arg);
+ PROF_MEASUREMENT(QUERY_PROFILE *profile_arg, const char *status_arg,
const char *function_arg,
const char *file_arg, unsigned int line_arg);
- ~PROFILE_ENTRY();
+ ~PROF_MEASUREMENT();
void collect();
};
/**
- The full profile for a single query, and includes multiple PROFILE_ENTRY
+ The full profile for a single query, and includes multiple PROF_MEASUREMENT
objects.
*/
class QUERY_PROFILE
@@ -220,21 +220,21 @@ private:
PROFILING *profiling;
- query_id_t server_query_id; /* Global id. */
query_id_t profiling_query_id; /* Session-specific id. */
char *query_source;
- PROFILE_ENTRY profile_start;
- PROFILE_ENTRY *profile_end;
- Queue<PROFILE_ENTRY> entries;
+ PROF_MEASUREMENT *profile_start;
+ PROF_MEASUREMENT *profile_end;
+ Queue<PROF_MEASUREMENT> entries;
- QUERY_PROFILE(PROFILING *profiling_arg, char *query_source_arg, uint query_length_arg);
+
+ QUERY_PROFILE(PROFILING *profiling_arg, const char *status_arg);
~QUERY_PROFILE();
void set_query_source(char *query_source_arg, uint query_length_arg);
/* Add a profile status change to the current profile. */
- void status(const char *status_arg,
+ void new_status(const char *status_arg,
const char *function_arg,
const char *file_arg, unsigned int line_arg);
@@ -252,7 +252,7 @@ private:
class PROFILING
{
private:
- friend class PROFILE_ENTRY;
+ friend class PROF_MEASUREMENT;
friend class QUERY_PROFILE;
/*
@@ -274,39 +274,12 @@ public:
~PROFILING();
void set_query_source(char *query_source_arg, uint query_length_arg);
- /** Reset the current profile and state of profiling for the next query. */
- void reset();
+ void start_new_query(const char *initial_state= "starting");
- /**
- Do we intend to keep the currently collected profile?
-
- We don't keep profiles for some commands, such as SHOW PROFILE, SHOW
- PROFILES, and some SQLCOM commands which aren't useful to profile. The
- keep() and discard() functions can be called many times, only the final
- setting when the query finishes is used to decide whether to discard the
- profile.
-
- The default is to keep the profile for all queries.
- */
- inline void keep() { keeping= true; };
+ void discard_current_query();
- /**
- Do we intend to keep the currently collected profile?
- @see keep()
- */
- inline void discard() { keeping= false; };
+ void finish_current_query();
- /**
- Stash this profile in the profile history and remove the oldest
- profile if the history queue is full, as defined by the
- profiling_history_size system variable.
- */
- void store();
-
- /**
- Called with every update of the status via thd_proc_info() , and is
- therefore the main hook into the profiling code.
- */
void status_change(const char *status_arg,
const char *function_arg,
const char *file_arg, unsigned int line_arg);