]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: trace: add allocation of buffer-sized trace buffers
authorWilly Tarreau <w@1wt.eu>
Mon, 19 Aug 2019 13:55:34 +0000 (15:55 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 22 Aug 2019 18:21:00 +0000 (20:21 +0200)
This will be needed so that we can implement protocol decoders which will
have to emit their contents into such a buffer.

include/proto/trace.h
src/trace.c

index 0838551e523657ae067dfaf076d10ef697d61370..a299237962cc4d6b7ba00c1e6183b7e0f51eeda5 100644 (file)
@@ -32,6 +32,7 @@
 #include <types/trace.h>
 
 extern struct list trace_sources;
+extern THREAD_LOCAL struct buffer trace_buf;
 
 /* registers trace source <source>. Modifies the list element!
  * The {start,pause,stop,report} events are not changed so the source may
index 97bd1b541febfa0505cf050df586d8d3ac8727f4..e77c3080ebe17b7dd818053458c665f8469d1904 100644 (file)
 #include <proto/trace.h>
 
 struct list trace_sources = LIST_HEAD_INIT(trace_sources);
+THREAD_LOCAL struct buffer trace_buf = { };
 
+/* allocates the trace buffers. Returns 0 in case of failure. It is safe to
+ * call to call this function multiple times if the size changes.
+ */
+static int alloc_trace_buffers_per_thread()
+{
+       chunk_init(&trace_buf, my_realloc2(trace_buf.area, global.tune.bufsize), global.tune.bufsize);
+       return !!trash.area;
+}
+
+static void free_trace_buffers_per_thread()
+{
+       chunk_destroy(&trace_buf);
+}
+
+REGISTER_PER_THREAD_ALLOC(alloc_trace_buffers_per_thread);
+REGISTER_PER_THREAD_FREE(free_trace_buffers_per_thread);
 /*
  * Local variables:
  *  c-indent-level: 8