diff options
author | unknown <cmiller@zippy.cornsilk.net> | 2007-02-22 10:03:08 -0500 |
---|---|---|
committer | unknown <cmiller@zippy.cornsilk.net> | 2007-02-22 10:03:08 -0500 |
commit | 607c224969df2aa13f6b236440e02713a18e6c34 (patch) | |
tree | 1bef9445e8b72c15c47554a6cfa32aef7e32ce69 /sql/sql_profile.h | |
parent | 98d31c694dc4d16420f0cc79c012c2ce13600883 (diff) | |
download | mariadb-git-607c224969df2aa13f6b236440e02713a18e6c34.tar.gz |
Prevent bugs by making DBUG_* expressions syntactically equivalent
to a single statement.
---
Bug#24795: SHOW PROFILE
Profiling is only partially functional on some architectures. Where
there is no getrusage() system call, presently Null values are
returned where it would be required. Notably, Windows needs some love
applied to make it as useful.
Syntax this adds:
SHOW PROFILES
SHOW PROFILE [types] [FOR QUERY n] [OFFSET n] [LIMIT n]
where "n" is an integer
and "types" is zero or many (comma-separated) of
"CPU"
"MEMORY" (not presently supported)
"BLOCK IO"
"CONTEXT SWITCHES"
"PAGE FAULTS"
"IPC"
"SWAPS"
"SOURCE"
"ALL"
It also adds a session variable (boolean) "profiling", set to "no"
by default, and (integer) profiling_history_size, set to 15 by
default.
This patch abstracts setting THDs' "proc_info" behind a macro that
can be used as a hook into the profiling code when profiling
support is compiled in. All future code in this line should use
that mechanism for setting thd->proc_info.
---
Tests are now set to omit the statistics.
---
Adds an Information_schema table, "profiling" for access to
"show profile" data.
---
Merge zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community-3--bug24795
into zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community
---
Fix merge problems.
---
Fixed one bug in the query_source being NULL.
Updated test results.
---
Include more thorough profiling tests.
Improve support for prepared statements.
Use session-specific query IDs, starting at zero.
---
Selecting from I_S.profiling is no longer quashed in profiling, as
requested by Giuseppe.
Limit the size of captured query text.
No longer log queries that are zero length.
BitKeeper/deleted/.del-profile.result:
Rename: mysql-test/r/profile.result -> BitKeeper/deleted/.del-profile.result
BitKeeper/deleted/.del-profile.test:
Rename: mysql-test/t/profile.test -> BitKeeper/deleted/.del-profile.test
BitKeeper/deleted/.del-sql_profile.cc:
Rename: sql/sql_profile.cc -> BitKeeper/deleted/.del-sql_profile.cc
BitKeeper/deleted/.del-sql_profile.h:
Rename: sql/sql_profile.h -> BitKeeper/deleted/.del-sql_profile.h
configure.in:
Add a configure-time option to enable/disable query profiling. The
default is enabled.
include/my_dbug.h:
DBUG_* statements should be syntactically equivalent to a single
statement.
myisam/mi_open.c:
DBUG_* statements should be syntactically equivalent to a single
statement.
mysql-test/r/information_schema.result:
Updated (re-recorded) tests that I missed somehow. I verified these
for correctness.
mysql-test/r/information_schema_db.result:
Updated test results I missed.
mysql-test/r/mysqlshow.result:
Fix merge problems.
ndb/src/ndbapi/DictCache.cpp:
DBUG_* statements should be syntactically equivalent to a single
statement.
sql/ha_archive.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/ha_berkeley.cc:
Include patch backported to 5.0-global.
THD::options is a ulonglong, not ulong.
sql/ha_myisam.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/ha_myisammrg.cc:
DBUG_* statements should be syntactically equivalent to a single
statement.
sql/ha_ndbcluster.cc:
DBUG_* statements should be syntactically equivalent to a single
statement.
sql/item_cmpfunc.cc:
DBUG_* statements should be syntactically equivalent to a single
statement.
sql/item_func.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/lock.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/log_event.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/mysql_priv.h:
Use 64-bit constants for the 64-bit bit field.
Add a new option bit for whether profiling is active or not.
sql/mysqld.cc:
Add semicolon to DBUG statement.
Add a new system variable and set it.
---
Set the minimum, which is zero and not 50.
sql/repl_failsafe.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/set_var.cc:
Make a new system global variable and session variable, to determine
behavior of profiling.
---
Include patch backported to 5.0-global.
THD::options is a ulonglong, not ulong.
sql/set_var.h:
The THD::options bit field is ulonglong, not ulong.
sql/slave.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
---
Include patch backported to 5.0-global.
THD::options is a ulonglong, not ulong.
sql/sp_head.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/sql_base.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
---
Include patch backported to 5.0-global.
THD::options is a ulonglong, not ulong.
sql/sql_cache.cc:
DBUG_* statements should be syntactically equivalent to a single
statement.
---
Fix merge problems.
sql/sql_class.cc:
Insert a pointer to the current thread in the profiling code.
---
Manual merge, undoing first patch.
---
Fix merge problems.
sql/sql_class.h:
Create a new system variable, profiling_history_size, and add a
member to THD to hold profiling information about this thread's
execution.
---
Manual merge, undoing first patch.
sql/sql_delete.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
---
Include patch backported to 5.0-global.
THD::options is a ulonglong, not ulong.
sql/sql_insert.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
---
Fix merge problems.
sql/sql_lex.cc:
Initialize profiling options to empty.
---
Manual merge, undoing first patch.
sql/sql_lex.h:
Add info to the lexer object so that we can hold data that comes from
parsing statements.
Reuse memory addresses of uints that can't occur in the same state-
ment.
This is dangerous because it involves knowledge of what symbols are
never used together, which is information stored obliquely in another
file.
---
Manual merge, undoing first patch.
sql/sql_parse.cc:
Add hooks to the parser to jump to profiling code.
If profiling is not present, then return an error message upon being
used.
---
Manual merge, undoing first patch.
---
Fix merge problems.
---
Include patch backported to 5.0-global.
THD::options is a ulonglong, not ulong.
sql/sql_prepare.cc:
From prepared statement execution, set the query source in the
profiler, as we can't get it from thd .
---
Make it less expensive to limit the size of the queries.
sql/sql_repl.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/sql_select.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
---
Fix merge problems.
sql/sql_show.cc:
Abstract setting thread-info into a function or macro.
Also, remove "static" qualification on schema_table_store_record()
so that external functions may use it.
---
Manual merge, undoing first patch.
sql/sql_table.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/sql_update.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/sql_view.cc:
Abstract setting thread-info into a function or macro.
---
Manual merge, undoing first patch.
sql/sql_yacc.yy:
Add new lexer symbols and insert new grammatical rules necessary to
retreive profiling information.
---
Manual merge, undoing first patch.
---
Fix merge problems.
sql/table.h:
Add enum item for query profiling.
BitKeeper/deleted/.del-profiling-master.opt:
New BitKeeper file ``mysql-test/t/profiling-master.opt''
mysql-test/r/profiling.result:
New BitKeeper file ``mysql-test/r/profiling.result''
---
Include more verbose that describes the queries so far.
Include Giuseppe's tests.
---
Selecting from I_S.profiling is no longer quashed in profiling, as
requested by Giuseppe.
mysql-test/t/profiling.test:
New BitKeeper file ``mysql-test/t/profiling.test''
---
Include more verbose that describes the queries so far.
Include Giuseppe's tests.
---
Selecting from I_S.profiling is no longer quashed in profiling, as
requested by Giuseppe.
sql/sql_profile.cc:
New BitKeeper file ``sql/sql_profile.cc''
---
If query_source is NULL, as can sometimes happen, then don't try
to copy that memory.
---
Make each new session use its own numbering of query_ids, and not
show the global-pool numbers to the user.
Provide a way for prepared statements to set the query_source.
---
Selecting from I_S.profiling is no longer quashed in profiling, as
requested by Giuseppe.
Limit the size of captured query text.
No longer log queries that are zero length.
sql/sql_profile.h:
New BitKeeper file ``sql/sql_profile.h''
---
Make each new session use its own numbering of query_ids, and not
show the global-pool numbers to the user.
Provide a way for prepared statements to set the query_source.
---
Make it less expensive to limit the size of the queries.
Diffstat (limited to 'sql/sql_profile.h')
-rw-r--r-- | sql/sql_profile.h | 248 |
1 files changed, 151 insertions, 97 deletions
diff --git a/sql/sql_profile.h b/sql/sql_profile.h index 698a80f07e4..006760cab79 100644 --- a/sql/sql_profile.h +++ b/sql/sql_profile.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2005 MySQL AB +/* Copyright (C) 2007 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -14,99 +14,135 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef SQL_PROFILE_H -#define SQL_PROFILE_H - -#include <sys/time.h> -#include <sys/resource.h> - -#if 1 -#define THD_PROC_INFO(thd, msg) do { if(unlikely((thd)->profiling.enabled)) { (thd)->profiling.status((msg), __FUNCTION__, __FILE__, __LINE__); } else { (thd)->proc_info= (msg); } } while (0) +#ifndef _SQL_PROFILE_H +#define _SQL_PROFILE_H + +#if __STDC_VERSION__ < 199901L +# if __GNUC__ >= 2 +# define __func__ __FUNCTION__ +# else +# define __func__ _db_func_ +extern const char *_db_func_; +# endif +#elif defined(_MSC_VER) +# if _MSC_VER < 1300 +# define __func__ _db_func_ +extern const char *_db_func_; +# else +# define __func__ __FUNCTION__ +# endif +#elif defined(__BORLANDC__) +# define __func__ __FUNC__ #else -#define THD_PROC_INFO(thd, msg) do { (thd)->proc_info= (msg); } while (0) +# define __func__ _db_func_ +extern const char *_db_func_; #endif -#if 0 - - struct rusage { - struct timeval ru_utime; /* user time used */ - struct timeval ru_stime; /* system time used */ - long ru_maxrss; /* integral max resident set size */ - long ru_ixrss; /* integral shared text memory size */ - long ru_idrss; /* integral unshared data size */ - long ru_isrss; /* integral unshared stack size */ - long ru_minflt; /* page reclaims */ - long ru_majflt; /* page faults */ - long ru_nswap; /* swaps */ - long ru_inblock; /* block input operations */ - long ru_oublock; /* block output operations */ - long ru_msgsnd; /* messages sent */ - long ru_msgrcv; /* messages received */ - long ru_nsignals; /* signals received */ - long ru_nvcsw; /* voluntary context switches */ - long ru_nivcsw; /* involuntary context switches */ - }; +extern ST_FIELD_INFO query_profile_statistics_info[]; +int fill_query_profile_statistics_info(THD *thd, struct st_table_list *tables, Item *cond); -#endif #define PROFILE_NONE 0 -#define PROFILE_CPU 1 -#define PROFILE_MEMORY 2 -#define PROFILE_BLOCK_IO 4 -#define PROFILE_CONTEXT 8 -#define PROFILE_PAGE_FAULTS 16 -#define PROFILE_IPC 32 -#define PROFILE_SWAPS 64 -#define PROFILE_SOURCE 16384 -#define PROFILE_ALL 32767 +#define PROFILE_CPU (1<<0) +#define PROFILE_MEMORY (1<<1) +#define PROFILE_BLOCK_IO (1<<2) +#define PROFILE_CONTEXT (1<<3) +#define PROFILE_PAGE_FAULTS (1<<4) +#define PROFILE_IPC (1<<5) +#define PROFILE_SWAPS (1<<6) +#define PROFILE_SOURCE (1<<16) +#define PROFILE_ALL (~0) + + +#ifndef ENABLED_PROFILING + +# define thd_proc_info(thd, msg) do { (thd)->proc_info= (msg); } while (0) + +#else + +# define thd_proc_info(thd, msg) \ + do { \ + if (unlikely(((thd)->options & OPTION_PROFILING) != 0)) \ + { \ + (thd)->profiling.status_change((msg), __func__, __FILE__, __LINE__); \ + } \ + else \ + { \ + (thd)->proc_info= (msg); \ + } \ + } while (0) + +#include "mysql_priv.h" + +#ifdef HAVE_SYS_RESOURCE_H +#include <sys/resource.h> +#endif + class PROFILE_ENTRY; -class PROFILE; +class QUERY_PROFILE; class PROFILING; -/* + +/** A single entry in a single profile. */ - -class PROFILE_ENTRY: public Sql_alloc +class PROFILE_ENTRY { -public: - PROFILE *profile; - char *status; - ulonglong time; +private: + friend class QUERY_PROFILE; + friend class PROFILING; + + QUERY_PROFILE *profile; + char *status; +#ifdef HAVE_GETRUSAGE struct rusage rusage; +#endif char *function; char *file; unsigned int line; + + double time_usecs; + char *allocated_status_memory; + + void set_status(const char *status_arg, const char *function_arg, + const char *file_arg, unsigned int line_arg); + void clean_up(); PROFILE_ENTRY(); - PROFILE_ENTRY(PROFILE *profile_arg, const char *status_arg); - PROFILE_ENTRY(PROFILE *profile_arg, const char *status_arg, + PROFILE_ENTRY(QUERY_PROFILE *profile_arg, const char *status_arg); + PROFILE_ENTRY(QUERY_PROFILE *profile_arg, const char *status_arg, const char *function_arg, const char *file_arg, unsigned int line_arg); ~PROFILE_ENTRY(); - - void set_status(const char *status_arg); void collect(); }; -/* - The full profile for a single query. Includes multiple PROFILE_ENTRY + +/** + The full profile for a single query, and includes multiple PROFILE_ENTRY objects. */ - -class PROFILE: public Sql_alloc +class QUERY_PROFILE { -public: +private: + friend class PROFILING; + PROFILING *profiling; - query_id_t query_id; + + 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; List<PROFILE_ENTRY> entries; - PROFILE(PROFILING *profiling_arg); - ~PROFILE(); + + QUERY_PROFILE(PROFILING *profiling_arg, char *query_source_arg, uint query_length_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, @@ -120,68 +156,86 @@ public: bool show(uint options); }; -/* - Profiling state for a single THD. Contains multiple PROFILE objects. -*/ -class PROFILING: public Sql_alloc +/** + Profiling state for a single THD; contains multiple QUERY_PROFILE objects. +*/ +class PROFILING { -public: - MEM_ROOT root; +private: + friend class PROFILE_ENTRY; + friend class QUERY_PROFILE; + + /* + Not the system query_id, but a counter unique to profiling. + */ + query_id_t profile_id_counter; + MEM_ROOT mem_root; THD *thd; - bool enabled; bool keeping; - PROFILE *current; - PROFILE *last; - List<PROFILE> history; + QUERY_PROFILE *current; + QUERY_PROFILE *last; + List<QUERY_PROFILE> history; + + query_id_t next_profile_id() { return(profile_id_counter++); } +public: PROFILING(); ~PROFILING(); + void set_query_source(char *query_source_arg, uint query_length_arg); - inline void set_thd(THD *thd_arg) { thd= thd_arg; }; - - /* - Should we try to collect profiling information at all? - - If we disable profiling, we cannot later decide to turn it back - on for the same query. - */ - inline void enable() { enabled= 1; }; - inline void disable() { enabled= 0; }; + /** Reset the current profile and state of profiling for the next query. */ + void reset(); - /* + /** 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. + 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= 1; }; - inline void discard() { keeping= 0; }; + inline void keep() { keeping= true; }; - void status(const char *status_arg, - const char *function_arg, - const char *file_arg, unsigned int line_arg); + /** + Do we intend to keep the currently collected profile? + @see keep() + */ + inline void discard() { keeping= false; }; - /* Stash this profile in the profile history. */ + /** + 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(); - - /* Reset the current profile and state of profiling for the next query. */ - void reset(); + + /** + 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); + + inline void set_thd(THD *thd_arg) { thd= thd_arg; }; /* SHOW PROFILES */ bool show_profiles(); /* SHOW PROFILE FOR QUERY query_id */ - bool show(uint options, uint query_id); + bool show(uint options, uint profiling_query_id); /* SHOW PROFILE */ bool show_last(uint options); + + /* ... from INFORMATION_SCHEMA.PROFILING ... */ + int fill_statistics_info(THD *thd, struct st_table_list *tables, Item *cond); }; -#endif /* SQL_PROFILE_H */ +# endif /* HAVE_PROFILING */ +#endif /* _SQL_PROFILE_H */ |