]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tools: add a function to write a thread execution context.
authorWilly Tarreau <w@1wt.eu>
Thu, 12 Mar 2026 06:48:14 +0000 (07:48 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 12 Mar 2026 17:06:37 +0000 (18:06 +0100)
The new function chunk_append_thread_ctx() appends to a buffer the given
execution context based on its type and pointer. The goal is to easily
use it in profiling output and thread dumps. For now it only handles
TH_EX_CTX_NONE (which prints nothing) and TH_EX_CTX_OTHER (which indicates
"other ctx" followed by the pointer). It will be extended by new types as
they arrive.

include/haproxy/tools.h
src/tools.c

index 2e266621d37c74e435b823d4e459759105fa7ad8..22a20a856ccde57e204507ed6cac68382f406e91 100644 (file)
@@ -1540,4 +1540,6 @@ void ha_freearray(char ***array);
 
 void ha_memset_s(void *s, int c, size_t n);
 
+void chunk_append_thread_ctx(struct buffer *output, const struct thread_exec_ctx *ctx, const char *pfx, const char *sfx);
+
 #endif /* _HAPROXY_TOOLS_H */
index cdbf7e20101fecae607711b54933a85f52c60a78..f6e1d273b601a8d98cf910198eb76d681470f468 100644 (file)
@@ -7502,6 +7502,28 @@ void ha_memset_s(void *s, int c, size_t n)
        __asm__ __volatile__("" : : "r"(s) : "memory");
 }
 
+/* Optionally appends the thread execution context as a string to the output,
+ * prefixed with <pfx> and suffixed with <sfx> if not NULL and only when the
+ * context type is not TH_EX_CTX_NONE. Otherwise it does nothing and leaves the
+ * chunk untouched.
+ */
+void chunk_append_thread_ctx(struct buffer *output, const struct thread_exec_ctx *ctx, const char *pfx, const char *sfx)
+{
+       if (!ctx->type)
+               return;
+
+       chunk_appendf(output,"%s", pfx ? pfx : "");
+
+       switch (ctx->type) {
+       default:
+               chunk_appendf(output,"other ctx %p", ctx->pointer);
+               break;
+       }
+
+       chunk_appendf(output,"%s", sfx ? sfx : "");
+}
+
+
 /*
  * Local variables:
  *  c-indent-level: 8