diff options
author | Jiri Olsa <jolsa@kernel.org> | 2019-02-24 14:06:44 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-02-25 08:42:05 -0500 |
commit | 145520631130bd64820b591775733256473eac62 (patch) | |
tree | 3e857a788cecfd1849031f0295a7bec4bd4cbf72 /tools/perf/util/data.c | |
parent | ccb7a71dcea071c7fd68192909c4e54561c88043 (diff) |
perf data: Add perf_data__(create_dir|close_dir) functions
Add perf_data__create_dir() to create nr files inside 'struct perf_data'
path directory:
int perf_data__create_dir(struct perf_data *data, int nr);
and function to close that data:
void perf_data__close_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-9-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.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c index d008c3973012..005b3909d1dc 100644 --- a/tools/perf/util/data.c +++ b/tools/perf/util/data.c | |||
@@ -7,11 +7,58 @@ | |||
7 | #include <fcntl.h> | 7 | #include <fcntl.h> |
8 | #include <unistd.h> | 8 | #include <unistd.h> |
9 | #include <string.h> | 9 | #include <string.h> |
10 | #include <asm/bug.h> | ||
10 | 11 | ||
11 | #include "data.h" | 12 | #include "data.h" |
12 | #include "util.h" | 13 | #include "util.h" |
13 | #include "debug.h" | 14 | #include "debug.h" |
14 | 15 | ||
16 | static void close_dir(struct perf_data_file *files, int nr) | ||
17 | { | ||
18 | while (--nr >= 1) { | ||
19 | close(files[nr].fd); | ||
20 | free(files[nr].path); | ||
21 | } | ||
22 | free(files); | ||
23 | } | ||
24 | |||
25 | void perf_data__close_dir(struct perf_data *data) | ||
26 | { | ||
27 | close_dir(data->dir.files, data->dir.nr); | ||
28 | } | ||
29 | |||
30 | int perf_data__create_dir(struct perf_data *data, int nr) | ||
31 | { | ||
32 | struct perf_data_file *files = NULL; | ||
33 | int i, ret = -1; | ||
34 | |||
35 | files = zalloc(nr * sizeof(*files)); | ||
36 | if (!files) | ||
37 | return -ENOMEM; | ||
38 | |||
39 | data->dir.files = files; | ||
40 | data->dir.nr = nr; | ||
41 | |||
42 | for (i = 0; i < nr; i++) { | ||
43 | struct perf_data_file *file = &files[i]; | ||
44 | |||
45 | if (asprintf(&file->path, "%s/data.%d", data->path, i) < 0) | ||
46 | goto out_err; | ||
47 | |||
48 | ret = open(file->path, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); | ||
49 | if (ret < 0) | ||
50 | goto out_err; | ||
51 | |||
52 | file->fd = ret; | ||
53 | } | ||
54 | |||
55 | return 0; | ||
56 | |||
57 | out_err: | ||
58 | close_dir(files, i); | ||
59 | return ret; | ||
60 | } | ||
61 | |||
15 | static bool check_pipe(struct perf_data *data) | 62 | static bool check_pipe(struct perf_data *data) |
16 | { | 63 | { |
17 | struct stat st; | 64 | struct stat st; |