#At file:///home/malff/BZR-TREE/mysql-6.0-perf/
2695 Marc Alff 2008-10-13
Instrumentation interface (draft), continued
modified:
include/Makefile.am
include/mysql/mysql_mutex.h
include/mysql/psi.h
include/mysql/psi_abi_v1.h.pp
sql/mysqld.cc
sql/sql_class.cc
sql/sql_class.h
storage/perfschema/psm.cc
storage/perfschema/psm.h
storage/perfschema/psm_server.cc
=== modified file 'include/Makefile.am'
--- a/include/Makefile.am 2008-07-24 11:55:49 +0000
+++ b/include/Makefile.am 2008-10-13 20:42:40 +0000
@@ -40,7 +40,8 @@ noinst_HEADERS = config-win.h config-net
atomic/gcc_builtins.h my_libwrap.h my_stacktrace.h \
wqueue.h
-EXTRA_DIST = mysql.h.pp mysql/plugin.h.pp
+EXTRA_DIST = mysql.h.pp mysql/plugin.h.pp \
+ mysql/psi_abi_v1.h.pp mysql/psi_abi_v2.h.pp
# Remove built files and the symlinked directories
CLEANFILES = $(BUILT_SOURCES) readline openssl
=== modified file 'include/mysql/mysql_mutex.h'
--- a/include/mysql/mysql_mutex.h 2008-10-10 20:34:55 +0000
+++ b/include/mysql/mysql_mutex.h 2008-10-13 20:42:40 +0000
@@ -2,6 +2,24 @@
#ifndef MYSQL_MUTEX_H
#define MYSQL_MUTEX_H
+/*
+ Note: there are several orthogonal dimensions here.
+
+ Dimension 1: Instrumentation
+ HAVE_PSI_INTERFACE is defined when the instrumentation is compiled in.
+ This may happen both in debug or production builds.
+
+ Dimension 2: Debug
+ SAFE_MUTEX is defined when debug is compiled in.
+ This may happen both with and without instrumentation.
+
+ Dimention 3: Platform
+ Mutexes are implemented with one of:
+ - the pthread library
+ - fast mutexes
+ - window apis
+*/
+
#ifdef HAVE_PSI_INTERFACE
#include "mysql/psi.h"
extern PSI *PSI_server;
@@ -10,19 +28,34 @@ extern PSI *PSI_server;
#define MYSQL_MUTEX_ASSERT_OWNER(M) safe_mutex_assert_owner(& (M)->m_mutex)
#define MYSQL_MUTEX_ASSERT_NOT_OWNER(M) safe_mutex_assert_not_owner(&
(M)->m_mutex)
+#ifdef HAVE_PSI_INTERFACE
+ #ifdef SAFE_MUTEX
+ #define MYSQL_MUTEX_INIT(M,K,A) mysql_mutex_init(M,K,A,__FILE__,__LINE__)
+ #else
+ #define MYSQL_MUTEX_INIT(M,K,A) mysql_mutex_init(M,K,A)
+ #endif
+ #define MYSQL_RWLOCK_INIT(M,K,A) mysql_rwlock_init(M,K,A)
+ #define MYSQL_COND_INIT(C,K,A) mysql_cond_init(C,K,A)
+#else
+ #ifdef SAFE_MUTEX
+ #define MYSQL_MUTEX_INIT(M,K,A) mysql_mutex_init(M,A,__FILE__,__LINE__)
+ #else
+ #define MYSQL_MUTEX_INIT(M,K,A) mysql_mutex_init(M,A)
+ #endif
+ #define MYSQL_RWLOCK_INIT(M,K,A) mysql_rwlock_init(M,A)
+ #define MYSQL_COND_INIT(C,K,A) mysql_cond_init(C,A)
+#endif
+
#ifdef SAFE_MUTEX
- #define MYSQL_MUTEX_INIT(M,K,A) mysql_mutex_init(M,K,A,__FILE__,__LINE__)
#define MYSQL_MUTEX_DESTROY(M) mysql_mutex_destroy(M,__FILE__,__LINE__)
#define MYSQL_MUTEX_LOCK(M) mysql_mutex_lock(M,__FILE__,__LINE__)
#define MYSQL_MUTEX_UNLOCK(M) mysql_mutex_unlock(M,__FILE__,__LINE__)
#else
- #define MYSQL_MUTEX_INIT(M,K,A) mysql_mutex_init(M,K,A)
#define MYSQL_MUTEX_DESTROY(M) mysql_mutex_destroy(M)
#define MYSQL_MUTEX_LOCK(M) mysql_mutex_lock(M)
#define MYSQL_MUTEX_UNLOCK(M) mysql_mutex_unlock(M)
#endif
-#define MYSQL_RWLOCK_INIT(M,K,A) mysql_rwlock_init(M,K,A)
#define MYSQL_RWLOCK_DESTROY(M) mysql_rwlock_destroy(M)
#define MYSQL_RWLOCK_RDLOCK(M) mysql_rwlock_rdlock(M)
#define MYSQL_RWLOCK_WRLOCK(M) mysql_rwlock_wrlock(M)
@@ -30,20 +63,12 @@ extern PSI *PSI_server;
#define MYSQL_RWLOCK_TRYWRLOCK(M) mysql_rwlock_trywrlock(M)
#define MYSQL_RWLOCK_UNLOCK(M) mysql_rwlock_unlock(M)
-#define MYSQL_COND_INIT(C,K,A) mysql_cond_init(C,K,A)
#define MYSQL_COND_DESTROY(C) mysql_cond_destroy(C)
#define MYSQL_COND_WAIT(C,M) mysql_cond_wait(C,M)
#define MYSQL_COND_TIMEDWAIT(C,M,W) mysql_cond_timedwait(C,M,W)
#define MYSQL_COND_SIGNAL(C) mysql_cond_signal(C)
#define MYSQL_COND_BROADCAST(C) mysql_cond_broadcast(C)
-/*
- Note: there are several orthogonal dimensions here.
- - HAVE_PSI_INTERFACE, flag controlling the performance schema
- instrumentation,
-
- - SAFE_MUTEX, flag controlling internal debugging tools
-*/
struct s_mysql_mutex
{
@@ -103,11 +128,9 @@ static inline int mysql_mutex_lock(
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_locker *locker= NULL;
- struct PSI_thread *thread;
if (PSI_server && that->m_psi)
- if ((thread= PSI_server->get_thread()))
- if ((locker= PSI_server->get_locker(thread)))
- PSI_server->start_wait(locker, that->m_psi, 1);
+ if ((locker= PSI_server->get_thread_locker()))
+ PSI_server->start_wait(locker, that->m_psi, 1);
#endif
#ifdef SAFE_MUTEX
result= safe_mutex_lock(& that->m_mutex, FALSE, file, line);
@@ -181,11 +204,9 @@ static inline int mysql_rwlock_rdlock(
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_locker *locker= NULL;
- struct PSI_thread *thread;
if (PSI_server && that->m_psi)
- if ((thread= PSI_server->get_thread()))
- if ((locker= PSI_server->get_locker(thread)))
- PSI_server->start_rdwait(locker, that->m_psi, 1);
+ if ((locker= PSI_server->get_thread_locker()))
+ PSI_server->start_rdwait(locker, that->m_psi, 1);
#endif
result= rw_rdlock(& that->m_rwlock);
#ifdef HAVE_PSI_INTERFACE
@@ -201,11 +222,9 @@ static inline int mysql_rwlock_wrlock(
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_locker *locker= NULL;
- struct PSI_thread *thread;
if (PSI_server && that->m_psi)
- if ((thread= PSI_server->get_thread()))
- if ((locker= PSI_server->get_locker(thread)))
- PSI_server->start_wrwait(locker, that->m_psi, 1);
+ if ((locker= PSI_server->get_thread_locker()))
+ PSI_server->start_wrwait(locker, that->m_psi, 1);
#endif
result= rw_rdlock(& that->m_rwlock);
#ifdef HAVE_PSI_INTERFACE
@@ -221,11 +240,9 @@ static inline int mysql_rwlock_tryrdlock
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_locker *locker= NULL;
- struct PSI_thread *thread;
if (PSI_server && that->m_psi)
- if ((thread= PSI_server->get_thread()))
- if ((locker= PSI_server->get_locker(thread)))
- PSI_server->start_rdwait(locker, that->m_psi, 0);
+ if ((locker= PSI_server->get_thread_locker()))
+ PSI_server->start_rdwait(locker, that->m_psi, 0);
#endif
result= rw_rdlock(& that->m_rwlock);
#ifdef HAVE_PSI_INTERFACE
@@ -241,11 +258,9 @@ static inline int mysql_rwlock_trywrlock
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_locker *locker= NULL;
- struct PSI_thread *thread;
if (PSI_server && that->m_psi)
- if ((thread= PSI_server->get_thread()))
- if ((locker= PSI_server->get_locker(thread)))
- PSI_server->start_wrwait(locker, that->m_psi, 0);
+ if ((locker= PSI_server->get_thread_locker()))
+ PSI_server->start_wrwait(locker, that->m_psi, 0);
#endif
result= rw_rdlock(& that->m_rwlock);
#ifdef HAVE_PSI_INTERFACE
@@ -309,11 +324,9 @@ static inline int mysql_cond_wait(
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_locker *locker= NULL;
- struct PSI_thread *thread;
if (PSI_server)
- if ((thread= PSI_server->get_thread()))
- if ((locker= PSI_server->get_locker(thread)))
- PSI_server->start_condwait(locker, that->m_psi, 1);
+ if ((locker= PSI_server->get_thread_locker()))
+ PSI_server->start_condwait(locker, that->m_psi, 1);
#endif
result= pthread_cond_wait(& that->m_cond, & mutex->m_mutex);
#ifdef HAVE_PSI_INTERFACE
@@ -331,11 +344,9 @@ static inline int mysql_cond_timedwait(
int result;
#ifdef HAVE_PSI_INTERFACE
struct PSI_locker *locker= NULL;
- struct PSI_thread *thread;
if (PSI_server && that->m_psi)
- if ((thread= PSI_server->get_thread()))
- if ((locker= PSI_server->get_locker(thread)))
- PSI_server->start_condwait(locker, that->m_psi, 0);
+ if ((locker= PSI_server->get_thread_locker()))
+ PSI_server->start_condwait(locker, that->m_psi, 0);
#endif
result= pthread_cond_timedwait(& that->m_cond, & mutex->m_mutex,
abstime);
#ifdef HAVE_PSI_INTERFACE
=== modified file 'include/mysql/psi.h'
--- a/include/mysql/psi.h 2008-10-10 20:34:55 +0000
+++ b/include/mysql/psi.h 2008-10-13 20:42:40 +0000
@@ -52,8 +52,10 @@ struct PSI_v1
struct PSI_thread* (*new_thread)();
struct PSI_thread* (*get_thread)();
+ void (*set_thread)(struct PSI_thread* thread);
void (*delete_thread)(struct PSI_thread *thread);
+ struct PSI_locker* (*get_thread_locker)();
struct PSI_locker* (*get_locker)(struct PSI_thread *thread);
void (*unlock_mutex)(struct PSI_thread *thread, struct PSI_mutex* mutex);
=== modified file 'include/mysql/psi_abi_v1.h.pp'
--- a/include/mysql/psi_abi_v1.h.pp 2008-10-10 20:34:55 +0000
+++ b/include/mysql/psi_abi_v1.h.pp 2008-10-13 20:42:40 +0000
@@ -24,7 +24,9 @@ struct PSI_v1
void (*destroy_cond)(struct PSI_cond* cond, void *identity);
struct PSI_thread* (*new_thread)();
struct PSI_thread* (*get_thread)();
+ void (*set_thread)(struct PSI_thread* thread);
void (*delete_thread)(struct PSI_thread *thread);
+ struct PSI_locker* (*get_thread_locker)();
struct PSI_locker* (*get_locker)(struct PSI_thread *thread);
void (*unlock_mutex)(struct PSI_thread *thread, struct PSI_mutex* mutex);
void (*unlock_rwlock)(struct PSI_thread *thread, struct PSI_rwlock* rwlock);
=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc 2008-10-10 20:34:55 +0000
+++ b/sql/mysqld.cc 2008-10-13 20:42:40 +0000
@@ -29,6 +29,10 @@
#include "ddl_blocker.h"
#include "sql_audit.h"
+#ifdef HAVE_PERFORMANCE_SCHEMA
+#include "../storage/perfschema/psm_server.h"
+#endif
+
#include "../storage/myisam/ha_myisam.h"
#include "rpl_injector.h"
@@ -4430,6 +4434,9 @@ void decrement_handler_count()
#define decrement_handler_count()
#endif /* defined(__NT__) || defined(HAVE_SMEM) */
+#ifdef HAVE_PSI_INTERFACE
+static void init_psi_server_keys();
+#endif
#ifndef EMBEDDED_LIBRARY
#ifdef __WIN__
@@ -4441,6 +4448,16 @@ int main(int argc, char **argv)
MY_INIT(argv[0]); // init my_sys library & pthreads
/* nothing should come before this line ^^^ */
+#ifdef HAVE_PERFORMANCE_SCHEMA
+ PSI_hook= initialize_performance_schema();
+#endif
+
+#ifdef HAVE_PSI_INTERFACE
+ if (PSI_hook)
+ PSI_server= (PSI*) PSI_hook->get_PSI(PSI_CURRENT_VERSION);
+ init_psi_server_keys();
+#endif
+
/* Set signal used to kill MySQL */
#if defined(SIGUSR2)
thr_kill_signal= thd_lib_detected == THD_LIB_LT ? SIGINT : SIGUSR2;
@@ -9065,18 +9082,14 @@ PSI_cond_key key_COND_thread_cache;
PSI_cond_key key_COND_flush_thread_cache;
PSI_mutex_key key_LOCK_rpl_status;
PSI_cond_key key_COND_rpl_status;
-
PSI_mutex_key key_LOCK_delete;
PSI_mutex_key key_hash_filo_lock;
PSI_mutex_key key_LOCK_ha_data;
-
PSI_mutex_key key_LOG_LOCK_log;
-
PSI_mutex_key key_BINLOG_LOCK_index;
PSI_mutex_key key_BINLOG_LOCK_prep_xids;
PSI_cond_key key_BINLOG_COND_prep_xids;
PSI_cond_key key_BINLOG_update_cond;
-
PSI_mutex_key key_LOCK_logger;
PSI_mutex_key key_LOG_INFO_lock;
PSI_mutex_key key_LOCK_backupid;
@@ -9113,8 +9126,6 @@ PSI_cond_key key_COND_caller_wait;
PSI_mutex_key key_BRC_run_lock;
PSI_mutex_key key_NDB_SHARE_mutex;
-
-
#ifdef HAVE_OPENSSL
PSI_mutex_key key_LOCK_des_key_file;
#endif
@@ -9131,12 +9142,124 @@ PSI_cond_key key_COND_pool;
void init_psi_server_keys()
{
-}
-
-#endif
+ PSI_mutex_key (*reg_mutex)(const char* name, int global);
+ PSI_rwlock_key (*reg_rwlock)(const char* name, int global);
+ PSI_cond_key (*reg_cond)(const char* name, int global);
+ int global= 1;
+ int multiple= 0;
+ if (PSI_server == NULL)
+ return;
+ reg_mutex= PSI_server->register_mutex;
+ reg_rwlock= PSI_server->register_rwlock;
+ reg_cond= PSI_server->register_cond;
+
+ /* ALL MUTEXES */
+ key_LOCK_mysql_create_db= (*reg_mutex)("LOCK_mysql_create_db", global);
+ key_LOCK_Acl= (*reg_mutex)("LOCK_Acl", global);
+ key_LOCK_open= (*reg_mutex)("LOCK_open", global);
+ key_LOCK_lock_db= (*reg_mutex)("LOCK_lock_db", global);
+ key_LOCK_thread_count= (*reg_mutex)("LOCK_thread_count", global);
+ key_LOCK_mapped_file= (*reg_mutex)("LOCK_mapped_file", global);
+ key_LOCK_status= (*reg_mutex)("LOCK_status", global);
+ key_LOCK_error_log= (*reg_mutex)("LOCK_error_log", global);
+ key_LOCK_delayed_insert= (*reg_mutex)("LOCK_delayed_insert", global);
+ key_LOCK_uuid_short= (*reg_mutex)("LOCK_uuid_short", global);
+ key_LOCK_delayed_status= (*reg_mutex)("LOCK_delayed_status", global);
+ key_LOCK_delayed_create= (*reg_mutex)("LOCK_delayed_create", global);
+ key_LOCK_crypt= (*reg_mutex)("LOCK_crypt", global);
+ key_LOCK_timezone= (*reg_mutex)("LOCK_timezone", global);
+ key_LOCK_slave_list= (*reg_mutex)("LOCK_slave_list", global);
+ key_LOCK_active_mi= (*reg_mutex)("LOCK_active_mi", global);
+ key_LOCK_manager= (*reg_mutex)("LOCK_manager", global);
+ key_LOCK_global_read_lock= (*reg_mutex)("LOCK_global_read_lock", global);
+ key_LOCK_global_system_variables= (*reg_mutex)("LOCK_global_system_variables", global);
+ key_LOCK_user_conn= (*reg_mutex)("LOCK_user_conn", global);
+ key_LOCK_prepared_stmt_count= (*reg_mutex)("LOCK_prepared_stmt_count", global);
+ key_LOCK_bytes_sent= (*reg_mutex)("LOCK_bytes_sent", global);
+ key_LOCK_bytes_received= (*reg_mutex)("LOCK_bytes_received", global);
+ key_LOCK_connection_count= (*reg_mutex)("LOCK_connection_count", global);
+ key_LOCK_server_started= (*reg_mutex)("LOCK_server_started", global);
+ key_LOCK_rpl_status= (*reg_mutex)("LOCK_rpl_status", global);
+ key_LOCK_delete= (*reg_mutex)("LOCK_delete", global);
+ key_hash_filo_lock= (*reg_mutex)("hash_filo_lock", global);
+ key_LOCK_ha_data= (*reg_mutex)("LOCK_ha_data", global);
+ key_LOG_LOCK_log= (*reg_mutex)("MYSQL_LOG::LOCK_log", global);
+ key_BINLOG_LOCK_index= (*reg_mutex)("MYSQL_BIN_LOG::LOCK_index", global);
+ key_BINLOG_LOCK_prep_xids= (*reg_mutex)("MYSQL_BIN_LOG::LOCK_prep_xids", global);
+ key_LOCK_logger= (*reg_mutex)("LOCK_logger", global);
+ key_LOG_INFO_lock= (*reg_mutex)("LOG_INFO_lock", global);
+ key_LOCK_backupid= (*reg_mutex)("LOCK_backupid", global);
+ key_structure_guard_mutex= (*reg_mutex)("Query_cache::guard", global);
+ key_RLI_run_lock= (*reg_mutex)("Relay_log_info::run_lock", global);
+ key_RLI_data_lock= (*reg_mutex)("Relay_log_info::data_lock", global);
+ key_RLI_log_space_lock= (*reg_mutex)("Relay_log_info::log_space_lock", global);
+ key_MI_run_lock= (*reg_mutex)("Master_info::run_lock", global);
+ key_MI_data_lock= (*reg_mutex)("Master_info::data_lock", global);
+ key_LOCK_event_metadata= (*reg_mutex)("LOCK_event_metadata", global);
+ key_LOCK_event_queue= (*reg_mutex)("LOCK_event_queue", global);
+ key_LOCK_scheduler_state= (*reg_mutex)("LOCK_scheduler_state", global);
+ key_THR_LOCK_DDL_blocker= (*reg_mutex)("THR_LOCK_DDL_blocker", global);
+ key_THR_LOCK_DDL_is_blocked= (*reg_mutex)("THR_LOCK_DDL_is_blocked", global);
+ key_THR_LOCK_DDL_blocker_blocked= (*reg_mutex)("THR_LOCK_DDL_blocker_blocked", global);
+ key_THR_LOCK_thread= (*reg_mutex)("THR_LOCK_thread", global);
+ key_THR_LOCK_caller= (*reg_mutex)("THR_LOCK_caller", global);
+ key_BRC_run_lock= (*reg_mutex)("Backup_restore_ctx::run_lock", global);
+ key_NDB_SHARE_mutex= (*reg_mutex)("NDB_SHARE::mutex", global);
+#ifdef HAVE_OPENSSL
+ key_LOCK_des_key_file= (*reg_mutex)("LOCK_des_key_file", global);
+#endif
+#ifdef HAVE_MMAP
+ key_PAGE_lock= (*reg_mutex)("PAGE::lock", global);
+ key_LOCK_sync= (*reg_mutex)("LOCK_sync", global);
+ key_LOCK_active= (*reg_mutex)("LOCK_active", global);
+ key_LOCK_pool= (*reg_mutex)("LOCK_pool", global);
+#endif
+
+ /* ALL RWLOCKS */
+
+ key_LOCK_grant= (*reg_rwlock)("LOCK_grant", global);
+ key_LOCK_sys_init_connect= (*reg_rwlock)("LOCK_sys_init_connect", global);
+ key_LOCK_sys_init_slave= (*reg_rwlock)("LOCK_sys_init_slave", global);
+ key_LOCK_system_variables_hash= (*reg_rwlock)("LOCK_system_variables_hash", global);
+ key_QCQ_lock= (*reg_rwlock)("Query_cache_query::lock", global);
+
+ /* ALL CONDITIONS */
+
+ key_COND_server_started= (*reg_cond)("COND_server_started", global);
+ key_COND_refresh= (*reg_cond)("COND_refresh", global);
+ key_COND_thread_count= (*reg_cond)("COND_thread_count", global);
+ key_COND_manager= (*reg_cond)("COND_manager", global);
+ key_COND_global_read_lock= (*reg_cond)("COND_global_read_lock", global);
+ key_COND_thread_cache= (*reg_cond)("COND_thread_cache", global);
+ key_COND_flush_thread_cache= (*reg_cond)("COND_flush_thread_cache", global);
+ key_COND_rpl_status= (*reg_cond)("COND_rpl_status", global);
+ key_BINLOG_COND_prep_xids= (*reg_cond)("BINLOG::COND_prep_xids", global);
+ key_BINLOG_update_cond= (*reg_cond)("BINLOG::update_cond", global);
+ key_COND_cache_status_changed= (*reg_cond)("COND_cache_status_changed", global);
+ key_RLI_data_cond= (*reg_cond)("Relay_log_info::data_cond", global);
+ key_RLI_start_cond= (*reg_cond)("Relay_log_info::start_cond", global);
+ key_RLI_stop_cond= (*reg_cond)("Relay_log_info::stop_cond", global);
+ key_RLI_log_space_cond= (*reg_cond)("Relay_log_info::log_space_cond", global);
+ key_MI_data_cond= (*reg_cond)("Master_info::data_cond", global);
+ key_MI_start_cond= (*reg_cond)("Master_info::start_cond", global);
+ key_MI_stop_cond= (*reg_cond)("Master_info::stop_cond", global);
+ key_Event_scheduler_COND_state= (*reg_cond)("Event_scheduler::COND_state", global);
+ key_COND_queue_state= (*reg_cond)("COND_queue_state", global);
+ key_COND_DDL_blocker= (*reg_cond)("COND_DDL_blocker", global);
+ key_COND_process_blocked= (*reg_cond)("COND_process_blocked", global);
+ key_COND_DDL_blocker_blocked= (*reg_cond)("COND_DDL_blocker_blocked", global);
+ key_COND_thread_wait= (*reg_cond)("COND_thread_wait", global);
+ key_COND_caller_wait= (*reg_cond)("COND_caller_wait", global);
+#ifdef HAVE_MMAP
+ key_PAGE_cond= (*reg_cond)("PAGE::cond", global);
+ key_COND_active= (*reg_cond)("COND_active", global);
+ key_COND_pool= (*reg_cond)("COND_pool", global);
+#endif
+}
+#endif
=== modified file 'sql/sql_class.cc'
--- a/sql/sql_class.cc 2008-10-10 20:34:55 +0000
+++ b/sql/sql_class.cc 2008-10-13 20:42:40 +0000
@@ -546,6 +546,10 @@ THD::THD()
{
ulong tmp;
+#ifdef HAVE_PSI_INTERFACE
+ m_psi= (PSI_server ? PSI_server->new_thread() : NULL);
+#endif
+
/*
Pass nominal parameters to init_alloc_root only to ensure that
the destructor works OK in case of an error. The main_mem_root
@@ -958,6 +962,12 @@ THD::~THD()
#endif
free_root(&main_mem_root, MYF(0));
+
+#ifdef HAVE_PSI_INTERFACE
+ if (PSI_server)
+ PSI_server->delete_thread(m_psi);
+#endif
+
DBUG_VOID_RETURN;
}
@@ -1092,6 +1102,11 @@ bool THD::store_globals()
*/
DBUG_ASSERT(thread_stack);
+#ifdef HAVE_PSI_INTERFACE
+ if (PSI_server)
+ PSI_server->set_thread(m_psi);
+#endif
+
if (my_pthread_setspecific_ptr(THR_THD, this) ||
my_pthread_setspecific_ptr(THR_MALLOC, &mem_root))
return 1;
=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h 2008-10-10 20:34:55 +0000
+++ b/sql/sql_class.h 2008-10-13 20:42:40 +0000
@@ -2385,6 +2385,11 @@ private:
tree itself is reused between executions and thus is stored elsewhere.
*/
MEM_ROOT main_mem_root;
+
+#ifdef HAVE_PSI_INTERFACE
+public:
+ PSI_thread *m_psi;
+#endif
};
=== modified file 'storage/perfschema/psm.cc'
--- a/storage/perfschema/psm.cc 2008-10-10 20:34:55 +0000
+++ b/storage/perfschema/psm.cc 2008-10-13 20:42:40 +0000
@@ -1,25 +1,31 @@
#include "psm.h"
+pthread_key(PSM_thread*, THR_PSM);
static PSI_mutex_key register_mutex_v1(const char* name, int global)
{
+ fprintf(stderr, "MUTEX: %s\n", name);
return 0;
}
static PSI_rwlock_key register_rwlock_v1(const char* name, int global)
{
+ fprintf(stderr, "RWLOCK: %s\n", name);
return 0;
}
static PSI_cond_key register_cond_v1(const char* name, int global)
{
+ fprintf(stderr, "COND: %s\n", name);
return 0;
}
static PSI_mutex* init_mutex_v1(PSI_mutex_key key, void *identity)
{
- return 0;
+ static PSM_mutex dummy;
+ PSM_mutex *psm= & dummy;
+ return (PSI_mutex*) psm;
}
static void destroy_mutex_v1(PSI_mutex* mutex, void *identity)
@@ -28,7 +34,9 @@ static void destroy_mutex_v1(PSI_mutex*
static PSI_rwlock* init_rwlock_v1(PSI_rwlock_key key, void *identity)
{
- return 0;
+ static PSM_rwlock dummy;
+ PSM_rwlock *psm= & dummy;
+ return (PSI_rwlock*) psm;
}
static void destroy_rwlock_v1(PSI_rwlock* rwlock, void *identity)
@@ -37,7 +45,9 @@ static void destroy_rwlock_v1(PSI_rwlock
static PSI_cond* init_cond_v1(PSI_cond_key key, void *identity)
{
- return 0;
+ static PSM_cond dummy;
+ PSM_cond *psm= & dummy;
+ return (PSI_cond*) psm;
}
static void destroy_cond_v1(PSI_cond* cond, void *identity)
@@ -46,21 +56,43 @@ static void destroy_cond_v1(PSI_cond* co
static PSI_thread* new_thread_v1()
{
- return 0;
+ static PSM_thread dummy;
+ PSM_thread *psm= & dummy;
+
+ my_pthread_setspecific_ptr(THR_PSM, psm);
+ return (PSI_thread*) psm;
}
static PSI_thread* get_thread_v1()
{
- return 0;
+ PSM_thread *psm;
+ psm= my_pthread_getspecific_ptr(PSM_thread*, THR_PSM);
+ return (PSI_thread*) psm;
+}
+
+static void set_thread_v1(struct PSI_thread* thread)
+{
+ PSM_thread *psm= (PSM_thread*) thread;
+ my_pthread_setspecific_ptr(THR_PSM, psm);
}
static void delete_thread_v1(PSI_thread *thread)
{
+ my_pthread_setspecific_ptr(THR_PSM, NULL);
+}
+
+static PSI_locker* get_thread_locker_v1()
+{
+ PSM_locker dummy;
+ PSM_locker *psm= & dummy;
+ return (PSI_locker*) psm;
}
static PSI_locker* get_locker_v1(PSI_thread *thread)
{
- return 0;
+ PSM_locker dummy;
+ PSM_locker *psm= & dummy;
+ return (PSI_locker*) psm;
}
static void unlock_mutex_v1(PSI_thread *thread, PSI_mutex* mutex)
@@ -124,7 +156,9 @@ struct PSI_v1 PSM_v1=
destroy_cond_v1,
new_thread_v1,
get_thread_v1,
+ set_thread_v1,
delete_thread_v1,
+ get_thread_locker_v1,
get_locker_v1,
unlock_mutex_v1,
unlock_rwlock_v1,
=== modified file 'storage/perfschema/psm.h'
--- a/storage/perfschema/psm.h 2008-10-10 20:34:55 +0000
+++ b/storage/perfschema/psm.h 2008-10-13 20:42:40 +0000
@@ -10,5 +10,33 @@
extern struct PSI_v1 PSM_v1;
extern struct PSI_v2 PSM_v2;
+struct PSM_mutex
+{
+ int todo;
+};
+
+struct PSM_rwlock
+{
+ int todo;
+};
+
+struct PSM_cond
+{
+ int todo;
+};
+
+struct PSM_thread
+{
+ int todo;
+};
+
+struct PSM_locker
+{
+ int todo;
+};
+
+#include "mysql_priv.h"
+extern pthread_key(PSM_thread*, THR_PSM);
+
#endif
=== modified file 'storage/perfschema/psm_server.cc'
--- a/storage/perfschema/psm_server.cc 2008-10-10 20:34:55 +0000
+++ b/storage/perfschema/psm_server.cc 2008-10-13 20:42:40 +0000
@@ -18,6 +18,9 @@ struct PSI_bootstrap PSM_boostrap=
struct PSI_bootstrap* initialize_performance_schema()
{
+ if (pthread_key_create(&THR_PSM, NULL))
+ return NULL;
+
return & PSM_boostrap;
}
| Thread |
|---|
| • bzr commit into mysql-6.0-perf branch (marc.alff:2695) | Marc Alff | 13 Oct |