Lines Matching refs:data

15 #include "data.h"
30 void perf_data__close_dir(struct perf_data *data)
32 close_dir(data->dir.files, data->dir.nr);
35 int perf_data__create_dir(struct perf_data *data, int nr)
40 if (WARN_ON(!data->is_dir))
50 ret = asprintf(&file->path, "%s/data.%d", data->path, i);
61 data->dir.version = PERF_DIR_VERSION;
62 data->dir.files = files;
63 data->dir.nr = nr;
71 int perf_data__open_dir(struct perf_data *data)
80 * Directory containing a single regular perf data file which is already
83 if (perf_data__is_single_file(data))
86 if (WARN_ON(!data->is_dir))
90 if (WARN_ON(data->dir.version != PERF_DIR_VERSION))
93 dir = opendir(data->path);
102 snprintf(path, sizeof(path), "%s/%s", data->path, dent->d_name);
106 if (!S_ISREG(st.st_mode) || strncmp(dent->d_name, "data.", 5))
134 data->dir.files = files;
135 data->dir.nr = nr;
144 int perf_data__update_dir(struct perf_data *data)
148 if (WARN_ON(!data->is_dir))
151 for (i = 0; i < data->dir.nr; i++) {
152 struct perf_data_file *file = &data->dir.files[i];
164 static bool check_pipe(struct perf_data *data)
168 int fd = perf_data__is_read(data) ?
171 if (!data->path) {
175 if (!strcmp(data->path, "-"))
180 data->file.fd = fd;
182 return data->is_pipe = is_pipe;
185 static int check_backup(struct perf_data *data)
189 if (perf_data__is_read(data))
192 if (!stat(data->path, &st) && st.st_size) {
197 data->path);
201 pr_err("Can't remove old data: %s (%s)\n",
208 if (rename(data->path, oldname)) {
209 pr_err("Can't move data: %s (%s to %s)\n",
211 data->path, oldname);
219 static bool is_dir(struct perf_data *data)
223 if (stat(data->path, &st))
229 static int open_file_read(struct perf_data *data)
235 fd = open(data->file.path, O_RDONLY);
239 pr_err("failed to open %s: %s", data->file.path,
241 if (err == ENOENT && !strcmp(data->file.path, "perf.data"))
250 if (!data->force && st.st_uid && (st.st_uid != geteuid())) {
252 data->file.path);
257 pr_info("zero-sized data (%s), nothing to do!\n",
258 data->file.path);
262 data->file.size = st.st_size;
270 static int open_file_write(struct perf_data *data)
275 fd = open(data->file.path, O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC,
279 pr_err("failed to open %s : %s\n", data->file.path,
285 static int open_file(struct perf_data *data)
289 fd = perf_data__is_read(data) ?
290 open_file_read(data) : open_file_write(data);
293 zfree(&data->file.path);
297 data->file.fd = fd;
301 static int open_file_dup(struct perf_data *data)
303 data->file.path = strdup(data->path);
304 if (!data->file.path)
307 return open_file(data);
310 static int open_dir(struct perf_data *data)
315 * So far we open only the header, so we can read the data version and
318 if (asprintf(&data->file.path, "%s/data", data->path) < 0)
321 if (perf_data__is_write(data) &&
322 mkdir(data->path, S_IRWXU) < 0)
325 ret = open_file(data);
328 if (ret && perf_data__is_write(data))
329 rm_rf_perf_data(data->path);
334 int perf_data__open(struct perf_data *data)
336 if (check_pipe(data))
339 if (!data->path)
340 data->path = "perf.data";
342 if (check_backup(data))
345 if (perf_data__is_read(data))
346 data->is_dir = is_dir(data);
348 return perf_data__is_dir(data) ?
349 open_dir(data) : open_file_dup(data);
352 void perf_data__close(struct perf_data *data)
354 if (perf_data__is_dir(data))
355 perf_data__close_dir(data);
357 zfree(&data->file.path);
358 close(data->file.fd);
367 ssize_t perf_data__write(struct perf_data *data,
370 return perf_data_file__write(&data->file, buf, size);
373 int perf_data__switch(struct perf_data *data,
380 if (check_pipe(data))
382 if (perf_data__is_read(data))
385 if (asprintf(new_filepath, "%s.%s", data->path, postfix) < 0)
392 if (rename(data->path, *new_filepath))
393 pr_warning("Failed to rename %s to %s\n", data->path, *new_filepath);
396 close(data->file.fd);
397 ret = perf_data__open(data);
401 if (lseek(data->file.fd, pos, SEEK_SET) == (off_t)-1) {
408 ret = data->file.fd;
413 unsigned long perf_data__size(struct perf_data *data)
415 u64 size = data->file.size;
418 if (perf_data__is_single_file(data))
421 for (i = 0; i < data->dir.nr; i++) {
422 struct perf_data_file *file = &data->dir.files[i];
430 int perf_data__make_kcore_dir(struct perf_data *data, char *buf, size_t buf_sz)
434 if (!data->is_dir)
437 ret = snprintf(buf, buf_sz, "%s/kcore_dir", data->path);
444 char *perf_data__kallsyms_name(struct perf_data *data)
449 if (!data->is_dir)
452 if (asprintf(&kallsyms_name, "%s/kcore_dir/kallsyms", data->path) < 0)