summaryrefslogtreecommitdiff
path: root/sql/sql_profile.h
diff options
context:
space:
mode:
authorcmiller@zippy.cornsilk.net <>2007-11-09 14:45:44 -0500
committercmiller@zippy.cornsilk.net <>2007-11-09 14:45:44 -0500
commitf12087af5886e46d458471a0d61b3703d128918f (patch)
treee6911122c3704492d4ff6b6c2535ca9f74e23b9d /sql/sql_profile.h
parent149581ecbbac6a47951c46c093e4d2a71ce95088 (diff)
downloadmariadb-git-f12087af5886e46d458471a0d61b3703d128918f.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.
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);