lkml.org 
[lkml]   [2021]   [Jun]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 08/10] perf record: Add new HEADER_BUILD_ID_MMAP feature
Date
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
\
 
 \ /
  Last update: 2021-06-22 17:40    [W:0.123 / U:0.780 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site