linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Andi Kleen <ak@linux.intel.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Alexander Antonov <alexander.antonov@linux.intel.com>,
	Alexei Budankov <abudankov@huawei.com>,
	Riccardo Mancini <rickyman7@gmail.com>
Subject: [PATCH v10 11/24] perf record: Init data file at mmap buffer object
Date: Mon, 12 Jul 2021 09:46:11 +0300	[thread overview]
Message-ID: <4303bdbda256737f6015aac645d55c75263804b7.1626072009.git.alexey.v.bayduraev@linux.intel.com> (raw)
In-Reply-To: <cover.1626072008.git.alexey.v.bayduraev@linux.intel.com>

Initialize data files located at mmap buffer objects so trace data
can be written into several data file located at data directory.

Acked-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Namhyung Kim <namhyung@gmail.com>
Signed-off-by: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
---
 tools/perf/builtin-record.c | 41 ++++++++++++++++++++++++++++++-------
 tools/perf/util/record.h    |  1 +
 2 files changed, 35 insertions(+), 7 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index d81da805ee93..791926ddc0b0 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -167,6 +167,11 @@ static inline pid_t gettid(void)
 }
 #endif
 
+static int record__threads_enabled(struct record *rec)
+{
+	return rec->opts.threads_spec;
+}
+
 static bool switch_output_signal(struct record *rec)
 {
 	return rec->switch_output.signal &&
@@ -1147,7 +1152,7 @@ static int record__alloc_thread_data(struct record *rec, struct evlist *evlist)
 static int record__mmap_evlist(struct record *rec,
 			       struct evlist *evlist)
 {
-	int ret;
+	int i, ret;
 	struct record_opts *opts = &rec->opts;
 	bool auxtrace_overwrite = opts->auxtrace_snapshot_mode ||
 				  opts->auxtrace_sample_mode;
@@ -1186,6 +1191,18 @@ static int record__mmap_evlist(struct record *rec,
 	if (ret)
 		return ret;
 
+	if (record__threads_enabled(rec)) {
+		ret = perf_data__create_dir(&rec->data, evlist->core.nr_mmaps);
+		if (ret)
+			return ret;
+		for (i = 0; i < evlist->core.nr_mmaps; i++) {
+			if (evlist->mmap)
+				evlist->mmap[i].file = &rec->data.dir.files[i];
+			if (evlist->overwrite_mmap)
+				evlist->overwrite_mmap[i].file = &rec->data.dir.files[i];
+		}
+	}
+
 	return 0;
 }
 
@@ -1496,8 +1513,12 @@ static int record__mmap_read_evlist(struct record *rec, struct evlist *evlist,
 	/*
 	 * Mark the round finished in case we wrote
 	 * at least one event.
+	 *
+	 * No need for round events in directory mode,
+	 * because per-cpu maps and files have data
+	 * sorted by kernel.
 	 */
-	if (bytes_written != rec->bytes_written)
+	if (!record__threads_enabled(rec) && bytes_written != rec->bytes_written)
 		rc = record__write(rec, NULL, &finished_round_event, sizeof(finished_round_event));
 
 	if (overwrite)
@@ -1613,7 +1634,9 @@ static void record__init_features(struct record *rec)
 	if (!rec->opts.use_clockid)
 		perf_header__clear_feat(&session->header, HEADER_CLOCK_DATA);
 
-	perf_header__clear_feat(&session->header, HEADER_DIR_FORMAT);
+	if (!record__threads_enabled(rec))
+		perf_header__clear_feat(&session->header, HEADER_DIR_FORMAT);
+
 	if (!record__comp_enabled(rec))
 		perf_header__clear_feat(&session->header, HEADER_COMPRESSED);
 
@@ -1624,15 +1647,21 @@ static void
 record__finish_output(struct record *rec)
 {
 	struct perf_data *data = &rec->data;
-	int fd = perf_data__fd(data);
+	int i, fd = perf_data__fd(data);
 
 	if (data->is_pipe)
 		return;
 
 	rec->session->header.data_size += rec->bytes_written;
 	data->file.size = lseek(perf_data__fd(data), 0, SEEK_CUR);
+	if (record__threads_enabled(rec)) {
+		for (i = 0; i < data->dir.nr; i++)
+			data->dir.files[i].size = lseek(data->dir.files[i].fd, 0, SEEK_CUR);
+	}
 
 	if (!rec->no_buildid) {
+		/* this will be recalculated during process_buildids() */
+		rec->samples = 0;
 		process_buildids(rec);
 
 		if (rec->buildid_all)
@@ -2578,8 +2607,6 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 		status = err;
 
 	record__synthesize(rec, true);
-	/* this will be recalculated during process_buildids() */
-	rec->samples = 0;
 
 	if (!err) {
 		if (!rec->timestamp_filename) {
@@ -3380,7 +3407,7 @@ int cmd_record(int argc, const char **argv)
 		goto out_opts;
 	}
 
-	if (rec->opts.kcore)
+	if (rec->opts.kcore || record__threads_enabled(rec))
 		rec->data.is_dir = true;
 
 	if (rec->opts.comp_level != 0) {
diff --git a/tools/perf/util/record.h b/tools/perf/util/record.h
index 68f471d9a88b..4d68b7e27272 100644
--- a/tools/perf/util/record.h
+++ b/tools/perf/util/record.h
@@ -77,6 +77,7 @@ struct record_opts {
 	int	      ctl_fd;
 	int	      ctl_fd_ack;
 	bool	      ctl_fd_close;
+	int	      threads_spec;
 };
 
 extern const char * const *record_usage;
-- 
2.19.0


  parent reply	other threads:[~2021-07-12  7:15 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-12  6:46 [PATCH v10 00/24] Introduce threaded trace streaming for basic perf record operation Alexey Bayduraev
2021-07-12  6:46 ` [PATCH v10 01/24] perf record: Introduce thread affinity and mmap masks Alexey Bayduraev
2021-07-12  6:46 ` [PATCH v10 02/24] tools lib: Introduce fdarray duplicate function Alexey Bayduraev
2021-07-12  6:46 ` [PATCH v10 03/24] perf record: Introduce thread specific data array Alexey Bayduraev
2021-07-12  6:46 ` [PATCH v10 04/24] perf record: Introduce function to propagate control commands Alexey Bayduraev
2021-07-12  6:46 ` [PATCH v10 05/24] perf record: Introduce thread local variable Alexey Bayduraev
2021-09-12 20:43   ` Jiri Olsa
2021-09-12 20:45   ` Jiri Olsa
2021-09-12 20:45   ` Jiri Olsa
2021-09-12 20:45   ` Jiri Olsa
2021-07-12  6:46 ` [PATCH v10 06/24] perf record: Stop threads in the end of trace streaming Alexey Bayduraev
2021-07-12  6:46 ` [PATCH v10 07/24] perf record: Start threads in the beginning " Alexey Bayduraev
2021-07-12  6:46 ` [PATCH v10 08/24] perf record: Introduce data file at mmap buffer object Alexey Bayduraev
2021-08-11 17:24   ` Riccardo Mancini
2021-07-12  6:46 ` [PATCH v10 09/24] perf record: Introduce bytes written stats to support --max-size option Alexey Bayduraev
2021-07-12  6:46 ` [PATCH v10 10/24] perf record: Introduce data transferred and compressed stats Alexey Bayduraev
2021-07-12  6:46 ` Alexey Bayduraev [this message]
2021-07-12  6:46 ` [PATCH v10 12/24] perf record: Introduce --threads command line option Alexey Bayduraev
2021-07-12  6:46 ` [PATCH v10 13/24] perf record: Extend " Alexey Bayduraev
2021-07-12  6:46 ` [PATCH v10 14/24] perf record: Implement compatibility checks Alexey Bayduraev
2021-07-12  6:46 ` [PATCH v10 15/24] perf report: Output non-zero offset for decompressed records Alexey Bayduraev
2021-07-12  6:46 ` [PATCH v10 16/24] perf report: Output data file name in raw trace dump Alexey Bayduraev
2021-07-12  6:46 ` [PATCH v10 17/24] perf session: Move reader structure to the top Alexey Bayduraev
2021-07-12  6:46 ` [PATCH v10 18/24] perf session: Introduce reader_state in reader object Alexey Bayduraev
2021-07-12  6:46 ` [PATCH v10 19/24] perf session: Introduce reader objects in session object Alexey Bayduraev
2021-07-12  6:46 ` [PATCH v10 20/24] perf session: Introduce decompressor into trace reader object Alexey Bayduraev
2021-07-12  6:46 ` [PATCH v10 21/24] perf session: Move init into reader__init function Alexey Bayduraev
2021-07-12  6:46 ` [PATCH v10 22/24] perf session: Move map/unmap into reader__mmap function Alexey Bayduraev
2021-07-12  6:46 ` [PATCH v10 23/24] perf session: Load single file for analysis Alexey Bayduraev
2021-07-12  6:46 ` [PATCH v10 24/24] perf session: Load data directory files " Alexey Bayduraev
2021-08-11 17:45 ` [PATCH v10 00/24] Introduce threaded trace streaming for basic perf record operation Riccardo Mancini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4303bdbda256737f6015aac645d55c75263804b7.1626072009.git.alexey.v.bayduraev@linux.intel.com \
    --to=alexey.v.bayduraev@linux.intel.com \
    --cc=abudankov@huawei.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.antonov@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rickyman7@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).