Skip to content
Advertisement

Getting lttng backtraces without liblttng-ust-cyg-profile

Is it possible to get backtraces from lttng without LD_PRELOADing liblttng-ust-cyg-profile and compiling with -finstrument-functions?

I can’t see from the lttng code what it’s doing differently when pre-loading that library to allow a trace viewer (tracecompass) to show the backtraces!?

Here’s my test app:

test_tracepoints.h:

#undef TRACEPOINT_PROVIDER
#define TRACEPOINT_PROVIDER test

#undef TRACEPOINT_INCLUDE
#define TRACEPOINT_INCLUDE "test_tracepoints.h"

#if !defined(TEST_TRACEPOINTS_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
#define TEST_TRACEPOINTS_H

#include <lttng/tracepoint.h>

TRACEPOINT_EVENT_CLASS(
    test,
    test_tc,
    TP_ARGS(const char *, str_arg, void *, func_addr),
    TP_FIELDS(ctf_integer_hex(unsigned long, addr, (unsigned long) func_addr)
              ctf_integer_hex(unsigned long, call_site, __builtin_return_address(0))
              ctf_string(str, str_arg)))

TRACEPOINT_EVENT_INSTANCE(
    test,
    test_tc,
    test_tp_start,
    TP_ARGS(const char *, str_arg, void *, func_addr))

TRACEPOINT_EVENT_INSTANCE(
    test,
    test_tc,
    test_tp_end,
    TP_ARGS(const char *, str_arg, void *, func_addr))

#endif

#include <lttng/tracepoint-event.h>

test_tracepoints.c:

#define TRACEPOINT_DEFINE
#define TRACEPOINT_CREATE_PROBES

#define TP_IP_PARAM func_addr

#include "test_tracepoints.h"

test.lttng.c:

#include "test_tracepoints.h"

#include <unistd.h>

void f(useconds_t usec)
{
    const char * str = "f";
    tracepoint(test, test_tp_start, str, f);
    usleep(usec);
    tracepoint(test, test_tp_end, str, f);
}

int main()
{
    for (unsigned n = 0; n != 10000; ++n)
    {
        f(100);
        f(200);
    }

    return 0;
}

I’m testing this with:

gcc -O0 -g -fno-omit-frame-pointer -I . test_tracepoints.c test.lttng.c -o test.lttng -llttng-ust -ldl
lttng-sessiond --daemonize
lttng create -o lttng.session.test test
lttng enable-event -u -a
lttng add-context -s test -u -t procname -t vtid
lttng list test
lttng start test
./test.lttng
lttng destroy test
pkill lttng-sessiond

Advertisement

Answer

No, it’s currently not directly supported. But it’s definitely on the wishlist.

When you preload the function tracing helper (liblttng-ust-cyg-profile.so, or its -fast version), LTTng events are emitted (prefixed with lttng_ust_cyg_profile) at each function entry/exit. You need to create an event rule to enable them explicitly:

lttng enable-event --userspace lttng_ust_cyg_profile'*'

I’m not sure if Trace Compass uses those event records at all in its analyses, though.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement