diff --git a/doc/configuration.txt b/doc/configuration.txt index 4288e8881..43b6e6b5f 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -24019,6 +24019,11 @@ term_events : string It must only be used for debugging purpose. The exact format is not documented because it may evolve depending on developers requirements. +tgroup : integer + Returns an integer value corresponding to the position of the thread group + calling the function, between 0 and (global.thread-groups - 1). This is + useful for logging and debugging purposes. + thread : integer Returns an integer value corresponding to the position of the thread calling the function, between 0 and (global.nbthread-1). This is useful for logging diff --git a/src/sample.c b/src/sample.c index 902db7056..370c0156a 100644 --- a/src/sample.c +++ b/src/sample.c @@ -5080,6 +5080,15 @@ smp_fetch_thread(const struct arg *args, struct sample *smp, const char *kw, voi return 1; } +/* returns the number of the current thread group (between 0 and nbtgroups-1) */ +static int +smp_fetch_tgroup(const struct arg *args, struct sample *smp, const char *kw, void *private) +{ + smp->data.type = SMP_T_SINT; + smp->data.u.sint = tgid - 1; // tgid starts at 1 + return 1; +} + /* generate a random 32-bit integer for whatever purpose, with an optional * range specified in argument. */ @@ -5659,6 +5668,7 @@ static struct sample_fetch_kw_list smp_kws = {ILH, { { "proc", smp_fetch_proc, 0, NULL, SMP_T_SINT, SMP_USE_CONST }, { "quic_enabled", smp_fetch_quic_enabled, 0, NULL, SMP_T_BOOL, SMP_USE_CONST }, { "thread", smp_fetch_thread, 0, NULL, SMP_T_SINT, SMP_USE_CONST }, + { "tgroup", smp_fetch_tgroup, 0, NULL, SMP_T_SINT, SMP_USE_CONST }, { "rand", smp_fetch_rand, ARG1(0,SINT), NULL, SMP_T_SINT, SMP_USE_CONST }, { "stopping", smp_fetch_stopping, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN }, { "uptime", smp_fetch_uptime, 0, NULL, SMP_T_SINT, SMP_USE_CONST },