Lines Matching refs:data

16 #include "data.h"
45 void perf_data__close_dir(struct perf_data *data)
47 close_dir(data->dir.files, data->dir.nr);
48 data->dir.files = NULL;
49 data->dir.nr = 0;
52 int perf_data__create_dir(struct perf_data *data, int nr)
58 if (WARN_ON(!data->is_dir))
68 ret = asprintf(&file->path, "%s/data.%d", data->path, i);
78 * If using parallel threads to collect data,
93 data->dir.version = PERF_DIR_VERSION;
94 data->dir.files = files;
95 data->dir.nr = nr;
103 int perf_data__open_dir(struct perf_data *data)
112 * Directory containing a single regular perf data file which is already
115 if (perf_data__is_single_file(data))
118 if (WARN_ON(!data->is_dir))
122 if (WARN_ON(data->dir.version != PERF_DIR_VERSION))
125 dir = opendir(data->path);
134 snprintf(path, sizeof(path), "%s/%s", data->path, dent->d_name);
138 if (!S_ISREG(st.st_mode) || strncmp(dent->d_name, "data.", 5))
171 data->dir.files = files;
172 data->dir.nr = nr;
181 static bool check_pipe(struct perf_data *data)
185 int fd = perf_data__is_read(data) ?
188 if (!data->path) {
192 if (!strcmp(data->path, "-"))
197 if (data->file.use_stdio) {
200 mode = perf_data__is_read(data) ? "r" : "w";
201 data->file.fptr = fdopen(fd, mode);
203 if (data->file.fptr == NULL) {
204 data->file.fd = fd;
205 data->file.use_stdio = false;
209 * When is_pipe and data->file.fd is given, use given fd
212 } else if (data->file.fd <= 0) {
213 data->file.fd = fd;
217 return data->is_pipe = is_pipe;
220 static int check_backup(struct perf_data *data)
224 if (perf_data__is_read(data))
227 if (!stat(data->path, &st) && st.st_size) {
232 data->path);
237 pr_err("Can't remove old data: Unknown file found (%s)\n", oldname);
239 pr_err("Can't remove old data: %m (%s)\n", oldname);
243 if (rename(data->path, oldname)) {
244 pr_err("Can't move data: %m (%s to %s)\n", data->path, oldname);
252 static bool is_dir(struct perf_data *data)
256 if (stat(data->path, &st))
262 static int open_file_read(struct perf_data *data)
264 int flags = data->in_place_update ? O_RDWR : O_RDONLY;
268 fd = open(data->file.path, flags);
272 pr_err("failed to open %s: %m", data->file.path);
273 if (err == ENOENT && !strcmp(data->file.path, "perf.data"))
282 if (!data->force && st.st_uid && (st.st_uid != geteuid())) {
284 data->file.path);
289 pr_info("zero-sized data (%s), nothing to do!\n",
290 data->file.path);
294 data->file.size = st.st_size;
302 static int open_file_write(struct perf_data *data)
304 int fd = open(data->file.path, O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC, S_IRUSR|S_IWUSR);
307 pr_err("failed to open %s : %m\n", data->file.path);
312 static int open_file(struct perf_data *data)
316 fd = perf_data__is_read(data) ?
317 open_file_read(data) : open_file_write(data);
320 zfree(&data->file.path);
324 data->file.fd = fd;
328 static int open_file_dup(struct perf_data *data)
330 data->file.path = strdup(data->path);
331 if (!data->file.path)
334 return open_file(data);
337 static int open_dir(struct perf_data *data)
342 * So far we open only the header, so we can read the data version and
345 if (asprintf(&data->file.path, "%s/data", data->path) < 0)
348 if (perf_data__is_write(data) && mkdir(data->path, 0700) < 0) {
349 zfree(&data->file.path);
353 ret = open_file(data);
356 if (ret && perf_data__is_write(data))
357 rm_rf_perf_data(data->path);
362 int perf_data__open(struct perf_data *data)
366 if (data->open)
369 if (check_pipe(data)) {
370 data->open = true;
375 data->file.use_stdio = false;
377 if (!data->path)
378 data->path = "perf.data";
380 if (check_backup(data))
383 if (perf_data__is_read(data))
384 data->is_dir = is_dir(data);
386 ret = perf_data__is_dir(data) ? open_dir(data) : open_file_dup(data);
389 data->open = true;
394 void perf_data__close(struct perf_data *data)
396 if (!data->open)
399 if (perf_data__is_dir(data))
400 perf_data__close_dir(data);
402 perf_data_file__close(&data->file);
403 data->open = false;
416 ssize_t perf_data__read(struct perf_data *data, void *buf, size_t size)
418 return perf_data_file__read(&data->file, buf, size);
432 ssize_t perf_data__write(struct perf_data *data,
435 return perf_data_file__write(&data->file, buf, size);
448 off_t perf_data__seek(struct perf_data *data, off_t offset, int whence)
451 return perf_data_file__seek(&data->file, offset, whence);
454 int perf_data__switch(struct perf_data *data,
461 if (perf_data__is_read(data))
464 if (asprintf(new_filepath, "%s.%s", data->path, postfix) < 0)
471 if (rename(data->path, *new_filepath))
472 pr_warning("Failed to rename %s to %s\n", data->path, *new_filepath);
475 perf_data_file__close(&data->file);
476 data->open = false;
477 ret = perf_data__open(data);
481 if (perf_data__seek(data, pos, SEEK_SET) == (off_t)-1) {
487 ret = perf_data__fd(data);
492 unsigned long perf_data__size(struct perf_data *data)
494 u64 size = data->file.size;
497 if (perf_data__is_single_file(data))
500 for (i = 0; i < data->dir.nr; i++) {
501 struct perf_data_file *file = &data->dir.files[i];
509 int perf_data__make_kcore_dir(struct perf_data *data, char *buf, size_t buf_sz)
513 if (!data->is_dir)
516 ret = snprintf(buf, buf_sz, "%s/kcore_dir", data->path);
542 char *perf_data__kallsyms_name(struct perf_data *data)
547 if (!data->is_dir)
550 if (asprintf(&kallsyms_name, "%s/kcore_dir/kallsyms", data->path) < 0)
561 char *perf_data__guest_kallsyms_name(struct perf_data *data, pid_t machine_pid)
566 if (!data->is_dir)
569 if (asprintf(&kallsyms_name, "%s/kcore_dir__%d/kallsyms", data->path, machine_pid) < 0)