Skip to content

Commit 37ed2cd

Browse files
rauls5382acmel
authored andcommitted
perf inject: Adjust output data offset for backward compatibility
When 'perf inject' creates a new file, it reuses the data offset from the input file. If there has been a change on the size of the header, as happened in v5.12 -> v5.13, the new offsets will be wrong, resulting in a corrupted output file. This change adds the function perf_session__data_offset to compute the data offset based on the current header size, and uses that instead of the offset from the original input file. Signed-off-by: Raul Silvera <rsilvera@google.com> Acked-by: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com> Cc: Colin Ian King <colin.king@intel.com> Cc: Dave Marchevsky <davemarchevsky@fb.com> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20220621152725.2668041-1-rsilvera@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 3713e24 commit 37ed2cd

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

tools/perf/builtin-inject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ static int __cmd_inject(struct perf_inject *inject)
918918
inject->tool.tracing_data = perf_event__repipe_tracing_data;
919919
}
920920

921-
output_data_offset = session->header.data_offset;
921+
output_data_offset = perf_session__data_offset(session->evlist);
922922

923923
if (inject->build_id_all) {
924924
inject->tool.mmap = perf_event__repipe_buildid_mmap;

tools/perf/util/header.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3686,6 +3686,20 @@ int perf_session__write_header(struct perf_session *session,
36863686
return perf_session__do_write_header(session, evlist, fd, at_exit, NULL);
36873687
}
36883688

3689+
size_t perf_session__data_offset(const struct evlist *evlist)
3690+
{
3691+
struct evsel *evsel;
3692+
size_t data_offset;
3693+
3694+
data_offset = sizeof(struct perf_file_header);
3695+
evlist__for_each_entry(evlist, evsel) {
3696+
data_offset += evsel->core.ids * sizeof(u64);
3697+
}
3698+
data_offset += evlist->core.nr_entries * sizeof(struct perf_file_attr);
3699+
3700+
return data_offset;
3701+
}
3702+
36893703
int perf_session__inject_header(struct perf_session *session,
36903704
struct evlist *evlist,
36913705
int fd,

tools/perf/util/header.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ int perf_session__inject_header(struct perf_session *session,
136136
int fd,
137137
struct feat_copier *fc);
138138

139+
size_t perf_session__data_offset(const struct evlist *evlist);
140+
139141
void perf_header__set_feat(struct perf_header *header, int feat);
140142
void perf_header__clear_feat(struct perf_header *header, int feat);
141143
bool perf_header__has_feat(const struct perf_header *header, int feat);

0 commit comments

Comments
 (0)