mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-24 23:31:40 +02:00
MINOR: trace: add per-level macros to produce traces
The new TRACE_<level>() macros take a mask, 4 args, a callback and a static message. From this they also inherit the TRACE_SOURCE macro from the caller, which contains the pointer to the trace source (so that it's not required to paste it everywhere), and an ist string is also made by the concatenation of the file name and the line number. This uses string concatenation by the preprocessor, and turns it into an ist by the compiler so that there is no operation at all to perform to adjust the data length as the compiler knows where to cut during the optimization phase. Last, the message is also automatically turned into an ist so that it's trivial to put it into an iovec without having to run strlen() on it. All arguments and the callback may be empty and will then automatically be replaced with a NULL pointer. This makes the TRACE calls slightly lighter especially since arguments are not always used. Several other options were considered to use variadic macros but there's no outstanding rule that justifies to place an argument before another one, and it still looks convenient to have the message be the last one to encourage copy- pasting of the trace statements. A generic TRACE() macro takes TRACE_LEVEL in from the source file as the trace level instead of taking it from its name. This may slightly simplify the production of traces that always run at the same level (internal core parts may probably only be called at developer level).
This commit is contained in:
parent
bfd14fc6eb
commit
4ab242136d
@ -31,6 +31,35 @@
|
|||||||
#include <types/sink.h>
|
#include <types/sink.h>
|
||||||
#include <types/trace.h>
|
#include <types/trace.h>
|
||||||
|
|
||||||
|
/* Make a string from the location of the trace producer as "file:line" */
|
||||||
|
#define TRC_LOC _TRC_LOC(__FILE__, __LINE__)
|
||||||
|
#define _TRC_LOC(f,l) __TRC_LOC(f, ":", l)
|
||||||
|
#define __TRC_LOC(f,c,l) f c #l
|
||||||
|
|
||||||
|
/* For convenience, TRACE() alone uses the file's default TRACE_LEVEL, most
|
||||||
|
* likely TRACE_LEVEL_DEVELOPER. The 4 arguments are the 4 source-specific
|
||||||
|
* arguments that are passed to the cb() callback dedicated to decoding, and
|
||||||
|
* which may be used for special tracking. These 4 arguments as well as the
|
||||||
|
* cb() function pointer may all be NULL, or simply omitted (in which case
|
||||||
|
* they will be replaced by a NULL). This ordering allows many TRACE() calls
|
||||||
|
* to be placed using copy-paste and just change the message at the end.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define TRACE(mask, a1, a2, a3, a4, cb, msg) \
|
||||||
|
trace(TRACE_LEVEL, (mask), TRACE_SOURCE, ist(TRC_LOC), DEFNULL(a1), DEFNULL(a2), DEFNULL(a3), DEFNULL(a4), DEFNULL(cb), ist(msg))
|
||||||
|
|
||||||
|
/* and explicit trace levels (recommended) */
|
||||||
|
#define TRACE_USER(mask, a1, a2, a3, a4, cb, msg) \
|
||||||
|
trace(TRACE_LEVEL_USER, (mask), TRACE_SOURCE, ist(TRC_LOC), DEFNULL(a1), DEFNULL(a2), DEFNULL(a3), DEFNULL(a4), DEFNULL(cb), ist(msg))
|
||||||
|
#define TRACE_PAYLOAD(mask, a1, a2, a3, a4, cb, msg) \
|
||||||
|
trace(TRACE_LEVEL_PAYLOAD, (mask), TRACE_SOURCE, ist(TRC_LOC), DEFNULL(a1), DEFNULL(a2), DEFNULL(a3), DEFNULL(a4), DEFNULL(cb), ist(msg))
|
||||||
|
#define TRACE_PROTO(mask, a1, a2, a3, a4, cb, msg) \
|
||||||
|
trace(TRACE_LEVEL_PROTO, (mask), TRACE_SOURCE, ist(TRC_LOC), DEFNULL(a1), DEFNULL(a2), DEFNULL(a3), DEFNULL(a4), DEFNULL(cb), ist(msg))
|
||||||
|
#define TRACE_STATE(mask, a1, a2, a3, a4, cb, msg) \
|
||||||
|
trace(TRACE_LEVEL_STATE, (mask), TRACE_SOURCE, ist(TRC_LOC), DEFNULL(a1), DEFNULL(a2), DEFNULL(a3), DEFNULL(a4), DEFNULL(cb), ist(msg))
|
||||||
|
#define TRACE_DEVEL(mask, a1, a2, a3, a4, cb, msg) \
|
||||||
|
trace(TRACE_LEVEL_DEVELOPER, (mask), TRACE_SOURCE, ist(TRC_LOC), DEFNULL(a1), DEFNULL(a2), DEFNULL(a3), DEFNULL(a4), DEFNULL(cb), ist(msg))
|
||||||
|
|
||||||
extern struct list trace_sources;
|
extern struct list trace_sources;
|
||||||
extern THREAD_LOCAL struct buffer trace_buf;
|
extern THREAD_LOCAL struct buffer trace_buf;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user