1 #include <linux/kernel.h>
9 static int perf_session__open(struct perf_session *self, bool force)
11 struct stat input_stat;
13 self->fd = open(self->filename, O_RDONLY);
15 pr_err("failed to open file: %s", self->filename);
16 if (!strcmp(self->filename, "perf.data"))
17 pr_err(" (try 'perf record' first)");
22 if (fstat(self->fd, &input_stat) < 0)
25 if (!force && input_stat.st_uid && (input_stat.st_uid != geteuid())) {
26 pr_err("file %s not owned by current user or root\n",
31 if (!input_stat.st_size) {
32 pr_info("zero-sized file (%s), nothing to do!\n",
37 if (perf_header__read(&self->header, self->fd) < 0) {
38 pr_err("incompatible file format");
42 self->size = input_stat.st_size;
51 struct perf_session *perf_session__new(const char *filename, int mode,
54 size_t len = strlen(filename) + 1;
55 struct perf_session *self = zalloc(sizeof(*self) + len);
60 if (perf_header__init(&self->header) < 0)
63 memcpy(self->filename, filename, len);
64 self->mmap_window = 32;
68 if (mode == O_RDONLY && perf_session__open(self, force) < 0) {
69 perf_session__delete(self);
79 void perf_session__delete(struct perf_session *self)
81 perf_header__exit(&self->header);