summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2022-07-11 12:32:05 +0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2022-07-20 17:08:37 +0300
commita5367ecb5353fbf28bfd3979fc4f61ddebec80b1 (patch)
treeeed8b8c2b6de100c6c798a4b70e19d469bd0ffe8
parent65691e9ff0c90109dd7d9d495d9528ad4c1b82d4 (diff)
downloadlinux-a5367ecb5353fbf28bfd3979fc4f61ddebec80b1.tar.xz
perf tools: Automatically use guest kcore_dir if present
When registering a guest machine using machine_pid from the id index, check perf.data for a matching kcore_dir subdirectory and set the kallsyms file name accordingly. If set, use it to find the machine's kernel symbols and object code (from kcore). Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Ian Rogers <irogers@google.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: kvm@vger.kernel.org Link: https://lore.kernel.org/r/20220711093218.10967-23-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/data.c19
-rw-r--r--tools/perf/util/data.h1
-rw-r--r--tools/perf/util/machine.h1
-rw-r--r--tools/perf/util/session.c2
-rw-r--r--tools/perf/util/symbol.c6
5 files changed, 27 insertions, 2 deletions
diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index 9782ccbe595d..a7f68c309545 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -518,6 +518,25 @@ char *perf_data__kallsyms_name(struct perf_data *data)
return kallsyms_name;
}
+char *perf_data__guest_kallsyms_name(struct perf_data *data, pid_t machine_pid)
+{
+ char *kallsyms_name;
+ struct stat st;
+
+ if (!data->is_dir)
+ return NULL;
+
+ if (asprintf(&kallsyms_name, "%s/kcore_dir__%d/kallsyms", data->path, machine_pid) < 0)
+ return NULL;
+
+ if (stat(kallsyms_name, &st)) {
+ free(kallsyms_name);
+ return NULL;
+ }
+
+ return kallsyms_name;
+}
+
bool is_perf_data(const char *path)
{
bool ret = false;
diff --git a/tools/perf/util/data.h b/tools/perf/util/data.h
index 7de53d6e2d7f..173132d502f5 100644
--- a/tools/perf/util/data.h
+++ b/tools/perf/util/data.h
@@ -101,5 +101,6 @@ unsigned long perf_data__size(struct perf_data *data);
int perf_data__make_kcore_dir(struct perf_data *data, char *buf, size_t buf_sz);
bool has_kcore_dir(const char *path);
char *perf_data__kallsyms_name(struct perf_data *data);
+char *perf_data__guest_kallsyms_name(struct perf_data *data, pid_t machine_pid);
bool is_perf_data(const char *path);
#endif /* __PERF_DATA_H */
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h
index e1476343cbb2..199807ac3c54 100644
--- a/tools/perf/util/machine.h
+++ b/tools/perf/util/machine.h
@@ -48,6 +48,7 @@ struct machine {
bool single_address_space;
char *root_dir;
char *mmap_name;
+ char *kallsyms_filename;
struct threads threads[THREADS__TABLE_SIZE];
struct vdso_info *vdso_info;
struct perf_env *env;
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 7ea0b91013ea..98e16659a149 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -2772,6 +2772,8 @@ static int perf_session__register_guest(struct perf_session *session, pid_t mach
return -ENOMEM;
thread__put(thread);
+ machine->kallsyms_filename = perf_data__guest_kallsyms_name(session->data, machine_pid);
+
return 0;
}
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index f72baf636724..a4b22caa7c24 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -2300,11 +2300,13 @@ do_kallsyms:
static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map)
{
int err;
- const char *kallsyms_filename = NULL;
+ const char *kallsyms_filename;
struct machine *machine = map__kmaps(map)->machine;
char path[PATH_MAX];
- if (machine__is_default_guest(machine)) {
+ if (machine->kallsyms_filename) {
+ kallsyms_filename = machine->kallsyms_filename;
+ } else if (machine__is_default_guest(machine)) {
/*
* if the user specified a vmlinux filename, use it and only
* it, reporting errors to the user if it cannot be used.