static int perf_session__open(struct perf_session *session) { struct perf_data_file *file = session->file; if (perf_session__read_header(session) < 0) { pr_err("incompatible file format (rerun with -v to learn more)"); return -1; } if (perf_data_file__is_pipe(file)) return 0; if (!perf_evlist__valid_sample_type(session->evlist)) { pr_err("non matching sample_type"); return -1; } if (!perf_evlist__valid_sample_id_all(session->evlist)) { pr_err("non matching sample_id_all"); return -1; } if (!perf_evlist__valid_read_format(session->evlist)) { pr_err("non matching read_format"); return -1; } return 0; }
static int perf_session__open(struct perf_session *self, bool force) { struct stat input_stat; if (!strcmp(self->filename, "-")) { self->fd_pipe = true; self->fd = STDIN_FILENO; if (perf_session__read_header(self) < 0) pr_err("incompatible file format (rerun with -v to learn more)"); return 0; } self->fd = open(self->filename, O_RDONLY); if (self->fd < 0) { int err = errno; pr_err("failed to open %s: %s", self->filename, strerror(err)); if (err == ENOENT && !strcmp(self->filename, "perf.data")) pr_err(" (try 'perf record' first)"); pr_err("\n"); return -errno; } if (fstat(self->fd, &input_stat) < 0) goto out_close; if (!force && input_stat.st_uid && (input_stat.st_uid != geteuid())) { pr_err("file %s not owned by current user or root\n", self->filename); goto out_close; } if (!input_stat.st_size) { pr_info("zero-sized file (%s), nothing to do!\n", self->filename); goto out_close; } if (perf_session__read_header(self) < 0) { pr_err("incompatible file format (rerun with -v to learn more)"); goto out_close; } if (!perf_evlist__valid_sample_type(self->evlist)) { pr_err("non matching sample_type"); goto out_close; } if (!perf_evlist__valid_sample_id_all(self->evlist)) { pr_err("non matching sample_id_all"); goto out_close; } if (!perf_evlist__valid_read_format(self->evlist)) { pr_err("non matching read_format"); goto out_close; } self->size = input_stat.st_size; return 0; out_close: close(self->fd); self->fd = -1; return -1; }