Commit 0ee879ff authored by Monty's avatar Monty

Improve performance for calculating memory allocation

Extend interface for 'show variables' with current scope
parent 67b24a23
...@@ -182,6 +182,11 @@ enum enum_mysql_show_type ...@@ -182,6 +182,11 @@ enum enum_mysql_show_type
#define SHOW_LONG SHOW_ULONG #define SHOW_LONG SHOW_ULONG
#define SHOW_LONGLONG SHOW_ULONGLONG #define SHOW_LONGLONG SHOW_ULONGLONG
enum enum_var_type
{
SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL
};
struct st_mysql_show_var { struct st_mysql_show_var {
const char *name; const char *name;
char *value; char *value;
...@@ -189,7 +194,7 @@ struct st_mysql_show_var { ...@@ -189,7 +194,7 @@ struct st_mysql_show_var {
}; };
#define SHOW_VAR_FUNC_BUFF_SIZE (256 * sizeof(void*)) #define SHOW_VAR_FUNC_BUFF_SIZE (256 * sizeof(void*))
typedef int (*mysql_show_var_func)(MYSQL_THD, struct st_mysql_show_var*, char *); typedef int (*mysql_show_var_func)(MYSQL_THD, struct st_mysql_show_var*, char *, enum enum_var_type);
/* /*
......
...@@ -212,12 +212,16 @@ enum enum_mysql_show_type ...@@ -212,12 +212,16 @@ enum enum_mysql_show_type
SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC, SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC,
SHOW_always_last SHOW_always_last
}; };
enum enum_var_type
{
SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL
};
struct st_mysql_show_var { struct st_mysql_show_var {
const char *name; const char *name;
char *value; char *value;
enum enum_mysql_show_type type; enum enum_mysql_show_type type;
}; };
typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *); typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *, enum enum_var_type);
struct st_mysql_sys_var; struct st_mysql_sys_var;
struct st_mysql_value; struct st_mysql_value;
typedef int (*mysql_var_check_func)(void* thd, typedef int (*mysql_var_check_func)(void* thd,
......
...@@ -212,12 +212,16 @@ enum enum_mysql_show_type ...@@ -212,12 +212,16 @@ enum enum_mysql_show_type
SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC, SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC,
SHOW_always_last SHOW_always_last
}; };
enum enum_var_type
{
SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL
};
struct st_mysql_show_var { struct st_mysql_show_var {
const char *name; const char *name;
char *value; char *value;
enum enum_mysql_show_type type; enum enum_mysql_show_type type;
}; };
typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *); typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *, enum enum_var_type);
struct st_mysql_sys_var; struct st_mysql_sys_var;
struct st_mysql_value; struct st_mysql_value;
typedef int (*mysql_var_check_func)(void* thd, typedef int (*mysql_var_check_func)(void* thd,
......
...@@ -212,12 +212,16 @@ enum enum_mysql_show_type ...@@ -212,12 +212,16 @@ enum enum_mysql_show_type
SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC, SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC,
SHOW_always_last SHOW_always_last
}; };
enum enum_var_type
{
SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL
};
struct st_mysql_show_var { struct st_mysql_show_var {
const char *name; const char *name;
char *value; char *value;
enum enum_mysql_show_type type; enum enum_mysql_show_type type;
}; };
typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *); typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *, enum enum_var_type);
struct st_mysql_sys_var; struct st_mysql_sys_var;
struct st_mysql_value; struct st_mysql_value;
typedef int (*mysql_var_check_func)(void* thd, typedef int (*mysql_var_check_func)(void* thd,
......
...@@ -212,12 +212,16 @@ enum enum_mysql_show_type ...@@ -212,12 +212,16 @@ enum enum_mysql_show_type
SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC, SHOW_SINT, SHOW_SLONG, SHOW_SLONGLONG, SHOW_SIMPLE_FUNC,
SHOW_always_last SHOW_always_last
}; };
enum enum_var_type
{
SHOW_OPT_DEFAULT= 0, SHOW_OPT_SESSION, SHOW_OPT_GLOBAL
};
struct st_mysql_show_var { struct st_mysql_show_var {
const char *name; const char *name;
char *value; char *value;
enum enum_mysql_show_type type; enum enum_mysql_show_type type;
}; };
typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *); typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *, enum enum_var_type);
struct st_mysql_sys_var; struct st_mysql_sys_var;
struct st_mysql_value; struct st_mysql_value;
typedef int (*mysql_var_check_func)(void* thd, typedef int (*mysql_var_check_func)(void* thd,
......
...@@ -3956,10 +3956,10 @@ extern "C" my_thread_id mariadb_dbug_id() ...@@ -3956,10 +3956,10 @@ extern "C" my_thread_id mariadb_dbug_id()
extern "C" { extern "C" {
static void my_malloc_size_cb_func(long long size, my_bool is_thread_specific) static void my_malloc_size_cb_func(long long size, my_bool is_thread_specific)
{ {
THD *thd= current_thd;
/* If thread specific memory */ /* If thread specific memory */
if (is_thread_specific) if (likely(is_thread_specific))
{ {
THD *thd= current_thd;
if (mysqld_server_initialized || thd) if (mysqld_server_initialized || thd)
{ {
/* /*
...@@ -3972,19 +3972,24 @@ static void my_malloc_size_cb_func(long long size, my_bool is_thread_specific) ...@@ -3972,19 +3972,24 @@ static void my_malloc_size_cb_func(long long size, my_bool is_thread_specific)
if (thd) if (thd)
{ {
DBUG_PRINT("info", ("memory_used: %lld size: %lld", DBUG_PRINT("info", ("memory_used: %lld size: %lld",
(longlong) thd->status_var.memory_used, size)); (longlong) thd->status_var.local_memory_used,
thd->status_var.memory_used+= size; size));
DBUG_ASSERT((longlong) thd->status_var.memory_used >= 0); thd->status_var.local_memory_used+= size;
DBUG_ASSERT((longlong) thd->status_var.local_memory_used >= 0);
} }
} }
} }
else if (likely(thd))
thd->status_var.global_memory_used+= size;
else
{
// workaround for gcc 4.2.4-1ubuntu4 -fPIE (from DEB_BUILD_HARDENING=1) // workaround for gcc 4.2.4-1ubuntu4 -fPIE (from DEB_BUILD_HARDENING=1)
int64 volatile * volatile ptr=&global_status_var.memory_used; int64 volatile * volatile ptr=&global_status_var.global_memory_used;
my_atomic_add64_explicit(ptr, size, MY_MEMORY_ORDER_RELAXED); my_atomic_add64_explicit(ptr, size, MY_MEMORY_ORDER_RELAXED);
}
} }
} }
static int init_common_variables() static int init_common_variables()
{ {
umask(((~my_umask) & 0666)); umask(((~my_umask) & 0666));
...@@ -7469,7 +7474,8 @@ struct my_option my_long_options[]= ...@@ -7469,7 +7474,8 @@ struct my_option my_long_options[]=
MYSQL_TO_BE_IMPLEMENTED_OPTION("validate-user-plugins") // NO_EMBEDDED_ACCESS_CHECKS MYSQL_TO_BE_IMPLEMENTED_OPTION("validate-user-plugins") // NO_EMBEDDED_ACCESS_CHECKS
}; };
static int show_queries(THD *thd, SHOW_VAR *var, char *buff) static int show_queries(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONGLONG; var->type= SHOW_LONGLONG;
var->value= (char *)&thd->query_id; var->value= (char *)&thd->query_id;
...@@ -7477,14 +7483,16 @@ static int show_queries(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7477,14 +7483,16 @@ static int show_queries(THD *thd, SHOW_VAR *var, char *buff)
} }
static int show_net_compression(THD *thd, SHOW_VAR *var, char *buff) static int show_net_compression(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_MY_BOOL; var->type= SHOW_MY_BOOL;
var->value= (char *)&thd->net.compress; var->value= (char *)&thd->net.compress;
return 0; return 0;
} }
static int show_starttime(THD *thd, SHOW_VAR *var, char *buff) static int show_starttime(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7493,7 +7501,8 @@ static int show_starttime(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7493,7 +7501,8 @@ static int show_starttime(THD *thd, SHOW_VAR *var, char *buff)
} }
#ifdef ENABLED_PROFILING #ifdef ENABLED_PROFILING
static int show_flushstatustime(THD *thd, SHOW_VAR *var, char *buff) static int show_flushstatustime(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7503,14 +7512,16 @@ static int show_flushstatustime(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7503,14 +7512,16 @@ static int show_flushstatustime(THD *thd, SHOW_VAR *var, char *buff)
#endif #endif
#ifdef HAVE_REPLICATION #ifdef HAVE_REPLICATION
static int show_rpl_status(THD *thd, SHOW_VAR *var, char *buff) static int show_rpl_status(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_CHAR; var->type= SHOW_CHAR;
var->value= const_cast<char*>(rpl_status_type[(int)rpl_status]); var->value= const_cast<char*>(rpl_status_type[(int)rpl_status]);
return 0; return 0;
} }
static int show_slave_running(THD *thd, SHOW_VAR *var, char *buff) static int show_slave_running(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
Master_info *mi= NULL; Master_info *mi= NULL;
bool tmp; bool tmp;
...@@ -7537,7 +7548,8 @@ static int show_slave_running(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7537,7 +7548,8 @@ static int show_slave_running(THD *thd, SHOW_VAR *var, char *buff)
} }
static int show_slave_received_heartbeats(THD *thd, SHOW_VAR *var, char *buff) static int show_slave_received_heartbeats(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
Master_info *mi= NULL; Master_info *mi= NULL;
longlong tmp; longlong tmp;
...@@ -7563,7 +7575,8 @@ static int show_slave_received_heartbeats(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7563,7 +7575,8 @@ static int show_slave_received_heartbeats(THD *thd, SHOW_VAR *var, char *buff)
} }
static int show_heartbeat_period(THD *thd, SHOW_VAR *var, char *buff) static int show_heartbeat_period(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
Master_info *mi= NULL; Master_info *mi= NULL;
float tmp; float tmp;
...@@ -7591,7 +7604,8 @@ static int show_heartbeat_period(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7591,7 +7604,8 @@ static int show_heartbeat_period(THD *thd, SHOW_VAR *var, char *buff)
#endif /* HAVE_REPLICATION */ #endif /* HAVE_REPLICATION */
static int show_open_tables(THD *thd, SHOW_VAR *var, char *buff) static int show_open_tables(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7599,7 +7613,8 @@ static int show_open_tables(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7599,7 +7613,8 @@ static int show_open_tables(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_prepared_stmt_count(THD *thd, SHOW_VAR *var, char *buff) static int show_prepared_stmt_count(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7609,7 +7624,8 @@ static int show_prepared_stmt_count(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7609,7 +7624,8 @@ static int show_prepared_stmt_count(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_table_definitions(THD *thd, SHOW_VAR *var, char *buff) static int show_table_definitions(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7618,7 +7634,8 @@ static int show_table_definitions(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7618,7 +7634,8 @@ static int show_table_definitions(THD *thd, SHOW_VAR *var, char *buff)
} }
static int show_flush_commands(THD *thd, SHOW_VAR *var, char *buff) static int show_flush_commands(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7629,7 +7646,8 @@ static int show_flush_commands(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7629,7 +7646,8 @@ static int show_flush_commands(THD *thd, SHOW_VAR *var, char *buff)
#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) #if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
/* Functions relying on CTX */ /* Functions relying on CTX */
static int show_ssl_ctx_sess_accept(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_ctx_sess_accept(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7638,7 +7656,8 @@ static int show_ssl_ctx_sess_accept(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7638,7 +7656,8 @@ static int show_ssl_ctx_sess_accept(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_ssl_ctx_sess_accept_good(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_ctx_sess_accept_good(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7647,7 +7666,8 @@ static int show_ssl_ctx_sess_accept_good(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7647,7 +7666,8 @@ static int show_ssl_ctx_sess_accept_good(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_ssl_ctx_sess_connect_good(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_ctx_sess_connect_good(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7656,7 +7676,9 @@ static int show_ssl_ctx_sess_connect_good(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7656,7 +7676,9 @@ static int show_ssl_ctx_sess_connect_good(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_ssl_ctx_sess_accept_renegotiate(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_ctx_sess_accept_renegotiate(THD *thd, SHOW_VAR *var,
char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7665,7 +7687,9 @@ static int show_ssl_ctx_sess_accept_renegotiate(THD *thd, SHOW_VAR *var, char *b ...@@ -7665,7 +7687,9 @@ static int show_ssl_ctx_sess_accept_renegotiate(THD *thd, SHOW_VAR *var, char *b
return 0; return 0;
} }
static int show_ssl_ctx_sess_connect_renegotiate(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_ctx_sess_connect_renegotiate(THD *thd, SHOW_VAR *var,
char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7674,7 +7698,8 @@ static int show_ssl_ctx_sess_connect_renegotiate(THD *thd, SHOW_VAR *var, char * ...@@ -7674,7 +7698,8 @@ static int show_ssl_ctx_sess_connect_renegotiate(THD *thd, SHOW_VAR *var, char *
return 0; return 0;
} }
static int show_ssl_ctx_sess_cb_hits(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_ctx_sess_cb_hits(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7683,7 +7708,8 @@ static int show_ssl_ctx_sess_cb_hits(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7683,7 +7708,8 @@ static int show_ssl_ctx_sess_cb_hits(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_ssl_ctx_sess_hits(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_ctx_sess_hits(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7692,7 +7718,8 @@ static int show_ssl_ctx_sess_hits(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7692,7 +7718,8 @@ static int show_ssl_ctx_sess_hits(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_ssl_ctx_sess_cache_full(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_ctx_sess_cache_full(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7701,7 +7728,8 @@ static int show_ssl_ctx_sess_cache_full(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7701,7 +7728,8 @@ static int show_ssl_ctx_sess_cache_full(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_ssl_ctx_sess_misses(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_ctx_sess_misses(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7710,7 +7738,8 @@ static int show_ssl_ctx_sess_misses(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7710,7 +7738,8 @@ static int show_ssl_ctx_sess_misses(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_ssl_ctx_sess_timeouts(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_ctx_sess_timeouts(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7719,7 +7748,8 @@ static int show_ssl_ctx_sess_timeouts(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7719,7 +7748,8 @@ static int show_ssl_ctx_sess_timeouts(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_ssl_ctx_sess_number(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_ctx_sess_number(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7728,7 +7758,8 @@ static int show_ssl_ctx_sess_number(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7728,7 +7758,8 @@ static int show_ssl_ctx_sess_number(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_ssl_ctx_sess_connect(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_ctx_sess_connect(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7737,7 +7768,9 @@ static int show_ssl_ctx_sess_connect(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7737,7 +7768,9 @@ static int show_ssl_ctx_sess_connect(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_ssl_ctx_sess_get_cache_size(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_ctx_sess_get_cache_size(THD *thd, SHOW_VAR *var,
char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7746,7 +7779,8 @@ static int show_ssl_ctx_sess_get_cache_size(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7746,7 +7779,8 @@ static int show_ssl_ctx_sess_get_cache_size(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_ssl_ctx_get_verify_mode(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_ctx_get_verify_mode(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7755,7 +7789,8 @@ static int show_ssl_ctx_get_verify_mode(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7755,7 +7789,8 @@ static int show_ssl_ctx_get_verify_mode(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_ssl_ctx_get_verify_depth(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_ctx_get_verify_depth(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7764,7 +7799,9 @@ static int show_ssl_ctx_get_verify_depth(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7764,7 +7799,9 @@ static int show_ssl_ctx_get_verify_depth(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_ssl_ctx_get_session_cache_mode(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_ctx_get_session_cache_mode(THD *thd, SHOW_VAR *var,
char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_CHAR; var->type= SHOW_CHAR;
if (!ssl_acceptor_fd) if (!ssl_acceptor_fd)
...@@ -7797,7 +7834,9 @@ static int show_ssl_ctx_get_session_cache_mode(THD *thd, SHOW_VAR *var, char *bu ...@@ -7797,7 +7834,9 @@ static int show_ssl_ctx_get_session_cache_mode(THD *thd, SHOW_VAR *var, char *bu
when session_status or global_status is requested from when session_status or global_status is requested from
inside an Event. inside an Event.
*/ */
static int show_ssl_get_version(THD *thd, SHOW_VAR *var, char *buff)
static int show_ssl_get_version(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_CHAR; var->type= SHOW_CHAR;
if( thd->vio_ok() && thd->net.vio->ssl_arg ) if( thd->vio_ok() && thd->net.vio->ssl_arg )
...@@ -7807,7 +7846,8 @@ static int show_ssl_get_version(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7807,7 +7846,8 @@ static int show_ssl_get_version(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_ssl_session_reused(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_session_reused(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7818,7 +7858,8 @@ static int show_ssl_session_reused(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7818,7 +7858,8 @@ static int show_ssl_session_reused(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_ssl_get_default_timeout(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_get_default_timeout(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7829,7 +7870,8 @@ static int show_ssl_get_default_timeout(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7829,7 +7870,8 @@ static int show_ssl_get_default_timeout(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_ssl_get_verify_mode(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_get_verify_mode(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7840,7 +7882,8 @@ static int show_ssl_get_verify_mode(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7840,7 +7882,8 @@ static int show_ssl_get_verify_mode(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_ssl_get_verify_depth(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_get_verify_depth(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_LONG; var->type= SHOW_LONG;
var->value= buff; var->value= buff;
...@@ -7851,7 +7894,8 @@ static int show_ssl_get_verify_depth(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7851,7 +7894,8 @@ static int show_ssl_get_verify_depth(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_ssl_get_cipher(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_get_cipher(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_CHAR; var->type= SHOW_CHAR;
if( thd->vio_ok() && thd->net.vio->ssl_arg ) if( thd->vio_ok() && thd->net.vio->ssl_arg )
...@@ -7861,7 +7905,8 @@ static int show_ssl_get_cipher(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7861,7 +7905,8 @@ static int show_ssl_get_cipher(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_ssl_get_cipher_list(THD *thd, SHOW_VAR *var, char *buff) static int show_ssl_get_cipher_list(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_CHAR; var->type= SHOW_CHAR;
var->value= buff; var->value= buff;
...@@ -7935,7 +7980,8 @@ end: ...@@ -7935,7 +7980,8 @@ end:
*/ */
static int static int
show_ssl_get_server_not_before(THD *thd, SHOW_VAR *var, char *buff) show_ssl_get_server_not_before(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_CHAR; var->type= SHOW_CHAR;
if(thd->vio_ok() && thd->net.vio->ssl_arg) if(thd->vio_ok() && thd->net.vio->ssl_arg)
...@@ -7968,7 +8014,8 @@ show_ssl_get_server_not_before(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7968,7 +8014,8 @@ show_ssl_get_server_not_before(THD *thd, SHOW_VAR *var, char *buff)
*/ */
static int static int
show_ssl_get_server_not_after(THD *thd, SHOW_VAR *var, char *buff) show_ssl_get_server_not_after(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_CHAR; var->type= SHOW_CHAR;
if(thd->vio_ok() && thd->net.vio->ssl_arg) if(thd->vio_ok() && thd->net.vio->ssl_arg)
...@@ -7989,7 +8036,8 @@ show_ssl_get_server_not_after(THD *thd, SHOW_VAR *var, char *buff) ...@@ -7989,7 +8036,8 @@ show_ssl_get_server_not_after(THD *thd, SHOW_VAR *var, char *buff)
#endif /* HAVE_OPENSSL && !EMBEDDED_LIBRARY */ #endif /* HAVE_OPENSSL && !EMBEDDED_LIBRARY */
static int show_default_keycache(THD *thd, SHOW_VAR *var, char *buff) static int show_default_keycache(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
struct st_data { struct st_data {
KEY_CACHE_STATISTICS stats; KEY_CACHE_STATISTICS stats;
...@@ -8029,8 +8077,24 @@ static int show_default_keycache(THD *thd, SHOW_VAR *var, char *buff) ...@@ -8029,8 +8077,24 @@ static int show_default_keycache(THD *thd, SHOW_VAR *var, char *buff)
return 0; return 0;
} }
static int show_memory_used(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{
var->type= SHOW_LONGLONG;
var->value= buff;
if (scope == OPT_GLOBAL)
*(longlong*) buff= (global_status_var.local_memory_used +
global_status_var.global_memory_used);
else
*(longlong*) buff= thd->status_var.local_memory_used;
return 0;
}
#ifndef DBUG_OFF #ifndef DBUG_OFF
static int debug_status_func(THD *thd, SHOW_VAR *var, char *buff) static int debug_status_func(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
#define add_var(X,Y,Z) \ #define add_var(X,Y,Z) \
v->name= X; \ v->name= X; \
...@@ -8066,7 +8130,8 @@ static int debug_status_func(THD *thd, SHOW_VAR *var, char *buff) ...@@ -8066,7 +8130,8 @@ static int debug_status_func(THD *thd, SHOW_VAR *var, char *buff)
#endif #endif
#ifdef HAVE_POOL_OF_THREADS #ifdef HAVE_POOL_OF_THREADS
int show_threadpool_idle_threads(THD *thd, SHOW_VAR *var, char *buff) int show_threadpool_idle_threads(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
var->type= SHOW_INT; var->type= SHOW_INT;
var->value= buff; var->value= buff;
...@@ -8152,7 +8217,7 @@ SHOW_VAR status_vars[]= { ...@@ -8152,7 +8217,7 @@ SHOW_VAR status_vars[]= {
{"Last_query_cost", (char*) offsetof(STATUS_VAR, last_query_cost), SHOW_DOUBLE_STATUS}, {"Last_query_cost", (char*) offsetof(STATUS_VAR, last_query_cost), SHOW_DOUBLE_STATUS},
{"Max_statement_time_exceeded", (char*) offsetof(STATUS_VAR, max_statement_time_exceeded), SHOW_LONG_STATUS}, {"Max_statement_time_exceeded", (char*) offsetof(STATUS_VAR, max_statement_time_exceeded), SHOW_LONG_STATUS},
{"Max_used_connections", (char*) &max_used_connections, SHOW_LONG}, {"Max_used_connections", (char*) &max_used_connections, SHOW_LONG},
{"Memory_used", (char*) offsetof(STATUS_VAR, memory_used), SHOW_LONGLONG_STATUS}, {"Memory_used", (char*) &show_memory_used, SHOW_SIMPLE_FUNC},
{"Not_flushed_delayed_rows", (char*) &delayed_rows_in_use, SHOW_LONG_NOFLUSH}, {"Not_flushed_delayed_rows", (char*) &delayed_rows_in_use, SHOW_LONG_NOFLUSH},
{"Open_files", (char*) &my_file_opened, SHOW_LONG_NOFLUSH}, {"Open_files", (char*) &my_file_opened, SHOW_LONG_NOFLUSH},
{"Open_streams", (char*) &my_stream_opened, SHOW_LONG_NOFLUSH}, {"Open_streams", (char*) &my_stream_opened, SHOW_LONG_NOFLUSH},
......
...@@ -54,6 +54,12 @@ typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */ ...@@ -54,6 +54,12 @@ typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */
#define TEST_SIGINT 1024 /**< Allow sigint on threads */ #define TEST_SIGINT 1024 /**< Allow sigint on threads */
#define TEST_SYNCHRONIZATION 2048 /**< get server to do sleep in #define TEST_SYNCHRONIZATION 2048 /**< get server to do sleep in
some places */ some places */
/* Keep things compatible */
#define OPT_DEFAULT SHOW_OPT_DEFAULT
#define OPT_SESSION SHOW_OPT_SESSION
#define OPT_GLOBAL SHOW_OPT_GLOBAL
/* Function prototypes */ /* Function prototypes */
void kill_mysql(void); void kill_mysql(void);
void close_connection(THD *thd, uint sql_errno= 0); void close_connection(THD *thd, uint sql_errno= 0);
......
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
#include "wsrep_mysqld.h" #include "wsrep_mysqld.h"
#include "wsrep_thd.h" #include "wsrep_thd.h"
#include "sql_connect.h" #include "sql_connect.h"
#include "my_atomic.h"
/* /*
The following is used to initialise Table_ident with a internal The following is used to initialise Table_ident with a internal
...@@ -934,7 +935,7 @@ THD::THD(bool is_wsrep_applier) ...@@ -934,7 +935,7 @@ THD::THD(bool is_wsrep_applier)
*/ */
THD *old_THR_THD= current_thd; THD *old_THR_THD= current_thd;
set_current_thd(this); set_current_thd(this);
status_var.memory_used= 0; status_var.local_memory_used= status_var.global_memory_used= 0;
main_da.init(); main_da.init();
/* /*
...@@ -1703,11 +1704,12 @@ THD::~THD() ...@@ -1703,11 +1704,12 @@ THD::~THD()
main_da.free_memory(); main_da.free_memory();
if (tdc_hash_pins) if (tdc_hash_pins)
lf_hash_put_pins(tdc_hash_pins); lf_hash_put_pins(tdc_hash_pins);
if (status_var.memory_used != 0) /* Ensure everything is freed */
if (status_var.local_memory_used != 0)
{ {
DBUG_PRINT("error", ("memory_used: %lld", status_var.memory_used)); DBUG_PRINT("error", ("memory_used: %lld", status_var.local_memory_used));
SAFEMALLOC_REPORT_MEMORY(my_thread_dbug_id()); SAFEMALLOC_REPORT_MEMORY(my_thread_dbug_id());
DBUG_ASSERT(status_var.memory_used == 0); // Ensure everything is freed DBUG_ASSERT(status_var.local_memory_used == 0);
} }
set_current_thd(orig_thd); set_current_thd(orig_thd);
...@@ -1747,6 +1749,16 @@ void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var) ...@@ -1747,6 +1749,16 @@ void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var)
to_var->binlog_bytes_written+= from_var->binlog_bytes_written; to_var->binlog_bytes_written+= from_var->binlog_bytes_written;
to_var->cpu_time+= from_var->cpu_time; to_var->cpu_time+= from_var->cpu_time;
to_var->busy_time+= from_var->busy_time; to_var->busy_time+= from_var->busy_time;
to_var->local_memory_used+= from_var->local_memory_used;
/*
Update global_memory_used. We have to do this with atomic_add as the
global value can change outside of LOCK_status.
*/
// workaround for gcc 4.2.4-1ubuntu4 -fPIE (from DEB_BUILD_HARDENING=1)
int64 volatile * volatile ptr= &to_var->global_memory_used;
my_atomic_add64_explicit(ptr, from_var->global_memory_used,
MY_MEMORY_ORDER_RELAXED);
} }
/* /*
...@@ -1784,6 +1796,11 @@ void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var, ...@@ -1784,6 +1796,11 @@ void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
dec_var->binlog_bytes_written; dec_var->binlog_bytes_written;
to_var->cpu_time+= from_var->cpu_time - dec_var->cpu_time; to_var->cpu_time+= from_var->cpu_time - dec_var->cpu_time;
to_var->busy_time+= from_var->busy_time - dec_var->busy_time; to_var->busy_time+= from_var->busy_time - dec_var->busy_time;
/*
We don't need to accumulate memory_used as these are not reset or used by
the calling functions. See execute_show_status().
*/
} }
#define SECONDS_TO_WAIT_FOR_KILL 2 #define SECONDS_TO_WAIT_FOR_KILL 2
......
...@@ -760,7 +760,10 @@ typedef struct system_status_var ...@@ -760,7 +760,10 @@ typedef struct system_status_var
double last_query_cost; double last_query_cost;
double cpu_time, busy_time; double cpu_time, busy_time;
/* Don't initialize */ /* Don't initialize */
volatile int64 memory_used; /* This shouldn't be accumulated */ /* Memory used for thread local storage */
volatile int64 local_memory_used;
/* Memory allocated for global usage */
volatile int64 global_memory_used;
} STATUS_VAR; } STATUS_VAR;
/* /*
...@@ -770,7 +773,7 @@ typedef struct system_status_var ...@@ -770,7 +773,7 @@ typedef struct system_status_var
*/ */
#define last_system_status_var questions #define last_system_status_var questions
#define last_cleared_system_status_var memory_used #define last_cleared_system_status_var local_memory_used
/* /*
Global status variables Global status variables
......
...@@ -347,11 +347,6 @@ enum enum_parsing_place ...@@ -347,11 +347,6 @@ enum enum_parsing_place
}; };
enum enum_var_type
{
OPT_DEFAULT= 0, OPT_SESSION, OPT_GLOBAL
};
class sys_var; class sys_var;
enum enum_yes_no_unknown enum enum_yes_no_unknown
......
...@@ -2822,7 +2822,7 @@ int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond) ...@@ -2822,7 +2822,7 @@ int fill_schema_processlist(THD* thd, TABLE_LIST* tables, COND* cond)
thread in this thread. However it's better that we notice it eventually thread in this thread. However it's better that we notice it eventually
than hide it. than hide it.
*/ */
table->field[12]->store((longlong) (tmp->status_var.memory_used + table->field[12]->store((longlong) (tmp->status_var.local_memory_used +
sizeof(THD)), sizeof(THD)),
FALSE); FALSE);
table->field[12]->set_notnull(); table->field[12]->set_notnull();
...@@ -3117,7 +3117,7 @@ static bool show_status_array(THD *thd, const char *wild, ...@@ -3117,7 +3117,7 @@ static bool show_status_array(THD *thd, const char *wild,
*/ */
for (var=variables; var->type == SHOW_FUNC || for (var=variables; var->type == SHOW_FUNC ||
var->type == SHOW_SIMPLE_FUNC; var= &tmp) var->type == SHOW_SIMPLE_FUNC; var= &tmp)
((mysql_show_var_func)(var->value))(thd, &tmp, buff); ((mysql_show_var_func)(var->value))(thd, &tmp, buff, scope);
SHOW_TYPE show_type=var->type; SHOW_TYPE show_type=var->type;
if (show_type == SHOW_ARRAY) if (show_type == SHOW_ARRAY)
......
...@@ -67,4 +67,5 @@ extern void tp_set_threadpool_stall_limit(uint val); ...@@ -67,4 +67,5 @@ extern void tp_set_threadpool_stall_limit(uint val);
/* Activate threadpool scheduler */ /* Activate threadpool scheduler */
extern void tp_scheduler(void); extern void tp_scheduler(void);
extern int show_threadpool_idle_threads(THD *thd, SHOW_VAR *var, char *buff); extern int show_threadpool_idle_threads(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope);
...@@ -112,7 +112,8 @@ extern const char* wsrep_provider_name; ...@@ -112,7 +112,8 @@ extern const char* wsrep_provider_name;
extern const char* wsrep_provider_version; extern const char* wsrep_provider_version;
extern const char* wsrep_provider_vendor; extern const char* wsrep_provider_vendor;
int wsrep_show_status(THD *thd, SHOW_VAR *var, char *buff); int wsrep_show_status(THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope);
int wsrep_init(); int wsrep_init();
void wsrep_deinit(bool free_options); void wsrep_deinit(bool free_options);
void wsrep_recover(); void wsrep_recover();
......
...@@ -38,7 +38,8 @@ static volatile int32 wsrep_bf_aborts_counter(0); ...@@ -38,7 +38,8 @@ static volatile int32 wsrep_bf_aborts_counter(0);
#define WSREP_ATOMIC_ADD_LONG my_atomic_add32 #define WSREP_ATOMIC_ADD_LONG my_atomic_add32
#endif #endif
int wsrep_show_bf_aborts (THD *thd, SHOW_VAR *var, char *buff) int wsrep_show_bf_aborts (THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
wsrep_local_bf_aborts = WSREP_ATOMIC_LOAD_LONG(&wsrep_bf_aborts_counter); wsrep_local_bf_aborts = WSREP_ATOMIC_LOAD_LONG(&wsrep_bf_aborts_counter);
var->type = SHOW_LONGLONG; var->type = SHOW_LONGLONG;
......
...@@ -22,7 +22,8 @@ ...@@ -22,7 +22,8 @@
#include "sql_class.h" #include "sql_class.h"
int wsrep_show_bf_aborts (THD *thd, SHOW_VAR *var, char *buff); int wsrep_show_bf_aborts (THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope);
void wsrep_client_rollback(THD *thd); void wsrep_client_rollback(THD *thd);
void wsrep_replay_transaction(THD *thd); void wsrep_replay_transaction(THD *thd);
void wsrep_create_appliers(long threads); void wsrep_create_appliers(long threads);
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "wsrep_var.h" #include "wsrep_var.h"
#include <sql_plugin.h>
#include <mysqld.h> #include <mysqld.h>
#include <sql_class.h> #include <sql_class.h>
#include <set_var.h> #include <set_var.h>
...@@ -535,7 +534,8 @@ static int show_var_cmp(const void *var1, const void *var2) ...@@ -535,7 +534,8 @@ static int show_var_cmp(const void *var1, const void *var2)
return strcasecmp(((SHOW_VAR*)var1)->name, ((SHOW_VAR*)var2)->name); return strcasecmp(((SHOW_VAR*)var1)->name, ((SHOW_VAR*)var2)->name);
} }
int wsrep_show_status (THD *thd, SHOW_VAR *var, char *buff) int wsrep_show_status (THD *thd, SHOW_VAR *var, char *buff,
enum enum_var_type scope)
{ {
uint i, maxi= SHOW_VAR_FUNC_BUFF_SIZE / sizeof(*var) - 1; uint i, maxi= SHOW_VAR_FUNC_BUFF_SIZE / sizeof(*var) - 1;
SHOW_VAR *v= (SHOW_VAR *)buff; SHOW_VAR *v= (SHOW_VAR *)buff;
......
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
// MySQL variables funcs // MySQL variables funcs
#include "sql_priv.h" #include "sql_priv.h"
#include <sql_plugin.h>
#include <mysql/plugin.h>
class sys_var; class sys_var;
class set_var; class set_var;
class THD; class THD;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment