Skip to content

Commit

Permalink
perf session: fix error message on failure to open perf.data
Browse files Browse the repository at this point in the history
If we cannot open our data file, print strerror(errno) for a more
comprehensible error message; and only suggest 'perf record' on ENOENT.

In particular, this fixes the nonsensical advice when:

    % sudo perf record sleep 1
    [ perf record: Woken up 1 times to write data ]
    [ perf record: Captured and wrote 0.009 MB perf.data (~381 samples) ]
    % perf trace
    failed to open file: perf.data  (try 'perf record' first)
    %

Cc: Ingo Molnar <mingo@elte.hu>
LPU-Reference: <20100612033615.GA24731@hexapodia.org>
Signed-off-by: Andy Isaacson <adi@hexapodia.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Andy Isaacson authored and Arnaldo Carvalho de Melo committed Jun 17, 2010
1 parent 84c104a commit 0f2c3de
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tools/perf/util/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ static int perf_session__open(struct perf_session *self, bool force)

self->fd = open(self->filename, O_RDONLY);
if (self->fd < 0) {
pr_err("failed to open file: %s", self->filename);
if (!strcmp(self->filename, "perf.data"))
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;
Expand Down

0 comments on commit 0f2c3de

Please sign in to comment.