Lines Matching full:data
16 #include "data.h"
32 void perf_data__close_dir(struct perf_data *data) in perf_data__close_dir() argument
34 close_dir(data->dir.files, data->dir.nr); in perf_data__close_dir()
37 int perf_data__create_dir(struct perf_data *data, int nr) in perf_data__create_dir() argument
43 if (WARN_ON(!data->is_dir)) in perf_data__create_dir()
53 ret = asprintf(&file->path, "%s/data.%d", data->path, i); in perf_data__create_dir()
63 * If using parallel threads to collect data, in perf_data__create_dir()
78 data->dir.version = PERF_DIR_VERSION; in perf_data__create_dir()
79 data->dir.files = files; in perf_data__create_dir()
80 data->dir.nr = nr; in perf_data__create_dir()
88 int perf_data__open_dir(struct perf_data *data) in perf_data__open_dir() argument
97 * Directory containing a single regular perf data file which is already in perf_data__open_dir()
100 if (perf_data__is_single_file(data)) in perf_data__open_dir()
103 if (WARN_ON(!data->is_dir)) in perf_data__open_dir()
107 if (WARN_ON(data->dir.version != PERF_DIR_VERSION)) in perf_data__open_dir()
110 dir = opendir(data->path); in perf_data__open_dir()
119 snprintf(path, sizeof(path), "%s/%s", data->path, dent->d_name); in perf_data__open_dir()
123 if (!S_ISREG(st.st_mode) || strncmp(dent->d_name, "data.", 5)) in perf_data__open_dir()
151 data->dir.files = files; in perf_data__open_dir()
152 data->dir.nr = nr; in perf_data__open_dir()
161 int perf_data__update_dir(struct perf_data *data) in perf_data__update_dir() argument
165 if (WARN_ON(!data->is_dir)) in perf_data__update_dir()
168 for (i = 0; i < data->dir.nr; i++) { in perf_data__update_dir()
169 struct perf_data_file *file = &data->dir.files[i]; in perf_data__update_dir()
181 static bool check_pipe(struct perf_data *data) in check_pipe() argument
185 int fd = perf_data__is_read(data) ? in check_pipe()
188 if (!data->path) { in check_pipe()
192 if (!strcmp(data->path, "-")) in check_pipe()
197 if (data->use_stdio) { in check_pipe()
200 mode = perf_data__is_read(data) ? "r" : "w"; in check_pipe()
201 data->file.fptr = fdopen(fd, mode); in check_pipe()
203 if (data->file.fptr == NULL) { in check_pipe()
204 data->file.fd = fd; in check_pipe()
205 data->use_stdio = false; in check_pipe()
209 * When is_pipe and data->file.fd is given, use given fd in check_pipe()
212 } else if (data->file.fd <= 0) { in check_pipe()
213 data->file.fd = fd; in check_pipe()
217 return data->is_pipe = is_pipe; in check_pipe()
220 static int check_backup(struct perf_data *data) in check_backup() argument
224 if (perf_data__is_read(data)) in check_backup()
227 if (!stat(data->path, &st) && st.st_size) { in check_backup()
232 data->path); in check_backup()
236 pr_err("Can't remove old data: %s (%s)\n", in check_backup()
243 if (rename(data->path, oldname)) { in check_backup()
244 pr_err("Can't move data: %s (%s to %s)\n", in check_backup()
246 data->path, oldname); in check_backup()
254 static bool is_dir(struct perf_data *data) in is_dir() argument
258 if (stat(data->path, &st)) in is_dir()
264 static int open_file_read(struct perf_data *data) in open_file_read() argument
266 int flags = data->in_place_update ? O_RDWR : O_RDONLY; in open_file_read()
271 fd = open(data->file.path, flags); in open_file_read()
275 pr_err("failed to open %s: %s", data->file.path, in open_file_read()
277 if (err == ENOENT && !strcmp(data->file.path, "perf.data")) in open_file_read()
286 if (!data->force && st.st_uid && (st.st_uid != geteuid())) { in open_file_read()
288 data->file.path); in open_file_read()
293 pr_info("zero-sized data (%s), nothing to do!\n", in open_file_read()
294 data->file.path); in open_file_read()
298 data->file.size = st.st_size; in open_file_read()
306 static int open_file_write(struct perf_data *data) in open_file_write() argument
311 fd = open(data->file.path, O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC, in open_file_write()
315 pr_err("failed to open %s : %s\n", data->file.path, in open_file_write()
321 static int open_file(struct perf_data *data) in open_file() argument
325 fd = perf_data__is_read(data) ? in open_file()
326 open_file_read(data) : open_file_write(data); in open_file()
329 zfree(&data->file.path); in open_file()
333 data->file.fd = fd; in open_file()
337 static int open_file_dup(struct perf_data *data) in open_file_dup() argument
339 data->file.path = strdup(data->path); in open_file_dup()
340 if (!data->file.path) in open_file_dup()
343 return open_file(data); in open_file_dup()
346 static int open_dir(struct perf_data *data) in open_dir() argument
351 * So far we open only the header, so we can read the data version and in open_dir()
354 if (asprintf(&data->file.path, "%s/data", data->path) < 0) in open_dir()
357 if (perf_data__is_write(data) && in open_dir()
358 mkdir(data->path, S_IRWXU) < 0) in open_dir()
361 ret = open_file(data); in open_dir()
364 if (ret && perf_data__is_write(data)) in open_dir()
365 rm_rf_perf_data(data->path); in open_dir()
370 int perf_data__open(struct perf_data *data) in perf_data__open() argument
372 if (check_pipe(data)) in perf_data__open()
376 data->use_stdio = false; in perf_data__open()
378 if (!data->path) in perf_data__open()
379 data->path = "perf.data"; in perf_data__open()
381 if (check_backup(data)) in perf_data__open()
384 if (perf_data__is_read(data)) in perf_data__open()
385 data->is_dir = is_dir(data); in perf_data__open()
387 return perf_data__is_dir(data) ? in perf_data__open()
388 open_dir(data) : open_file_dup(data); in perf_data__open()
391 void perf_data__close(struct perf_data *data) in perf_data__close() argument
393 if (perf_data__is_dir(data)) in perf_data__close()
394 perf_data__close_dir(data); in perf_data__close()
396 zfree(&data->file.path); in perf_data__close()
398 if (data->use_stdio) in perf_data__close()
399 fclose(data->file.fptr); in perf_data__close()
401 close(data->file.fd); in perf_data__close()
404 ssize_t perf_data__read(struct perf_data *data, void *buf, size_t size) in perf_data__read() argument
406 if (data->use_stdio) { in perf_data__read()
407 if (fread(buf, size, 1, data->file.fptr) == 1) in perf_data__read()
409 return feof(data->file.fptr) ? 0 : -1; in perf_data__read()
411 return readn(data->file.fd, buf, size); in perf_data__read()
420 ssize_t perf_data__write(struct perf_data *data, in perf_data__write() argument
423 if (data->use_stdio) { in perf_data__write()
424 if (fwrite(buf, size, 1, data->file.fptr) == 1) in perf_data__write()
428 return perf_data_file__write(&data->file, buf, size); in perf_data__write()
431 int perf_data__switch(struct perf_data *data, in perf_data__switch() argument
438 if (perf_data__is_read(data)) in perf_data__switch()
441 if (asprintf(new_filepath, "%s.%s", data->path, postfix) < 0) in perf_data__switch()
448 if (rename(data->path, *new_filepath)) in perf_data__switch()
449 pr_warning("Failed to rename %s to %s\n", data->path, *new_filepath); in perf_data__switch()
452 close(data->file.fd); in perf_data__switch()
453 ret = perf_data__open(data); in perf_data__switch()
457 if (lseek(data->file.fd, pos, SEEK_SET) == (off_t)-1) { in perf_data__switch()
464 ret = data->file.fd; in perf_data__switch()
469 unsigned long perf_data__size(struct perf_data *data) in perf_data__size() argument
471 u64 size = data->file.size; in perf_data__size()
474 if (perf_data__is_single_file(data)) in perf_data__size()
477 for (i = 0; i < data->dir.nr; i++) { in perf_data__size()
478 struct perf_data_file *file = &data->dir.files[i]; in perf_data__size()
486 int perf_data__make_kcore_dir(struct perf_data *data, char *buf, size_t buf_sz) in perf_data__make_kcore_dir() argument
490 if (!data->is_dir) in perf_data__make_kcore_dir()
493 ret = snprintf(buf, buf_sz, "%s/kcore_dir", data->path); in perf_data__make_kcore_dir()
519 char *perf_data__kallsyms_name(struct perf_data *data) in perf_data__kallsyms_name() argument
524 if (!data->is_dir) in perf_data__kallsyms_name()
527 if (asprintf(&kallsyms_name, "%s/kcore_dir/kallsyms", data->path) < 0) in perf_data__kallsyms_name()
538 char *perf_data__guest_kallsyms_name(struct perf_data *data, pid_t machine_pid) in perf_data__guest_kallsyms_name() argument
543 if (!data->is_dir) in perf_data__guest_kallsyms_name()
546 if (asprintf(&kallsyms_name, "%s/kcore_dir__%d/kallsyms", data->path, machine_pid) < 0) in perf_data__guest_kallsyms_name()