From: Jeff Hostetler via GitGitGadget Date: Mon, 20 Dec 2021 15:01:04 GMT Subject: [PATCH 4/9] trace2: add thread-name override to event target Message-ID: In-Reply-To: From: Jeff Hostetler Teach the Trace2 event target to allow the thread-name field to be specified rather than always inherited from the TLS CTX. This will be used in a future commit for global events that should not be tied to a particular thread, such as a global stopwatch timer that aggregates data from all threads. Signed-off-by: Jeff Hostetler --- trace2/tr2_tgt_event.c | 59 ++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/trace2/tr2_tgt_event.c b/trace2/tr2_tgt_event.c index ca48d00aebc..4ce50944298 100644 --- a/trace2/tr2_tgt_event.c +++ b/trace2/tr2_tgt_event.c @@ -81,14 +81,17 @@ static void fn_term(void) */ static void event_fmt_prepare(const char *event_name, const char *file, int line, const struct repository *repo, - struct json_writer *jw) + struct json_writer *jw, + const char *thread_name_override) { - struct tr2tls_thread_ctx *ctx = tr2tls_get_self(); struct tr2_tbuf tb_now; jw_object_string(jw, "event", event_name); jw_object_string(jw, "sid", tr2_sid_get()); - jw_object_string(jw, "thread", ctx->thread_name); + jw_object_string(jw, "thread", + ((thread_name_override && *thread_name_override) + ? thread_name_override + : tr2tls_get_self()->thread_name)); /* * In brief mode, only emit