Make cpu timers optional #1190

Introduced 2 new global variables:
* mysql-stats_time_backend_query (default true)
* mysql-stats_time_query_processor (default true)

For backward compatibility, they are both enabled by default
pull/1209/head 1.4.4
René Cannaò 9 years ago
parent 8b23edcbcc
commit 80bad8a811

@ -227,6 +227,10 @@ class MySQL_Thread
unsigned int active_transactions;
} status_variables;
struct {
bool stats_time_backend_query;
bool stats_time_query_processor;
} variables;
#ifdef PROXYSQL_MYSQL_PTHREAD_MUTEX
pthread_mutex_t thread_mutex;
@ -396,6 +400,8 @@ class MySQL_Threads_Handler
char * ssl_p2s_key;
char * ssl_p2s_cipher;
int query_cache_size_MB;
bool stats_time_backend_query;
bool stats_time_query_processor;
} variables;
struct {
unsigned int mirror_sessions_current;

@ -1944,7 +1944,7 @@ __get_pkts_from_client:
return -1;
}
}
{
if (thread->variables.stats_time_query_processor) {
timespec begint;
clock_gettime(CLOCK_THREAD_CPUTIME_ID,&begint);
qpo=GloQPro->process_mysql_query(this,pkt.ptr,pkt.size,&CurrentQuery);
@ -2510,7 +2510,9 @@ handler_again:
}
int rc;
timespec begint;
clock_gettime(CLOCK_THREAD_CPUTIME_ID,&begint);
if (thread->variables.stats_time_backend_query) {
clock_gettime(CLOCK_THREAD_CPUTIME_ID,&begint);
}
switch (status) {
case PROCESSING_QUERY:
rc=myconn->async_query(myds->revents, myds->mysql_real_query.QueryPtr,myds->mysql_real_query.QuerySize);
@ -2529,10 +2531,12 @@ handler_again:
break;
}
timespec endt;
clock_gettime(CLOCK_THREAD_CPUTIME_ID,&endt);
thread->status_variables.backend_query_time=thread->status_variables.backend_query_time +
(endt.tv_sec*1000000000+endt.tv_nsec) -
(begint.tv_sec*1000000000+begint.tv_nsec);
if (thread->variables.stats_time_backend_query) {
clock_gettime(CLOCK_THREAD_CPUTIME_ID,&endt);
thread->status_variables.backend_query_time=thread->status_variables.backend_query_time +
(endt.tv_sec*1000000000+endt.tv_nsec) -
(begint.tv_sec*1000000000+begint.tv_nsec);
}
if (rc==0) {
// check if multiplexing needs to be disabled
char *qdt=CurrentQuery.get_digest_text();
@ -3431,7 +3435,9 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
l_free(pkt->size,pkt->ptr); // free old pkt
// allocate new pkt
timespec begint;
clock_gettime(CLOCK_THREAD_CPUTIME_ID,&begint);
if (thread->variables.stats_time_query_processor) {
clock_gettime(CLOCK_THREAD_CPUTIME_ID,&begint);
}
pkt->size=sizeof(mysql_hdr)+1+qpo->new_query->length();
pkt->ptr=l_alloc(pkt->size);
mysql_hdr hdr;
@ -3445,10 +3451,12 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
CurrentQuery.begin((unsigned char *)pkt->ptr,pkt->size,true);
delete qpo->new_query;
timespec endt;
clock_gettime(CLOCK_THREAD_CPUTIME_ID,&endt);
thread->status_variables.query_processor_time=thread->status_variables.query_processor_time +
(endt.tv_sec*1000000000+endt.tv_nsec) -
(begint.tv_sec*1000000000+begint.tv_nsec);
if (thread->variables.stats_time_query_processor) {
clock_gettime(CLOCK_THREAD_CPUTIME_ID,&endt);
thread->status_variables.query_processor_time=thread->status_variables.query_processor_time +
(endt.tv_sec*1000000000+endt.tv_nsec) -
(begint.tv_sec*1000000000+begint.tv_nsec);
}
}
if (pkt->size > (unsigned int) mysql_thread___max_allowed_packet) {

@ -283,6 +283,8 @@ static char * mysql_thread_variables_names[]= {
(char *)"init_connect",
(char *)"default_sql_mode",
(char *)"default_time_zone",
(char *)"stats_time_backend_query",
(char *)"stats_time_query_processor",
NULL
};
@ -381,6 +383,8 @@ MySQL_Threads_Handler::MySQL_Threads_Handler() {
variables.autocommit_false_not_reusable=false;
variables.query_digests=true;
variables.query_digests_lowercase=false;
variables.stats_time_backend_query=true;
variables.stats_time_query_processor=true;
variables.sessions_sort=true;
#ifdef IDLE_THREADS
variables.session_idle_ms=1000;
@ -624,6 +628,8 @@ int MySQL_Threads_Handler::get_variable_int(char *name) {
if (!strcasecmp(name,"commands_stats")) return (int)variables.commands_stats;
if (!strcasecmp(name,"query_digests")) return (int)variables.query_digests;
if (!strcasecmp(name,"query_digests_lowercase")) return (int)variables.query_digests_lowercase;
if (!strcasecmp(name,"stats_time_backend_query")) return (int)variables.stats_time_backend_query;
if (!strcasecmp(name,"stats_time_query_processor")) return (int)variables.stats_time_query_processor;
if (!strcasecmp(name,"sessions_sort")) return (int)variables.sessions_sort;
#ifdef IDLE_THREADS
if (!strcasecmp(name,"session_idle_show_processlist")) return (int)variables.session_idle_show_processlist;
@ -967,6 +973,12 @@ char * MySQL_Threads_Handler::get_variable(char *name) { // this is the public f
if (!strcasecmp(name,"query_digests_lowercase")) {
return strdup((variables.query_digests_lowercase ? "true" : "false"));
}
if (!strcasecmp(name,"stats_time_backend_query")) {
return strdup((variables.stats_time_backend_query ? "true" : "false"));
}
if (!strcasecmp(name,"stats_time_query_processor")) {
return strdup((variables.stats_time_query_processor ? "true" : "false"));
}
if (!strcasecmp(name,"sessions_sort")) {
return strdup((variables.sessions_sort ? "true" : "false"));
}
@ -1780,6 +1792,28 @@ bool MySQL_Threads_Handler::set_variable(char *name, char *value) { // this is t
}
return false;
}
if (!strcasecmp(name,"stats_time_backend_query")) {
if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) {
variables.stats_time_backend_query=true;
return true;
}
if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) {
variables.stats_time_backend_query=false;
return true;
}
return false;
}
if (!strcasecmp(name,"stats_time_query_processor")) {
if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) {
variables.stats_time_query_processor=true;
return true;
}
if (strcasecmp(value,"false")==0 || strcasecmp(value,"0")==0) {
variables.stats_time_query_processor=false;
return true;
}
return false;
}
#ifdef IDLE_THREADS
if (!strcasecmp(name,"session_idle_show_processlist")) {
if (strcasecmp(value,"true")==0 || strcasecmp(value,"1")==0) {
@ -3101,6 +3135,8 @@ void MySQL_Thread::refresh_variables() {
mysql_thread___commands_stats=(bool)GloMTH->get_variable_int((char *)"commands_stats");
mysql_thread___query_digests=(bool)GloMTH->get_variable_int((char *)"query_digests");
mysql_thread___query_digests_lowercase=(bool)GloMTH->get_variable_int((char *)"query_digests_lowercase");
variables.stats_time_backend_query=(bool)GloMTH->get_variable_int((char *)"stats_time_backend_query");
variables.stats_time_query_processor=(bool)GloMTH->get_variable_int((char *)"stats_time_query_processor");
mysql_thread___sessions_sort=(bool)GloMTH->get_variable_int((char *)"sessions_sort");
#ifdef IDLE_THREADS
mysql_thread___session_idle_show_processlist=(bool)GloMTH->get_variable_int((char *)"session_idle_show_processlist");
@ -3174,6 +3210,9 @@ MySQL_Thread::MySQL_Thread() {
status_variables.active_transactions=0;
match_regexes=NULL;
variables.stats_time_backend_query=true;
variables.stats_time_query_processor=true;
}
void MySQL_Thread::register_session_connection_handler(MySQL_Session *_sess, bool _new) {

Loading…
Cancel
Save