Set thread names

pull/4574/head
Andriy Utkin 2 years ago
parent b6e92936d3
commit 5e79afa8e0

@ -11,6 +11,7 @@
#include <sys/types.h>
#include <dirent.h>
#include <sys/resource.h>
#include <assert.h>
#include "sqlite3db.h"
@ -258,4 +259,12 @@ void close_all_non_term_fd(std::vector<int> excludeFDs);
*/
std::pair<int,const char*> get_dollar_quote_error(const char* version);
static inline void set_thread_name(const char name[16]) {
#if defined(__linux__) || defined(__FreeBSD__)
int rc;
rc = pthread_setname_np(pthread_self(), name);
assert(!rc);
#endif
}
#endif

@ -1475,6 +1475,7 @@ static void * sqlite3server_main_loop(void *arg)
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
set_thread_name("ClickHouseMain");
while (glovars.shutdown==0 && *shutdown==0)
{
int *client;

@ -442,6 +442,7 @@ void addGtid(const gtid_t& gtid, gtid_set_t& gtid_executed) {
void * GTID_syncer_run() {
//struct ev_loop * gtid_ev_loop;
//gtid_ev_loop = NULL;
set_thread_name("GTID");
MyHGM->gtid_ev_loop = ev_loop_new (EVBACKEND_POLL | EVFLAG_NOENV);
if (MyHGM->gtid_ev_loop == NULL) {
proxy_error("could not initialise GTID sync loop\n");

@ -85,6 +85,7 @@ static int wait_for_mysql(MYSQL *mysql, int status) {
//static void * HGCU_thread_run() {
static void * HGCU_thread_run() {
PtrArray *conn_array=new PtrArray();
set_thread_name("MyHGCU");
while(1) {
MySQL_Connection *myconn= NULL;
myconn = (MySQL_Connection *)MyHGM->queue.remove();

@ -68,6 +68,9 @@ class ConsumerThread : public Thread {
thrn=_n;
}
void* run() {
char thr_name[16];
snprintf(thr_name, sizeof(thr_name), "%.12s%03d", typeid(T).name(), thrn);
set_thread_name(thr_name);
// Remove 1 item at a time and process it. Blocks if no items are
// available to process.
for (int i = 0; (thrn ? i < thrn : 1); i++) {
@ -729,6 +732,7 @@ void * monitor_connect_pthread(void *arg) {
bool cache=false;
mallctl("thread.tcache.enabled", NULL, NULL, &cache, sizeof(bool));
#endif
set_thread_name("MonitorConnect");
while (GloMTH==NULL) {
usleep(50000);
}
@ -742,6 +746,7 @@ void * monitor_ping_pthread(void *arg) {
bool cache=false;
mallctl("thread.tcache.enabled", NULL, NULL, &cache, sizeof(bool));
#endif
set_thread_name("MonitorPing");
while (GloMTH==NULL) {
usleep(50000);
}
@ -755,6 +760,7 @@ void * monitor_read_only_pthread(void *arg) {
bool cache=false;
mallctl("thread.tcache.enabled", NULL, NULL, &cache, sizeof(bool));
#endif
set_thread_name("MonitorReadOnly");
while (GloMTH==NULL) {
usleep(50000);
}
@ -768,6 +774,7 @@ void * monitor_group_replication_pthread(void *arg) {
bool cache=false;
mallctl("thread.tcache.enabled", NULL, NULL, &cache, sizeof(bool));
#endif
set_thread_name("MonitorGR");
while (GloMTH==NULL) {
usleep(50000);
}
@ -782,6 +789,7 @@ void * monitor_galera_pthread(void *arg) {
bool cache=false;
mallctl("thread.tcache.enabled", NULL, NULL, &cache, sizeof(bool));
#endif
set_thread_name("MonitorGalera");
while (GloMTH==NULL) {
usleep(50000);
}
@ -795,6 +803,7 @@ void * monitor_aws_aurora_pthread(void *arg) {
// bool cache=false;
// mallctl("thread.tcache.enabled", NULL, NULL, &cache, sizeof(bool));
//#endif
set_thread_name("MonitorAurora");
while (GloMTH==NULL) {
usleep(50000);
}
@ -808,6 +817,7 @@ void * monitor_replication_lag_pthread(void *arg) {
bool cache=false;
mallctl("thread.tcache.enabled", NULL, NULL, &cache, sizeof(bool));
#endif
set_thread_name("MonitReplicLag");
while (GloMTH==NULL) {
usleep(50000);
}
@ -821,6 +831,7 @@ void* monitor_dns_cache_pthread(void* arg) {
bool cache = false;
mallctl("thread.tcache.enabled", NULL, NULL, &cache, sizeof(bool));
#endif
set_thread_name("MonitorDNSCache");
while (GloMTH == NULL) {
usleep(50000);
}
@ -3996,6 +4007,7 @@ struct mon_thread_info_t {
void* monitor_GR_thread_HG(void *arg) {
uint32_t wr_hg = *(static_cast<uint32_t*>(arg));
set_thread_name("MonitorGRwrHG");
proxy_info("Started Monitor thread for Group Replication writer HG %u\n", wr_hg);
// Quick exit during shutdown/restart
@ -5854,6 +5866,7 @@ void * monitor_AWS_Aurora_thread_HG(void *arg) {
unsigned int min_lag_ms = 0;
unsigned int lag_num_checks = 1;
//unsigned int i = 0;
set_thread_name("MonitorAuroraHG");
proxy_info("Started Monitor thread for AWS Aurora writer HG %u\n", wHG);
unsigned int MySQL_Monitor__thread_MySQL_Thread_Variables_version;

@ -264,6 +264,7 @@ void* kill_query_thread(void *arg) {
KillArgs *ka=(KillArgs *)arg;
//! It initializes a new MySQL_Thread object to handle MySQL-related operations.
std::unique_ptr<MySQL_Thread> mysql_thr(new MySQL_Thread());
set_thread_name("KillQuery");
//! Retrieves the current time and refreshes thread variables.
mysql_thr->curtime=monotonic_time();
mysql_thr->refresh_variables();

@ -2386,6 +2386,7 @@ void MySQL_Threads_Handler::init(unsigned int num, size_t stack) {
* @return A pointer to the created MySQL thread.
*/
proxysql_mysql_thread_t * MySQL_Threads_Handler::create_thread(unsigned int tn, void *(*start_routine) (void *), bool idles) {
char thr_name[16];
if (idles==false) {
if (pthread_create(&mysql_threads[tn].thread_id, &attr, start_routine , &mysql_threads[tn]) != 0 ) {
// LCOV_EXCL_START
@ -2393,6 +2394,8 @@ proxysql_mysql_thread_t * MySQL_Threads_Handler::create_thread(unsigned int tn,
assert(0);
// LCOV_EXCL_STOP
}
snprintf(thr_name, sizeof(thr_name), "MySQLWorker%d", tn);
pthread_setname_np(mysql_threads[tn].thread_id, thr_name);
#ifdef IDLE_THREADS
} else {
if (GloVars.global.idle_threads) {
@ -2402,6 +2405,7 @@ proxysql_mysql_thread_t * MySQL_Threads_Handler::create_thread(unsigned int tn,
assert(0);
// LCOV_EXCL_STOP
}
snprintf(thr_name, sizeof(thr_name), "MySQLIdle%d", tn);
}
#endif // IDLE_THREADS
}

@ -5682,6 +5682,7 @@ static void * admin_main_loop(void *arg)
int *callback_func=((struct _main_args *)arg)->callback_func;
volatile int *shutdown=((struct _main_args *)arg)->shutdown;
char *socket_names[MAX_ADMIN_LISTENERS];
set_thread_name("Admin");
for (i=0;i<MAX_ADMIN_LISTENERS;i++) { socket_names[i]=NULL; }
pthread_attr_t attr;
pthread_attr_init(&attr);

@ -47,6 +47,7 @@ extern MySQL_Authentication* GloMyAuth;
void * ProxySQL_Cluster_Monitor_thread(void *args) {
pthread_attr_t thread_attr;
size_t tmp_stack_size=0;
set_thread_name("ClusterMonitor");
if (!pthread_attr_init(&thread_attr)) {
if (!pthread_attr_getstacksize(&thread_attr , &tmp_stack_size )) {
__sync_fetch_and_add(&GloVars.statuses.stack_memory_cluster_threads,tmp_stack_size);

@ -329,6 +329,7 @@ public:
};
void * restapi_server_thread(void *arg) {
set_thread_name("RESTAPI_Server");
httpserver::webserver * ws = (httpserver::webserver *)arg;
ws->start(true);
return NULL;

@ -792,6 +792,7 @@ void * Query_Cache::purgeHash_thread(void *) {
unsigned int MySQL_Monitor__thread_MySQL_Thread_Variables_version;
MySQL_Thread * mysql_thr = new MySQL_Thread();
MySQL_Monitor__thread_MySQL_Thread_Variables_version=GloMTH->get_global_version();
set_thread_name("QueryCachePurge");
mysql_thr->refresh_variables();
max_memory_size = (uint64_t) mysql_thread___query_cache_size_MB*1024*1024;
while (shutdown==0) {

@ -770,6 +770,7 @@ void * get_query_digests_total_size_parallel(void *_arg) {
unsigned long long i = 0;
unsigned long long m = arg->m;
unsigned long long ret = 0;
set_thread_name("GetQueryDigeTota");
for (std::unordered_map<uint64_t, void *>::iterator it=arg->gu->begin(); it!=arg->gu->end(); ++it) {
if ((i%DIGEST_STATS_FAST_THREADS)==m) {
QP_query_digest_stats *qds=(QP_query_digest_stats *)it->second;
@ -805,6 +806,7 @@ void * get_query_digests_parallel(void *_arg) {
unsigned long long i = 0;
unsigned long long m = arg->m;
unsigned long long ret = 0;
set_thread_name("GetQueryDigests");
if (arg->free_me) {
if (arg->defer_free) {
size_t map_size = arg->gu->size();
@ -852,6 +854,7 @@ void * purge_query_digests_parallel(void *_arg) {
unsigned long long i = 0;
unsigned long long r = 0;
unsigned long long m = arg->m;
set_thread_name("PurgeQueryDigest");
for (std::unordered_map<uint64_t, void *>::iterator it=arg->gu->begin(); it!=arg->gu->end(); ++it) {
if ((i%DIGEST_STATS_FAST_THREADS)==m) {
QP_query_digest_stats *qds=(QP_query_digest_stats *)it->second;

@ -1021,6 +1021,7 @@ static void *child_mysql(void *arg) {
int client = *(int *)arg;
set_thread_name("SQLiteChildMySQL");
GloMTH->wrlock();
{
char *s=GloMTH->get_variable((char *)"server_capabilities");
@ -1133,6 +1134,7 @@ static void * sqlite3server_main_loop(void *arg)
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
set_thread_name("SQLite3_Main");
while (glovars.shutdown==0 && *shutdown==0)
{
int *client;

@ -78,6 +78,7 @@ static pthread_mutex_t *lockarray;
static void * waitpid_thread(void *arg) {
pid_t *cpid_ptr=(pid_t *)arg;
int status;
set_thread_name("waitpid");
waitpid(*cpid_ptr, &status, 0);
free(cpid_ptr);
return NULL;
@ -195,6 +196,7 @@ static char * main_check_latest_version() {
* @return NULL.
*/
void * main_check_latest_version_thread(void *arg) {
set_thread_name("CheckLatestVers");
// Fetch the latest version information
char * latest_version = main_check_latest_version();
// we check for potential invalid data , see issue #4042

Loading…
Cancel
Save