All of lore.kernel.org
 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 v13 08/16] perf record: Introduce data file at mmap buffer object
Date: Mon, 17 Jan 2022 21:34:28 +0300	[thread overview]
Message-ID: <177077f7734b63e5c999ccd75ac6dc3c694f0d0d.1642440724.git.alexey.v.bayduraev@linux.intel.com> (raw)
In-Reply-To: <cover.1642440724.git.alexey.v.bayduraev@linux.intel.com>

Introduce data file objects into mmap object so it could be used to
process and store data stream from the corresponding kernel data buffer.
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 | 37 ++++++++++++++++++++++++++++++++-----
 tools/perf/util/mmap.h      |  1 +
 2 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 517520ae1520..8766a3dc9440 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -205,12 +205,16 @@ static int record__write(struct record *rec, struct mmap *map __maybe_unused,
 {
 	struct perf_data_file *file = &rec->session->data->file;
 
+	if (map && map->file)
+		file = map->file;
+
 	if (perf_data_file__write(file, bf, size) < 0) {
 		pr_err("failed to write perf data, error: %m\n");
 		return -1;
 	}
 
-	rec->bytes_written += size;
+	if (!(map && map->file))
+		rec->bytes_written += size;
 
 	if (record__output_max_size_exceeded(rec) && !done) {
 		fprintf(stderr, "[ perf record: perf size limit reached (%" PRIu64 " KB),"
@@ -1103,7 +1107,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;
@@ -1142,6 +1146,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;
 }
 
@@ -1448,8 +1464,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)
@@ -1566,7 +1586,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);
 
@@ -1576,6 +1598,7 @@ static void record__init_features(struct record *rec)
 static void
 record__finish_output(struct record *rec)
 {
+	int i;
 	struct perf_data *data = &rec->data;
 	int fd = perf_data__fd(data);
 
@@ -1584,6 +1607,10 @@ record__finish_output(struct record *rec)
 
 	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) {
 		process_buildids(rec);
@@ -3330,7 +3357,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/mmap.h b/tools/perf/util/mmap.h
index 83f6bd4d4082..62f38d7977bb 100644
--- a/tools/perf/util/mmap.h
+++ b/tools/perf/util/mmap.h
@@ -45,6 +45,7 @@ struct mmap {
 	struct mmap_cpu_mask	affinity_mask;
 	void		*data;
 	int		comp_level;
+	struct perf_data_file *file;
 };
 
 struct mmap_params {
-- 
2.19.0


  parent reply	other threads:[~2022-01-17 18:35 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-17 18:34 [PATCH v13 00/16] Introduce threaded trace streaming for basic perf record operation Alexey Bayduraev
2022-01-17 18:34 ` [PATCH v13 01/16] perf record: Introduce thread affinity and mmap masks Alexey Bayduraev
2022-01-31 21:00   ` Arnaldo Carvalho de Melo
2022-01-31 21:16     ` Arnaldo Carvalho de Melo
2022-02-01 11:46       ` Bayduraev, Alexey V
2022-01-31 22:03     ` Arnaldo Carvalho de Melo
2022-01-31 22:04       ` Arnaldo Carvalho de Melo
2022-04-04 22:25   ` Ian Rogers
2022-04-05 16:21     ` Bayduraev, Alexey V
2022-04-06 16:46       ` Ian Rogers
2022-01-17 18:34 ` [PATCH v13 02/16] tools lib: Introduce fdarray duplicate function Alexey Bayduraev
2022-01-17 18:34 ` [PATCH v13 03/16] perf record: Introduce thread specific data array Alexey Bayduraev
2022-01-31 21:39   ` Arnaldo Carvalho de Melo
2022-01-31 22:21     ` Arnaldo Carvalho de Melo
2022-02-11 16:51       ` Arnaldo Carvalho de Melo
2022-02-11 16:52         ` Arnaldo Carvalho de Melo
2022-02-11 19:34         ` Alexei Budankov
2022-01-17 18:34 ` [PATCH v13 04/16] perf record: Introduce function to propagate control commands Alexey Bayduraev
2022-01-17 18:34 ` [PATCH v13 05/16] perf record: Introduce thread local variable Alexey Bayduraev
2022-01-31 21:42   ` Arnaldo Carvalho de Melo
2022-01-31 21:45   ` Arnaldo Carvalho de Melo
2022-02-01  7:35     ` Bayduraev, Alexey V
2022-01-17 18:34 ` [PATCH v13 06/16] perf record: Stop threads in the end of trace streaming Alexey Bayduraev
2022-01-17 18:34 ` [PATCH v13 07/16] perf record: Start threads in the beginning " Alexey Bayduraev
2022-01-17 18:34 ` Alexey Bayduraev [this message]
2022-01-17 18:34 ` [PATCH v13 09/16] perf record: Introduce bytes written stats Alexey Bayduraev
2022-01-17 18:34 ` [PATCH v13 10/16] perf record: Introduce compressor at mmap buffer object Alexey Bayduraev
2022-01-31 21:56   ` Arnaldo Carvalho de Melo
2022-02-01  8:08     ` Bayduraev, Alexey V
2022-01-17 18:34 ` [PATCH v13 11/16] perf record: Introduce data transferred and compressed stats Alexey Bayduraev
2022-01-24 15:28   ` Arnaldo Carvalho de Melo
2022-01-24 16:39     ` Arnaldo Carvalho de Melo
2022-01-17 18:34 ` [PATCH v13 12/16] perf record: Introduce --threads command line option Alexey Bayduraev
2022-01-17 18:34 ` [PATCH v13 13/16] perf record: Extend " Alexey Bayduraev
2022-01-17 18:34 ` [PATCH v13 14/16] perf record: Implement compatibility checks Alexey Bayduraev
2022-01-17 18:34 ` [PATCH v13 15/16] perf session: Load data directory files for analysis Alexey Bayduraev
2022-01-17 18:34 ` [PATCH v13 16/16] perf report: Output data file name in raw trace dump Alexey Bayduraev
2022-01-24 15:45 ` [PATCH v13 00/16] Introduce threaded trace streaming for basic perf record operation Jiri Olsa

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=177077f7734b63e5c999ccd75ac6dc3c694f0d0d.1642440724.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.