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__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>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
eb617670 14552063

+60
+59
tools/perf/util/data.c
··· 8 8 #include <unistd.h> 9 9 #include <string.h> 10 10 #include <asm/bug.h> 11 + #include <sys/types.h> 12 + #include <dirent.h> 11 13 12 14 #include "data.h" 13 15 #include "util.h" ··· 58 56 59 57 out_err: 60 58 close_dir(files, i); 59 + return ret; 60 + } 61 + 62 + int perf_data__open_dir(struct perf_data *data) 63 + { 64 + struct perf_data_file *files = NULL; 65 + struct dirent *dent; 66 + int ret = -1; 67 + DIR *dir; 68 + int nr = 0; 69 + 70 + dir = opendir(data->path); 71 + if (!dir) 72 + return -EINVAL; 73 + 74 + while ((dent = readdir(dir)) != NULL) { 75 + struct perf_data_file *file; 76 + char path[PATH_MAX]; 77 + struct stat st; 78 + 79 + snprintf(path, sizeof(path), "%s/%s", data->path, dent->d_name); 80 + if (stat(path, &st)) 81 + continue; 82 + 83 + if (!S_ISREG(st.st_mode) || strncmp(dent->d_name, "data", 4)) 84 + continue; 85 + 86 + ret = -ENOMEM; 87 + 88 + file = realloc(files, (nr + 1) * sizeof(*files)); 89 + if (!file) 90 + goto out_err; 91 + 92 + files = file; 93 + file = &files[nr++]; 94 + 95 + file->path = strdup(path); 96 + if (!file->path) 97 + goto out_err; 98 + 99 + ret = open(file->path, O_RDONLY); 100 + if (ret < 0) 101 + goto out_err; 102 + 103 + file->fd = ret; 104 + file->size = st.st_size; 105 + } 106 + 107 + if (!files) 108 + return -EINVAL; 109 + 110 + data->dir.files = files; 111 + data->dir.nr = nr; 112 + return 0; 113 + 114 + out_err: 115 + close_dir(files, nr); 61 116 return ret; 62 117 } 63 118
+1
tools/perf/util/data.h
··· 71 71 size_t pos, bool at_exit); 72 72 73 73 int perf_data__create_dir(struct perf_data *data, int nr); 74 + int perf_data__open_dir(struct perf_data *data); 74 75 void perf_data__close_dir(struct perf_data *data); 75 76 #endif /* __PERF_DATA_H */