Skip to content

Commit

Permalink
debug: Name some more threads
Browse files Browse the repository at this point in the history
Signed-off-by: Akshat Sikarwar <[email protected]>
  • Loading branch information
akshatsikarwar committed Dec 19, 2024
1 parent 465a3ad commit 6fad0d4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
4 changes: 4 additions & 0 deletions lua/sp.c
Original file line number Diff line number Diff line change
Expand Up @@ -7322,6 +7322,10 @@ void lua_func(sqlite3_context *context, int argc, sqlite3_value **argv)

void *exec_trigger(char *spname)
{
char thdname[16];
snprintf(thdname, sizeof(thdname), "T:%s", spname);
comdb2_name_thread(thdname);

char sql[128];
snprintf(sql, sizeof(sql), "exec procedure %s()", spname);

Expand Down
26 changes: 20 additions & 6 deletions net/net_evbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,10 +587,14 @@ static struct host_info *host_info_new(char *host)
h->host_interned = intern_ptr(host);
h->host = h->host_interned->str;
if (reader_policy == POLICY_PER_HOST) {
init_base(&h->per_host.rdthd, &h->per_host.rdbase, h->host);
char thdname[16];
snprintf(thdname, sizeof(thdname), "R:%s", h->host);
init_base(&h->per_host.rdthd, &h->per_host.rdbase, strdup(thdname));
}
if (writer_policy == POLICY_PER_HOST) {
init_base(&h->per_host.wrthd, &h->per_host.wrbase, h->host);
char thdname[16];
snprintf(thdname, sizeof(thdname), "W:%s", h->host);
init_base(&h->per_host.wrthd, &h->per_host.wrbase, strdup(thdname));
}
LIST_INIT(&h->event_list);
LIST_INSERT_HEAD(&host_list, h, entry);
Expand Down Expand Up @@ -637,10 +641,14 @@ static struct net_info *net_info_new(netinfo_type *netinfo_ptr)
// See increase_net_buf()
n->rd_max = n->wr_max = MB(8);
if (reader_policy == POLICY_PER_NET) {
init_base(&n->per_net.rdthd, &n->per_net.rdbase, n->service);
char thdname[16];
snprintf(thdname, sizeof(thdname), "R:%s", n->service);
init_base(&n->per_net.rdthd, &n->per_net.rdbase, strdup(thdname));
}
if (writer_policy == POLICY_PER_NET) {
init_base(&n->per_net.wrthd, &n->per_net.wrbase, n->service);
char thdname[16];
snprintf(thdname, sizeof(thdname), "W:%s", n->service);
init_base(&n->per_net.wrthd, &n->per_net.wrbase, strdup(thdname));
}
LIST_INIT(&n->event_list);
LIST_INSERT_HEAD(&net_list, n, entry);
Expand Down Expand Up @@ -740,10 +748,16 @@ static struct event_info *event_info_new(struct net_info *n, struct host_info *h
hash_add(event_hash, entry);
Pthread_mutex_unlock(&event_hash_lk);
if (reader_policy == POLICY_PER_EVENT) {
init_base(&e->per_event.rdthd, &e->per_event.rdbase, entry->key);
char thdname[16];
int x = snprintf(thdname, sizeof(thdname), "R:%s", entry->key);
(void)x;
init_base(&e->per_event.rdthd, &e->per_event.rdbase, strdup(thdname));
}
if (writer_policy == POLICY_PER_EVENT) {
init_base(&e->per_event.wrthd, &e->per_event.wrbase, entry->key);
char thdname[16];
int x = snprintf(thdname, sizeof(thdname), "W:%s", entry->key);
(void)x;
init_base(&e->per_event.wrthd, &e->per_event.wrbase, strdup(thdname));
}
/* set up rd_worker */
Pthread_mutex_init(&e->rd_lk, NULL);
Expand Down
9 changes: 8 additions & 1 deletion util/thdpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ static void *thdpool_thd(void *voidarg)
struct thdpool *pool = thd->pool;

comdb2_name_thread(pool->name);

ATOMIC_ADD32(pool->nactthd, 1);
# ifndef NDEBUG
logmsg(LOGMSG_DEBUG, "%s(%s): thread going active: %u active\n",
Expand Down Expand Up @@ -1302,7 +1303,13 @@ void thdpool_set_queued_callback(struct thdpool *pool, void(*callback)(void*))

void comdb2_name_thread(const char *name) {
#ifdef __linux
pthread_setname_np(pthread_self(), name);
char buf[16];
const char *ptr = name;
if (strlen(name) > 15) {
snprintf(buf, sizeof(buf), "%.14s!", name);
ptr = buf;
}
pthread_setname_np(pthread_self(), ptr);
#elif defined __APPLE__
pthread_setname_np(name);
#endif
Expand Down

0 comments on commit 6fad0d4

Please sign in to comment.