summaryrefslogtreecommitdiff
path: root/sql/sql_profile.h
diff options
context:
space:
mode:
authorunknown <cmiller@zippy.cornsilk.net>2007-01-03 17:15:10 -0500
committerunknown <cmiller@zippy.cornsilk.net>2007-01-03 17:15:10 -0500
commit66dfd85cf4d55e6d87e8bb81b8fc8450eb9b3f67 (patch)
tree3ccc1d229c4d2704fc85d800e206032a74a7a2e0 /sql/sql_profile.h
parent96fa010c66bffd1f904d5d71bd2d0a0087ad287b (diff)
downloadmariadb-git-66dfd85cf4d55e6d87e8bb81b8fc8450eb9b3f67.tar.gz
Bug#24795: Add SHOW PROFILE
Patch contributed by Jeremy Cole. CLA received Oct 2006 by Kaj Arnö Add rudimentary query profiling support. libmysqld/Makefile.am: Add profile file to source list. sql/Makefile.am: Add profiling files to source and header lists. sql/ha_archive.cc: Macro-ized other discovered instances of setting proc_info. sql/ha_myisam.cc: Macroize setting thread-state info sql/item_func.cc: Macro-ized other discovered instances of setting proc_info. sql/lex.h: Add lexer info for profiling. sql/lock.cc: Macroize setting thread-state info sql/log_event.cc: Macro-ized other discovered instances of setting proc_info. sql/mysql_priv.h: Set constants for profiling. sql/repl_failsafe.cc: Macro-ized other discovered instances of setting proc_info. sql/slave.cc: Macro-ized other discovered instances of setting proc_info. sql/sp_head.cc: Macro-ized other discovered instances of setting proc_info. sql/sql_base.cc: Macroize setting thread-state info --- Macro-ized other discovered instances of setting proc_info. sql/sql_cache.cc: Macroize setting thread-state info sql/sql_class.cc: Integrate profiling. sql/sql_class.h: Instantiate profiling object. sql/sql_delete.cc: Macroize setting thread-state info sql/sql_insert.cc: Macroize setting thread-state info --- Macro-ized other discovered instances of setting proc_info. sql/sql_lex.cc: Initialize profiling. sql/sql_lex.h: Define lex tokens and allocate space for profiling options. sql/sql_parse.cc: Integrate profiling. --- Macro-ized other discovered instances of setting proc_info. sql/sql_repl.cc: Macro-ized other discovered instances of setting proc_info. sql/sql_select.cc: Macroize setting thread-state info. Clean up some lines. sql/sql_show.cc: Macro-ized other discovered instances of setting proc_info. --- Revert bad use of macro. sql/sql_table.cc: Macroize setting thread-state info sql/sql_update.cc: Macroize setting thread-state info sql/sql_view.cc: Macro-ized other discovered instances of setting proc_info. sql/sql_yacc.yy: Add parser info for profiling. --- Fix new YACC shift/reduce conflict. (Now at 249.) mysql-test/r/profile.result: Test profiling code. --- A not-very-useful result. mysql-test/t/profile.test: Test profiling code. --- Test syntax, but not values of profiles code. sql/sql_profile.cc: Add profiling code. --- Add wishlist comment. sql/sql_profile.h: Add profiling code. --- Changed the value of the macro so that it's syntactically equivalent to a single statement.
Diffstat (limited to 'sql/sql_profile.h')
-rw-r--r--sql/sql_profile.h187
1 files changed, 187 insertions, 0 deletions
diff --git a/sql/sql_profile.h b/sql/sql_profile.h
new file mode 100644
index 00000000000..698a80f07e4
--- /dev/null
+++ b/sql/sql_profile.h
@@ -0,0 +1,187 @@
+/* Copyright (C) 2005 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ 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)
+#else
+#define THD_PROC_INFO(thd, msg) do { (thd)->proc_info= (msg); } while (0)
+#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 */
+ };
+
+#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
+
+class PROFILE_ENTRY;
+class PROFILE;
+class PROFILING;
+
+/*
+ A single entry in a single profile.
+*/
+
+class PROFILE_ENTRY: public Sql_alloc
+{
+public:
+ PROFILE *profile;
+ char *status;
+ ulonglong time;
+ struct rusage rusage;
+
+ char *function;
+ char *file;
+ unsigned int line;
+
+ PROFILE_ENTRY();
+ PROFILE_ENTRY(PROFILE *profile_arg, const char *status_arg);
+ PROFILE_ENTRY(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
+ objects.
+*/
+
+class PROFILE: public Sql_alloc
+{
+public:
+ PROFILING *profiling;
+ query_id_t query_id;
+ PROFILE_ENTRY profile_start;
+ PROFILE_ENTRY *profile_end;
+ List<PROFILE_ENTRY> entries;
+
+ PROFILE(PROFILING *profiling_arg);
+ ~PROFILE();
+
+ /* Add a profile status change to the current profile. */
+ void status(const char *status_arg,
+ const char *function_arg,
+ const char *file_arg, unsigned int line_arg);
+
+ /* Reset the contents of this profile entry. */
+ void reset();
+
+ /* Show this profile. This is called by PROFILING. */
+ bool show(uint options);
+};
+
+/*
+ Profiling state for a single THD. Contains multiple PROFILE objects.
+*/
+
+class PROFILING: public Sql_alloc
+{
+public:
+ MEM_ROOT root;
+ THD *thd;
+ bool enabled;
+ bool keeping;
+
+ PROFILE *current;
+ PROFILE *last;
+ List<PROFILE> history;
+
+ PROFILING();
+ ~PROFILING();
+
+ 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; };
+
+ /*
+ 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= 1; };
+ inline void discard() { keeping= 0; };
+
+ void status(const char *status_arg,
+ const char *function_arg,
+ const char *file_arg, unsigned int line_arg);
+
+ /* Stash this profile in the profile history. */
+ void store();
+
+ /* Reset the current profile and state of profiling for the next query. */
+ void reset();
+
+ /* SHOW PROFILES */
+ bool show_profiles();
+
+ /* SHOW PROFILE FOR QUERY query_id */
+ bool show(uint options, uint query_id);
+
+ /* SHOW PROFILE */
+ bool show_last(uint options);
+};
+
+#endif /* SQL_PROFILE_H */