[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <3ffc49a1f6a621ec23782839042ca3616dc1d84c.1629186429.git.alexey.v.bayduraev@linux.intel.com>
Date: Tue, 17 Aug 2021 11:23:23 +0300
From: Alexey Bayduraev <alexey.v.bayduraev@...ux.intel.com>
To: Arnaldo Carvalho de Melo <acme@...nel.org>
Cc: Jiri Olsa <jolsa@...hat.com>, Namhyung Kim <namhyung@...nel.org>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
linux-kernel <linux-kernel@...r.kernel.org>,
Andi Kleen <ak@...ux.intel.com>,
Adrian Hunter <adrian.hunter@...el.com>,
Alexander Antonov <alexander.antonov@...ux.intel.com>,
Alexei Budankov <abudankov@...wei.com>,
Riccardo Mancini <rickyman7@...il.com>
Subject: [PATCH v11 20/24] perf session: Introduce decompressor into trace reader object
Introduce decompressor into trace reader object so that decompression
could be executed on per data file basis separately for every data
file located in data directory.
Acked-by: Namhyung Kim <namhyung@...il.com>
Reviewed-by: Riccardo Mancini <rickyman7@...il.com>
Tested-by: Riccardo Mancini <rickyman7@...il.com>
Signed-off-by: Alexey Bayduraev <alexey.v.bayduraev@...ux.intel.com>
---
tools/perf/util/session.c | 54 +++++++++++++++++++++++++++++----------
tools/perf/util/session.h | 1 +
2 files changed, 42 insertions(+), 13 deletions(-)
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 1f92d3cfcb1d..ed41bccb15ff 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -73,6 +73,9 @@ struct reader {
u64 data_offset;
reader_cb_t process;
bool in_place_update;
+ struct zstd_data zstd_data;
+ struct decomp *decomp;
+ struct decomp *decomp_last;
struct reader_state state;
};
@@ -85,7 +88,10 @@ static int perf_session__process_compressed_event(struct perf_session *session,
size_t decomp_size, src_size;
u64 decomp_last_rem = 0;
size_t mmap_len, decomp_len = session->header.env.comp_mmap_len;
- struct decomp *decomp, *decomp_last = session->decomp_last;
+ struct decomp *decomp, *decomp_last = session->active_reader ?
+ session->active_reader->decomp_last : session->decomp_last;
+ struct zstd_data *zstd_data = session->active_reader ?
+ &session->active_reader->zstd_data : &session->zstd_data;
if (decomp_last) {
decomp_last_rem = decomp_last->size - decomp_last->head;
@@ -113,7 +119,7 @@ static int perf_session__process_compressed_event(struct perf_session *session,
src = (void *)event + sizeof(struct perf_record_compressed);
src_size = event->pack.header.size - sizeof(struct perf_record_compressed);
- decomp_size = zstd_decompress_stream(&(session->zstd_data), src, src_size,
+ decomp_size = zstd_decompress_stream(zstd_data, src, src_size,
&(decomp->data[decomp_last_rem]), decomp_len - decomp_last_rem);
if (!decomp_size) {
munmap(decomp, mmap_len);
@@ -123,12 +129,22 @@ static int perf_session__process_compressed_event(struct perf_session *session,
decomp->size += decomp_size;
- if (session->decomp == NULL) {
- session->decomp = decomp;
- session->decomp_last = decomp;
+ if (session->active_reader) {
+ if (session->active_reader->decomp == NULL) {
+ session->active_reader->decomp = decomp;
+ session->active_reader->decomp_last = decomp;
+ } else {
+ session->active_reader->decomp_last->next = decomp;
+ session->active_reader->decomp_last = decomp;
+ }
} else {
- session->decomp_last->next = decomp;
- session->decomp_last = decomp;
+ if (session->decomp == NULL) {
+ session->decomp = decomp;
+ session->decomp_last = decomp;
+ } else {
+ session->decomp_last->next = decomp;
+ session->decomp_last = decomp;
+ }
}
pr_debug("decomp (B): %zd to %zd\n", src_size, decomp_size);
@@ -320,11 +336,11 @@ static void perf_session__delete_threads(struct perf_session *session)
machine__delete_threads(&session->machines.host);
}
-static void perf_session__release_decomp_events(struct perf_session *session)
+static void perf_decomp__release_events(struct decomp *next)
{
- struct decomp *next, *decomp;
+ struct decomp *decomp;
size_t mmap_len;
- next = session->decomp;
+
do {
decomp = next;
if (decomp == NULL)
@@ -337,6 +353,8 @@ static void perf_session__release_decomp_events(struct perf_session *session)
void perf_session__delete(struct perf_session *session)
{
+ int r;
+
if (session == NULL)
return;
auxtrace__free(session);
@@ -344,10 +362,14 @@ void perf_session__delete(struct perf_session *session)
perf_session__destroy_kernel_maps(session);
perf_session__delete_threads(session);
if (session->readers) {
+ for (r = 0; r < session->nr_readers; r++) {
+ perf_decomp__release_events(session->readers[r].decomp);
+ zstd_fini(&session->readers[r].zstd_data);
+ }
zfree(&session->readers);
session->nr_readers = 0;
}
- perf_session__release_decomp_events(session);
+ perf_decomp__release_events(session->decomp);
perf_env__exit(&session->header.env);
machines__exit(&session->machines);
if (session->data) {
@@ -2162,7 +2184,8 @@ static int __perf_session__process_decomp_events(struct perf_session *session)
{
s64 skip;
u64 size;
- struct decomp *decomp = session->decomp_last;
+ struct decomp *decomp = session->active_reader ?
+ session->active_reader->decomp_last : session->decomp_last;
if (!decomp)
return 0;
@@ -2219,6 +2242,9 @@ reader__process_events(struct reader *rd, struct perf_session *session,
memset(mmaps, 0, sizeof(st->mmaps));
+ if (zstd_init(&rd->zstd_data, 0))
+ return -1;
+
mmap_prot = PROT_READ;
mmap_flags = MAP_SHARED;
@@ -2262,12 +2288,13 @@ reader__process_events(struct reader *rd, struct perf_session *session,
goto remap;
}
+ session->active_reader = rd;
size = event->header.size;
skip = -EINVAL;
if (size < sizeof(struct perf_event_header) ||
- (skip = rd->process(session, event, st->file_pos, rd->path)) < 0) {
+ (skip = perf_session__process_event(session, event, st->file_pos, rd->path)) < 0) {
pr_err("%#" PRIx64 " [%s] [%#x]: failed to process type: %d [%s]\n",
st->file_offset + st->head, rd->path, event->header.size,
event->header.type, strerror(-skip));
@@ -2294,6 +2321,7 @@ reader__process_events(struct reader *rd, struct perf_session *session,
goto more;
out:
+ session->active_reader = NULL;
return err;
}
diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h
index b9b9468d8f17..8073331d0490 100644
--- a/tools/perf/util/session.h
+++ b/tools/perf/util/session.h
@@ -44,6 +44,7 @@ struct perf_session {
struct decomp *decomp_last;
struct reader *readers;
int nr_readers;
+ struct reader *active_reader;
};
struct decomp {
--
2.19.0
Powered by blists - more mailing lists