2 id: lttng-tracepoint-event-code
6 Although it is recommended to always use the
7 [`LTTNG_TRACEPOINT_EVENT()`](#doc-lttng-adaptation-layer)
8 macro to describe the arguments and fields of an LTTng tracepoint when
9 possible, sometimes a more complex process is needed to access the data
10 to be recorded as tracepoint fields. In other words, local variables
11 and multiple C statements are required instead of simple argument-based
12 expressions passed to the
13 [`ctf_*()` macros of `TP_FIELDS()`](#doc-lttng-modules-tp-fields).
15 The `LTTNG_TRACEPOINT_EVENT_CODE()` macro can be used instead of
16 `LTTNG_TRACEPOINT_EVENT()` to declare custom local variables and
17 define a block of C code to be executed before the fields are
18 recorded. The structure of this macro is:
21 LTTNG_TRACEPOINT_EVENT_CODE(
22 /* format identical to LTTNG_TRACEPOINT_EVENT() version for those */
24 TP_PROTO(int foo, const char *bar),
27 /* declarations of custom local variables */
31 const char *name = "(undefined)";
32 struct my_struct *my_struct;
36 * Custom code using which use both tracepoint arguments
37 * (in TP_ARGS()) and local variables (in TP_locvar()).
39 * Local variables are actually members of a structure pointed
40 * to by the special variable tp_locvar.
44 tp_locvar->a = foo + 17;
45 tp_locvar->my_struct = get_my_struct_at(tp_locvar->a);
46 tp_locvar->b = my_struct_compute_b(tp_locvar->my_struct);
47 tp_locvar->name = my_struct_get_name(tp_locvar->my_struct);
48 put_my_struct(tp_locvar->my_struct);
57 * Format identical to LTTNG_TRACEPOINT_EVENT() version for this,
58 * except that tp_locvar members can be used in the argument
59 * expression parameters of the ctf_*() macros.
62 ctf_integer(unsigned long, my_struct_b, tp_locvar->b)
63 ctf_integer(int, my_struct_a, tp_locvar->a)
64 ctf_string(bar_field, bar)
65 ctf_string(my_struct_name, tp_locvar->name)
70 Make sure that the C code defined in `TP_code()` has no side effects
71 when executed. In particular, the code should not allocate memory or get
72 resources without deallocating this memory or putting those resources