All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Ingo Molnar <mingo@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Michael Petlan <mpetlan@redhat.com>,
	Ian Rogers <irogers@google.com>
Subject: [PATCH 08/10] perf record: Add new HEADER_BUILD_ID_MMAP feature
Date: Tue, 22 Jun 2021 17:39:16 +0200	[thread overview]
Message-ID: <20210622153918.688500-9-jolsa@kernel.org> (raw)
In-Reply-To: <20210622153918.688500-1-jolsa@kernel.org>

Adding new HEADER_BUILD_ID_MMAP feature to store faulst/lost/fixed
counts for --buildid-mmap setup. We skip post processing for build_id,
so we need to store session stats.

The feature data has following format:

	struct {
	       u32 version;
	       u64 faults;
	       u64 lost;
	       u64 fixed;
	};

The version is set to 1.
The faults has the value of faulted build id retrievals for the session.
The lost has the value of faulted lost events for the session.
The fixed has the value of fixed build ids by post-processing.

The perf report --header-only display for when fixes is 0:

  # build id mmap stats: FAULTS 4, LOST 0, NOT FIXED

If fixed is defined:

  # build id mmap stats: FAULTS 4, LOST 0, FIXED(4)

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 .../Documentation/perf.data-file-format.txt   | 19 +++++
 tools/perf/builtin-record.c                   |  7 ++
 tools/perf/util/env.h                         |  6 ++
 tools/perf/util/header.c                      | 80 +++++++++++++++++++
 tools/perf/util/header.h                      |  1 +
 5 files changed, 113 insertions(+)

diff --git a/tools/perf/Documentation/perf.data-file-format.txt b/tools/perf/Documentation/perf.data-file-format.txt
index e6ff8c898ada..223fea2ba662 100644
--- a/tools/perf/Documentation/perf.data-file-format.txt
+++ b/tools/perf/Documentation/perf.data-file-format.txt
@@ -438,6 +438,25 @@ struct {
 	other bits are reserved and should ignored for now
 	HEADER_FEAT_BITS	= 256,
 
+	HEADER_BUILD_ID_MMAP = 32,
+
+	It contains stats values for session with --buildid-mmap option.
+
+struct {
+	u32 version;
+	u64 faults;
+	u64 lost;
+	u64 fixed;
+};
+
+	The version is set to 1.
+	The faults has the value of faulted build id retrievals for the session.
+	The lost has the value of faulted lost events for the session.
+	The fixed has the value of fixed build ids by post-processing.
+
+	other bits are reserved and should ignored for now
+	HEADER_FEAT_BITS	= 256,
+
 Attributes
 
 This is an array of perf_event_attrs, each attr_size bytes long, which defines
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index bf3958ce18e3..cae1a38a9e2a 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1221,6 +1221,9 @@ static void record__init_features(struct record *rec)
 	if (!rec->opts.use_clockid)
 		perf_header__clear_feat(&session->header, HEADER_CLOCK_DATA);
 
+	if (!rec->buildid_mmap)
+		perf_header__clear_feat(&session->header, HEADER_BUILD_ID_MMAP);
+
 	perf_header__clear_feat(&session->header, HEADER_DIR_FORMAT);
 	if (!record__comp_enabled(rec))
 		perf_header__clear_feat(&session->header, HEADER_COMPRESSED);
@@ -1296,6 +1299,7 @@ evlist__read_session_stats(struct evlist *evlist, struct session_stats *st)
 
 static void read_session_stats(struct record *rec)
 {
+	struct perf_session *session = rec->session;
 	struct session_stats st;
 
 	if (evlist__read_session_stats(rec->evlist, &st))
@@ -1310,6 +1314,9 @@ static void read_session_stats(struct record *rec)
 		fprintf(stderr,	"[ perf record: Lost %lu chunks]\n",
 			st.lost);
 	}
+
+	session->header.env.build_id_mmap.faults = st.build_id_faults;
+	session->header.env.build_id_mmap.lost = st.lost;
 }
 
 static void
diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h
index 6824a7423a2d..8d45c774ad75 100644
--- a/tools/perf/util/env.h
+++ b/tools/perf/util/env.h
@@ -128,6 +128,12 @@ struct perf_env {
 		 */
 		bool	enabled;
 	} clock;
+
+	struct {
+		u64	faults;
+		u64	lost;
+		u64	fixed;
+	} build_id_mmap;
 };
 
 enum perf_compress_type {
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 0158d2945bab..ac4f62170107 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1528,6 +1528,39 @@ static int write_hybrid_cpu_pmu_caps(struct feat_fd *ff,
 	return 0;
 }
 
+static int write_build_id_mmap(struct feat_fd *ff,
+			       struct evlist *evlist __maybe_unused)
+{
+	u64 data64;
+	u32 data32;
+	int ret;
+
+	/* version */
+	data32 = 1;
+
+	ret = do_write(ff, &data32, sizeof(data32));
+	if (ret < 0)
+		return ret;
+
+	/* faults */
+	data64 = ff->ph->env.build_id_mmap.faults;
+
+	ret = do_write(ff, &data64, sizeof(data64));
+	if (ret < 0)
+		return ret;
+
+	/* lost */
+	data64 = ff->ph->env.build_id_mmap.lost;
+
+	ret = do_write(ff, &data64, sizeof(data64));
+	if (ret < 0)
+		return ret;
+
+	/* fixed */
+	data64 = ff->ph->env.build_id_mmap.fixed;
+	return do_write(ff, &data64, sizeof(data64));
+}
+
 static void print_hostname(struct feat_fd *ff, FILE *fp)
 {
 	fprintf(fp, "# hostname : %s\n", ff->ph->env.hostname);
@@ -2048,6 +2081,19 @@ static void print_hybrid_cpu_pmu_caps(struct feat_fd *ff, FILE *fp)
 	}
 }
 
+static void print_build_id_mmap(struct feat_fd *ff, FILE *fp)
+{
+	fprintf(fp, "# build id mmap stats: FAULTS %" PRIu64 ", LOST %" PRIu64 ",%s FIXED",
+		ff->ph->env.build_id_mmap.faults,
+		ff->ph->env.build_id_mmap.lost,
+		ff->ph->env.build_id_mmap.fixed ? "" : " NOT");
+
+	if (ff->ph->env.build_id_mmap.fixed)
+		fprintf(fp, "(%" PRIu64 ")", ff->ph->env.build_id_mmap.fixed);
+
+	fprintf(fp, "\n");
+}
+
 static void print_pmu_mappings(struct feat_fd *ff, FILE *fp)
 {
 	const char *delimiter = "# pmu mappings: ";
@@ -3265,6 +3311,39 @@ static int process_hybrid_cpu_pmu_caps(struct feat_fd *ff,
 	return ret;
 }
 
+static int process_build_id_mmap(struct feat_fd *ff,
+				 void *data __maybe_unused)
+{
+	u32 data32;
+	u64 data64;
+
+	/* version */
+	if (do_read_u32(ff, &data32))
+		return -1;
+
+	if (data32 != 1)
+		return -1;
+
+	/* faults */
+	if (do_read_u64(ff, &data64))
+		return -1;
+
+	ff->ph->env.build_id_mmap.faults = data64;
+
+	/* lost */
+	if (do_read_u64(ff, &data64))
+		return -1;
+
+	ff->ph->env.build_id_mmap.lost = data64;
+
+	/* fixed */
+	if (do_read_u64(ff, &data64))
+		return -1;
+
+	ff->ph->env.build_id_mmap.fixed = data64;
+	return 0;
+}
+
 #define FEAT_OPR(n, func, __full_only) \
 	[HEADER_##n] = {					\
 		.name	    = __stringify(n),			\
@@ -3328,6 +3407,7 @@ const struct perf_header_feature_ops feat_ops[HEADER_LAST_FEATURE] = {
 	FEAT_OPR(CLOCK_DATA,	clock_data,	false),
 	FEAT_OPN(HYBRID_TOPOLOGY,	hybrid_topology,	true),
 	FEAT_OPR(HYBRID_CPU_PMU_CAPS,	hybrid_cpu_pmu_caps,	false),
+	FEAT_OPR(BUILD_ID_MMAP,		build_id_mmap,		false),
 };
 
 struct header_print_data {
diff --git a/tools/perf/util/header.h b/tools/perf/util/header.h
index ae6b1cf19a7d..a9fe37bb03cc 100644
--- a/tools/perf/util/header.h
+++ b/tools/perf/util/header.h
@@ -47,6 +47,7 @@ enum {
 	HEADER_CLOCK_DATA,
 	HEADER_HYBRID_TOPOLOGY,
 	HEADER_HYBRID_CPU_PMU_CAPS,
+	HEADER_BUILD_ID_MMAP,
 	HEADER_LAST_FEATURE,
 	HEADER_FEAT_BITS	= 256,
 };
-- 
2.31.1


  parent reply	other threads:[~2021-06-22 15:39 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-22 15:39 [RFC 00/10] perf: Add build id parsing fault detection/fix Jiri Olsa
2021-06-22 15:39 ` [PATCH 01/10] perf: Track build id faults for mmap2 event Jiri Olsa
2021-06-22 15:39 ` [PATCH 02/10] perf: Move build_id_parse to check only regular files Jiri Olsa
2021-06-22 15:39 ` [PATCH 03/10] perf: Add new read_format bit to read build id faults Jiri Olsa
2021-06-22 15:39 ` [PATCH 04/10] perf: Add new read_format bit to read lost events Jiri Olsa
2021-06-22 15:39 ` [PATCH 05/10] tools: Sync perf_event.h uapi Jiri Olsa
2021-06-22 15:39 ` [PATCH 06/10] libperf: Do not allow PERF_FORMAT_GROUP in perf_evsel__read Jiri Olsa
2021-06-22 15:39 ` [PATCH 07/10] perf record: Add support to read build id fails Jiri Olsa
2021-06-22 15:39 ` Jiri Olsa [this message]
2021-06-22 15:39 ` [PATCH 09/10] perf report: Display build id fails stats Jiri Olsa
2021-06-22 15:39 ` [PATCH 10/10] perf inject: Add --buildid-mmap2 option to fix failed build ids Jiri Olsa
2021-06-22 17:39 ` [RFC 00/10] perf: Add build id parsing fault detection/fix Arnaldo Carvalho de Melo
2021-06-22 17:47   ` Ian Rogers
2021-06-22 18:14     ` Arnaldo Carvalho de Melo
2021-06-22 21:19       ` Jiri Olsa
2021-06-23 19:48         ` Namhyung Kim
2021-06-24 11:44           ` Michael Petlan
2021-06-27 17:27             ` Jiri Olsa
2021-06-27 17:25           ` Jiri Olsa
2021-06-28  3:39             ` Namhyung Kim
2021-06-23 20:15 ` Namhyung Kim

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=20210622153918.688500-9-jolsa@kernel.org \
    --to=jolsa@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@kernel.org \
    --cc=mpetlan@redhat.com \
    --cc=namhyung@kernel.org \
    /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.