Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Add support to read build id from compressed elf

Adding support to decompress file before reading build id.

Adding filename__read_build_id and change its current versions to
read_build_id.

Shutting down stderr output of perf list in the shell test:
82: Check open filename arg using perf trace + vfs_getname : Ok

because with decompression code in the place we the
filename__read_build_id function is more verbose in case
of error and the test did not account for that.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Budankov <abudankov@huawei.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20201214105457.543111-7-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
47dce51a 8abceacf

+36 -3
+1 -1
tools/perf/tests/shell/trace+probe_vfs_getname.sh
··· 20 20 file=$(mktemp /tmp/temporary_file.XXXXX) 21 21 22 22 trace_open_vfs_getname() { 23 - evts=$(echo $(perf list syscalls:sys_enter_open* 2>&1 | egrep 'open(at)? ' | sed -r 's/.*sys_enter_([a-z]+) +\[.*$/\1/') | sed 's/ /,/') 23 + evts=$(echo $(perf list syscalls:sys_enter_open* 2>/dev/null | egrep 'open(at)? ' | sed -r 's/.*sys_enter_([a-z]+) +\[.*$/\1/') | sed 's/ /,/') 24 24 perf trace -e $evts touch $file 2>&1 | \ 25 25 egrep " +[0-9]+\.[0-9]+ +\( +[0-9]+\.[0-9]+ ms\): +touch\/[0-9]+ open(at)?\((dfd: +CWD, +)?filename: +${file}, +flags: CREAT\|NOCTTY\|NONBLOCK\|WRONLY, +mode: +IRUGO\|IWUGO\) += +[0-9]+$" 26 26 }
+35 -2
tools/perf/util/symbol-elf.c
··· 534 534 535 535 #ifdef HAVE_LIBBFD_BUILDID_SUPPORT 536 536 537 - int filename__read_build_id(const char *filename, struct build_id *bid) 537 + static int read_build_id(const char *filename, struct build_id *bid) 538 538 { 539 539 size_t size = sizeof(bid->data); 540 540 int err = -1; ··· 563 563 564 564 #else // HAVE_LIBBFD_BUILDID_SUPPORT 565 565 566 - int filename__read_build_id(const char *filename, struct build_id *bid) 566 + static int read_build_id(const char *filename, struct build_id *bid) 567 567 { 568 568 size_t size = sizeof(bid->data); 569 569 int fd, err = -1; ··· 594 594 } 595 595 596 596 #endif // HAVE_LIBBFD_BUILDID_SUPPORT 597 + 598 + int filename__read_build_id(const char *filename, struct build_id *bid) 599 + { 600 + struct kmod_path m = { .name = NULL, }; 601 + char path[PATH_MAX]; 602 + int err; 603 + 604 + if (!filename) 605 + return -EFAULT; 606 + 607 + err = kmod_path__parse(&m, filename); 608 + if (err) 609 + return -1; 610 + 611 + if (m.comp) { 612 + int error = 0, fd; 613 + 614 + fd = filename__decompress(filename, path, sizeof(path), m.comp, &error); 615 + if (fd < 0) { 616 + pr_debug("Failed to decompress (error %d) %s\n", 617 + error, filename); 618 + return -1; 619 + } 620 + close(fd); 621 + filename = path; 622 + } 623 + 624 + err = read_build_id(filename, bid); 625 + 626 + if (m.comp) 627 + unlink(filename); 628 + return err; 629 + } 597 630 598 631 int sysfs__read_build_id(const char *filename, struct build_id *bid) 599 632 {