linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	"Arnaldo Carvalho de Melo" <acme@redhat.com>,
	"Adrian Hunter" <adrian.hunter@intel.com>,
	"David Ahern" <dsahern@gmail.com>, "Jiri Olsa" <jolsa@kernel.org>,
	"Martin Liška" <mliska@suse.cz>,
	"Namhyung Kim" <namhyung@kernel.org>,
	"Wang Nan" <wangnan0@huawei.com>
Subject: [PATCH 14/17] perf annotate: Introduce annotation__scnprintf_samples_period() method
Date: Tue,  3 Apr 2018 23:21:55 -0300	[thread overview]
Message-ID: <20180404022158.12190-15-acme@kernel.org> (raw)
In-Reply-To: <20180404022158.12190-1-acme@kernel.org>

From: Arnaldo Carvalho de Melo <acme@redhat.com>

To print a string using the total period (nr_events) and the number of
samples for a given annotation, i.e. for a given symbol, the counterpart
to hists__scnprintf_samples_period(), that is for all the samples in a
session (be it a live session, think 'perf top' or a perf.data file,
think 'perf report').

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Martin Liška <mliska@suse.cz>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=196935
Link: https://lkml.kernel.org/n/tip-goj2wu4fxutc8vd46mw3yg14@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/annotate.c | 38 ++++++++++++++++++++++++++++++++++++++
 tools/perf/util/annotate.h | 12 ++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 3a428d7c59b9..b956bb7eabcf 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -17,6 +17,7 @@
 #include "config.h"
 #include "cache.h"
 #include "symbol.h"
+#include "units.h"
 #include "debug.h"
 #include "annotate.h"
 #include "evsel.h"
@@ -2597,6 +2598,43 @@ int symbol__annotate2(struct symbol *sym, struct map *map, struct perf_evsel *ev
 	return -1;
 }
 
+int __annotation__scnprintf_samples_period(struct annotation *notes,
+					   char *bf, size_t size,
+					   struct perf_evsel *evsel,
+					   bool show_freq)
+{
+	const char *ev_name = perf_evsel__name(evsel);
+	char ref[30] = " show reference callgraph, ";
+	char sample_freq_str[64] = "";
+	unsigned long nr_samples = 0;
+	int nr_members = 1;
+	bool enable_ref = false;
+	u64 nr_events = 0;
+	char unit;
+	int i;
+
+	if (perf_evsel__is_group_event(evsel))
+                nr_members = evsel->nr_members;
+
+	for (i = 0; i < nr_members; i++) {
+		struct sym_hist *ah = annotation__histogram(notes, evsel->idx + i);
+
+		nr_samples += ah->nr_samples;
+		nr_events  += ah->period;
+	}
+
+	if (symbol_conf.show_ref_callgraph && strstr(ev_name, "call-graph=no"))
+		enable_ref = true;
+
+	if (show_freq)
+		scnprintf(sample_freq_str, sizeof(sample_freq_str), " %d Hz,", evsel->attr.sample_freq);
+
+	nr_samples = convert_unit(nr_samples, &unit);
+	return scnprintf(bf, size, "Samples: %lu%c of event%s '%s',%s%sEvent count (approx.): %" PRIu64,
+			 nr_samples, unit, evsel->nr_members > 1 ? "s" : "",
+			 ev_name, sample_freq_str, enable_ref ? ref : " ", nr_events);
+}
+
 #define ANNOTATION__CFG(n) \
 	{ .name = #n, .value = &annotation__default_options.n, }
 
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index ff7e3df31efa..db8d09bea07e 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -151,6 +151,18 @@ double annotation_line__max_percent(struct annotation_line *al, struct annotatio
 void annotation_line__write(struct annotation_line *al, struct annotation *notes,
 			    struct annotation_write_ops *ops);
 
+int __annotation__scnprintf_samples_period(struct annotation *notes,
+					   char *bf, size_t size,
+					   struct perf_evsel *evsel,
+					   bool show_freq);
+
+static inline int annotation__scnprintf_samples_period(struct annotation *notes,
+						       char *bf, size_t size,
+						       struct perf_evsel *evsel)
+{
+	return __annotation__scnprintf_samples_period(notes, bf, size, evsel, true);
+}
+
 int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool raw);
 size_t disasm__fprintf(struct list_head *head, FILE *fp);
 void symbol__calc_percent(struct symbol *sym, struct perf_evsel *evsel);
-- 
2.14.3

  parent reply	other threads:[~2018-04-04  2:21 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-04  2:21 [GIT PULL 00/17] perf/core improvements and fixes Arnaldo Carvalho de Melo
2018-04-04  2:21 ` [PATCH 01/17] perf tools: Add a "dso_size" sort order Arnaldo Carvalho de Melo
2018-04-04  2:21 ` [PATCH 02/17] tools headers: Synchronize x86's cpufeatures.h Arnaldo Carvalho de Melo
2018-04-04  2:21 ` [PATCH 03/17] perf trace: Show only failing syscalls Arnaldo Carvalho de Melo
2018-04-04  2:21 ` [PATCH 04/17] tools include: Add config.h header file Arnaldo Carvalho de Melo
2018-04-04  2:21 ` [PATCH 06/17] perf config: Rename to HAVE_DWARF_GETLOCATIONS_SUPPORT Arnaldo Carvalho de Melo
2018-04-04  2:21 ` [PATCH 07/17] perf version: Print the compiled-in status of libraries Arnaldo Carvalho de Melo
2018-04-04  2:21 ` [PATCH 08/17] perf tools: Add 'perf -vv' as an alias to 'perf version --build-options' Arnaldo Carvalho de Melo
2018-04-04  2:21 ` [PATCH 09/17] perf version: Add man page Arnaldo Carvalho de Melo
2018-04-04  2:21 ` [PATCH 10/17] perf hists browser: Rename perf_evsel_browser_title to a more descriptive name Arnaldo Carvalho de Melo
2018-04-04  2:21 ` [PATCH 11/17] perf hists: Introduce hists__scnprint_title() Arnaldo Carvalho de Melo
2018-04-04  2:21 ` [PATCH 12/17] perf hists: Move hists__scnprintf_title() away from the TUI code Arnaldo Carvalho de Melo
2018-04-04  2:21 ` [PATCH 13/17] perf ui browser: Move the extra title lines from the hists browser Arnaldo Carvalho de Melo
2018-04-04  2:21 ` Arnaldo Carvalho de Melo [this message]
2018-04-04  2:21 ` [PATCH 15/17] perf annotate browser: Show extra title line with event information Arnaldo Carvalho de Melo
2018-04-04  2:21 ` [PATCH 16/17] perf annotate stdio2: Print more descriptive event information header Arnaldo Carvalho de Melo
2018-04-04  2:21 ` [PATCH 17/17] perf trace: Remove redundant ')' Arnaldo Carvalho de Melo
2018-04-04  5:25 ` [GIT PULL 00/17] perf/core improvements and fixes Ingo Molnar

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=20180404022158.12190-15-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=dsahern@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mliska@suse.cz \
    --cc=namhyung@kernel.org \
    --cc=wangnan0@huawei.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).