Name worker threads according to event slot and number.
The following discussion from !4519 should be addressed:
-
@graven started a discussion: (+1 comment) presumably calling
pthread_setname_np
has negligible overhead, in which case we could maybe afford to make it a bit more specific, eg. add the event number (or slot? or ???) from theevtctx
. That would require a RAII wrapper to then also 'reset' the name whenoperator()
returns, eg:struct ThreadName { std::array<char,16> prev_name; // only 15 characters are allowed by pthread_{get, set}name_np ThreadName( char const* n ) { if (strlen(n)>16) throw Gaudi::Exception("name too long",__PRETTY_FUNCTION__,StatusCode::FAILURE); pthread_getname_np( pthread_self(), prev_name.data() ); pthread_setname_np( pthread_self(), n ); } ~ThreadName() { pthread_setname_np( pthread_self(), prev_name.data() ); } }; auto _ = ThreadName{fmt::format("w_{:03}_{:08x}",evtctx.slot(),evtctx.eventID().event_number()).c_str()}; return f( evtctx );
It would imply that the thread name fluctuates rapidly... (unless eg. processing gets stuck, at which point there is a hint of what event it is stuck on -- and one could see whether there is still progress being made by looking at the name ;-)