]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sample: Add "thread" sample fetch
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 21 Nov 2017 20:45:38 +0000 (21:45 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 23 Nov 2017 15:33:13 +0000 (16:33 +0100)
It returns id of the thread calling the function.

doc/configuration.txt
src/sample.c

index cc397e1884c09ddef774af656444ba5dee418859..9082fcc0f48b54ee4a7e27999d84ae3ae04c6d68 100644 (file)
@@ -13559,6 +13559,11 @@ table_cnt([<table>]) : integer
   stick-table or in the designated stick-table. See also src_conn_cnt and
   table_avl for other entry counting methods.
 
+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
+  and debugging purposes.
+
 var(<var-name>) : undefined
   Returns a variable with the stored type. If the variable is not set, the
   sample fetch fails. The name of the variable starts with an indication
index f1cfad4f36582734d9297ca0e7ffc1488c15f0b5..9389766f4cf68108c0a48ec90bd50a6994f8ccac 100644 (file)
@@ -2595,6 +2595,15 @@ smp_fetch_proc(const struct arg *args, struct sample *smp, const char *kw, void
        return 1;
 }
 
+/* returns the number of the current thread (between 1 and nbthread */
+static int
+smp_fetch_thread(const struct arg *args, struct sample *smp, const char *kw, void *private)
+{
+       smp->data.type = SMP_T_SINT;
+       smp->data.u.sint = tid;
+       return 1;
+}
+
 /* generate a random 32-bit integer for whatever purpose, with an optional
  * range specified in argument.
  */
@@ -2753,6 +2762,7 @@ static struct sample_fetch_kw_list smp_kws = {ILH, {
        { "hostname",     smp_fetch_hostname, 0,         NULL, SMP_T_STR,  SMP_USE_INTRN },
        { "nbproc",       smp_fetch_nbproc,0,            NULL, SMP_T_SINT, SMP_USE_INTRN },
        { "proc",         smp_fetch_proc,  0,            NULL, SMP_T_SINT, SMP_USE_INTRN },
+       { "thread",       smp_fetch_thread,  0,          NULL, SMP_T_SINT, SMP_USE_INTRN },
        { "rand",         smp_fetch_rand,  ARG1(0,SINT), NULL, SMP_T_SINT, SMP_USE_INTRN },
        { "stopping",     smp_fetch_stopping, 0,         NULL, SMP_T_BOOL, SMP_USE_INTRN },