trace2: rename the thread_name argument to trace2_thread_start

Rename the `thread_name` argument in `tr2tls_create_self()` and `trace2_thread_start()` to be `thread_base_name` to make it clearer that the passed argument is a component used in the construction of the actual `struct tr2tls_thread_ctx.thread_name` variable. The base name will be used along with the thread id to create a unique thread name. This commit does not change how the `thread_name` field is allocated or stored within the `tr2tls_thread_ctx` structure. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff Hostetler committed Oct 24, 2022 at 13:41 UTC a70839cf36c9cad10e514f75fa1bec2e6180dbda
4 files changed +12 -11
trace2.c
+3 -3
@@ -466,7 +466,7 @@ void trace2_exec_result_fl(const char *file, int line, int exec_id, int code)
466 file, line, us_elapsed_absolute, exec_id, code);
467 }
468
469 -void trace2_thread_start_fl(const char *file, int line, const char *thread_name)
469 +void trace2_thread_start_fl(const char *file, int line, const char *thread_base_name)
470 {
471 struct tr2_tgt *tgt_j;
472 int j;
@@ -488,14 +488,14 @@ void trace2_thread_start_fl(const char *file, int line, const char *thread_name)
488 */
489 trace2_region_enter_printf_fl(file, line, NULL, NULL, NULL,
490 "thread-proc on main: %s",
491 - thread_name);
491 + thread_base_name);
492 return;
493 }
494
495 us_now = getnanotime() / 1000;
496 us_elapsed_absolute = tr2tls_absolute_elapsed(us_now);
497
498 - tr2tls_create_self(thread_name, us_now);
498 + tr2tls_create_self(thread_base_name, us_now);
499
500 for_each_wanted_builtin (j, tgt_j)
501 if (tgt_j->pfn_thread_start_fl)
trace2.h
+6 -5
@@ -304,14 +304,15 @@ void trace2_exec_result_fl(const char *file, int line, int exec_id, int code);
304 * thread-proc to allow the thread to create its own thread-local
305 * storage.
306 *
307 - * Thread names should be descriptive, like "preload_index".
308 - * Thread names will be decorated with an instance number automatically.
307 + * The thread base name should be descriptive, like "preload_index" or
308 + * taken from the thread-proc function. A unique thread name will be
309 + * created from the given base name and the thread id automatically.
310 */
311 void trace2_thread_start_fl(const char *file, int line,
311 - const char *thread_name);
312 + const char *thread_base_name);
313
313 -#define trace2_thread_start(thread_name) \
314 - trace2_thread_start_fl(__FILE__, __LINE__, (thread_name))
314 +#define trace2_thread_start(thread_base_name) \
315 + trace2_thread_start_fl(__FILE__, __LINE__, (thread_base_name))
316
317 /*
318 * Emit a 'thread_exit' event. This must be called from inside the
trace2/tr2_tls.c
+2 -2
@@ -31,7 +31,7 @@ void tr2tls_start_process_clock(void)
31 tr2tls_us_start_process = getnanotime() / 1000;
32 }
33
34 -struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name,
34 +struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_base_name,
35 uint64_t us_thread_start)
36 {
37 struct tr2tls_thread_ctx *ctx = xcalloc(1, sizeof(*ctx));
@@ -50,7 +50,7 @@ struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name,
50 strbuf_init(&ctx->thread_name, 0);
51 if (ctx->thread_id)
52 strbuf_addf(&ctx->thread_name, "th%02d:", ctx->thread_id);
53 - strbuf_addstr(&ctx->thread_name, thread_name);
53 + strbuf_addstr(&ctx->thread_name, thread_base_name);
54 if (ctx->thread_name.len > TR2_MAX_THREAD_NAME)
55 strbuf_setlen(&ctx->thread_name, TR2_MAX_THREAD_NAME);
56
trace2/tr2_tls.h
+1 -1
@@ -35,7 +35,7 @@ struct tr2tls_thread_ctx {
35 * In this and all following functions the term "self" refers to the
36 * current thread.
37 */
38 -struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_name,
38 +struct tr2tls_thread_ctx *tr2tls_create_self(const char *thread_base_name,
39 uint64_t us_thread_start);
40
41 /*