Lines Matching refs:data

16 #include "data.h"
31 void perf_data__close_dir(struct perf_data *data)
33 close_dir(data->dir.files, data->dir.nr);
36 int perf_data__create_dir(struct perf_data *data, int nr)
41 if (WARN_ON(!data->is_dir))
51 ret = asprintf(&file->path, "%s/data.%d", data->path, i);
66 data->dir.version = PERF_DIR_VERSION;
67 data->dir.files = files;
68 data->dir.nr = nr;
76 int perf_data__open_dir(struct perf_data *data)
85 * Directory containing a single regular perf data file which is already
88 if (perf_data__is_single_file(data))
91 if (WARN_ON(!data->is_dir))
95 if (WARN_ON(data->dir.version != PERF_DIR_VERSION))
98 dir = opendir(data->path);
107 snprintf(path, sizeof(path), "%s/%s", data->path, dent->d_name);
111 if (!S_ISREG(st.st_mode) || strncmp(dent->d_name, "data.", 5))
139 data->dir.files = files;
140 data->dir.nr = nr;
149 int perf_data__update_dir(struct perf_data *data)
153 if (WARN_ON(!data->is_dir))
156 for (i = 0; i < data->dir.nr; i++) {
157 struct perf_data_file *file = &data->dir.files[i];
169 static bool check_pipe(struct perf_data *data)
173 int fd = perf_data__is_read(data) ?
176 if (!data->path) {
180 if (!strcmp(data->path, "-"))
185 if (data->use_stdio) {
188 mode = perf_data__is_read(data) ? "r" : "w";
189 data->file.fptr = fdopen(fd, mode);
191 if (data->file.fptr == NULL) {
192 data->file.fd = fd;
193 data->use_stdio = false;
196 data->file.fd = fd;
200 return data->is_pipe = is_pipe;
203 static int check_backup(struct perf_data *data)
207 if (perf_data__is_read(data))
210 if (!stat(data->path, &st) && st.st_size) {
215 data->path);
219 pr_err("Can't remove old data: %s (%s)\n",
226 if (rename(data->path, oldname)) {
227 pr_err("Can't move data: %s (%s to %s)\n",
229 data->path, oldname);
237 static bool is_dir(struct perf_data *data)
241 if (stat(data->path, &st))
247 static int open_file_read(struct perf_data *data)
249 int flags = data->in_place_update ? O_RDWR : O_RDONLY;
254 fd = open(data->file.path, flags);
258 pr_err("failed to open %s: %s", data->file.path,
260 if (err == ENOENT && !strcmp(data->file.path, "perf.data"))
269 if (!data->force && st.st_uid && (st.st_uid != geteuid())) {
271 data->file.path);
276 pr_info("zero-sized data (%s), nothing to do!\n",
277 data->file.path);
281 data->file.size = st.st_size;
289 static int open_file_write(struct perf_data *data)
294 fd = open(data->file.path, O_CREAT|O_RDWR|O_TRUNC|O_CLOEXEC,
298 pr_err("failed to open %s : %s\n", data->file.path,
304 static int open_file(struct perf_data *data)
308 fd = perf_data__is_read(data) ?
309 open_file_read(data) : open_file_write(data);
312 zfree(&data->file.path);
316 data->file.fd = fd;
320 static int open_file_dup(struct perf_data *data)
322 data->file.path = strdup(data->path);
323 if (!data->file.path)
326 return open_file(data);
329 static int open_dir(struct perf_data *data)
334 * So far we open only the header, so we can read the data version and
337 if (asprintf(&data->file.path, "%s/data", data->path) < 0)
340 if (perf_data__is_write(data) &&
341 mkdir(data->path, S_IRWXU) < 0)
344 ret = open_file(data);
347 if (ret && perf_data__is_write(data))
348 rm_rf_perf_data(data->path);
353 int perf_data__open(struct perf_data *data)
355 if (check_pipe(data))
359 data->use_stdio = false;
361 if (!data->path)
362 data->path = "perf.data";
364 if (check_backup(data))
367 if (perf_data__is_read(data))
368 data->is_dir = is_dir(data);
370 return perf_data__is_dir(data) ?
371 open_dir(data) : open_file_dup(data);
374 void perf_data__close(struct perf_data *data)
376 if (perf_data__is_dir(data))
377 perf_data__close_dir(data);
379 zfree(&data->file.path);
381 if (data->use_stdio)
382 fclose(data->file.fptr);
384 close(data->file.fd);
387 ssize_t perf_data__read(struct perf_data *data, void *buf, size_t size)
389 if (data->use_stdio) {
390 if (fread(buf, size, 1, data->file.fptr) == 1)
392 return feof(data->file.fptr) ? 0 : -1;
394 return readn(data->file.fd, buf, size);
403 ssize_t perf_data__write(struct perf_data *data,
406 if (data->use_stdio) {
407 if (fwrite(buf, size, 1, data->file.fptr) == 1)
411 return perf_data_file__write(&data->file, buf, size);
414 int perf_data__switch(struct perf_data *data,
421 if (perf_data__is_read(data))
424 if (asprintf(new_filepath, "%s.%s", data->path, postfix) < 0)
431 if (rename(data->path, *new_filepath))
432 pr_warning("Failed to rename %s to %s\n", data->path, *new_filepath);
435 close(data->file.fd);
436 ret = perf_data__open(data);
440 if (lseek(data->file.fd, pos, SEEK_SET) == (off_t)-1) {
447 ret = data->file.fd;
452 unsigned long perf_data__size(struct perf_data *data)
454 u64 size = data->file.size;
457 if (perf_data__is_single_file(data))
460 for (i = 0; i < data->dir.nr; i++) {
461 struct perf_data_file *file = &data->dir.files[i];
469 int perf_data__make_kcore_dir(struct perf_data *data, char *buf, size_t buf_sz)
473 if (!data->is_dir)
476 ret = snprintf(buf, buf_sz, "%s/kcore_dir", data->path);
502 char *perf_data__kallsyms_name(struct perf_data *data)
507 if (!data->is_dir)
510 if (asprintf(&kallsyms_name, "%s/kcore_dir/kallsyms", data->path) < 0)
521 char *perf_data__guest_kallsyms_name(struct perf_data *data, pid_t machine_pid)
526 if (!data->is_dir)
529 if (asprintf(&kallsyms_name, "%s/kcore_dir__%d/kallsyms", data->path, machine_pid) < 0)