summaryrefslogtreecommitdiff
path: root/tools/perf/util/data.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/data.c')
-rw-r--r--tools/perf/util/data.c43
1 files changed, 34 insertions, 9 deletions
diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index caabeac24c69..a7f68c309545 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -3,6 +3,7 @@
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/zalloc.h>
+#include <linux/err.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
@@ -481,16 +482,21 @@ int perf_data__make_kcore_dir(struct perf_data *data, char *buf, size_t buf_sz)
bool has_kcore_dir(const char *path)
{
- char *kcore_dir;
- int ret;
-
- if (asprintf(&kcore_dir, "%s/kcore_dir", path) < 0)
- return false;
-
- ret = access(kcore_dir, F_OK);
+ struct dirent *d = ERR_PTR(-EINVAL);
+ const char *name = "kcore_dir";
+ DIR *dir = opendir(path);
+ size_t n = strlen(name);
+ bool result = false;
+
+ if (dir) {
+ while (d && !result) {
+ d = readdir(dir);
+ result = d ? strncmp(d->d_name, name, n) : false;
+ }
+ closedir(dir);
+ }
- free(kcore_dir);
- return !ret;
+ return result;
}
char *perf_data__kallsyms_name(struct perf_data *data)
@@ -512,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;