[PATCH 4/6] perf session: Move init/exit into reader__init/reader__exit functions
From: Alexey Bayduraev
Date: Wed Sep 29 2021 - 04:42:16 EST
Separating init/exit code into reader__init and reader__exit function.
Suggested-by: Jiri Olsa <jolsa@xxxxxxxxxx>
Acked-by: Namhyung Kim <namhyung@xxxxxxxxx>
Reviewed-by: Riccardo Mancini <rickyman7@xxxxxxxxx>
Tested-by: Riccardo Mancini <rickyman7@xxxxxxxxx>
Signed-off-by: Alexey Bayduraev <alexey.v.bayduraev@xxxxxxxxxxxxxxx>
---
tools/perf/util/session.c | 42 ++++++++++++++++++++++++++++-----------
1 file changed, 30 insertions(+), 12 deletions(-)
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 3bea0830b3b8..85142d2a9a5a 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -2203,28 +2203,23 @@ static int __perf_session__process_decomp_events(struct perf_session *session)
}
static int
-reader__process_events(struct reader *rd, struct perf_session *session,
- struct ui_progress *prog)
+reader__init(struct reader *rd, bool *one_mmap)
{
struct reader_state *st = &rd->state;
- u64 page_offset, size;
- int err = 0, mmap_prot, mmap_flags;
- char *buf, **mmaps = st->mmaps;
- union perf_event *event;
- s64 skip;
+ u64 page_offset;
+ char **mmaps = st->mmaps;
page_offset = page_size * (rd->data_offset / page_size);
st->file_offset = page_offset;
st->head = rd->data_offset - page_offset;
- ui_progress__init_size(prog, rd->data_size, "Processing events...");
-
st->data_size = rd->data_size + rd->data_offset;
st->mmap_size = MMAP_SIZE;
if (st->mmap_size > st->data_size) {
st->mmap_size = st->data_size;
- session->one_mmap = true;
+ if (one_mmap)
+ *one_mmap = true;
}
memset(mmaps, 0, sizeof(st->mmaps));
@@ -2232,6 +2227,27 @@ reader__process_events(struct reader *rd, struct perf_session *session,
if (zstd_init(&rd->zstd_data, 0))
return -1;
+ return 0;
+}
+
+static void
+reader__exit(struct reader *rd)
+{
+ perf_decomp__release_events(rd->decomp);
+ zstd_fini(&rd->zstd_data);
+}
+
+static int
+reader__process_events(struct reader *rd, struct perf_session *session,
+ struct ui_progress *prog)
+{
+ struct reader_state *st = &rd->state;
+ u64 page_offset, size;
+ int err = 0, mmap_prot, mmap_flags;
+ char *buf, **mmaps = st->mmaps;
+ union perf_event *event;
+ s64 skip;
+
mmap_prot = PROT_READ;
mmap_flags = MAP_SHARED;
@@ -2309,8 +2325,6 @@ reader__process_events(struct reader *rd, struct perf_session *session,
out:
session->active_reader = NULL;
- perf_decomp__release_events(rd->decomp);
- zstd_fini(&rd->zstd_data);
return err;
}
@@ -2342,6 +2356,9 @@ static int __perf_session__process_events(struct perf_session *session)
ui_progress__init_size(&prog, rd.data_size, "Processing events...");
+ err = reader__init(&rd, &session->one_mmap);
+ if (err)
+ goto out_err;
err = reader__process_events(&rd, session, &prog);
if (err)
goto out_err;
@@ -2364,6 +2381,7 @@ static int __perf_session__process_events(struct perf_session *session)
ordered_events__reinit(&session->ordered_events);
auxtrace__free_events(session);
session->one_mmap = false;
+ reader__exit(&rd);
return err;
}
--
2.19.0