mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-28 05:56:33 +02:00
tracing: dedup TRACE macros & rename to TRACEPOINT
This deduplicates the TRACEx macros by using systemtaps STAP_PROBEV[0] variadic macro instead of the DTrace compability DTRACE_PROBE[1] macros. Bitcoin Core never had DTrace tracepoints, so we don't need to use the drop-in replacement for it. As noted in pr25541[2], these macros aren't compatibile with DTrace on macOS anyway. This also renames the TRACEx macro to TRACEPOINT to clarify what the macro does: inserting a tracepoint vs tracing (logging) something. [0]: https://sourceware.org/git/?p=systemtap.git;a=blob;f=includes/sys/sdt.h;h=24d5e01c37805e55c36f7202e5d4e821b85167a1;hb=ecab2afea46099b4e7dfd551462689224afdbe3a#l407 [1]: https://sourceware.org/git/?p=systemtap.git;a=blob;f=includes/sys/sdt.h;h=24d5e01c37805e55c36f7202e5d4e821b85167a1;hb=ecab2afea46099b4e7dfd551462689224afdbe3a#l490 [2]: https://github.com/bitcoin/bitcoin/pull/25541/files#diff-553886c5f808e01e3452c7b21e879cc355da388ef7680bf310f6acb926d43266R30-R31 Co-authored-by: Martin Leitner-Ankerl <martin.ankerl@gmail.com>
This commit is contained in:
@@ -265,35 +265,19 @@ Arguments passed:
|
||||
|
||||
## Adding tracepoints to Bitcoin Core
|
||||
|
||||
To add a new tracepoint, `#include <util/trace.h>` in the compilation unit where
|
||||
the tracepoint is inserted. Use one of the `TRACEx` macros listed below
|
||||
depending on the number of arguments passed to the tracepoint. Up to 12
|
||||
arguments can be provided. The `context` and `event` specify the names by which
|
||||
the tracepoint is referred to. Please use `snake_case` and try to make sure that
|
||||
the tracepoint names make sense even without detailed knowledge of the
|
||||
implementation details. Do not forget to update the tracepoint list in this
|
||||
Use the `TRACEPOINT` macro to add a new tracepoint. If not yet included, include
|
||||
`util/trace.h` (defines the tracepoint macros) with `#include <util/trace.h>`.
|
||||
Each tracepoint needs a `context` and an `event`. Please use `snake_case` and
|
||||
try to make sure that the tracepoint names make sense even without detailed
|
||||
knowledge of the implementation details. You can pass zero to twelve arguments
|
||||
to the tracepoint. Do not forget to update the tracepoint list in this
|
||||
document.
|
||||
|
||||
```c
|
||||
#define TRACE(context, event)
|
||||
#define TRACE1(context, event, a)
|
||||
#define TRACE2(context, event, a, b)
|
||||
#define TRACE3(context, event, a, b, c)
|
||||
#define TRACE4(context, event, a, b, c, d)
|
||||
#define TRACE5(context, event, a, b, c, d, e)
|
||||
#define TRACE6(context, event, a, b, c, d, e, f)
|
||||
#define TRACE7(context, event, a, b, c, d, e, f, g)
|
||||
#define TRACE8(context, event, a, b, c, d, e, f, g, h)
|
||||
#define TRACE9(context, event, a, b, c, d, e, f, g, h, i)
|
||||
#define TRACE10(context, event, a, b, c, d, e, f, g, h, i, j)
|
||||
#define TRACE11(context, event, a, b, c, d, e, f, g, h, i, j, k)
|
||||
#define TRACE12(context, event, a, b, c, d, e, f, g, h, i, j, k, l)
|
||||
```
|
||||
|
||||
For example:
|
||||
For example, a tracepoint in the `net` context for the event `inbound_message`
|
||||
and six arguments:
|
||||
|
||||
```C++
|
||||
TRACE6(net, inbound_message,
|
||||
TRACEPOINT(net, inbound_message,
|
||||
pnode->GetId(),
|
||||
pnode->m_addr_name.c_str(),
|
||||
pnode->ConnectionTypeAsString().c_str(),
|
||||
@@ -347,7 +331,7 @@ first six argument fields. Binary data can be placed in later arguments. The BCC
|
||||
supports reading from all 12 arguments.
|
||||
|
||||
#### Strings as C-style String
|
||||
Generally, strings should be passed into the `TRACEx` macros as pointers to
|
||||
Generally, strings should be passed into the `TRACEPOINT` macros as pointers to
|
||||
C-style strings (a null-terminated sequence of characters). For C++
|
||||
`std::strings`, [`c_str()`] can be used. It's recommended to document the
|
||||
maximum expected string size if known.
|
||||
|
Reference in New Issue
Block a user