mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
WL#2360 Performance schema
Part IV: sql instrumentation
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
|
||||
/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
|
||||
|
||||
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
|
||||
@ -341,18 +341,14 @@ TODO list:
|
||||
#endif
|
||||
|
||||
#if !defined(EXTRA_DBUG) && !defined(DBUG_OFF)
|
||||
#define MUTEX_LOCK(M) { DBUG_PRINT("lock", ("mutex lock 0x%lx", (ulong)(M))); \
|
||||
pthread_mutex_lock(M);}
|
||||
#define MUTEX_UNLOCK(M) {DBUG_PRINT("lock", ("mutex unlock 0x%lx",\
|
||||
(ulong)(M))); pthread_mutex_unlock(M);}
|
||||
#define RW_WLOCK(M) {DBUG_PRINT("lock", ("rwlock wlock 0x%lx",(ulong)(M))); \
|
||||
if (!rw_wrlock(M)) DBUG_PRINT("lock", ("rwlock wlock ok")); \
|
||||
if (!mysql_rwlock_wrlock(M)) DBUG_PRINT("lock", ("rwlock wlock ok")); \
|
||||
else DBUG_PRINT("lock", ("rwlock wlock FAILED %d", errno)); }
|
||||
#define RW_RLOCK(M) {DBUG_PRINT("lock", ("rwlock rlock 0x%lx", (ulong)(M))); \
|
||||
if (!rw_rdlock(M)) DBUG_PRINT("lock", ("rwlock rlock ok")); \
|
||||
if (!mysql_rwlock_rdlock(M)) DBUG_PRINT("lock", ("rwlock rlock ok")); \
|
||||
else DBUG_PRINT("lock", ("rwlock wlock FAILED %d", errno)); }
|
||||
#define RW_UNLOCK(M) {DBUG_PRINT("lock", ("rwlock unlock 0x%lx",(ulong)(M))); \
|
||||
if (!rw_unlock(M)) DBUG_PRINT("lock", ("rwlock unlock ok")); \
|
||||
if (!mysql_rwlock_unlock(M)) DBUG_PRINT("lock", ("rwlock unlock ok")); \
|
||||
else DBUG_PRINT("lock", ("rwlock unlock FAILED %d", errno)); }
|
||||
#define BLOCK_LOCK_WR(B) {DBUG_PRINT("lock", ("%d LOCK_WR 0x%lx",\
|
||||
__LINE__,(ulong)(B))); \
|
||||
@ -395,11 +391,9 @@ static void debug_wait_for_kill(const char *info)
|
||||
}
|
||||
|
||||
#else
|
||||
#define MUTEX_LOCK(M) pthread_mutex_lock(M)
|
||||
#define MUTEX_UNLOCK(M) pthread_mutex_unlock(M)
|
||||
#define RW_WLOCK(M) rw_wrlock(M)
|
||||
#define RW_RLOCK(M) rw_rdlock(M)
|
||||
#define RW_UNLOCK(M) rw_unlock(M)
|
||||
#define RW_WLOCK(M) mysql_rwlock_wrlock(M)
|
||||
#define RW_RLOCK(M) mysql_rwlock_rdlock(M)
|
||||
#define RW_UNLOCK(M) mysql_rwlock_unlock(M)
|
||||
#define BLOCK_LOCK_WR(B) B->query()->lock_writing()
|
||||
#define BLOCK_LOCK_RD(B) B->query()->lock_reading()
|
||||
#define BLOCK_UNLOCK_WR(B) B->query()->unlock_writing()
|
||||
@ -430,7 +424,7 @@ bool Query_cache::try_lock(bool use_timeout)
|
||||
bool interrupt= FALSE;
|
||||
DBUG_ENTER("Query_cache::try_lock");
|
||||
|
||||
pthread_mutex_lock(&structure_guard_mutex);
|
||||
mysql_mutex_lock(&structure_guard_mutex);
|
||||
while (1)
|
||||
{
|
||||
if (m_cache_lock_status == Query_cache::UNLOCKED)
|
||||
@ -463,8 +457,8 @@ bool Query_cache::try_lock(bool use_timeout)
|
||||
{
|
||||
struct timespec waittime;
|
||||
set_timespec_nsec(waittime,(ulong)(50000000L)); /* Wait for 50 msec */
|
||||
int res= pthread_cond_timedwait(&COND_cache_status_changed,
|
||||
&structure_guard_mutex,&waittime);
|
||||
int res= mysql_cond_timedwait(&COND_cache_status_changed,
|
||||
&structure_guard_mutex, &waittime);
|
||||
if (res == ETIMEDOUT)
|
||||
{
|
||||
interrupt= TRUE;
|
||||
@ -473,11 +467,11 @@ bool Query_cache::try_lock(bool use_timeout)
|
||||
}
|
||||
else
|
||||
{
|
||||
pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex);
|
||||
mysql_cond_wait(&COND_cache_status_changed, &structure_guard_mutex);
|
||||
}
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&structure_guard_mutex);
|
||||
mysql_mutex_unlock(&structure_guard_mutex);
|
||||
|
||||
DBUG_RETURN(interrupt);
|
||||
}
|
||||
@ -498,9 +492,9 @@ void Query_cache::lock_and_suspend(void)
|
||||
{
|
||||
DBUG_ENTER("Query_cache::lock_and_suspend");
|
||||
|
||||
pthread_mutex_lock(&structure_guard_mutex);
|
||||
mysql_mutex_lock(&structure_guard_mutex);
|
||||
while (m_cache_lock_status != Query_cache::UNLOCKED)
|
||||
pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex);
|
||||
mysql_cond_wait(&COND_cache_status_changed, &structure_guard_mutex);
|
||||
m_cache_lock_status= Query_cache::LOCKED_NO_WAIT;
|
||||
#ifndef DBUG_OFF
|
||||
THD *thd= current_thd;
|
||||
@ -508,8 +502,8 @@ void Query_cache::lock_and_suspend(void)
|
||||
m_cache_lock_thread_id= thd->thread_id;
|
||||
#endif
|
||||
/* Wake up everybody, a whole cache flush is starting! */
|
||||
pthread_cond_broadcast(&COND_cache_status_changed);
|
||||
pthread_mutex_unlock(&structure_guard_mutex);
|
||||
mysql_cond_broadcast(&COND_cache_status_changed);
|
||||
mysql_mutex_unlock(&structure_guard_mutex);
|
||||
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
@ -526,16 +520,16 @@ void Query_cache::lock(void)
|
||||
{
|
||||
DBUG_ENTER("Query_cache::lock");
|
||||
|
||||
pthread_mutex_lock(&structure_guard_mutex);
|
||||
mysql_mutex_lock(&structure_guard_mutex);
|
||||
while (m_cache_lock_status != Query_cache::UNLOCKED)
|
||||
pthread_cond_wait(&COND_cache_status_changed, &structure_guard_mutex);
|
||||
mysql_cond_wait(&COND_cache_status_changed, &structure_guard_mutex);
|
||||
m_cache_lock_status= Query_cache::LOCKED;
|
||||
#ifndef DBUG_OFF
|
||||
THD *thd= current_thd;
|
||||
if (thd)
|
||||
m_cache_lock_thread_id= thd->thread_id;
|
||||
#endif
|
||||
pthread_mutex_unlock(&structure_guard_mutex);
|
||||
mysql_mutex_unlock(&structure_guard_mutex);
|
||||
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
@ -548,7 +542,7 @@ void Query_cache::lock(void)
|
||||
void Query_cache::unlock(void)
|
||||
{
|
||||
DBUG_ENTER("Query_cache::unlock");
|
||||
pthread_mutex_lock(&structure_guard_mutex);
|
||||
mysql_mutex_lock(&structure_guard_mutex);
|
||||
#ifndef DBUG_OFF
|
||||
THD *thd= current_thd;
|
||||
if (thd)
|
||||
@ -558,8 +552,8 @@ void Query_cache::unlock(void)
|
||||
m_cache_lock_status == Query_cache::LOCKED_NO_WAIT);
|
||||
m_cache_lock_status= Query_cache::UNLOCKED;
|
||||
DBUG_PRINT("Query_cache",("Sending signal"));
|
||||
pthread_cond_signal(&COND_cache_status_changed);
|
||||
pthread_mutex_unlock(&structure_guard_mutex);
|
||||
mysql_cond_signal(&COND_cache_status_changed);
|
||||
mysql_mutex_unlock(&structure_guard_mutex);
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
@ -728,7 +722,7 @@ inline void Query_cache_query::lock_writing()
|
||||
my_bool Query_cache_query::try_lock_writing()
|
||||
{
|
||||
DBUG_ENTER("Query_cache_block::try_lock_writing");
|
||||
if (rw_trywrlock(&lock)!=0)
|
||||
if (mysql_rwlock_trywrlock(&lock) != 0)
|
||||
{
|
||||
DBUG_PRINT("info", ("can't lock rwlock"));
|
||||
DBUG_RETURN(0);
|
||||
@ -760,7 +754,7 @@ void Query_cache_query::init_n_lock()
|
||||
{
|
||||
DBUG_ENTER("Query_cache_query::init_n_lock");
|
||||
res=0; wri = 0; len = 0;
|
||||
my_rwlock_init(&lock, NULL);
|
||||
mysql_rwlock_init(key_rwlock_query_cache_query_lock, &lock);
|
||||
lock_writing();
|
||||
DBUG_PRINT("qcache", ("inited & locked query for block 0x%lx",
|
||||
(long) (((uchar*) this) -
|
||||
@ -780,7 +774,7 @@ void Query_cache_query::unlock_n_destroy()
|
||||
active semaphore
|
||||
*/
|
||||
this->unlock_writing();
|
||||
rwlock_destroy(&lock);
|
||||
mysql_rwlock_destroy(&lock);
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
@ -1984,8 +1978,8 @@ void Query_cache::destroy()
|
||||
free_cache();
|
||||
unlock();
|
||||
|
||||
pthread_cond_destroy(&COND_cache_status_changed);
|
||||
pthread_mutex_destroy(&structure_guard_mutex);
|
||||
mysql_cond_destroy(&COND_cache_status_changed);
|
||||
mysql_mutex_destroy(&structure_guard_mutex);
|
||||
initialized = 0;
|
||||
}
|
||||
DBUG_VOID_RETURN;
|
||||
@ -1999,8 +1993,10 @@ void Query_cache::destroy()
|
||||
void Query_cache::init()
|
||||
{
|
||||
DBUG_ENTER("Query_cache::init");
|
||||
pthread_mutex_init(&structure_guard_mutex,MY_MUTEX_INIT_FAST);
|
||||
pthread_cond_init(&COND_cache_status_changed, NULL);
|
||||
mysql_mutex_init(key_structure_guard_mutex,
|
||||
&structure_guard_mutex, MY_MUTEX_INIT_FAST);
|
||||
mysql_cond_init(key_COND_cache_status_changed,
|
||||
&COND_cache_status_changed, NULL);
|
||||
m_cache_lock_status= Query_cache::UNLOCKED;
|
||||
initialized = 1;
|
||||
/*
|
||||
@ -3846,7 +3842,7 @@ my_bool Query_cache::move_by_type(uchar **border,
|
||||
} while ( result_block != first_result_block );
|
||||
}
|
||||
Query_cache_query *new_query= ((Query_cache_query *) new_block->data());
|
||||
my_rwlock_init(&new_query->lock, NULL);
|
||||
mysql_rwlock_init(key_rwlock_query_cache_query_lock, &new_query->lock);
|
||||
|
||||
/*
|
||||
If someone is writing to this block, inform the writer that the block
|
||||
|
Reference in New Issue
Block a user