]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: trace: implement a call to a decode function
authorWilly Tarreau <w@1wt.eu>
Mon, 19 Aug 2019 14:28:07 +0000 (16:28 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 22 Aug 2019 18:21:00 +0000 (20:21 +0200)
The trace() call will support an optional decoding callback and 4
arguments that this function is supposed to know how to use to provide
extra information. The output remains unchanged when the function is
NULL. Otherwise, the message is pre-filled into the thread-local
trace_buf, and the function is called with all arguments so that it
completes the buffer in a readable form depending on the expected
level of detail.

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

index 7875d149145b4763c4662f66816fa7bc96329f0a..e995e357034a67b1ec925f4e90f4b5b6240f9726 100644 (file)
 extern struct list trace_sources;
 extern THREAD_LOCAL struct buffer trace_buf;
 
-void __trace(enum trace_level level, uint64_t mask, struct trace_source *src, const struct ist where, const struct ist msg);
+void __trace(enum trace_level level, uint64_t mask, struct trace_source *src, const struct ist where,
+             const void *a1, const void *a2, const void *a3, const void *a4,
+             void (*cb)(enum trace_level level, uint64_t mask, const struct trace_source *src, const struct ist where,
+                        const void *a1, const void *a2, const void *a3, const void *a4),
+             const struct ist msg);
 
 /* return a single char to describe a trace state */
 static inline char trace_state_char(enum trace_state st)
@@ -66,10 +70,14 @@ static inline void trace_register_source(struct trace_source *source)
 }
 
 /* sends a trace for the given source */
-static inline void trace(enum trace_level level, uint64_t mask, struct trace_source *src, const struct ist where, const struct ist msg)
+static inline void trace(enum trace_level level, uint64_t mask, struct trace_source *src, const struct ist where,
+                         const void *a1, const void *a2, const void *a3, const void *a4,
+                         void (*cb)(enum trace_level level, uint64_t mask, const struct trace_source *src, const struct ist where,
+                                    const void *a1, const void *a2, const void *a3, const void *a4),
+                         const struct ist msg)
 {
        if (unlikely(src->state != TRACE_STATE_STOPPED))
-               __trace(level, mask, src, where, msg);
+               __trace(level, mask, src, where, a1, a2, a3, a4, cb, msg);
 }
 
 #endif /* _PROTO_TRACE_H */
index 03656ff19b30a5b8a970f515baed6a59f0fe53b0..eec34779bdcf9fc102f614662cec79647ef25fed 100644 (file)
@@ -49,7 +49,11 @@ REGISTER_PER_THREAD_ALLOC(alloc_trace_buffers_per_thread);
 REGISTER_PER_THREAD_FREE(free_trace_buffers_per_thread);
 
 /* write a message for the given trace source */
-void __trace(enum trace_level level, uint64_t mask, struct trace_source *src, const struct ist where, const struct ist msg)
+void __trace(enum trace_level level, uint64_t mask, struct trace_source *src, const struct ist where,
+             const void *a1, const void *a2, const void *a3, const void *a4,
+             void (*cb)(enum trace_level level, uint64_t mask, const struct trace_source *src, const struct ist where,
+                        const void *a1, const void *a2, const void *a3, const void *a4),
+             const struct ist msg)
 {
        struct ist line[8];
 
@@ -87,7 +91,20 @@ void __trace(enum trace_level level, uint64_t mask, struct trace_source *src, co
                line[1].len = 10;
        }
        line[2] = ist("] ");
-       line[3] = msg;
+
+       if (cb) {
+               /* decode function passed, we want to pre-fill the
+                * buffer with the message and let the decode function
+                * do its job, possibly even overwriting it.
+                */
+               b_reset(&trace_buf);
+               b_istput(&trace_buf, msg);
+               cb(level, mask, src, where, a1, a2, a3, a4);
+               line[3].ptr = trace_buf.area;
+               line[3].len = trace_buf.data;
+       }
+       else
+               line[3] = msg;
 
        if (src->sink)
                sink_write(src->sink, line, 4);