From 92fd905c1aa4b37f710c924ae3d43e2b8a996944 Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Wed, 17 Apr 2024 17:43:00 +0000 Subject: [PATCH] broker/module.c: name threads Tiny change, but handy. problem: As it is, all threads are named `flux-broker-` when identified with `info threads` in gdb, or in perf, or wherever. solution: Since almost all threads are actually actors executing a specific module, name the thread using the module name during module setup. --- src/broker/module.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/broker/module.c b/src/broker/module.c index 686f54d8ca34..7ba751fb309b 100644 --- a/src/broker/module.c +++ b/src/broker/module.c @@ -91,6 +91,18 @@ static int setup_module_profiling (module_t *p) cali_begin_int_byname ("flux.rank", p->rank); cali_begin_string_byname ("flux.name", p->name); #endif + size_t len = strlen (p->name); + // one character longer than target to pass -Wstringop-truncation + char local_name[17] = {0}; + const char *name_ptr = p->name; + // pthread name is limited to 16 bytes including \0 on linux + if (len > 15) { + strncpy (local_name, p->name, 16); + local_name[15] = 0; + name_ptr = local_name; + } + // Set the name of each thread to its module name + (void) pthread_setname_np (pthread_self (), name_ptr); return (0); }