* [PATCH] perf data: if a bad header size, retry in pipe mode
@ 2020-04-09 18:57 Ian Rogers
2020-04-14 12:51 ` Jiri Olsa
0 siblings, 1 reply; 5+ messages in thread
From: Ian Rogers @ 2020-04-09 18:57 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
Kan Liang, Adrian Hunter, Alexey Budankov, linux-kernel
Cc: Ian Rogers
Currently pipe mode files fail like:
$ perf record -o - sleep 1 > /tmp/perf.pipe.data
$ perf report -i /tmp/perf.pipe.data
incompatible file format (rerun with -v to learn more)
This change makes it so that if a perf.data file's header size is wrong
it is re-checked in pipe mode, where if wrong it fails as it currently
does.
Signed-off-by: Ian Rogers <irogers@google.com>
---
| 35 ++++++++++++++++++++++++++---------
| 5 -----
2 files changed, 26 insertions(+), 14 deletions(-)
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index acbd046bf95c..1df00a4a71b6 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -3329,8 +3329,15 @@ static int check_magic_endian(u64 magic, uint64_t hdr_sz,
return 0;
}
-int perf_file_header__read(struct perf_file_header *header,
- struct perf_header *ph, int fd)
+enum header_read_status {
+ HEADER_READ_OK,
+ HEADER_READ_BAD_SIZE,
+ HEADER_READ_BAD,
+};
+
+static enum header_read_status
+perf_file_header__read(struct perf_file_header *header,
+ struct perf_header *ph, int fd)
{
ssize_t ret;
@@ -3338,12 +3345,12 @@ int perf_file_header__read(struct perf_file_header *header,
ret = readn(fd, header, sizeof(*header));
if (ret <= 0)
- return -1;
+ return HEADER_READ_BAD;
if (check_magic_endian(header->magic,
header->attr_size, false, ph) < 0) {
pr_debug("magic/endian check failed\n");
- return -1;
+ return HEADER_READ_BAD;
}
if (ph->needs_swap) {
@@ -3356,7 +3363,7 @@ int perf_file_header__read(struct perf_file_header *header,
if (header->size == offsetof(typeof(*header), adds_features))
bitmap_zero(header->adds_features, HEADER_FEAT_BITS);
else
- return -1;
+ return HEADER_READ_BAD_SIZE;
} else if (ph->needs_swap) {
/*
* feature bitmap is declared as an array of unsigned longs --
@@ -3398,7 +3405,7 @@ int perf_file_header__read(struct perf_file_header *header,
ph->data_offset = header->data.offset;
ph->data_size = header->data.size;
ph->feat_offset = header->data.offset + header->data.size;
- return 0;
+ return HEADER_READ_OK;
}
static int perf_file_section__process(struct perf_file_section *section,
@@ -3580,12 +3587,22 @@ int perf_session__read_header(struct perf_session *session)
session->evlist->env = &header->env;
session->machines.host.env = &header->env;
+
+ if (!perf_data__is_pipe(data)) {
+ enum header_read_status status =
+ perf_file_header__read(&f_header, header, fd);
+ if (status == HEADER_READ_BAD)
+ return -EINVAL;
+ if (status == HEADER_READ_BAD_SIZE) {
+ pr_debug("Data had a bad header size, retrying in pipe mode\n");
+ lseek(fd, 0, SEEK_SET);
+ data->is_pipe = true;
+ }
+ }
+
if (perf_data__is_pipe(data))
return perf_header__read_pipe(session);
- if (perf_file_header__read(&f_header, header, fd) < 0)
- return -EINVAL;
-
/*
* Sanity check that perf.data was written cleanly; data size is
* initialized to 0 and updated only if the on_exit function is run.
--git a/tools/perf/util/header.h b/tools/perf/util/header.h
index 840f95cee349..3d7f39358265 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -73,11 +73,6 @@ struct perf_pipe_file_header {
u64 size;
};
-struct perf_header;
-
-int perf_file_header__read(struct perf_file_header *header,
- struct perf_header *ph, int fd);
-
struct perf_header {
enum perf_header_version version;
bool needs_swap;
--
2.26.0.292.g33ef6b2f38-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] perf data: if a bad header size, retry in pipe mode
2020-04-09 18:57 [PATCH] perf data: if a bad header size, retry in pipe mode Ian Rogers
@ 2020-04-14 12:51 ` Jiri Olsa
2020-04-14 14:01 ` Ian Rogers
0 siblings, 1 reply; 5+ messages in thread
From: Jiri Olsa @ 2020-04-14 12:51 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Namhyung Kim, Kan Liang,
Adrian Hunter, Alexey Budankov, linux-kernel
On Thu, Apr 09, 2020 at 11:57:44AM -0700, Ian Rogers wrote:
> Currently pipe mode files fail like:
> $ perf record -o - sleep 1 > /tmp/perf.pipe.data
> $ perf report -i /tmp/perf.pipe.data
> incompatible file format (rerun with -v to learn more)
>
> This change makes it so that if a perf.data file's header size is wrong
> it is re-checked in pipe mode, where if wrong it fails as it currently
> does.
>
hi,
how about doing it the other way round like below,
read header and find out if it's pipe..
seems it's less changes
jirka
---
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index acbd046bf95c..20c34cec9a46 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -3469,7 +3469,7 @@ static int perf_header__read_pipe(struct perf_session *session)
return -EINVAL;
}
- return 0;
+ return f_header.size == sizeof(f_header) ? 0 : -1;
}
static int read_attr(int fd, struct perf_header *ph,
@@ -3571,7 +3571,7 @@ int perf_session__read_header(struct perf_session *session)
struct perf_file_header f_header;
struct perf_file_attr f_attr;
u64 f_id;
- int nr_attrs, nr_ids, i, j;
+ int nr_attrs, nr_ids, i, j, err;
int fd = perf_data__fd(data);
session->evlist = evlist__new();
@@ -3580,8 +3580,16 @@ int perf_session__read_header(struct perf_session *session)
session->evlist->env = &header->env;
session->machines.host.env = &header->env;
- if (perf_data__is_pipe(data))
- return perf_header__read_pipe(session);
+
+ /*
+ * We could still read 'pipe' data from regular file,
+ * check for the pipe header first.
+ */
+ err = perf_header__read_pipe(session);
+ if (!err || (err && perf_data__is_pipe(data))) {
+ data->is_pipe = true;
+ return err;
+ }
if (perf_file_header__read(&f_header, header, fd) < 0)
return -EINVAL;
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] perf data: if a bad header size, retry in pipe mode
2020-04-14 12:51 ` Jiri Olsa
@ 2020-04-14 14:01 ` Ian Rogers
2020-04-30 14:12 ` Ian Rogers
0 siblings, 1 reply; 5+ messages in thread
From: Ian Rogers @ 2020-04-14 14:01 UTC (permalink / raw)
To: Jiri Olsa
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Namhyung Kim, Kan Liang,
Adrian Hunter, Alexey Budankov, LKML
On Tue, Apr 14, 2020 at 5:51 AM Jiri Olsa <jolsa@redhat.com> wrote:
>
> On Thu, Apr 09, 2020 at 11:57:44AM -0700, Ian Rogers wrote:
> > Currently pipe mode files fail like:
> > $ perf record -o - sleep 1 > /tmp/perf.pipe.data
> > $ perf report -i /tmp/perf.pipe.data
> > incompatible file format (rerun with -v to learn more)
> >
> > This change makes it so that if a perf.data file's header size is wrong
> > it is re-checked in pipe mode, where if wrong it fails as it currently
> > does.
> >
>
> hi,
> how about doing it the other way round like below,
> read header and find out if it's pipe..
>
> seems it's less changes
>
> jirka
Looks good to me. I think removing the function declaration from
util/header.h is still worthwhile, but needn't be in a patch with this
change.
Thanks!
Ian
> ---
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index acbd046bf95c..20c34cec9a46 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -3469,7 +3469,7 @@ static int perf_header__read_pipe(struct perf_session *session)
> return -EINVAL;
> }
>
> - return 0;
> + return f_header.size == sizeof(f_header) ? 0 : -1;
> }
>
> static int read_attr(int fd, struct perf_header *ph,
> @@ -3571,7 +3571,7 @@ int perf_session__read_header(struct perf_session *session)
> struct perf_file_header f_header;
> struct perf_file_attr f_attr;
> u64 f_id;
> - int nr_attrs, nr_ids, i, j;
> + int nr_attrs, nr_ids, i, j, err;
> int fd = perf_data__fd(data);
>
> session->evlist = evlist__new();
> @@ -3580,8 +3580,16 @@ int perf_session__read_header(struct perf_session *session)
>
> session->evlist->env = &header->env;
> session->machines.host.env = &header->env;
> - if (perf_data__is_pipe(data))
> - return perf_header__read_pipe(session);
> +
> + /*
> + * We could still read 'pipe' data from regular file,
> + * check for the pipe header first.
> + */
> + err = perf_header__read_pipe(session);
> + if (!err || (err && perf_data__is_pipe(data))) {
> + data->is_pipe = true;
> + return err;
> + }
>
> if (perf_file_header__read(&f_header, header, fd) < 0)
> return -EINVAL;
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] perf data: if a bad header size, retry in pipe mode
2020-04-14 14:01 ` Ian Rogers
@ 2020-04-30 14:12 ` Ian Rogers
2020-04-30 15:34 ` Jiri Olsa
0 siblings, 1 reply; 5+ messages in thread
From: Ian Rogers @ 2020-04-30 14:12 UTC (permalink / raw)
To: Jiri Olsa
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Namhyung Kim, Kan Liang,
Adrian Hunter, Alexey Budankov, LKML
On Tue, Apr 14, 2020 at 7:01 AM Ian Rogers <irogers@google.com> wrote:
>
> On Tue, Apr 14, 2020 at 5:51 AM Jiri Olsa <jolsa@redhat.com> wrote:
> >
> > On Thu, Apr 09, 2020 at 11:57:44AM -0700, Ian Rogers wrote:
> > > Currently pipe mode files fail like:
> > > $ perf record -o - sleep 1 > /tmp/perf.pipe.data
> > > $ perf report -i /tmp/perf.pipe.data
> > > incompatible file format (rerun with -v to learn more)
> > >
> > > This change makes it so that if a perf.data file's header size is wrong
> > > it is re-checked in pipe mode, where if wrong it fails as it currently
> > > does.
> > >
> >
> > hi,
> > how about doing it the other way round like below,
> > read header and find out if it's pipe..
> >
> > seems it's less changes
> >
> > jirka
>
> Looks good to me. I think removing the function declaration from
> util/header.h is still worthwhile, but needn't be in a patch with this
> change.
Hi Jiri,
Do you need to send this patch?
Thanks,
Ian
> Thanks!
> Ian
>
> > ---
> > diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> > index acbd046bf95c..20c34cec9a46 100644
> > --- a/tools/perf/util/header.c
> > +++ b/tools/perf/util/header.c
> > @@ -3469,7 +3469,7 @@ static int perf_header__read_pipe(struct perf_session *session)
> > return -EINVAL;
> > }
> >
> > - return 0;
> > + return f_header.size == sizeof(f_header) ? 0 : -1;
> > }
> >
> > static int read_attr(int fd, struct perf_header *ph,
> > @@ -3571,7 +3571,7 @@ int perf_session__read_header(struct perf_session *session)
> > struct perf_file_header f_header;
> > struct perf_file_attr f_attr;
> > u64 f_id;
> > - int nr_attrs, nr_ids, i, j;
> > + int nr_attrs, nr_ids, i, j, err;
> > int fd = perf_data__fd(data);
> >
> > session->evlist = evlist__new();
> > @@ -3580,8 +3580,16 @@ int perf_session__read_header(struct perf_session *session)
> >
> > session->evlist->env = &header->env;
> > session->machines.host.env = &header->env;
> > - if (perf_data__is_pipe(data))
> > - return perf_header__read_pipe(session);
> > +
> > + /*
> > + * We could still read 'pipe' data from regular file,
> > + * check for the pipe header first.
> > + */
> > + err = perf_header__read_pipe(session);
> > + if (!err || (err && perf_data__is_pipe(data))) {
> > + data->is_pipe = true;
> > + return err;
> > + }
> >
> > if (perf_file_header__read(&f_header, header, fd) < 0)
> > return -EINVAL;
> >
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] perf data: if a bad header size, retry in pipe mode
2020-04-30 14:12 ` Ian Rogers
@ 2020-04-30 15:34 ` Jiri Olsa
0 siblings, 0 replies; 5+ messages in thread
From: Jiri Olsa @ 2020-04-30 15:34 UTC (permalink / raw)
To: Ian Rogers
Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Mark Rutland, Alexander Shishkin, Namhyung Kim, Kan Liang,
Adrian Hunter, Alexey Budankov, LKML
On Thu, Apr 30, 2020 at 07:12:49AM -0700, Ian Rogers wrote:
> On Tue, Apr 14, 2020 at 7:01 AM Ian Rogers <irogers@google.com> wrote:
> >
> > On Tue, Apr 14, 2020 at 5:51 AM Jiri Olsa <jolsa@redhat.com> wrote:
> > >
> > > On Thu, Apr 09, 2020 at 11:57:44AM -0700, Ian Rogers wrote:
> > > > Currently pipe mode files fail like:
> > > > $ perf record -o - sleep 1 > /tmp/perf.pipe.data
> > > > $ perf report -i /tmp/perf.pipe.data
> > > > incompatible file format (rerun with -v to learn more)
> > > >
> > > > This change makes it so that if a perf.data file's header size is wrong
> > > > it is re-checked in pipe mode, where if wrong it fails as it currently
> > > > does.
> > > >
> > >
> > > hi,
> > > how about doing it the other way round like below,
> > > read header and find out if it's pipe..
> > >
> > > seems it's less changes
> > >
> > > jirka
> >
> > Looks good to me. I think removing the function declaration from
> > util/header.h is still worthwhile, but needn't be in a patch with this
> > change.
>
> Hi Jiri,
>
> Do you need to send this patch?
ah right, will post, thanks for reminder
jirka
>
> Thanks,
> Ian
>
> > Thanks!
> > Ian
> >
> > > ---
> > > diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> > > index acbd046bf95c..20c34cec9a46 100644
> > > --- a/tools/perf/util/header.c
> > > +++ b/tools/perf/util/header.c
> > > @@ -3469,7 +3469,7 @@ static int perf_header__read_pipe(struct perf_session *session)
> > > return -EINVAL;
> > > }
> > >
> > > - return 0;
> > > + return f_header.size == sizeof(f_header) ? 0 : -1;
> > > }
> > >
> > > static int read_attr(int fd, struct perf_header *ph,
> > > @@ -3571,7 +3571,7 @@ int perf_session__read_header(struct perf_session *session)
> > > struct perf_file_header f_header;
> > > struct perf_file_attr f_attr;
> > > u64 f_id;
> > > - int nr_attrs, nr_ids, i, j;
> > > + int nr_attrs, nr_ids, i, j, err;
> > > int fd = perf_data__fd(data);
> > >
> > > session->evlist = evlist__new();
> > > @@ -3580,8 +3580,16 @@ int perf_session__read_header(struct perf_session *session)
> > >
> > > session->evlist->env = &header->env;
> > > session->machines.host.env = &header->env;
> > > - if (perf_data__is_pipe(data))
> > > - return perf_header__read_pipe(session);
> > > +
> > > + /*
> > > + * We could still read 'pipe' data from regular file,
> > > + * check for the pipe header first.
> > > + */
> > > + err = perf_header__read_pipe(session);
> > > + if (!err || (err && perf_data__is_pipe(data))) {
> > > + data->is_pipe = true;
> > > + return err;
> > > + }
> > >
> > > if (perf_file_header__read(&f_header, header, fd) < 0)
> > > return -EINVAL;
> > >
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-04-30 15:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-09 18:57 [PATCH] perf data: if a bad header size, retry in pipe mode Ian Rogers
2020-04-14 12:51 ` Jiri Olsa
2020-04-14 14:01 ` Ian Rogers
2020-04-30 14:12 ` Ian Rogers
2020-04-30 15:34 ` Jiri Olsa
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.