#define _FILE_OFFSET_BITS 64
#include <linux/kernel.h>
#include <byteswap.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include "evlist.h"
#include "evsel.h"
#include "session.h"
#include "sort.h"
#include "util.h"
static int perf_session__read_evlist(struct perf_session *session)
{
int i, j;
session->evlist = perf_evlist__new(NULL, NULL);
if (session->evlist == NULL)
return -ENOMEM;
for (i = 0; i < session->header.attrs; ++i) {
struct perf_header_attr *hattr = session->header.attr[i];
struct perf_evsel *evsel = perf_evsel__new(&hattr->attr, i);
if (evsel == NULL)
goto out_delete_evlist;
/*
* Do it before so that if perf_evsel__alloc_id fails, this
* entry gets purged too at perf_evlist__delete().
*/
perf_evlist__add(session->evlist, evsel);
/*
* We don't have the cpu and thread maps on the header, so
* for allocating the perf_sample_id table we fake 1 cpu and
* hattr->ids threads.
*/
if (perf_evsel__alloc_id(evsel, 1, hattr->ids))
goto out_delete_evlist;
for (j = 0; j < hattr->ids; ++j)
perf_evlist__id_hash(session->evlist, evsel, 0, j,
hattr->id[j]);
}
return 0;
out_delete_evlist:
perf_evlist__delete(session->evlist);
session->evlist = NULL;
return -ENOMEM;
}
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_header__read(self, self->fd) < 0)
pr_err("incompatible file format");
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_header__read(self,