]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf sample: Add file_offset field to struct perf_sample
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 1 Jun 2026 16:07:52 +0000 (13:07 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 3 Jun 2026 19:31:03 +0000 (16:31 -0300)
Add a file_offset field to struct perf_sample so that event processing
callbacks can report the byte offset of the problematic event in
perf.data, letting users cross-reference with 'perf report -D' output.

Set sample.file_offset in perf_session__deliver_event(), which is the
common entry point for both file mode (mmap'd offset) and pipe mode
(running byte counter from __perf_session__process_pipe_events).

The assignment is placed after evsel__parse_sample(), which zeroes
the struct via memset.

Preserve file_offset through the deferred callchain delivery path by
storing it in struct deferred_event and restoring it after
evlist__parse_sample() in both evlist__deliver_deferred_callchain()
and session__flush_deferred_samples().

Subsequent patches will use this field in skip/stop warning messages.

Reviewed-by: Ian Rogers <irogers@google.com>
Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/sample.h
tools/perf/util/session.c

index e556c9b656ea9cd68af8adeeb1be45c4f3fdd4cd..c4eae8b2fd06035a0f26660b076584c3829488fc 100644 (file)
@@ -158,6 +158,8 @@ struct perf_sample {
        u64 code_page_size;
        /** @cgroup: The sample event PERF_SAMPLE_CGROUP value. */
        u64 cgroup;
+       /** @file_offset: Byte offset of this event in the perf.data file. */
+       u64 file_offset;
        /** @flags: Extra flag data from auxiliary events like intel-pt. */
        u32 flags;
        /** @machine_pid: The guest machine pid derived from the sample id. */
index e2e821b77766dbfcf0a7c216f37db4421df854ec..7996787d742e32c6f8b6aa5326fcc39682f9b5cf 100644 (file)
@@ -1824,6 +1824,7 @@ static int evlist__deliver_sample(struct evlist *evlist, const struct perf_tool
 struct deferred_event {
        struct list_head list;
        union perf_event *event;
+       u64 file_offset;
 };
 
 /*
@@ -1858,6 +1859,7 @@ static int evlist__deliver_deferred_callchain(struct evlist *evlist,
                        perf_sample__exit(&orig_sample);
                        break;
                }
+               orig_sample.file_offset = de->file_offset;
 
                if (sample->tid != orig_sample.tid) {
                        perf_sample__exit(&orig_sample);
@@ -1906,6 +1908,7 @@ static int session__flush_deferred_samples(struct perf_session *session,
                        perf_sample__exit(&sample);
                        break;
                }
+               sample.file_offset = de->file_offset;
 
                sample.evsel = evlist__id2evsel(evlist, sample.id);
                ret = evlist__deliver_sample(evlist, tool, de->event,
@@ -1984,6 +1987,7 @@ static int machines__deliver_event(struct machines *machines,
                                return -ENOMEM;
                        }
                        memcpy(de->event, event, sz);
+                       de->file_offset = sample->file_offset;
                        list_add_tail(&de->list, &evlist->deferred_samples);
                        return 0;
                }
@@ -2126,6 +2130,7 @@ static int perf_session__deliver_event(struct perf_session *session,
                pr_err("Can't parse sample, err = %d\n", ret);
                goto out;
        }
+       sample.file_offset = file_offset;
        /*
         * evsel__parse_sample() doesn't populate machine_pid/vcpu,
         * which are needed by machines__find_for_cpumode() to