[PATCH v5 07/12] eu-stacktrace [7/12]: use Dwflst_Process_Tracker for Elf * caching
Aaron Merey
amerey@redhat.com
Fri Apr 25 05:57:42 GMT 2025
On Thu, Apr 24, 2025 at 5:50 PM Serhei Makarov <serhei@serhei.io> wrote:
>
> Changes for v4:
>
> - Separate out libdwfl_stacktrace, as requested.
>
> * * *
>
> * src/Makefile.am (AM_CPPFLAGS): Include headers from
> ../libdwfl_stacktrace.
> * src/stacktrace.c (tracker): New global variable.
> (sample_callbacks): Use dwflst_tracker_linux_proc_find_elf for
> caching.
> (sysprof_init_dwfl): Use dwflst_tracker_dwfl_begin.
> (main): Initialize and clean up tracker.
> ---
> src/Makefile.am | 3 ++-
> src/stacktrace.c | 12 +++++++++---
> 2 files changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/src/Makefile.am b/src/Makefile.am
> index 6d713e88..4a3fb957 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -23,7 +23,8 @@ DEFS += $(YYDEBUG) -DDEBUGPRED=@DEBUGPRED@ \
> DEFAULT_INCLUDES =
> AM_CPPFLAGS += -I$(srcdir)/../libelf -I$(srcdir)/../libebl \
> -I$(srcdir)/../libdw -I$(srcdir)/../libdwelf \
> - -I$(srcdir)/../libdwfl -I$(srcdir)/../libasm -I../debuginfod
> + -I$(srcdir)/../libdwfl -I$(srcdir)/../libdwfl_stacktrace \
> + -I$(srcdir)/../libasm -I../debuginfod
>
> AM_LDFLAGS = -Wl,-rpath-link,../libelf:../libdw $(STACK_USAGE_NO_ERROR)
>
> diff --git a/src/stacktrace.c b/src/stacktrace.c
> index 3f5950fb..c0c9929d 100644
> --- a/src/stacktrace.c
> +++ b/src/stacktrace.c
> @@ -98,6 +98,7 @@
> #include "../libdwfl/libdwflP.h"
> /* XXX: Private header needed for find_procfile, sysprof_init_dwfl,
> sample_set_initial_registers. */
> +#include ELFUTILS_HEADER(dwfl_stacktrace)
>
> /*************************************
> * Includes: sysprof data structures *
> @@ -657,6 +658,8 @@ static const Dwfl_Thread_Callbacks sample_thread_callbacks =
> * Dwfl and statistics table for multiple processes *
> ****************************************************/
>
> +Dwflst_Process_Tracker *tracker = NULL;
> +
> /* This echoes lib/dynamicsizehash.* with some necessary modifications. */
> typedef struct
> {
> @@ -889,7 +892,7 @@ static char *debuginfo_path = NULL;
>
> static const Dwfl_Callbacks sample_callbacks =
> {
> - .find_elf = dwfl_linux_proc_find_elf,
> + .find_elf = dwflst_tracker_linux_proc_find_elf,
> .find_debuginfo = dwfl_standard_find_debuginfo,
> .debuginfo_path = &debuginfo_path,
> };
> @@ -915,7 +918,7 @@ nop_find_debuginfo (Dwfl_Module *mod __attribute__((unused)),
>
> static const Dwfl_Callbacks sample_callbacks =
> {
> - .find_elf = dwfl_linux_proc_find_elf,
> + .find_elf = dwflst_tracker_linux_proc_find_elf,
> .find_debuginfo = nop_find_debuginfo, /* work with CFI only */
> };
>
> @@ -1038,7 +1041,7 @@ sysprof_init_dwfl (struct sysprof_unwind_info *sui,
> cached = true;
> goto reuse;
> }
> - dwfl = dwfl_begin (&sample_callbacks);
> + dwfl = dwflst_tracker_dwfl_begin (tracker);
>
> int err = dwfl_linux_proc_report (dwfl, pid);
> if (err < 0)
> @@ -1532,6 +1535,7 @@ https://sourceware.org/cgit/elfutils/tree/README.eu-stacktrace?h=users/serhei/eu
> (void)maxframes;
> #else
> fprintf(stderr, "\n=== starting eu-stacktrace ===\n");
> + tracker = dwflst_tracker_begin (&sample_callbacks);
>
> /* TODO: For now, code the processing loop for sysprof only; generalize later. */
> assert (input_format == FORMAT_SYSPROF);
> @@ -1615,5 +1619,7 @@ https://sourceware.org/cgit/elfutils/tree/README.eu-stacktrace?h=users/serhei/eu
> if (output_fd != -1)
> close (output_fd);
>
> + dwflst_tracker_end (tracker);
> +
> return EXIT_OK;
> }
> --
> 2.47.0
>
LGTM.
Aaron
More information about the Elfutils-devel
mailing list