lkml.org 
[lkml]   [2020]   [Apr]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH] perf data: if a bad header size, retry in pipe mode
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;
\
 
 \ /
  Last update: 2020-04-14 14:51    [W:0.778 / U:0.184 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site