diff --git a/include/MySQL_Thread.h b/include/MySQL_Thread.h index 445ec6b11..05d407cc9 100644 --- a/include/MySQL_Thread.h +++ b/include/MySQL_Thread.h @@ -158,9 +158,14 @@ class MySQL_Thread int shutdown; PtrArray *mysql_sessions; + // status variables are per thread only + // in this way, there is no need for atomic operation and there is no cache miss + // when it is needed a total, all threads are checked struct { unsigned long long queries; unsigned long long queries_slow; + unsigned long long queries_backends_bytes_sent; + unsigned long long queries_backends_bytes_recv; } status_variables; @@ -323,6 +328,8 @@ class MySQL_Threads_Handler bool kill_session(uint32_t _thread_session_id); unsigned long long get_total_queries(); unsigned long long get_slow_queries(); + unsigned long long get_queries_backends_bytes_recv(); + unsigned long long get_queries_backends_bytes_sent(); }; diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index f19897d4b..35ce165ce 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -1677,6 +1677,8 @@ MySQL_Thread::MySQL_Thread() { status_variables.queries=0; status_variables.queries_slow=0; + status_variables.queries_backends_bytes_sent=0; + status_variables.queries_backends_bytes_recv=0; } @@ -1787,6 +1789,18 @@ SQLite3_result * MySQL_Threads_Handler::SQL3_GlobalStatus() { pta[1]=buf; result->add_row(pta); } + { // Queries bytes recv + pta[0]=(char *)"Queries_backends_bytes_recv"; + sprintf(buf,"%llu",get_queries_backends_bytes_recv()); + pta[1]=buf; + result->add_row(pta); + } + { // Queries bytes recv + pta[0]=(char *)"Queries_backends_bytes_sent"; + sprintf(buf,"%llu",get_queries_backends_bytes_sent()); + pta[1]=buf; + result->add_row(pta); + } { // Queries pta[0]=(char *)"Questions"; sprintf(buf,"%llu",get_total_queries()); @@ -2019,3 +2033,29 @@ unsigned long long MySQL_Threads_Handler::get_slow_queries() { } return q; } + +unsigned long long MySQL_Threads_Handler::get_queries_backends_bytes_recv() { + unsigned long long q=0; + unsigned int i; + for (i=0;istatus_variables.queries_backends_bytes_recv,0); + } + } + return q; +} + +unsigned long long MySQL_Threads_Handler::get_queries_backends_bytes_sent() { + unsigned long long q=0; + unsigned int i; + for (i=0;istatus_variables.queries_backends_bytes_sent,0); + } + } + return q; +} diff --git a/lib/mysql_connection.cpp b/lib/mysql_connection.cpp index b17c479f0..520966659 100644 --- a/lib/mysql_connection.cpp +++ b/lib/mysql_connection.cpp @@ -466,6 +466,7 @@ handler_again: real_query_start(); __sync_fetch_and_add(&parent->queries_sent,1); __sync_fetch_and_add(&parent->bytes_sent,query.length); + myds->sess->thread->status_variables.queries_backends_bytes_sent+=query.length; if (async_exit_status) { next_event(ASYNC_QUERY_CONT); } else { @@ -534,6 +535,7 @@ handler_again: if (mysql_row) { unsigned int br=MyRS->add_row(mysql_row); __sync_fetch_and_add(&parent->bytes_recv,br); + myds->sess->thread->status_variables.queries_backends_bytes_recv+=br; NEXT_IMMEDIATE(ASYNC_USE_RESULT_CONT); } else { MyRS->add_eof();