AW: [lttng-dev] Record stacktraces at userspace tracing domain

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Wed Dec 11 10:43:54 EST 2024


On 2024-12-11 05:32, Alexander Krabler via lttng-dev wrote:
> Hi Christophe and Kienan,
> 
> 
> Internal
> On 12/2/24 4:17 PM, Christophe Bédard via lttng-dev wrote:
>> I did the same thing a while ago, i.e., trigger tracepoints on
>> malloc/free/etc. using liblttng-ust-libc-wrapper and collect userspace
>> callstack information (so that the indirect calls to malloc/free can be
>> removed from an application).
>> ...
> Thank you for the information and links!
> I have looked into it, seems promising.
> 
> 
> On 12/10/24 11:41 AM, Kienan Stewart via lttng-dev wrote:
>> Depending on the type of information you require, it could be possible
>> to use the instruction-pointer (ip) context[1], the statedump[2] and/or
>> lttng-ust-dl[3] for base addresses, and the symbol table in-order to
>> resolve ip -> symbol name in the offline analysis phase with the help of
>> babeltrace's debug-info plugin[4]. While a bit more work for the
>> analysis, this process reduces the impact of the tracing on the program
>> at run-time.
> Thanks for the hints.
> This would be possible, but that would give me only the instruction pointer of the top-level stack frame.
> If malloc and free calls are wrapped inside of functions (e.g. think about std::string, std::unique/shared_ptr for C++),
> I would only see that it's called from that specific type.
> But, for me, it's important to see the context, too, where the string/smart pointer is used.

Another approach then is to add tracepoints within your C++ standard
library functions. Then you can use the caller ip of _those_ functions
and pass them to the tracepoint as "ip" context override. Here is how
it is done e.g. in src/lib/lttng-ust-libc-wrapper/lttng-ust-malloc.c :

#define LTTNG_UST_TRACEPOINT_DEFINE
#define LTTNG_UST_TRACEPOINT_CREATE_PROBES
#define LTTNG_UST_TP_IP_PARAM ip                        <------ this.
#include "ust_libc.h"

src/lib/lttng-ust-libc-wrapper/ust_libc.h :

LTTNG_UST_TRACEPOINT_EVENT(lttng_ust_libc, malloc,
         LTTNG_UST_TP_ARGS(size_t, size, void *, ptr, void *, ip),
         LTTNG_UST_TP_FIELDS(
                 lttng_ust_field_integer(size_t, size, size)
                 lttng_ust_field_integer_hex(void *, ptr, ptr)
                 lttng_ust_field_unused(ip)
         )
)

You can similarly specify which parameter end up being used to
override the caller ip sampling.

Are those C++ functions something that is under your control ?

Thanks,

Mathieu


> Therefore I want to record the instruction pointer of every stackframe (or at least the top N ones in order to be able to locate the "problem").
> 
> As stacktraces are only wanted/needed for specific events, I also consider adding new tracepoints
> like lttng_ust_libc:malloc_stacktrace to lttng-ust-libc-wrapper directly
> recording the desired information into the trace buffer as an alternative solution.
> 
> Best regards,
> Alexander

-- 
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com



More information about the lttng-dev mailing list