[PATCH v1 01/13] perf session: Don't flush remaining events once processing is done
From: Ian Rogers
Date: Fri Oct 02 2026 - 14:26:46 EST
When session_done() is set, for example by SIGINT or by a python
callback requesting processing stop, the reader loops stop but the
deferred samples and auxtrace data are still flushed afterwards. For
large traces decoding and delivering the remaining auxtrace data can be
slow, and the events are delivered to tools that asked to stop.
Discard the remaining deferred samples, and skip
auxtrace__flush_events(), when session_done() is set. The
ordered_events flush already honors session_done().
Assisted-by: Antigravity:gemini-3.1-pro
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
tools/perf/util/auxtrace.c | 7 +++++++
tools/perf/util/session.c | 8 ++++++++
2 files changed, 15 insertions(+)
diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index ed2113190785..f30f86156a3a 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -2978,6 +2978,13 @@ int auxtrace__flush_events(struct perf_session *session, const struct perf_tool
if (!session->auxtrace)
return 0;
+ /*
+ * Processing was stopped early, e.g. by SIGINT, so don't decode and
+ * deliver the remaining trace data which can be slow.
+ */
+ if (session_done())
+ return 0;
+
return session->auxtrace->flush_events(session, tool);
}
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 7fea9e72726c..74b0fc0514d3 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -2018,6 +2018,14 @@ static int session__flush_deferred_samples(struct perf_session *session,
struct perf_sample sample;
struct evsel *new_evsel;
+ if (session_done()) {
+ /* Processing was stopped early, discard the sample. */
+ list_del(&de->list);
+ free(de->event);
+ free(de);
+ continue;
+ }
+
perf_sample__init(&sample, /*all=*/false);
ret = evlist__parse_sample(evlist, de->event, &sample);
if (ret < 0) {
--
2.56.0.rc1.315.gc6ed9934b7-goog