--- mariadb-10.0.4-original/plugin/query_response_time/query_response_time.cc 2013-08-18 02:55:32.733267143 -0300 +++ mariadb-10.0.4/plugin/query_response_time/query_response_time.cc 2013-08-18 05:06:54.012734054 -0300 @@ -8,6 +8,8 @@ #include "sql_show.h" #include "query_response_time.h" +#include /* THD */ + #define TIME_STRING_POSITIVE_POWER_LENGTH QRT_TIME_STRING_POSITIVE_POWER_LENGTH #define TIME_STRING_NEGATIVE_POWER_LENGTH 6 #define TOTAL_STRING_POSITIVE_POWER_LENGTH QRT_TOTAL_STRING_POSITIVE_POWER_LENGTH @@ -170,15 +172,31 @@ my_atomic_rwlock_rdunlock(&time_collector_lock); return result; } + uint32 qc_count(uint index) + { + my_atomic_rwlock_rdlock(&time_collector_lock); + uint32 result= my_atomic_load32((int32*)&m_qc_count[index]); + my_atomic_rwlock_rdunlock(&time_collector_lock); + return result; + } + uint64 qc_total(uint index) + { + my_atomic_rwlock_rdlock(&time_collector_lock); + uint64 result= my_atomic_load64((int64*)&m_qc_total[index]); + my_atomic_rwlock_rdunlock(&time_collector_lock); + return result; + } public: void flush() { my_atomic_rwlock_wrlock(&time_collector_lock); memset((void*)&m_count,0,sizeof(m_count)); memset((void*)&m_total,0,sizeof(m_total)); + memset((void*)&m_qc_count,0,sizeof(m_qc_count)); + memset((void*)&m_qc_total,0,sizeof(m_qc_total)); my_atomic_rwlock_wrunlock(&time_collector_lock); } - void collect(uint64 time) + void collect(uchar qc, uint64 time) { int i= 0; for(int count= m_utility->bound_count(); count > i; ++i) @@ -188,6 +206,10 @@ my_atomic_rwlock_wrlock(&time_collector_lock); my_atomic_add32((int32*)(&m_count[i]), 1); my_atomic_add64((int64*)(&m_total[i]), time); + if(qc!=0){ /* query cache used */ + my_atomic_add32((int32*)(&m_qc_count[i]), 1); + my_atomic_add64((int64*)(&m_qc_total[i]), time); + } my_atomic_rwlock_wrunlock(&time_collector_lock); break; } @@ -201,6 +223,9 @@ my_atomic_rwlock_t time_collector_lock; uint32 m_count[OVERALL_POWER_COUNT + 1]; uint64 m_total[OVERALL_POWER_COUNT + 1]; + + uint32 m_qc_count[OVERALL_POWER_COUNT + 1]; + uint64 m_qc_total[OVERALL_POWER_COUNT + 1]; }; class collector @@ -226,21 +251,27 @@ { char time[TIME_STRING_BUFFER_LENGTH]; char total[TOTAL_STRING_BUFFER_LENGTH]; + char qc_total[TOTAL_STRING_BUFFER_LENGTH]; if(i == bound_count()) { assert(sizeof(TIME_OVERFLOW) <= TIME_STRING_BUFFER_LENGTH); assert(sizeof(TIME_OVERFLOW) <= TOTAL_STRING_BUFFER_LENGTH); memcpy(time,TIME_OVERFLOW,sizeof(TIME_OVERFLOW)); memcpy(total,TIME_OVERFLOW,sizeof(TIME_OVERFLOW)); + memcpy(qc_total,TIME_OVERFLOW,sizeof(TIME_OVERFLOW)); } else { print_time(time, sizeof(time), TIME_STRING_FORMAT, this->bound(i)); print_time(total, sizeof(total), TOTAL_STRING_FORMAT, this->total(i)); + print_time(qc_total, sizeof(qc_total), TOTAL_STRING_FORMAT, this->qc_total(i)); } fields[0]->store(time,strlen(time),system_charset_info); fields[1]->store(this->count(i)); fields[2]->store(total,strlen(total),system_charset_info); + + fields[3]->store(this->qc_count(i)); + fields[4]->store(qc_total,strlen(qc_total),system_charset_info); if (schema_table_store_record(thd, table)) { DBUG_RETURN(1); @@ -248,9 +279,9 @@ } DBUG_RETURN(0); } - void collect(ulonglong time) + void collect(uchar qc, ulonglong time) { - m_time.collect(time); + m_time.collect(qc, time); } uint bound_count() const { @@ -268,6 +299,14 @@ { return m_time.total(index); } + ulonglong qc_count(uint index) + { + return m_time.qc_count(index); + } + ulonglong qc_total(uint index) + { + return m_time.qc_total(index); + } private: utility m_utility; time_collector m_time; @@ -290,9 +329,9 @@ { query_response_time::g_collector.flush(); } -void query_response_time_collect(ulonglong query_time) +void query_response_time_collect(uchar qc, ulonglong query_time) { - query_response_time::g_collector.collect(query_time); + query_response_time::g_collector.collect(qc, query_time); } int query_response_time_fill(THD* thd, TABLE_LIST *tables, COND *cond)