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]
Date:   Tue, 22 Jun 2021 17:39:17 +0200
From:   Jiri Olsa <jolsa@...hat.com>
To:     Arnaldo Carvalho de Melo <acme@...nel.org>
Cc:     lkml <linux-kernel@...r.kernel.org>,
        Peter Zijlstra <a.p.zijlstra@...llo.nl>,
        Ingo Molnar <mingo@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Namhyung Kim <namhyung@...nel.org>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Michael Petlan <mpetlan@...hat.com>,
        Ian Rogers <irogers@...gle.com>
Subject: [PATCH 09/10] perf report: Display build id fails stats

Adding support to display build id fails in --stats option:

  # perf report --stat

  Aggregated stats:
           TOTAL events:        104
            COMM events:          2  ( 1.9%)
                    ....
         BUILD_ID fails:          4  (14.3%)

This stat is displayed only for session recorded with --buildid-mmap
and contains HEADER_BUILD_ID_MMAP header feature.

We process all MMAP2 events and in case it does not contain build id
and it should - it's regular file, we count the BUILD_ID fail and
display it.

Signed-off-by: Jiri Olsa <jolsa@...nel.org>
---
 tools/perf/builtin-report.c | 35 +++++++++++++++++++++++++++++++++++
 tools/perf/util/map.h       | 15 +++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index bc5c393021dc..b5c03bcc4395 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -13,6 +13,7 @@
 #include "util/annotate.h"
 #include "util/color.h"
 #include "util/dso.h"
+#include "util/vdso.h"
 #include <linux/list.h>
 #include <linux/rbtree.h>
 #include <linux/err.h>
@@ -100,6 +101,8 @@ struct report {
 	u64			nr_entries;
 	u64			queue_size;
 	u64			total_cycles;
+	u64			buildid_fails;
+	u64			buildid_total;
 	int			socket_filter;
 	DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
 	struct branch_type_stat	brtype_stat;
@@ -729,10 +732,36 @@ static int count_sample_event(struct perf_tool *tool __maybe_unused,
 	return 0;
 }
 
+static int count_buildid_fails(struct perf_tool *tool,
+			       union perf_event *event,
+			       struct perf_sample *sample __maybe_unused,
+			       struct machine *machine __maybe_unused)
+{
+	struct report *rep = container_of(tool, struct report, tool);
+	struct perf_record_mmap2 *mmap2 = &event->mmap2;
+
+	/* No build id should be generated */
+	if (!is_buildid_memory(mmap2->filename))
+		return 0;
+
+	rep->buildid_total++;
+
+	/* The build id should be generated, but wasn't - fault. */
+	if (!(mmap2->header.misc & PERF_RECORD_MISC_MMAP_BUILD_ID))
+		rep->buildid_fails++;
+
+	return 0;
+}
+
 static void stats_setup(struct report *rep)
 {
 	memset(&rep->tool, 0, sizeof(rep->tool));
 	rep->tool.sample = count_sample_event;
+
+	if (perf_header__has_feat(&rep->session->header,
+				  HEADER_BUILD_ID_MMAP))
+		rep->tool.mmap2 = count_buildid_fails;
+
 	rep->tool.no_warn = true;
 }
 
@@ -742,6 +771,12 @@ static int stats_print(struct report *rep)
 
 	perf_session__fprintf_nr_events(session, stdout, rep->skip_empty);
 	evlist__fprintf_nr_events(session->evlist, stdout, rep->skip_empty);
+
+	if (rep->buildid_fails) {
+		fprintf(stdout, "%23s: %10" PRIu64 "  (%4.1f%%)\n", "BUILD_ID fails",
+			rep->buildid_fails,
+			100.0 * rep->buildid_fails / rep->buildid_total);
+	}
 	return 0;
 }
 
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index d32f5b28c1fb..9b96ebed412d 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -10,6 +10,7 @@
 #include <string.h>
 #include <stdbool.h>
 #include <linux/types.h>
+#include "vdso.h"
 
 struct dso;
 struct maps;
@@ -186,4 +187,18 @@ static inline int is_no_dso_memory(const char *filename)
 	       !strncmp(filename, "/SYSV", 5)  ||
 	       !strcmp(filename, "[heap]");
 }
+
+static inline int is_vsyscall_memory(const char *filename)
+{
+	return !strcmp(filename, "[vsyscall]");
+}
+
+static inline int is_buildid_memory(const char *filename)
+{
+	return !is_anon_memory(filename) &&
+	       !is_vdso_map(filename) &&
+	       !is_no_dso_memory(filename) &&
+	       !is_vsyscall_memory(filename);
+}
+
 #endif /* __PERF_MAP_H */
-- 
2.31.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ