Creating an LTTng tracepoint file

LTTng is a framework to collect kernel tracepoint logs with low overhead (see 5.5 in Desnoyers’ thesis for eval). Instrumenting the kernel is done in two parts: adding a kernel tracepoint, and writing the LTTng adaptation layer. The process is documented in a section of the LTTng docs, however there are a few points that required fixing to make the adaptation layer work, detailed here.

The docs (at the time of writing of this post) show the following adaptation header:

Correct #include

Compiling our module, with the described changes produced an error:

We fixed those by removing “#include <linux/tracepoint.h>” and instead adding  “#include “../../../probes/lttng-tracepoint-event.h” as the first include.

Include guards

The next hurdle was many warnings that LTTNG_TRACEPOINT_EVENT is redefined:

Other LTTng headers in lttng-modules have changed their include guards from the linux kernel’s tracepoint files. For example:

versus LTTng:

Having separate macros to guard the kernel header and the LTTng adaptation header fixed the warnings.

 Translating macros

Here’s a quick translation for some of the macros:

TRACE_EVENT = LTTNG_TRACEPOINT_EVENT
DECLARE_EVENT_CLASS = LTTNG_TRACEPOINT_EVENT_CLASS
DEFINE_EVENT = LTTNG_TRACEPOINT_EVENT_INSTANCE

Fixing semicolons

While the kernel tracepoints require a semicolon (;) after DEFINE_EVENT, these cause problems for LTTng, for example:

Removing all semicolons after the LTTNG_TRACEPOINT_* macros fixes this.

Multiple adaptation headers in one lttng-probe-*.c file – doesn’t work

Not everyone might encounter this, but if you’re trying to #include multiple LTTng adaptation headers in one file, this does not seem to be supported (at least not in the git repo of mid-January 2015). Both cases failed: (1) multiple headers are included for the same TRACE_SYSTEM (2) multiple headers with different TRACE_SYSTEMs. The macros redefine some functions, causing a compile error. FYI!

Happy LTTng’ing!

Posted in Tech Blog.

Leave a Reply

Your email address will not be published. Required fields are marked *