Hi Serhei, On Tue, Oct 15, 2024 at 11:27 AM Serhei Makarov <ser...@serhei.io> wrote > eu-stacktrace: add eu-stacktrace tool > > eu-stacktrace is a utility to process a stream of raw stack > samples (such as those obtained from the Linux kernel's > PERF_SAMPLE_STACK facility) into a stream of stack traces (such as > those obtained from PERF_SAMPLE_CALLCHAIN), freeing other profiling > utilities from having to implement their own backtracing logic.
Please add an eu-stacktrace entry to NEWS. > > eu-stacktrace accepts data from a profiling tool via a pipe or > fifo. The initial version of the tool works on x86 architectures and > accepts data from Sysprof [1]. For future work, it will make sense > to expand support to other profilers, in particular perf tool. > > Further patches in this series provide configury, docs, and improved > diagnostics for tracking the method used to unwind each frame in the > stack trace. > > [1]: The following patched version of Sysprof (upstream submission ETA > ~very_soon) can produce data with stack samples: > > https://git.sr.ht/~serhei/sysprof-experiments/log/serhei/samples-via-fifo > > Invoking the patched sysprof with eu-stacktrace: > > $ sudo sysprof-cli --use-stacktrace > $ sudo sysprof-cli --use-stacktrace --stacktrace-path=/path/to/eu-stacktrace I tried to run this but I kept getting: Failed to complete recording: GDBus.Error[...]: Action org.gnome.sysprof3.profile is not registered On the eu-stacktrace side I got: TOTAL -- received 0 samples, lost 0 samples, loaded 0 processes > > Invoking the patched sysprof and eu-stacktrace manually through a fifo: > > $ mkfifo /tmp/test.fifo > $ sudo eu-stacktrace --input /tmp/test.fifo --output test.syscap & > $ sysprof-cli --sample-method=stack --use-fifo=/tmp/test.fifo test.syscap I ran eu-stacktrace under `valgrind --leak-check=full`. Memory allocated at stacktrace.c:1542 and 1543 is leaked. > > Note that sysprof polkit actions must be installed systemwide > (e.g. installing the system sysprof package will provide these). > > * src/stacktrace.c: Add new tool. > > [...] > > +/************************************* > + * Includes: sysprof data structures * > + *************************************/ > + > +#if HAVE_SYSPROF_6_HEADERS > +#include <sysprof-6/sysprof-capture-types.h> > +#define HAVE_SYSPROF_HEADERS 1 > +#elif HAVE_SYSPROF_4_HEADERS > +#include <sysprof-4/sysprof-capture-types.h> > +#define HAVE_SYSPROF_HEADERS 1 > +#else > +#define HAVE_SYSPROF_HEADERS 0 > +#endif > + > +#if HAVE_SYSPROF_HEADERS > + > +/* XXX: To be added to new versions of sysprof. */ > +#ifndef SYSPROF_CAPTURE_FRAME_STACK_USER > + > +#undef SYSPROF_CAPTURE_FRAME_LAST > +#define SYSPROF_CAPTURE_FRAME_STACK_USER 18 > +#define SYSPROF_CAPTURE_FRAME_LAST 19 > + > +SYSPROF_ALIGNED_BEGIN(1) > +typedef struct > +{ > + SysprofCaptureFrame frame; > + uint64_t size; > + int32_t tid; > + uint32_t padding; > + uint8_t data[0]; > +} SysprofCaptureStackUser > +SYSPROF_ALIGNED_END(1); > + > +/* Does not appear standalone; instead, appended to the end of a > SysprofCaptureStackUser frame. */ > +SYSPROF_ALIGNED_BEGIN(1) > +typedef struct > +{ > + uint32_t n_regs; > + uint32_t abi; > + uint64_t regs[0]; > +} SysprofCaptureUserRegs > +SYSPROF_ALIGNED_END(1); I got a "conflicting types" error when trying to compile this due to SysprofCaptureStackUser and SysprofCaptureUserRegs being defined both here and in sysprof-capture-types.h. Should these structs instead be defined when HAVE_SYSPROF_HEADERS is 0? I was able to build eu-stacktrace by making that change. I'm not familiar with the sysprof APIs so I'm not able to do a thorough review of the rest of this particular patch before the next elfutils release on Oct 18. Normally I'd say lets hold off on merging this so close to the release. However you do indicate in the eu-stacktrace usage text that this is a WIP feature: > + const struct argp argp = > + { > + .options = options, > + .parser = parse_opt, > + .doc = N_("Process a stream of stack samples into stack traces.\n\ > +\n\ > +Utility is a work-in-progress, see README.eu-stacktrace in the source > branch.") > + }; Also the patches that modify other parts of elfutils aren't risky IMO. I'm comfortable with this being merged for the release as long as any build errors are sorted out and we emphasize in the usage text and NEWS that eu-stacktrace is an experimental feature with a possibly unstable ABI. Aaron