[PATCH 1/4] perf timechart: Release event samples at the end
From: Namhyung Kim
Date: Fri Jun 05 2026 - 19:17:10 EST
Add timechart__release() to free all data structures added during the
sample processing.
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/builtin-timechart.c | 54 ++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 04dbb944a42720b4..7c4ace51302e260c 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -1548,6 +1548,59 @@ static void write_svg_file(struct timechart *tchart, const char *filename)
svg_close();
}
+static void timechart__release(struct timechart *tchart)
+{
+ struct per_pid *p = tchart->all_data;
+ struct power_event *pwr = tchart->power_events;
+ struct wake_event *we = tchart->wake_events;
+
+ while (p) {
+ struct per_pid *next_pid = p->next;
+ struct per_pidcomm *c = p->all;
+
+ while (c) {
+ struct per_pidcomm *next_comm = c->next;
+ struct cpu_sample *cs = c->samples;
+ struct io_sample *ios = c->io_samples;
+
+ while (cs) {
+ struct cpu_sample *next = cs->next;
+
+ free((char *)cs->backtrace);
+ free(cs);
+ cs = next;
+ }
+
+ while (ios) {
+ struct io_sample *next = ios->next;
+
+ free(ios);
+ ios = next;
+ }
+
+ free(c->comm);
+ free(c);
+ c = next_comm;
+ }
+ p = next_pid;
+ }
+
+ while (pwr) {
+ struct power_event *next = pwr->next;
+
+ free(pwr);
+ pwr = next;
+ }
+
+ while (we) {
+ struct wake_event *next = we->next;
+
+ free((char *)we->backtrace);
+ free(we);
+ we = next;
+ }
+}
+
static int process_header(struct perf_file_section *section __maybe_unused,
struct perf_header *ph,
int feat,
@@ -2079,6 +2132,7 @@ int cmd_timechart(int argc, const char **argv)
ret = __cmd_timechart(&tchart, output_name);
out:
+ timechart__release(&tchart);
zfree(&cpus_cstate_start_times);
zfree(&cpus_cstate_state);
zfree(&cpus_pstate_start_times);
--
2.54.0.1032.g2f8565e1d1-goog