[PATCH] perf util: Display warning when perf report/annotate is missing some libs

Jin Yao
2018-01-11T03:08:16Z

We keep having bug reports that when users build perf on their own,
but they don't install some needed libraries like libelf, libbfd/libibery.

The perf can build, but it is missing important functionality.

For example, perf report doesn't display any symbols and perf annotate
doesn't work.

This patch displays warnings that these libraries are missing in build
when perf report / perf annotate are used.

Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
---
tools/perf/builtin-annotate.c | 2 ++
tools/perf/builtin-report.c | 2 ++
tools/perf/util/symbol.c | 21 +++++++++++++++++++++
tools/perf/util/symbol.h | 2 ++
4 files changed, 27 insertions(+)

diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index f15731a..609eb7a 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -511,6 +511,8 @@ int cmd_annotate(int argc, const char **argv)

setup_browser(true);

+ build_lib_warning();
+
ret = __cmd_annotate(&annotate);

out_delete:
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index dd4df9a..550adb7 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -1293,6 +1293,8 @@ int cmd_report(int argc, const char **argv)
}
}

+ build_lib_warning();
+
if (symbol__init(&session->header.env) < 0)
goto error;

diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index cc065d4..4205ba8 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -2224,3 +2224,24 @@ int symbol__config_symfs(const struct option *opt __maybe_unused,
free(bf);
return 0;
}
+
+void build_lib_warning(void)
+{
+#ifndef HAVE_LIBELF_SUPPORT
+ pr_warning("Symbols are disabled!\n"
+ "Please install libelf-dev, libelf-devel "
+ "or elfutils-libelf-devel before building perf.\n");
+#endif
+
+#ifndef HAVE_DWARF_SUPPORT
+ pr_warning("Unwind support is disabled!\n"
+ "Please install elfutils-devel/libdw-dev "
+ "before building perf.\n");
+#endif
+
+#ifndef HAVE_LIBBFD_SUPPORT
+ pr_warning("C++ demangling and line numbers are disabled!\n"
+ "Please install binutils-dev[el]/"
+ "libiberty-dev before building perf.\n");
+#endif
+}
diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
index 0563f33..d88e046 100644
--- a/tools/perf/util/symbol.h
+++ b/tools/perf/util/symbol.h
@@ -383,6 +383,8 @@ int get_sdt_note_list(struct list_head *head, const char *target);
int cleanup_sdt_note_list(struct list_head *sdt_notes);
int sdt_notes__get_count(struct list_head *start);

+void build_lib_warning(void);
+
#define SDT_BASE_SCN ".stapsdt.base"
#define SDT_NOTE_SCN ".note.stapsdt"
#define SDT_NOTE_TYPE 3
--
2.7.4