summaryrefslogtreecommitdiff
path: root/storage/perfschema/pfs_instr_class.h
diff options
context:
space:
mode:
Diffstat (limited to 'storage/perfschema/pfs_instr_class.h')
-rw-r--r--storage/perfschema/pfs_instr_class.h327
1 files changed, 282 insertions, 45 deletions
diff --git a/storage/perfschema/pfs_instr_class.h b/storage/perfschema/pfs_instr_class.h
index b84691ccde5..bef25e76467 100644
--- a/storage/perfschema/pfs_instr_class.h
+++ b/storage/perfschema/pfs_instr_class.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
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
@@ -39,9 +39,13 @@
#define PFS_MAX_FULL_PREFIX_NAME_LENGTH 32
#include <my_global.h>
+#include <my_sys.h>
#include <mysql/psi/psi.h>
#include "pfs_lock.h"
#include "pfs_stat.h"
+#include "pfs_column_types.h"
+
+struct PFS_global_param;
/**
@addtogroup Performance_schema_buffers
@@ -49,6 +53,7 @@
*/
extern my_bool pfs_enabled;
+extern enum_timer_name *class_timers[];
/** Key, naming a synch instrument (mutex, rwlock, cond). */
typedef unsigned int PFS_sync_key;
@@ -56,55 +61,143 @@ typedef unsigned int PFS_sync_key;
typedef unsigned int PFS_thread_key;
/** Key, naming a file instrument. */
typedef unsigned int PFS_file_key;
+/** Key, naming a stage instrument. */
+typedef unsigned int PFS_stage_key;
+/** Key, naming a statement instrument. */
+typedef unsigned int PFS_statement_key;
+/** Key, naming a socket instrument. */
+typedef unsigned int PFS_socket_key;
+
+enum PFS_class_type
+{
+ PFS_CLASS_NONE= 0,
+ PFS_CLASS_MUTEX= 1,
+ PFS_CLASS_RWLOCK= 2,
+ PFS_CLASS_COND= 3,
+ PFS_CLASS_FILE= 4,
+ PFS_CLASS_TABLE= 5,
+ PFS_CLASS_STAGE= 6,
+ PFS_CLASS_STATEMENT= 7,
+ PFS_CLASS_SOCKET= 8,
+ PFS_CLASS_TABLE_IO= 9,
+ PFS_CLASS_TABLE_LOCK= 10,
+ PFS_CLASS_IDLE= 11,
+ PFS_CLASS_LAST= PFS_CLASS_IDLE,
+ PFS_CLASS_MAX= PFS_CLASS_LAST + 1
+};
+
+/** User-defined instrument configuration. */
+struct PFS_instr_config
+{
+ /* Instrument name. */
+ char *m_name;
+ /* Name length. */
+ uint m_name_length;
+ /** Enabled flag. */
+ bool m_enabled;
+ /** Timed flag. */
+ bool m_timed;
+};
+
+extern DYNAMIC_ARRAY pfs_instr_config_array;
+extern int pfs_instr_config_state;
+
+static const int PFS_INSTR_CONFIG_NOT_INITIALIZED= 0;
+static const int PFS_INSTR_CONFIG_ALLOCATED= 1;
+static const int PFS_INSTR_CONFIG_DEALLOCATED= 2;
struct PFS_thread;
+extern uint mutex_class_start;
+extern uint rwlock_class_start;
+extern uint cond_class_start;
+extern uint file_class_start;
+extern uint table_class_start;
+extern uint socket_class_start;
+extern uint wait_class_max;
+
/** Information for all instrumentation. */
struct PFS_instr_class
{
- /** Instrument name. */
- char m_name[PFS_MAX_INFO_NAME_LENGTH];
- /** Length in bytes of @c m_name. */
- uint m_name_length;
- /** Instrument flags. */
- int m_flags;
+ /** Class type */
+ PFS_class_type m_type;
/** True if this instrument is enabled. */
bool m_enabled;
/** True if this instrument is timed. */
bool m_timed;
- /** Wait statistics chain. */
- PFS_single_stat_chain m_wait_stat;
+ /** Instrument flags. */
+ int m_flags;
+ /**
+ Instrument name index.
+ Self index in:
+ - EVENTS_WAITS_SUMMARY_*_BY_EVENT_NAME for waits
+ - EVENTS_STAGES_SUMMARY_*_BY_EVENT_NAME for stages
+ - EVENTS_STATEMENTS_SUMMARY_*_BY_EVENT_NAME for statements
+ */
+ uint m_event_name_index;
+ /** Instrument name. */
+ char m_name[PFS_MAX_INFO_NAME_LENGTH];
+ /** Length in bytes of @c m_name. */
+ uint m_name_length;
+ /** Timer associated with this class. */
+ enum_timer_name *m_timer;
+
+ bool is_singleton() const
+ {
+ return m_flags & PSI_FLAG_GLOBAL;
+ }
+ static void set_enabled(PFS_instr_class *pfs, bool enabled);
+ static void set_timed(PFS_instr_class *pfs, bool timed);
+
+ bool is_deferred() const
+ {
+ switch(m_type)
+ {
+ case PFS_CLASS_SOCKET:
+ return true;
+ break;
+ default:
+ return false;
+ break;
+ };
+ }
};
+struct PFS_mutex;
+
/** Instrumentation metadata for a MUTEX. */
struct PFS_mutex_class : public PFS_instr_class
{
/**
- Lock statistics chain.
+ Lock statistics.
This statistic is not exposed in user visible tables yet.
*/
- PFS_single_stat_chain m_lock_stat;
- /** Self index in @c mutex_class_array. */
- uint m_index;
+ PFS_single_stat m_lock_stat;
+ /** Singleton instance. */
+ PFS_mutex *m_singleton;
};
+struct PFS_rwlock;
+
/** Instrumentation metadata for a RWLOCK. */
struct PFS_rwlock_class : public PFS_instr_class
{
/**
- Read lock statistics chain.
+ Read lock statistics.
This statistic is not exposed in user visible tables yet.
*/
- PFS_single_stat_chain m_read_lock_stat;
+ PFS_single_stat m_read_lock_stat;
/**
- Write lock statistics chain.
+ Write lock statistics.
This statistic is not exposed in user visible tables yet.
*/
- PFS_single_stat_chain m_write_lock_stat;
- /** Self index in @c rwlock_class_array. */
- uint m_index;
+ PFS_single_stat m_write_lock_stat;
+ /** Singleton instance. */
+ PFS_rwlock *m_singleton;
};
+struct PFS_cond;
+
/** Instrumentation metadata for a COND. */
struct PFS_cond_class : public PFS_instr_class
{
@@ -113,19 +206,21 @@ struct PFS_cond_class : public PFS_instr_class
This statistic is not exposed in user visible tables yet.
*/
PFS_cond_stat m_cond_stat;
- /** Self index in @c cond_class_array. */
- uint m_index;
+ /** Singleton instance. */
+ PFS_cond *m_singleton;
};
/** Instrumentation metadata of a thread. */
struct PFS_thread_class
{
+ /** True if this thread instrument is enabled. */
+ bool m_enabled;
+ /** Singleton instance. */
+ PFS_thread *m_singleton;
/** Thread instrument name. */
char m_name[PFS_MAX_INFO_NAME_LENGTH];
/** Length in bytes of @c m_name. */
uint m_name_length;
- /** True if this thread instrument is enabled. */
- bool m_enabled;
};
#define PFS_TABLESHARE_HASHKEY_SIZE (NAME_LEN + 1 + NAME_LEN + 1)
@@ -136,7 +231,7 @@ struct PFS_table_share_key
/**
Hash search key.
This has to be a string for LF_HASH,
- the format is "<schema_name><0x00><object_name><0x00>"
+ the format is "<enum_object_type><schema_name><0x00><object_name><0x00>"
@see create_table_def_key
*/
char m_hash_key[PFS_TABLESHARE_HASHKEY_SIZE];
@@ -144,11 +239,70 @@ struct PFS_table_share_key
uint m_key_length;
};
+/** Table index or 'key' */
+struct PFS_table_key
+{
+ /** Index name */
+ char m_name[NAME_LEN];
+ /** Length in bytes of @c m_name. */
+ uint m_name_length;
+};
+
/** Instrumentation metadata for a table share. */
struct PFS_table_share
{
+public:
+ uint32 get_version()
+ { return m_lock.get_version(); }
+
+ enum_object_type get_object_type()
+ {
+ return (enum_object_type) m_key.m_hash_key[0];
+ }
+
+ void aggregate_io(void);
+ void aggregate_lock(void);
+
+ inline void aggregate(void)
+ {
+ aggregate_io();
+ aggregate_lock();
+ }
+
+ inline void init_refcount(void)
+ {
+ PFS_atomic::store_32(& m_refcount, 1);
+ }
+
+ inline int get_refcount(void)
+ {
+ return PFS_atomic::load_32(& m_refcount);
+ }
+
+ inline void inc_refcount(void)
+ {
+ PFS_atomic::add_32(& m_refcount, 1);
+ }
+
+ inline void dec_refcount(void)
+ {
+ PFS_atomic::add_32(& m_refcount, -1);
+ }
+
+ void refresh_setup_object_flags(PFS_thread *thread);
+
/** Internal lock. */
pfs_lock m_lock;
+ /**
+ True if table instrumentation is enabled.
+ This flag is computed from the content of table setup_objects.
+ */
+ bool m_enabled;
+ /**
+ True if table instrumentation is timed.
+ This flag is computed from the content of table setup_objects.
+ */
+ bool m_timed;
/** Search key. */
PFS_table_share_key m_key;
/** Schema name. */
@@ -159,32 +313,73 @@ struct PFS_table_share
const char *m_table_name;
/** Length in bytes of @c m_table_name. */
uint m_table_name_length;
- /** Wait statistics chain. */
- PFS_single_stat_chain m_wait_stat;
- /** True if this table instrument is enabled. */
- bool m_enabled;
- /** True if this table instrument is timed. */
- bool m_timed;
- /** True if this table instrument is aggregated. */
- bool m_aggregated;
+ /** Number of indexes. */
+ uint m_key_count;
+ /** Table statistics. */
+ PFS_table_stat m_table_stat;
+ /** Index names. */
+ PFS_table_key m_keys[MAX_KEY];
+
+private:
+ /** Number of opened table handles. */
+ int m_refcount;
};
/**
- Instrument controlling all tables.
- This instrument is used as a default when there is no
- entry present in SETUP_OBJECTS.
+ Instrument controlling all table io.
+ This instrument is used with table SETUP_OBJECTS.
*/
-extern PFS_instr_class global_table_class;
+extern PFS_instr_class global_table_io_class;
+
+/**
+ Instrument controlling all table lock.
+ This instrument is used with table SETUP_OBJECTS.
+*/
+extern PFS_instr_class global_table_lock_class;
+
+/**
+ Instrument controlling all idle waits.
+*/
+extern PFS_instr_class global_idle_class;
+
+struct PFS_file;
/** Instrumentation metadata for a file. */
struct PFS_file_class : public PFS_instr_class
{
/** File usage statistics. */
PFS_file_stat m_file_stat;
- /** Self index in @c file_class_array. */
- uint m_index;
+ /** Singleton instance. */
+ PFS_file *m_singleton;
};
+/** Instrumentation metadata for a stage. */
+struct PFS_stage_class : public PFS_instr_class
+{
+ /** Stage usage statistics. */
+ PFS_stage_stat m_stage_stat;
+};
+
+/** Instrumentation metadata for a statement. */
+struct PFS_statement_class : public PFS_instr_class
+{
+};
+
+struct PFS_socket;
+
+/** Instrumentation metadata for a socket. */
+struct PFS_socket_class : public PFS_instr_class
+{
+ /** Socket usage statistics. */
+ PFS_socket_stat m_socket_stat;
+ /** Singleton instance. */
+ PFS_socket *m_singleton;
+};
+
+void init_event_name_sizing(const PFS_global_param *param);
+
+void register_global_classes();
+
int init_sync_class(uint mutex_class_sizing,
uint rwlock_class_sizing,
uint cond_class_sizing);
@@ -198,6 +393,12 @@ int init_table_share_hash();
void cleanup_table_share_hash();
int init_file_class(uint file_class_sizing);
void cleanup_file_class();
+int init_stage_class(uint stage_class_sizing);
+void cleanup_stage_class();
+int init_statement_class(uint statement_class_sizing);
+void cleanup_statement_class();
+int init_socket_class(uint socket_class_sizing);
+void cleanup_socket_class();
PFS_sync_key register_mutex_class(const char *name, uint name_length,
int flags);
@@ -214,6 +415,15 @@ PFS_thread_key register_thread_class(const char *name, uint name_length,
PFS_file_key register_file_class(const char *name, uint name_length,
int flags);
+PFS_stage_key register_stage_class(const char *name, uint name_length,
+ int flags);
+
+PFS_statement_key register_statement_class(const char *name, uint name_length,
+ int flags);
+
+PFS_socket_key register_socket_class(const char *name, uint name_length,
+ int flags);
+
PFS_mutex_class *find_mutex_class(PSI_mutex_key key);
PFS_mutex_class *sanitize_mutex_class(PFS_mutex_class *unsafe);
PFS_rwlock_class *find_rwlock_class(PSI_rwlock_key key);
@@ -224,14 +434,25 @@ PFS_thread_class *find_thread_class(PSI_thread_key key);
PFS_thread_class *sanitize_thread_class(PFS_thread_class *unsafe);
PFS_file_class *find_file_class(PSI_file_key key);
PFS_file_class *sanitize_file_class(PFS_file_class *unsafe);
-const char *sanitize_table_schema_name(const char *unsafe);
-const char *sanitize_table_object_name(const char *unsafe);
+PFS_stage_class *find_stage_class(PSI_stage_key key);
+PFS_stage_class *sanitize_stage_class(PFS_stage_class *unsafe);
+PFS_statement_class *find_statement_class(PSI_statement_key key);
+PFS_statement_class *sanitize_statement_class(PFS_statement_class *unsafe);
+PFS_instr_class *find_table_class(uint index);
+PFS_instr_class *sanitize_table_class(PFS_instr_class *unsafe);
+PFS_socket_class *find_socket_class(PSI_socket_key key);
+PFS_socket_class *sanitize_socket_class(PFS_socket_class *unsafe);
+PFS_instr_class *find_idle_class(uint index);
+PFS_instr_class *sanitize_idle_class(PFS_instr_class *unsafe);
PFS_table_share *find_or_create_table_share(PFS_thread *thread,
- const char *schema_name,
- uint schema_name_length,
- const char *table_name,
- uint table_name_length);
+ bool temporary,
+ const TABLE_SHARE *share);
+void release_table_share(PFS_table_share *pfs);
+void drop_table_share(PFS_thread *thread,
+ bool temporary,
+ const char *schema_name, uint schema_name_length,
+ const char *table_name, uint table_name_length);
PFS_table_share *sanitize_table_share(PFS_table_share *unsafe);
@@ -245,12 +466,28 @@ extern ulong thread_class_max;
extern ulong thread_class_lost;
extern ulong file_class_max;
extern ulong file_class_lost;
+extern ulong stage_class_max;
+extern ulong stage_class_lost;
+extern ulong statement_class_max;
+extern ulong statement_class_lost;
+extern ulong socket_class_max;
+extern ulong socket_class_lost;
extern ulong table_share_max;
extern ulong table_share_lost;
+
+/* Exposing the data directly, for iterators. */
+
+extern PFS_mutex_class *mutex_class_array;
+extern PFS_rwlock_class *rwlock_class_array;
+extern PFS_cond_class *cond_class_array;
+extern PFS_file_class *file_class_array;
extern PFS_table_share *table_share_array;
-void reset_instrument_class_waits();
void reset_file_class_io();
+void reset_socket_class_io();
+
+/** Update derived flags for all table shares. */
+void update_table_share_derived_flags(PFS_thread *thread);
/** @} */
#endif