Skip to content

Commit 648b054

Browse files
algrant-armacmel
authored andcommitted
perf inject: Correct event attribute sizes
When 'perf inject' reads a perf.data file from an older version of perf, it writes event attributes into the output with the original size field, but lays them out as if they had the size currently used. Readers see a corrupt file. Update the size field to match the layout. Signed-off-by: Al Grant <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Denis Nikitin <[email protected]> Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 5501e92 commit 648b054

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

tools/perf/util/header.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3323,6 +3323,14 @@ int perf_session__write_header(struct perf_session *session,
33233323
attr_offset = lseek(ff.fd, 0, SEEK_CUR);
33243324

33253325
evlist__for_each_entry(evlist, evsel) {
3326+
if (evsel->core.attr.size < sizeof(evsel->core.attr)) {
3327+
/*
3328+
* We are likely in "perf inject" and have read
3329+
* from an older file. Update attr size so that
3330+
* reader gets the right offset to the ids.
3331+
*/
3332+
evsel->core.attr.size = sizeof(evsel->core.attr);
3333+
}
33263334
f_attr = (struct perf_file_attr){
33273335
.attr = evsel->core.attr,
33283336
.ids = {

0 commit comments

Comments
 (0)