Skip to content

Commit c7a14fd

Browse files
fcheacmel
authored andcommitted
perf build-ids: Fall back to debuginfod query if debuginfo not found
During a perf-record, use the -ldebuginfod API to query a debuginfod server, should the debug data not be found in the usual system locations. If successful, the usual $HOME/.debug dir is populated. Tested with: $ find . . ./ctags-debuginfo-5.8-26.fc31.x86_64.rpm ./usr ./usr/lib ./usr/lib/debug ./usr/lib/debug/.build-id ./usr/lib/debug/.build-id/ca ./usr/lib/debug/.build-id/ca/46f6ae6a0cee57d85abc1d461c49074248908d ./usr/lib/debug/.build-id/ca/46f6ae6a0cee57d85abc1d461c49074248908d.debug ./usr/lib/debug/usr ./usr/lib/debug/usr/bin ./usr/lib/debug/usr/bin/ctags-5.8-26.fc31.x86_64.debug $ debuginfod -F . ... $ rm -rf ~/.debug/ ; mkdir ~/.debug $ perf record make tags BUILD: Doing 'make -j8' parallel build GEN tags [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.107 MB perf.data (1483 samples) ] $ find ~/.debug | grep ctags /home/jolsa/.debug/usr/bin/ctags /home/jolsa/.debug/usr/bin/ctags/ca46f6ae6a0cee57d85abc1d461c49074248908d /home/jolsa/.debug/usr/bin/ctags/ca46f6ae6a0cee57d85abc1d461c49074248908d/elf /home/jolsa/.debug/usr/bin/ctags/ca46f6ae6a0cee57d85abc1d461c49074248908d/probes $ rm -rf ~/.debug/ ; mkdir ~/.debug $ DEBUGINFOD_URLS=http://localhost:8002 perf record make tags BUILD: Doing 'make -j8' parallel build GEN tags [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.108 MB perf.data (1531 samples) ] $ find ~/.debug | grep ctag /home/jolsa/.debug/usr/bin/ctags /home/jolsa/.debug/usr/bin/ctags/ca46f6ae6a0cee57d85abc1d461c49074248908d /home/jolsa/.debug/usr/bin/ctags/ca46f6ae6a0cee57d85abc1d461c49074248908d/debug /home/jolsa/.debug/usr/bin/ctags/ca46f6ae6a0cee57d85abc1d461c49074248908d/elf /home/jolsa/.debug/usr/bin/ctags/ca46f6ae6a0cee57d85abc1d461c49074248908d/probes Note the 'debug' file is created in the last run. Note that currently the debuginfo data are downloaded only on record path, we still need add this support to perf build-id/report.. and test ;-) Tested-by: Jiri Olsa <[email protected]> Signed-off-by: Jiri Olsa <[email protected]> Signed-off-by: Frank Ch. Eigler <[email protected]> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent a508d06 commit c7a14fd

File tree

6 files changed

+43
-1
lines changed

6 files changed

+43
-1
lines changed

tools/build/Makefile.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ FEATURE_TESTS_EXTRA := \
9898
llvm-version \
9999
clang \
100100
libbpf \
101-
libpfm4
101+
libpfm4 \
102+
libdebuginfod
102103

103104
FEATURE_TESTS ?= $(FEATURE_TESTS_BASIC)
104105

tools/build/feature/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ FILES= \
2626
test-libelf-gelf_getnote.bin \
2727
test-libelf-getshdrstrndx.bin \
2828
test-libelf-mmap.bin \
29+
test-libdebuginfod.bin \
2930
test-libnuma.bin \
3031
test-numa_num_possible_cpus.bin \
3132
test-libperl.bin \
@@ -157,6 +158,9 @@ $(OUTPUT)test-libelf-gelf_getnote.bin:
157158
$(OUTPUT)test-libelf-getshdrstrndx.bin:
158159
$(BUILD) -lelf
159160

161+
$(OUTPUT)test-libdebuginfod.bin:
162+
$(BUILD) -ldebuginfod
163+
160164
$(OUTPUT)test-libnuma.bin:
161165
$(BUILD) -lnuma
162166

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include <elfutils/debuginfod.h>
3+
4+
int main(void)
5+
{
6+
debuginfod_client* c = debuginfod_begin();
7+
return (long)c;
8+
}

tools/perf/Makefile.config

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,14 @@ ifndef NO_LIBELF
501501
CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT
502502
endif
503503

504+
ifndef NO_LIBDEBUGINFOD
505+
$(call feature_check,libdebuginfod)
506+
ifeq ($(feature-libdebuginfod), 1)
507+
CFLAGS += -DHAVE_DEBUGINFOD_SUPPORT
508+
EXTLIBS += -ldebuginfod
509+
endif
510+
endif
511+
504512
ifndef NO_DWARF
505513
ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
506514
msg := $(warning DWARF register mappings have not been defined for architecture $(SRCARCH), DWARF support disabled);

tools/perf/Makefile.perf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ include ../scripts/utilities.mak
124124
#
125125
# Define LIBPFM4 to enable libpfm4 events extension.
126126
#
127+
# Define NO_LIBDEBUGINFOD if you do not want support debuginfod
128+
#
127129

128130
# As per kernel Makefile, avoid funny character set dependencies
129131
unexport LC_ALL

tools/perf/util/build-id.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#include "probe-file.h"
3232
#include "strlist.h"
3333

34+
#ifdef HAVE_DEBUGINFOD_SUPPORT
35+
#include <elfutils/debuginfod.h>
36+
#endif
37+
3438
#include <linux/ctype.h>
3539
#include <linux/zalloc.h>
3640

@@ -636,6 +640,21 @@ static char *build_id_cache__find_debug(const char *sbuild_id,
636640
if (realname && access(realname, R_OK))
637641
zfree(&realname);
638642
nsinfo__mountns_exit(&nsc);
643+
644+
#ifdef HAVE_DEBUGINFOD_SUPPORT
645+
if (realname == NULL) {
646+
debuginfod_client* c = debuginfod_begin();
647+
if (c != NULL) {
648+
int fd = debuginfod_find_debuginfo(c,
649+
(const unsigned char*)sbuild_id, 0,
650+
&realname);
651+
if (fd >= 0)
652+
close(fd); /* retaining reference by realname */
653+
debuginfod_end(c);
654+
}
655+
}
656+
#endif
657+
639658
out:
640659
free(debugfile);
641660
return realname;

0 commit comments

Comments
 (0)