aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/data.c
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2019-02-24 14:06:45 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-02-25 08:43:07 -0500
commiteb6176709b235b96511c7b4745c30412568395c7 (patch)
tree3c30b15b245b6670820d8b4180cb0ddd63a1f4e3 /tools/perf/util/data.c
parent145520631130bd64820b591775733256473eac62 (diff)
perf data: Add perf_data__open_dir_data function
Add perf_data__open_dir_data to open files inside 'struct perf_data' path directory: static int perf_data__open_dir(struct perf_data *data); Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexey Budankov <alexey.budankov@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/20190224190656.30163-10-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/data.c')
-rw-r--r--tools/perf/util/data.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
index 005b3909d1dc..7bd5ddeb7a41 100644
--- a/tools/perf/util/data.c
+++ b/tools/perf/util/data.c
@@ -8,6 +8,8 @@
8#include <unistd.h> 8#include <unistd.h>
9#include <string.h> 9#include <string.h>
10#include <asm/bug.h> 10#include <asm/bug.h>
11#include <sys/types.h>
12#include <dirent.h>
11 13
12#include "data.h" 14#include "data.h"
13#include "util.h" 15#include "util.h"
@@ -59,6 +61,63 @@ out_err:
59 return ret; 61 return ret;
60} 62}
61 63
64int perf_data__open_dir(struct perf_data *data)
65{
66 struct perf_data_file *files = NULL;
67 struct dirent *dent;
68 int ret = -1;
69 DIR *dir;
70 int nr = 0;
71
72 dir = opendir(data->path);
73 if (!dir)
74 return -EINVAL;
75
76 while ((dent = readdir(dir)) != NULL) {
77 struct perf_data_file *file;
78 char path[PATH_MAX];
79 struct stat st;
80
81 snprintf(path, sizeof(path), "%s/%s", data->path, dent->d_name);
82 if (stat(path, &st))
83 continue;
84
85 if (!S_ISREG(st.st_mode) || strncmp(dent->d_name, "data", 4))
86 continue;
87
88 ret = -ENOMEM;
89
90 file = realloc(files, (nr + 1) * sizeof(*files));
91 if (!file)
92 goto out_err;
93
94 files = file;
95 file = &files[nr++];
96
97 file->path = strdup(path);
98 if (!file->path)
99 goto out_err;
100
101 ret = open(file->path, O_RDONLY);
102 if (ret < 0)
103 goto out_err;
104
105 file->fd = ret;
106 file->size = st.st_size;
107 }
108
109 if (!files)
110 return -EINVAL;
111
112 data->dir.files = files;
113 data->dir.nr = nr;
114 return 0;
115
116out_err:
117 close_dir(files, nr);
118 return ret;
119}
120
62static bool check_pipe(struct perf_data *data) 121static bool check_pipe(struct perf_data *data)
63{ 122{
64 struct stat st; 123 struct stat st;