Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 288729
b: refs/heads/master
c: 69996df
h: refs/heads/master
i:
  288727: ddd211b
v: v3
  • Loading branch information
Stephane Eranian authored and Ingo Molnar committed Mar 9, 2012
1 parent 79483dc commit 7a5f88f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: cb5d76999029ae7a517cb07dfa732c1b5a934fc2
refs/heads/master: 69996df486fc3921bbaaa17fca0d68f537f9eabf
53 changes: 48 additions & 5 deletions trunk/tools/perf/util/header.c
Original file line number Diff line number Diff line change
Expand Up @@ -1973,6 +1973,51 @@ static int perf_header__read_pipe(struct perf_session *session, int fd)
return 0;
}

static int read_attr(int fd, struct perf_header *ph,
struct perf_file_attr *f_attr)
{
struct perf_event_attr *attr = &f_attr->attr;
size_t sz, left;
size_t our_sz = sizeof(f_attr->attr);
int ret;

memset(f_attr, 0, sizeof(*f_attr));

/* read minimal guaranteed structure */
ret = readn(fd, attr, PERF_ATTR_SIZE_VER0);
if (ret <= 0) {
pr_debug("cannot read %d bytes of header attr\n",
PERF_ATTR_SIZE_VER0);
return -1;
}

/* on file perf_event_attr size */
sz = attr->size;
if (ph->needs_swap)
sz = bswap_32(sz);

if (sz == 0) {
/* assume ABI0 */
sz = PERF_ATTR_SIZE_VER0;
} else if (sz > our_sz) {
pr_debug("file uses a more recent and unsupported ABI"
" (%zu bytes extra)\n", sz - our_sz);
return -1;
}
/* what we have not yet read and that we know about */
left = sz - PERF_ATTR_SIZE_VER0;
if (left) {
void *ptr = attr;
ptr += PERF_ATTR_SIZE_VER0;

ret = readn(fd, ptr, left);
}
/* read perf_file_section, ids are read in caller */
ret = readn(fd, &f_attr->ids, sizeof(f_attr->ids));

return ret <= 0 ? -1 : 0;
}

int perf_session__read_header(struct perf_session *session, int fd)
{
struct perf_header *header = &session->header;
Expand All @@ -1988,19 +2033,17 @@ int perf_session__read_header(struct perf_session *session, int fd)
if (session->fd_pipe)
return perf_header__read_pipe(session, fd);

if (perf_file_header__read(&f_header, header, fd) < 0) {
pr_debug("incompatible file format\n");
if (perf_file_header__read(&f_header, header, fd) < 0)
return -EINVAL;
}

nr_attrs = f_header.attrs.size / sizeof(f_attr);
nr_attrs = f_header.attrs.size / f_header.attr_size;
lseek(fd, f_header.attrs.offset, SEEK_SET);

for (i = 0; i < nr_attrs; i++) {
struct perf_evsel *evsel;
off_t tmp;

if (readn(fd, &f_attr, sizeof(f_attr)) <= 0)
if (read_attr(fd, header, &f_attr) < 0)
goto out_errno;

if (header->needs_swap)
Expand Down
4 changes: 2 additions & 2 deletions trunk/tools/perf/util/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static int perf_session__open(struct perf_session *self, bool force)
self->fd = STDIN_FILENO;

if (perf_session__read_header(self, self->fd) < 0)
pr_err("incompatible file format");
pr_err("incompatible file format (rerun with -v to learn more)");

return 0;
}
Expand Down Expand Up @@ -56,7 +56,7 @@ static int perf_session__open(struct perf_session *self, bool force)
}

if (perf_session__read_header(self, self->fd) < 0) {
pr_err("incompatible file format");
pr_err("incompatible file format (rerun with -v to learn more)");
goto out_close;
}

Expand Down

0 comments on commit 7a5f88f

Please sign in to comment.