lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <d3f3ab63-7841-97c5-76a0-87d1a763566d@linux.intel.com>
Date:   Mon, 16 Nov 2020 15:25:18 +0300
From:   Alexey Budankov <alexey.budankov@...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>,
        Alexey Bayduraev <alexey.v.bayduraev@...ux.intel.com>,
        Alexander Antonov <alexander.antonov@...ux.intel.com>
Subject: [PATCH v3 12/12] perf session: use reader functions to load perf data
 file


Use the reader functions to load data file similar to loading of
data directory files.

Signed-off-by: Alexey Budankov <alexey.budankov@...ux.intel.com>
---
 tools/perf/util/session.c | 215 ++++++++++++--------------------------
 1 file changed, 66 insertions(+), 149 deletions(-)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 3cb30c1667c0..f6b06187c6f5 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -2194,109 +2194,6 @@ static int __perf_session__process_decomp_events(struct perf_session *session)
 	return 0;
 }
 
-static int
-reader__process_events(struct reader *rd, struct perf_session *session,
-		       struct ui_progress *prog)
-{
-	u64 data_size = rd->data_size;
-	u64 head, page_offset, file_offset, file_pos, size;
-	int err = 0, mmap_prot, mmap_flags, map_idx = 0;
-	size_t	mmap_size;
-	char *buf, *mmaps[NUM_MMAPS];
-	union perf_event *event;
-	s64 skip;
-
-	page_offset = page_size * (rd->data_offset / page_size);
-	file_offset = page_offset;
-	head = rd->data_offset - page_offset;
-
-	ui_progress__init_size(prog, data_size, "Processing events...");
-
-	data_size += rd->data_offset;
-
-	mmap_size = MMAP_SIZE;
-	if (mmap_size > data_size) {
-		mmap_size = data_size;
-		session->one_mmap = true;
-	}
-
-	memset(mmaps, 0, sizeof(mmaps));
-
-	mmap_prot  = PROT_READ;
-	mmap_flags = MAP_SHARED;
-
-	if (session->header.needs_swap) {
-		mmap_prot  |= PROT_WRITE;
-		mmap_flags = MAP_PRIVATE;
-	}
-remap:
-	buf = mmap(NULL, mmap_size, mmap_prot, mmap_flags, rd->fd,
-		   file_offset);
-	if (buf == MAP_FAILED) {
-		pr_err("failed to mmap file\n");
-		err = -errno;
-		goto out;
-	}
-	mmaps[map_idx] = buf;
-	map_idx = (map_idx + 1) & (ARRAY_SIZE(mmaps) - 1);
-	file_pos = file_offset + head;
-	if (session->one_mmap) {
-		session->one_mmap_addr = buf;
-		session->one_mmap_offset = file_offset;
-	}
-
-more:
-	event = fetch_mmaped_event(head, mmap_size, buf, session->header.needs_swap);
-	if (IS_ERR(event))
-		return PTR_ERR(event);
-
-	if (!event) {
-		if (mmaps[map_idx]) {
-			munmap(mmaps[map_idx], mmap_size);
-			mmaps[map_idx] = NULL;
-		}
-
-		page_offset = page_size * (head / page_size);
-		file_offset += page_offset;
-		head -= page_offset;
-		goto remap;
-	}
-
-	size = event->header.size;
-
-	skip = -EINVAL;
-
-	if (size < sizeof(struct perf_event_header) ||
-	    (skip = rd->process(session, event, file_pos, rd->path)) < 0) {
-		pr_err("%#" PRIx64 " [%s] [%#x]: failed to process type: %d [%s]\n",
-		       file_offset + head, rd->path, event->header.size,
-		       event->header.type, strerror(-skip));
-		err = skip;
-		goto out;
-	}
-
-	if (skip)
-		size += skip;
-
-	head += size;
-	file_pos += size;
-
-	err = __perf_session__process_decomp_events(session);
-	if (err)
-		goto out;
-
-	ui_progress__update(prog, size);
-
-	if (session_done())
-		goto out;
-
-	if (file_pos < data_size)
-		goto more;
-
-out:
-	return err;
-}
-
 static s64 process_simple(struct perf_session *session,
 			  union perf_event *event,
 			  u64 file_offset,
@@ -2305,52 +2202,6 @@ static s64 process_simple(struct perf_session *session,
 	return perf_session__process_event(session, event, file_offset, file_path);
 }
 
-static int __perf_session__process_events(struct perf_session *session)
-{
-	struct reader rd = {
-		.fd		= perf_data__fd(session->data),
-		.data_size	= session->header.data_size,
-		.data_offset	= session->header.data_offset,
-		.process	= process_simple,
-		.path		= session->data->file.path,
-	};
-	struct ordered_events *oe = &session->ordered_events;
-	struct perf_tool *tool = session->tool;
-	struct ui_progress prog;
-	int err;
-
-	perf_tool__fill_defaults(tool);
-
-	if (rd.data_size == 0)
-		return -1;
-
-	ui_progress__init_size(&prog, rd.data_size, "Processing events...");
-
-	err = reader__process_events(&rd, session, &prog);
-	if (err)
-		goto out_err;
-	/* do the final flush for ordered samples */
-	err = ordered_events__flush(oe, OE_FLUSH__FINAL);
-	if (err)
-		goto out_err;
-	err = auxtrace__flush_events(session, tool);
-	if (err)
-		goto out_err;
-	err = perf_session__flush_thread_stacks(session);
-out_err:
-	ui_progress__finish();
-	if (!tool->no_warn)
-		perf_session__warn_about_errors(session);
-	/*
-	 * We may switching perf.data output, make ordered_events
-	 * reusable.
-	 */
-	ordered_events__reinit(&session->ordered_events);
-	auxtrace__free_events(session);
-	session->one_mmap = false;
-	return err;
-}
-
 static int
 reader__init(struct reader *rd, bool *one_mmap)
 {
@@ -2467,6 +2318,72 @@ reader__read_event(struct reader *rd, struct perf_session *session,
 	session->active_reader = NULL;;
 	return ret;
 }
+
+static int __perf_session__process_events(struct perf_session *session)
+{
+	struct reader *rd;
+	struct ordered_events *oe = &session->ordered_events;
+	struct perf_tool *tool = session->tool;
+	struct ui_progress prog;
+	int err;
+
+	perf_tool__fill_defaults(tool);
+
+	rd = session->readers = zalloc(sizeof(struct reader));
+	if (!rd)
+		return -ENOMEM;
+
+	session->nr_readers = 1;
+
+	*rd = (struct reader) {
+		.fd		= perf_data__fd(session->data),
+		.data_size	= session->header.data_size,
+		.data_offset	= session->header.data_offset,
+		.process	= process_simple,
+		.path		= session->data->file.path,
+	};
+
+	ui_progress__init_size(&prog, rd->data_size, "Processing events...");
+
+	reader__init(rd, &session->one_mmap);
+	if (reader__mmap(rd, session) != READER_OK)
+		goto out_err;
+
+	while (true) {
+		if (session_done())
+			break;
+
+		err = reader__read_event(rd, session, &prog);
+		if (err < 0)
+			break;
+		if (err == READER_EOF) {
+			err = reader__mmap(rd, session);
+			if (err <= 0)
+				break;
+		}
+	}
+
+	/* do the final flush for ordered samples */
+	err = ordered_events__flush(oe, OE_FLUSH__FINAL);
+	if (err)
+		goto out_err;
+	err = auxtrace__flush_events(session, tool);
+	if (err)
+		goto out_err;
+	err = perf_session__flush_thread_stacks(session);
+out_err:
+	ui_progress__finish();
+	if (!tool->no_warn)
+		perf_session__warn_about_errors(session);
+	/*
+	 * We may switching perf.data output, make ordered_events
+	 * reusable.
+	 */
+	ordered_events__reinit(&session->ordered_events);
+	auxtrace__free_events(session);
+	session->one_mmap = false;
+	return err;
+}
 /*
  * This function reads, merge and process directory data.
  * It assumens the version 1 of directory data, where each
-- 
2.24.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ