Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
14552063 ccb7a71d

+55
+47
tools/perf/util/data.c
··· 7 7 #include <fcntl.h> 8 8 #include <unistd.h> 9 9 #include <string.h> 10 + #include <asm/bug.h> 10 11 11 12 #include "data.h" 12 13 #include "util.h" 13 14 #include "debug.h" 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 + } 14 61 15 62 static bool check_pipe(struct perf_data *data) 16 63 {
+8
tools/perf/util/data.h
··· 21 21 bool is_pipe; 22 22 bool force; 23 23 enum perf_data_mode mode; 24 + 25 + struct { 26 + struct perf_data_file *files; 27 + int nr; 28 + } dir; 24 29 }; 25 30 26 31 static inline bool perf_data__is_read(struct perf_data *data) ··· 69 64 int perf_data__switch(struct perf_data *data, 70 65 const char *postfix, 71 66 size_t pos, bool at_exit); 67 + 68 + int perf_data__create_dir(struct perf_data *data, int nr); 69 + void perf_data__close_dir(struct perf_data *data); 72 70 #endif /* __PERF_DATA_H */