Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: Mathieu Desnoyers via lttng-dev <lttng-dev@lists.lttng.org>
To: "Alexander Krabler" <Alexander.Krabler@kuka.com>,
	"Kienan Stewart" <kstewart@efficios.com>,
	"Christophe Bédard" <bedard.christophe@gmail.com>
Cc: "lttng-dev@lists.lttng.org" <lttng-dev@lists.lttng.org>
Subject: Re: AW: [lttng-dev] Record stacktraces at userspace tracing domain
Date: Wed, 11 Dec 2024 10:43:54 -0500	[thread overview]
Message-ID: <8b3dc807-e512-4ea9-be7b-39abae58d886@efficios.com> (raw)
In-Reply-To: <VI1PR01MB684540CF33FFE72F69417E62823E2@VI1PR01MB6845.eurprd01.prod.exchangelabs.com>

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


  reply	other threads:[~2024-12-11 15:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-02 16:29 Alexander Krabler via lttng-dev
2024-12-02 21:17 ` Christophe Bédard via lttng-dev
2024-12-10 16:41   ` Kienan Stewart via lttng-dev
2024-12-11 10:32     ` AW: " Alexander Krabler via lttng-dev
2024-12-11 15:43       ` Mathieu Desnoyers via lttng-dev [this message]
2024-12-12 16:52         ` Alexander Krabler via lttng-dev
2024-12-12 16:56           ` Dirk Eibach via lttng-dev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8b3dc807-e512-4ea9-be7b-39abae58d886@efficios.com \
    --to=lttng-dev@lists.lttng.org \
    --cc=Alexander.Krabler@kuka.com \
    --cc=bedard.christophe@gmail.com \
    --cc=kstewart@efficios.com \
    --cc=mathieu.desnoyers@efficios.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox