linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local
@ 2018-08-04 13:05 Jiri Olsa
  2018-08-04 13:05 ` [PATCH 01/20] " Jiri Olsa
                   ` (19 more replies)
  0 siblings, 20 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

hi,
Stephane asked for key/option switch between local/global
percentage in annotation output/browser [1]. Local means
% within symbol, global within the whole perf data.

Adding the support to specify this by new --precent-type
option added for perf annotate and report.

Also adding 'p' key binding to annotation browser to change
between local/global percentages.

Also available in:
  git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
  perf/fixes

thanks,
jirka


[1] https://marc.info/?l=linux-kernel&m=153195093118669&w=2

---
Jiri Olsa (20):
      perf annotate: Make symbol__annotate_fprintf2 local
      perf annotate: Make annotation_line__max_percent static
      perf annotate: Get rid of annotation__scnprintf_samples_period
      perf annotate: Rename struct annotation_line::samples* to data*
      perf annotate: Rename local sample variables to data
      perf annotate: Rename hist to sym_hist in annotation__calc_percent
      perf annotate: Loop group events directly in annotation__calc_percent
      perf annotate: Switch struct annotation_data::percent to array
      perf annotate: Add PERCENT_HITS_GLOBAL percent value
      perf annotate: Add PERCENT_PERIOD_LOCAL percent value
      perf annotate: Add PERCENT_PERIOD_GLOBAL percent value
      perf annotate: Add percent_type to struct annotation_options
      perf annotate: Pass struct annotation_options to symbol__calc_lines
      perf annotate: Pass struct annotation_options to map_symbol__annotation_dump
      perf annotate: Pass browser percent_type in annotate_browser__calc_percent
      perf annotate: Add support to togle percent type
      perf annotate: Make local period the default percent type
      perf annotate: Display percent type in stdio output
      perf annotate: Add --percent-type option
      perf report: Add --percent-type option

 tools/perf/Documentation/perf-annotate.txt |   9 ++++
 tools/perf/Documentation/perf-report.txt   |   9 ++++
 tools/perf/builtin-annotate.c              |   4 ++
 tools/perf/builtin-report.c                |   3 ++
 tools/perf/ui/browsers/annotate.c          |  81 +++++++++++++++++++++++++-------
 tools/perf/util/annotate.c                 | 302 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------------------------
 tools/perf/util/annotate.h                 |  55 ++++++++++++++++------
 tools/perf/util/evsel.h                    |   7 +++
 8 files changed, 319 insertions(+), 151 deletions(-)

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH 01/20] perf annotate: Make symbol__annotate_fprintf2 local
  2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
@ 2018-08-04 13:05 ` Jiri Olsa
  2018-08-06 15:00   ` Arnaldo Carvalho de Melo
  2018-08-18 11:25   ` [tip:perf/urgent] perf annotate: Make symbol__annotate_fprintf2() local tip-bot for Jiri Olsa
  2018-08-04 13:05 ` [PATCH 02/20] perf annotate: Make annotation_line__max_percent static Jiri Olsa
                   ` (18 subsequent siblings)
  19 siblings, 2 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

There's no outside user of it.

Link: http://lkml.kernel.org/n/tip-hivnt3n3i6ab66ji1tydyf0u@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/annotate.c | 2 +-
 tools/perf/util/annotate.h | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index f91775b4bc3c..b6e7d0d56622 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2129,7 +2129,7 @@ static void FILE__write_graph(void *fp, int graph)
 	fputs(s, fp);
 }
 
-int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp)
+static int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp)
 {
 	struct annotation *notes = symbol__annotation(sym);
 	struct annotation_write_ops ops = {
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index a4c0d91907e6..5f24fc9dcc7c 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -340,7 +340,6 @@ int symbol__strerror_disassemble(struct symbol *sym, struct map *map,
 int symbol__annotate_printf(struct symbol *sym, struct map *map,
 			    struct perf_evsel *evsel,
 			    struct annotation_options *options);
-int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp);
 void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
 void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
 void annotated_source__purge(struct annotated_source *as);
-- 
2.17.1


^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH 02/20] perf annotate: Make annotation_line__max_percent static
  2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
  2018-08-04 13:05 ` [PATCH 01/20] " Jiri Olsa
@ 2018-08-04 13:05 ` Jiri Olsa
  2018-08-06 15:01   ` Arnaldo Carvalho de Melo
  2018-08-18 11:26   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  2018-08-04 13:05 ` [PATCH 03/20] perf annotate: Get rid of annotation__scnprintf_samples_period Jiri Olsa
                   ` (17 subsequent siblings)
  19 siblings, 2 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

There's no outside user of it.

Link: http://lkml.kernel.org/n/tip-uz4w6fxnmyavi5z409r05fqk@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/annotate.c | 3 ++-
 tools/perf/util/annotate.h | 1 -
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index b6e7d0d56622..956c9b19d81c 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2441,7 +2441,8 @@ bool ui__has_annotation(void)
 }
 
 
-double annotation_line__max_percent(struct annotation_line *al, struct annotation *notes)
+static double annotation_line__max_percent(struct annotation_line *al,
+					   struct annotation *notes)
 {
 	double percent_max = 0.0;
 	int i;
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 5f24fc9dcc7c..a93502d0c582 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -169,7 +169,6 @@ struct annotation_write_ops {
 	void (*write_graph)(void *obj, int graph);
 };
 
-double annotation_line__max_percent(struct annotation_line *al, struct annotation *notes);
 void annotation_line__write(struct annotation_line *al, struct annotation *notes,
 			    struct annotation_write_ops *ops);
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH 03/20] perf annotate: Get rid of annotation__scnprintf_samples_period
  2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
  2018-08-04 13:05 ` [PATCH 01/20] " Jiri Olsa
  2018-08-04 13:05 ` [PATCH 02/20] perf annotate: Make annotation_line__max_percent static Jiri Olsa
@ 2018-08-04 13:05 ` Jiri Olsa
  2018-08-06 15:07   ` Arnaldo Carvalho de Melo
  2018-08-18 11:26   ` [tip:perf/urgent] perf annotate: Get rid of annotation__scnprintf_samples_period() tip-bot for Jiri Olsa
  2018-08-04 13:05 ` [PATCH 04/20] perf annotate: Rename struct annotation_line::samples* to data* Jiri Olsa
                   ` (16 subsequent siblings)
  19 siblings, 2 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

We have more current function tto get the title for annotation,
which is hists__scnprintf_title. They both have same output as
far as the annotation's header line goes.

They differ in counting of the nr_samples, hists__scnprintf_title
provides more accurate number based on the setup of the
symbol_conf.filter_relative variable.

Plus it also displays any uid/thread/dso/socket filters/zooms
if there are set any, which annotation__scnprintf_samples_period
does not.

Link: http://lkml.kernel.org/n/tip-62qw9sep9mqep1qtvlns0dww@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/ui/browsers/annotate.c |  3 +--
 tools/perf/util/annotate.c        | 44 ++-----------------------------
 tools/perf/util/annotate.h        |  7 -----
 3 files changed, 3 insertions(+), 51 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 3b4f1c10ff57..d264916d2648 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -624,8 +624,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
 	char title[256];
 	int key;
 
-	annotation__scnprintf_samples_period(notes, title, sizeof(title), evsel);
-
+	hists__scnprintf_title(hists, title, sizeof(title));
 	if (annotate_browser__show(&browser->b, title, help) < 0)
 		return -1;
 
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 956c9b19d81c..0d40cee13f6b 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2389,7 +2389,7 @@ int symbol__tty_annotate2(struct symbol *sym, struct map *map,
 {
 	struct dso *dso = map->dso;
 	struct rb_root source_line = RB_ROOT;
-	struct annotation *notes = symbol__annotation(sym);
+	struct hists *hists = evsel__hists(evsel);
 	char buf[1024];
 
 	if (symbol__annotate2(sym, map, evsel, opts, NULL) < 0)
@@ -2401,7 +2401,7 @@ int symbol__tty_annotate2(struct symbol *sym, struct map *map,
 		print_summary(&source_line, dso->long_name);
 	}
 
-	annotation__scnprintf_samples_period(notes, buf, sizeof(buf), evsel);
+	hists__scnprintf_title(hists, buf, sizeof(buf));
 	fprintf(stdout, "%s\n%s() %s\n", buf, sym->name, dso->long_name);
 	symbol__annotate_fprintf2(sym, stdout);
 
@@ -2689,46 +2689,6 @@ 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 buf[1024], 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)) {
-		perf_evsel__group_desc(evsel, buf, sizeof(buf));
-		ev_name = buf;
-                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 a93502d0c582..d06f14c656c6 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -177,13 +177,6 @@ int __annotation__scnprintf_samples_period(struct annotation *notes,
 					   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.17.1


^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH 04/20] perf annotate: Rename struct annotation_line::samples* to data*
  2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
                   ` (2 preceding siblings ...)
  2018-08-04 13:05 ` [PATCH 03/20] perf annotate: Get rid of annotation__scnprintf_samples_period Jiri Olsa
@ 2018-08-04 13:05 ` Jiri Olsa
  2018-08-06 15:08   ` Arnaldo Carvalho de Melo
  2018-08-18 11:27   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  2018-08-04 13:05 ` [PATCH 05/20] perf annotate: Rename local sample variables to data Jiri Olsa
                   ` (15 subsequent siblings)
  19 siblings, 2 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

The name 'samples*' is little confusing because we have
nested 'struct sym_hist_entry' under annotation_line struct,
which holds 'nr_samples' as well.

Also the holding struct name is 'annotation_data' so the
'data' name fits better.

Link: http://lkml.kernel.org/n/tip-l4r03qp9b76ay98dlzgf6z2c@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/ui/browsers/annotate.c | 10 +++---
 tools/perf/util/annotate.c        | 52 +++++++++++++++----------------
 tools/perf/util/annotate.h        |  4 +--
 3 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index d264916d2648..d648d1e153f3 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -227,10 +227,10 @@ static int disasm__cmp(struct annotation_line *a, struct annotation_line *b)
 {
 	int i;
 
-	for (i = 0; i < a->samples_nr; i++) {
-		if (a->samples[i].percent == b->samples[i].percent)
+	for (i = 0; i < a->data_nr; i++) {
+		if (a->data[i].percent == b->data[i].percent)
 			continue;
-		return a->samples[i].percent < b->samples[i].percent;
+		return a->data[i].percent < b->data[i].percent;
 	}
 	return 0;
 }
@@ -314,8 +314,8 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
 			continue;
 		}
 
-		for (i = 0; i < pos->al.samples_nr; i++) {
-			struct annotation_data *sample = &pos->al.samples[i];
+		for (i = 0; i < pos->al.data_nr; i++) {
+			struct annotation_data *sample = &pos->al.data[i];
 
 			if (max_percent < sample->percent)
 				max_percent = sample->percent;
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 0d40cee13f6b..e4cb8963db1a 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1108,7 +1108,7 @@ annotation_line__new(struct annotate_args *args, size_t privsize)
 	if (perf_evsel__is_group_event(evsel))
 		nr = evsel->nr_members;
 
-	size += sizeof(al->samples[0]) * nr;
+	size += sizeof(al->data[0]) * nr;
 
 	al = zalloc(size);
 	if (al) {
@@ -1117,7 +1117,7 @@ annotation_line__new(struct annotate_args *args, size_t privsize)
 		al->offset     = args->offset;
 		al->line       = strdup(args->line);
 		al->line_nr    = args->line_nr;
-		al->samples_nr = nr;
+		al->data_nr    = nr;
 	}
 
 	return al;
@@ -1309,15 +1309,15 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 		const char *color;
 		struct annotation *notes = symbol__annotation(sym);
 
-		for (i = 0; i < al->samples_nr; i++) {
-			struct annotation_data *sample = &al->samples[i];
+		for (i = 0; i < al->data_nr; i++) {
+			struct annotation_data *sample = &al->data[i];
 
 			if (sample->percent > max_percent)
 				max_percent = sample->percent;
 		}
 
-		if (al->samples_nr > nr_percent)
-			nr_percent = al->samples_nr;
+		if (al->data_nr > nr_percent)
+			nr_percent = al->data_nr;
 
 		if (max_percent < min_pcnt)
 			return -1;
@@ -1351,7 +1351,7 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 		}
 
 		for (i = 0; i < nr_percent; i++) {
-			struct annotation_data *sample = &al->samples[i];
+			struct annotation_data *sample = &al->data[i];
 
 			color = get_percent_color(sample->percent);
 
@@ -1788,12 +1788,12 @@ static void annotation__calc_percent(struct annotation *notes,
 		next = annotation_line__next(al, &notes->src->source);
 		end  = next ? next->offset : len;
 
-		for (i = 0; i < al->samples_nr; i++) {
+		for (i = 0; i < al->data_nr; i++) {
 			struct annotation_data *sample;
 			struct sym_hist *hist;
 
 			hist   = annotation__histogram(notes, evsel->idx + i);
-			sample = &al->samples[i];
+			sample = &al->data[i];
 
 			calc_percent(hist, sample, al->offset, end);
 		}
@@ -1859,8 +1859,8 @@ static void insert_source_line(struct rb_root *root, struct annotation_line *al)
 
 		ret = strcmp(iter->path, al->path);
 		if (ret == 0) {
-			for (i = 0; i < al->samples_nr; i++)
-				iter->samples[i].percent_sum += al->samples[i].percent;
+			for (i = 0; i < al->data_nr; i++)
+				iter->data[i].percent_sum += al->data[i].percent;
 			return;
 		}
 
@@ -1870,8 +1870,8 @@ static void insert_source_line(struct rb_root *root, struct annotation_line *al)
 			p = &(*p)->rb_right;
 	}
 
-	for (i = 0; i < al->samples_nr; i++)
-		al->samples[i].percent_sum = al->samples[i].percent;
+	for (i = 0; i < al->data_nr; i++)
+		al->data[i].percent_sum = al->data[i].percent;
 
 	rb_link_node(&al->rb_node, parent, p);
 	rb_insert_color(&al->rb_node, root);
@@ -1881,10 +1881,10 @@ static int cmp_source_line(struct annotation_line *a, struct annotation_line *b)
 {
 	int i;
 
-	for (i = 0; i < a->samples_nr; i++) {
-		if (a->samples[i].percent_sum == b->samples[i].percent_sum)
+	for (i = 0; i < a->data_nr; i++) {
+		if (a->data[i].percent_sum == b->data[i].percent_sum)
 			continue;
-		return a->samples[i].percent_sum > b->samples[i].percent_sum;
+		return a->data[i].percent_sum > b->data[i].percent_sum;
 	}
 
 	return 0;
@@ -1949,8 +1949,8 @@ static void print_summary(struct rb_root *root, const char *filename)
 		int i;
 
 		al = rb_entry(node, struct annotation_line, rb_node);
-		for (i = 0; i < al->samples_nr; i++) {
-			percent = al->samples[i].percent_sum;
+		for (i = 0; i < al->data_nr; i++) {
+			percent = al->data[i].percent_sum;
 			color = get_percent_color(percent);
 			color_fprintf(stdout, color, " %7.2f", percent);
 
@@ -2355,10 +2355,10 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map,
 		double percent_max = 0.0;
 		int i;
 
-		for (i = 0; i < al->samples_nr; i++) {
+		for (i = 0; i < al->data_nr; i++) {
 			struct annotation_data *sample;
 
-			sample = &al->samples[i];
+			sample = &al->data[i];
 
 			if (sample->percent > percent_max)
 				percent_max = sample->percent;
@@ -2448,8 +2448,8 @@ static double annotation_line__max_percent(struct annotation_line *al,
 	int i;
 
 	for (i = 0; i < notes->nr_events; i++) {
-		if (al->samples[i].percent > percent_max)
-			percent_max = al->samples[i].percent;
+		if (al->data[i].percent > percent_max)
+			percent_max = al->data[i].percent;
 	}
 
 	return percent_max;
@@ -2515,15 +2515,15 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
 		int i;
 
 		for (i = 0; i < notes->nr_events; i++) {
-			obj__set_percent_color(obj, al->samples[i].percent, current_entry);
+			obj__set_percent_color(obj, al->data[i].percent, current_entry);
 			if (notes->options->show_total_period) {
-				obj__printf(obj, "%11" PRIu64 " ", al->samples[i].he.period);
+				obj__printf(obj, "%11" PRIu64 " ", al->data[i].he.period);
 			} else if (notes->options->show_nr_samples) {
 				obj__printf(obj, "%6" PRIu64 " ",
-						   al->samples[i].he.nr_samples);
+						   al->data[i].he.nr_samples);
 			} else {
 				obj__printf(obj, "%6.2f ",
-						   al->samples[i].percent);
+						   al->data[i].percent);
 			}
 		}
 	} else {
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index d06f14c656c6..58aa14c55bab 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -122,8 +122,8 @@ struct annotation_line {
 	char			*path;
 	u32			 idx;
 	int			 idx_asm;
-	int			 samples_nr;
-	struct annotation_data	 samples[0];
+	int			 data_nr;
+	struct annotation_data	 data[0];
 };
 
 struct disasm_line {
-- 
2.17.1


^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH 05/20] perf annotate: Rename local sample variables to data
  2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
                   ` (3 preceding siblings ...)
  2018-08-04 13:05 ` [PATCH 04/20] perf annotate: Rename struct annotation_line::samples* to data* Jiri Olsa
@ 2018-08-04 13:05 ` Jiri Olsa
  2018-08-06 15:09   ` Arnaldo Carvalho de Melo
  2018-08-18 11:27   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  2018-08-04 13:05 ` [PATCH 06/20] perf annotate: Rename hist to sym_hist in annotation__calc_percent Jiri Olsa
                   ` (14 subsequent siblings)
  19 siblings, 2 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Based on previous rename, changing also the local
variable names to fit properly.

Link: http://lkml.kernel.org/n/tip-5hjxeetp2v8c3n0zbttlki2j@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/annotate.c | 40 +++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index e4cb8963db1a..8bd278a71004 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1310,10 +1310,10 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 		struct annotation *notes = symbol__annotation(sym);
 
 		for (i = 0; i < al->data_nr; i++) {
-			struct annotation_data *sample = &al->data[i];
+			struct annotation_data *data = &al->data[i];
 
-			if (sample->percent > max_percent)
-				max_percent = sample->percent;
+			if (data->percent > max_percent)
+				max_percent = data->percent;
 		}
 
 		if (al->data_nr > nr_percent)
@@ -1351,18 +1351,18 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 		}
 
 		for (i = 0; i < nr_percent; i++) {
-			struct annotation_data *sample = &al->data[i];
+			struct annotation_data *data = &al->data[i];
 
-			color = get_percent_color(sample->percent);
+			color = get_percent_color(data->percent);
 
 			if (symbol_conf.show_total_period)
 				color_fprintf(stdout, color, " %11" PRIu64,
-					      sample->he.period);
+					      data->he.period);
 			else if (symbol_conf.show_nr_samples)
 				color_fprintf(stdout, color, " %7" PRIu64,
-					      sample->he.nr_samples);
+					      data->he.nr_samples);
 			else
-				color_fprintf(stdout, color, " %7.2f", sample->percent);
+				color_fprintf(stdout, color, " %7.2f", data->percent);
 		}
 
 		printf(" : ");
@@ -1754,7 +1754,7 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
 }
 
 static void calc_percent(struct sym_hist *hist,
-			 struct annotation_data *sample,
+			 struct annotation_data *data,
 			 s64 offset, s64 end)
 {
 	unsigned int hits = 0;
@@ -1767,9 +1767,9 @@ static void calc_percent(struct sym_hist *hist,
 	}
 
 	if (hist->nr_samples) {
-		sample->he.period     = period;
-		sample->he.nr_samples = hits;
-		sample->percent = 100.0 * hits / hist->nr_samples;
+		data->he.period     = period;
+		data->he.nr_samples = hits;
+		data->percent = 100.0 * hits / hist->nr_samples;
 	}
 }
 
@@ -1789,13 +1789,13 @@ static void annotation__calc_percent(struct annotation *notes,
 		end  = next ? next->offset : len;
 
 		for (i = 0; i < al->data_nr; i++) {
-			struct annotation_data *sample;
+			struct annotation_data *data;
 			struct sym_hist *hist;
 
-			hist   = annotation__histogram(notes, evsel->idx + i);
-			sample = &al->data[i];
+			hist = annotation__histogram(notes, evsel->idx + i);
+			data = &al->data[i];
 
-			calc_percent(hist, sample, al->offset, end);
+			calc_percent(hist, data, al->offset, end);
 		}
 	}
 }
@@ -2356,12 +2356,12 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map,
 		int i;
 
 		for (i = 0; i < al->data_nr; i++) {
-			struct annotation_data *sample;
+			struct annotation_data *data;
 
-			sample = &al->data[i];
+			data = &al->data[i];
 
-			if (sample->percent > percent_max)
-				percent_max = sample->percent;
+			if (data->percent > percent_max)
+				percent_max = data->percent;
 		}
 
 		if (percent_max <= 0.5)
-- 
2.17.1


^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH 06/20] perf annotate: Rename hist to sym_hist in annotation__calc_percent
  2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
                   ` (4 preceding siblings ...)
  2018-08-04 13:05 ` [PATCH 05/20] perf annotate: Rename local sample variables to data Jiri Olsa
@ 2018-08-04 13:05 ` Jiri Olsa
  2018-08-06 15:10   ` Arnaldo Carvalho de Melo
  2018-08-18 11:28   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  2018-08-04 13:05 ` [PATCH 07/20] perf annotate: Loop group events directly " Jiri Olsa
                   ` (13 subsequent siblings)
  19 siblings, 2 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

We will need to bring in 'struct hists' variable in this scope,
so it's better we do this rename first.

Link: http://lkml.kernel.org/n/tip-33a3t65t9t3h0cdtd39bphta@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/annotate.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 8bd278a71004..728603636adc 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1753,7 +1753,7 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
 	goto out_free_command;
 }
 
-static void calc_percent(struct sym_hist *hist,
+static void calc_percent(struct sym_hist *sym_hist,
 			 struct annotation_data *data,
 			 s64 offset, s64 end)
 {
@@ -1761,15 +1761,15 @@ static void calc_percent(struct sym_hist *hist,
 	u64 period = 0;
 
 	while (offset < end) {
-		hits   += hist->addr[offset].nr_samples;
-		period += hist->addr[offset].period;
+		hits   += sym_hist->addr[offset].nr_samples;
+		period += sym_hist->addr[offset].period;
 		++offset;
 	}
 
-	if (hist->nr_samples) {
+	if (sym_hist->nr_samples) {
 		data->he.period     = period;
 		data->he.nr_samples = hits;
-		data->percent = 100.0 * hits / hist->nr_samples;
+		data->percent = 100.0 * hits / sym_hist->nr_samples;
 	}
 }
 
@@ -1790,12 +1790,12 @@ static void annotation__calc_percent(struct annotation *notes,
 
 		for (i = 0; i < al->data_nr; i++) {
 			struct annotation_data *data;
-			struct sym_hist *hist;
+			struct sym_hist *sym_hist;
 
-			hist = annotation__histogram(notes, evsel->idx + i);
+			sym_hist = annotation__histogram(notes, evsel->idx + i);
 			data = &al->data[i];
 
-			calc_percent(hist, data, al->offset, end);
+			calc_percent(sym_hist, data, al->offset, end);
 		}
 	}
 }
-- 
2.17.1


^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH 07/20] perf annotate: Loop group events directly in annotation__calc_percent
  2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
                   ` (5 preceding siblings ...)
  2018-08-04 13:05 ` [PATCH 06/20] perf annotate: Rename hist to sym_hist in annotation__calc_percent Jiri Olsa
@ 2018-08-04 13:05 ` Jiri Olsa
  2018-08-06 15:12   ` Arnaldo Carvalho de Melo
  2018-08-18 11:28   ` [tip:perf/urgent] perf annotate: Loop group events directly in annotation__calc_percent() tip-bot for Jiri Olsa
  2018-08-04 13:05 ` [PATCH 08/20] perf annotate: Switch struct annotation_data::percent to array Jiri Olsa
                   ` (12 subsequent siblings)
  19 siblings, 2 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

We need to bring in 'struct hists' object and for that
we need 'struct perf_evsel' object in the scope.

Switching the group data loop with the evsel group loop.
It does the same thing, but it brings evsel object, that
we can use later get the 'struct hists' object.

Link: http://lkml.kernel.org/n/tip-iecglh5ltkg9zgkn8dhfco5z@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/annotate.c | 13 ++++++++-----
 tools/perf/util/evsel.h    |  7 +++++++
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 728603636adc..34d4bb73aa84 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1774,13 +1774,14 @@ static void calc_percent(struct sym_hist *sym_hist,
 }
 
 static void annotation__calc_percent(struct annotation *notes,
-				     struct perf_evsel *evsel, s64 len)
+				     struct perf_evsel *leader, s64 len)
 {
 	struct annotation_line *al, *next;
+	struct perf_evsel *evsel;
 
 	list_for_each_entry(al, &notes->src->source, node) {
 		s64 end;
-		int i;
+		int i = 0;
 
 		if (al->offset == -1)
 			continue;
@@ -1788,12 +1789,14 @@ static void annotation__calc_percent(struct annotation *notes,
 		next = annotation_line__next(al, &notes->src->source);
 		end  = next ? next->offset : len;
 
-		for (i = 0; i < al->data_nr; i++) {
+		for_each_group_evsel(evsel, leader) {
 			struct annotation_data *data;
 			struct sym_hist *sym_hist;
 
-			sym_hist = annotation__histogram(notes, evsel->idx + i);
-			data = &al->data[i];
+			BUG_ON(i >= al->data_nr);
+
+			sym_hist = annotation__histogram(notes, evsel->idx);
+			data = &al->data[i++];
 
 			calc_percent(sym_hist, data, al->offset, end);
 		}
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 973c03167947..163c960614d3 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -452,11 +452,18 @@ static inline int perf_evsel__group_idx(struct perf_evsel *evsel)
 	return evsel->idx - evsel->leader->idx;
 }
 
+/* Iterates group WITHOUT the leader. */
 #define for_each_group_member(_evsel, _leader) 					\
 for ((_evsel) = list_entry((_leader)->node.next, struct perf_evsel, node); 	\
      (_evsel) && (_evsel)->leader == (_leader);					\
      (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node))
 
+/* Iterates group WITH the leader. */
+#define for_each_group_evsel(_evsel, _leader) 					\
+for ((_evsel) = _leader; 							\
+     (_evsel) && (_evsel)->leader == (_leader);					\
+     (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node))
+
 static inline bool perf_evsel__has_branch_callstack(const struct perf_evsel *evsel)
 {
 	return evsel->attr.branch_sample_type & PERF_SAMPLE_BRANCH_CALL_STACK;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH 08/20] perf annotate: Switch struct annotation_data::percent to array
  2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
                   ` (6 preceding siblings ...)
  2018-08-04 13:05 ` [PATCH 07/20] perf annotate: Loop group events directly " Jiri Olsa
@ 2018-08-04 13:05 ` Jiri Olsa
  2018-08-06 15:14   ` Arnaldo Carvalho de Melo
  2018-08-18 11:29   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  2018-08-04 13:05 ` [PATCH 09/20] perf annotate: Add PERCENT_HITS_GLOBAL percent value Jiri Olsa
                   ` (11 subsequent siblings)
  19 siblings, 2 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

So we can hold multiple percent values for annotation line.

The first member of this array is current local hits percent
value (PERCENT_HITS_LOCAL index), so no functional change is
expected.

Adding annotation_data__percent function to return requested
percent value from struct annotation_data.

Link: http://lkml.kernel.org/n/tip-7y4x2ws9r6hnrb6anclj93nj@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/ui/browsers/annotate.c |  9 +++--
 tools/perf/util/annotate.c        | 57 ++++++++++++++++++++-----------
 tools/perf/util/annotate.h        | 13 ++++++-
 3 files changed, 56 insertions(+), 23 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index d648d1e153f3..81876c3923d2 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -315,10 +315,13 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
 		}
 
 		for (i = 0; i < pos->al.data_nr; i++) {
-			struct annotation_data *sample = &pos->al.data[i];
+			double percent;
 
-			if (max_percent < sample->percent)
-				max_percent = sample->percent;
+			percent = annotation_data__percent(&pos->al.data[i],
+							   PERCENT_HITS_LOCAL);
+
+			if (max_percent < percent)
+				max_percent = percent;
 		}
 
 		if (max_percent < 0.01 && pos->al.ipc == 0) {
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 34d4bb73aa84..074adb2a831e 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1310,10 +1310,13 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 		struct annotation *notes = symbol__annotation(sym);
 
 		for (i = 0; i < al->data_nr; i++) {
-			struct annotation_data *data = &al->data[i];
+			double percent;
+
+			percent = annotation_data__percent(&al->data[i],
+							   PERCENT_HITS_LOCAL);
 
-			if (data->percent > max_percent)
-				max_percent = data->percent;
+			if (percent > max_percent)
+				max_percent = percent;
 		}
 
 		if (al->data_nr > nr_percent)
@@ -1352,8 +1355,10 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 
 		for (i = 0; i < nr_percent; i++) {
 			struct annotation_data *data = &al->data[i];
+			double percent;
 
-			color = get_percent_color(data->percent);
+			percent = annotation_data__percent(data, PERCENT_HITS_LOCAL);
+			color = get_percent_color(percent);
 
 			if (symbol_conf.show_total_period)
 				color_fprintf(stdout, color, " %11" PRIu64,
@@ -1362,7 +1367,7 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 				color_fprintf(stdout, color, " %7" PRIu64,
 					      data->he.nr_samples);
 			else
-				color_fprintf(stdout, color, " %7.2f", data->percent);
+				color_fprintf(stdout, color, " %7.2f", percent);
 		}
 
 		printf(" : ");
@@ -1769,7 +1774,7 @@ static void calc_percent(struct sym_hist *sym_hist,
 	if (sym_hist->nr_samples) {
 		data->he.period     = period;
 		data->he.nr_samples = hits;
-		data->percent = 100.0 * hits / sym_hist->nr_samples;
+		data->percent[PERCENT_HITS_LOCAL] = 100.0 * hits / sym_hist->nr_samples;
 	}
 }
 
@@ -1862,8 +1867,10 @@ static void insert_source_line(struct rb_root *root, struct annotation_line *al)
 
 		ret = strcmp(iter->path, al->path);
 		if (ret == 0) {
-			for (i = 0; i < al->data_nr; i++)
-				iter->data[i].percent_sum += al->data[i].percent;
+			for (i = 0; i < al->data_nr; i++) {
+				iter->data[i].percent_sum += annotation_data__percent(&al->data[i],
+										      PERCENT_HITS_LOCAL);
+			}
 			return;
 		}
 
@@ -1873,8 +1880,10 @@ static void insert_source_line(struct rb_root *root, struct annotation_line *al)
 			p = &(*p)->rb_right;
 	}
 
-	for (i = 0; i < al->data_nr; i++)
-		al->data[i].percent_sum = al->data[i].percent;
+	for (i = 0; i < al->data_nr; i++) {
+		al->data[i].percent_sum = annotation_data__percent(&al->data[i],
+								   PERCENT_HITS_LOCAL);
+	}
 
 	rb_link_node(&al->rb_node, parent, p);
 	rb_insert_color(&al->rb_node, root);
@@ -2359,12 +2368,13 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map,
 		int i;
 
 		for (i = 0; i < al->data_nr; i++) {
-			struct annotation_data *data;
+			double percent;
 
-			data = &al->data[i];
+			percent = annotation_data__percent(&al->data[i],
+							   PERCENT_HITS_LOCAL);
 
-			if (data->percent > percent_max)
-				percent_max = data->percent;
+			if (percent > percent_max)
+				percent_max = percent;
 		}
 
 		if (percent_max <= 0.5)
@@ -2451,8 +2461,13 @@ static double annotation_line__max_percent(struct annotation_line *al,
 	int i;
 
 	for (i = 0; i < notes->nr_events; i++) {
-		if (al->data[i].percent > percent_max)
-			percent_max = al->data[i].percent;
+		double percent;
+
+		percent = annotation_data__percent(&al->data[i],
+						   PERCENT_HITS_LOCAL);
+
+		if (percent > percent_max)
+			percent_max = percent;
 	}
 
 	return percent_max;
@@ -2518,15 +2533,19 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
 		int i;
 
 		for (i = 0; i < notes->nr_events; i++) {
-			obj__set_percent_color(obj, al->data[i].percent, current_entry);
+			double percent;
+
+			percent = annotation_data__percent(&al->data[i],
+							   PERCENT_HITS_LOCAL);
+
+			obj__set_percent_color(obj, percent, current_entry);
 			if (notes->options->show_total_period) {
 				obj__printf(obj, "%11" PRIu64 " ", al->data[i].he.period);
 			} else if (notes->options->show_nr_samples) {
 				obj__printf(obj, "%6" PRIu64 " ",
 						   al->data[i].he.nr_samples);
 			} else {
-				obj__printf(obj, "%6.2f ",
-						   al->data[i].percent);
+				obj__printf(obj, "%6.2f ", percent);
 			}
 		}
 	} else {
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 58aa14c55bab..0afbf8075fca 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -101,8 +101,13 @@ struct sym_hist_entry {
 	u64		period;
 };
 
+enum {
+	PERCENT_HITS_LOCAL,
+	PERCENT_MAX,
+};
+
 struct annotation_data {
-	double			 percent;
+	double			 percent[PERCENT_MAX];
 	double			 percent_sum;
 	struct sym_hist_entry	 he;
 };
@@ -134,6 +139,12 @@ struct disasm_line {
 	struct annotation_line	 al;
 };
 
+static inline double annotation_data__percent(struct annotation_data *data,
+					      unsigned int which)
+{
+	return which < PERCENT_MAX ? data->percent[which] : -1;
+}
+
 static inline struct disasm_line *disasm_line(struct annotation_line *al)
 {
 	return al ? container_of(al, struct disasm_line, al) : NULL;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH 09/20] perf annotate: Add PERCENT_HITS_GLOBAL percent value
  2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
                   ` (7 preceding siblings ...)
  2018-08-04 13:05 ` [PATCH 08/20] perf annotate: Switch struct annotation_data::percent to array Jiri Olsa
@ 2018-08-04 13:05 ` Jiri Olsa
  2018-08-06 15:15   ` Arnaldo Carvalho de Melo
  2018-08-18 11:29   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  2018-08-04 13:05 ` [PATCH 10/20] perf annotate: Add PERCENT_PERIOD_LOCAL " Jiri Olsa
                   ` (10 subsequent siblings)
  19 siblings, 2 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Adding and computing global hits percent value for
annotation line. Storing it in struct annotation_data
percent array under new PERCENT_HITS_GLOBAL index.

At the moment it's not displayed, it's coming in
following patches.

Link: http://lkml.kernel.org/n/tip-2w3em3e57zpbn2ukl7qucc3s@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/annotate.c | 8 +++++++-
 tools/perf/util/annotate.h | 1 +
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 074adb2a831e..b7485a512da1 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1759,6 +1759,7 @@ static int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
 }
 
 static void calc_percent(struct sym_hist *sym_hist,
+			 struct hists *hists,
 			 struct annotation_data *data,
 			 s64 offset, s64 end)
 {
@@ -1776,6 +1777,10 @@ static void calc_percent(struct sym_hist *sym_hist,
 		data->he.nr_samples = hits;
 		data->percent[PERCENT_HITS_LOCAL] = 100.0 * hits / sym_hist->nr_samples;
 	}
+
+	if (hists->stats.nr_non_filtered_samples)
+		data->percent[PERCENT_HITS_GLOBAL] = 100.0 * hits / hists->stats.nr_non_filtered_samples;
+
 }
 
 static void annotation__calc_percent(struct annotation *notes,
@@ -1795,6 +1800,7 @@ static void annotation__calc_percent(struct annotation *notes,
 		end  = next ? next->offset : len;
 
 		for_each_group_evsel(evsel, leader) {
+			struct hists *hists = evsel__hists(evsel);
 			struct annotation_data *data;
 			struct sym_hist *sym_hist;
 
@@ -1803,7 +1809,7 @@ static void annotation__calc_percent(struct annotation *notes,
 			sym_hist = annotation__histogram(notes, evsel->idx);
 			data = &al->data[i++];
 
-			calc_percent(sym_hist, data, al->offset, end);
+			calc_percent(sym_hist, hists, data, al->offset, end);
 		}
 	}
 }
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 0afbf8075fca..3a06cb2b6e28 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -103,6 +103,7 @@ struct sym_hist_entry {
 
 enum {
 	PERCENT_HITS_LOCAL,
+	PERCENT_HITS_GLOBAL,
 	PERCENT_MAX,
 };
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH 10/20] perf annotate: Add PERCENT_PERIOD_LOCAL percent value
  2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
                   ` (8 preceding siblings ...)
  2018-08-04 13:05 ` [PATCH 09/20] perf annotate: Add PERCENT_HITS_GLOBAL percent value Jiri Olsa
@ 2018-08-04 13:05 ` Jiri Olsa
  2018-08-06 15:16   ` Arnaldo Carvalho de Melo
  2018-08-18 11:30   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  2018-08-04 13:05 ` [PATCH 11/20] perf annotate: Add PERCENT_PERIOD_GLOBAL " Jiri Olsa
                   ` (9 subsequent siblings)
  19 siblings, 2 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Adding and computing local period percent value for
annotation line. Storing it in struct annotation_data
percent array under new PERCENT_PERIOD_LOCAL index.

At the moment it's not displayed, it's coming in
following patches.

Link: http://lkml.kernel.org/n/tip-s1qlyipdi22uewyk0eh18fw1@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/annotate.c | 2 ++
 tools/perf/util/annotate.h | 1 +
 2 files changed, 3 insertions(+)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index b7485a512da1..b37e8cc18668 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1781,6 +1781,8 @@ static void calc_percent(struct sym_hist *sym_hist,
 	if (hists->stats.nr_non_filtered_samples)
 		data->percent[PERCENT_HITS_GLOBAL] = 100.0 * hits / hists->stats.nr_non_filtered_samples;
 
+	if (sym_hist->period)
+		data->percent[PERCENT_PERIOD_LOCAL] = 100.0 * period / sym_hist->period;
 }
 
 static void annotation__calc_percent(struct annotation *notes,
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 3a06cb2b6e28..890b6869caa9 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -104,6 +104,7 @@ struct sym_hist_entry {
 enum {
 	PERCENT_HITS_LOCAL,
 	PERCENT_HITS_GLOBAL,
+	PERCENT_PERIOD_LOCAL,
 	PERCENT_MAX,
 };
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH 11/20] perf annotate: Add PERCENT_PERIOD_GLOBAL percent value
  2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
                   ` (9 preceding siblings ...)
  2018-08-04 13:05 ` [PATCH 10/20] perf annotate: Add PERCENT_PERIOD_LOCAL " Jiri Olsa
@ 2018-08-04 13:05 ` Jiri Olsa
  2018-08-06 15:16   ` Arnaldo Carvalho de Melo
  2018-08-18 11:30   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  2018-08-04 13:05 ` [PATCH 12/20] perf annotate: Add percent_type to struct annotation_options Jiri Olsa
                   ` (8 subsequent siblings)
  19 siblings, 2 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Adding and computing global period percent value for
annotation line.  Storing it in struct annotation_data
percent array under new PERCENT_PERIOD_GLOBAL index.

At the moment it's not displayed, it's coming in
following patches.

Link: http://lkml.kernel.org/n/tip-ehmmnz453rkon5bn52zuk0nu@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/annotate.c | 3 +++
 tools/perf/util/annotate.h | 1 +
 2 files changed, 4 insertions(+)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index b37e8cc18668..e890164592b0 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1783,6 +1783,9 @@ static void calc_percent(struct sym_hist *sym_hist,
 
 	if (sym_hist->period)
 		data->percent[PERCENT_PERIOD_LOCAL] = 100.0 * period / sym_hist->period;
+
+	if (hists->stats.total_period)
+		data->percent[PERCENT_PERIOD_GLOBAL] = 100.0 * period / hists->stats.total_period;
 }
 
 static void annotation__calc_percent(struct annotation *notes,
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 890b6869caa9..48fe2aa6b5a8 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -105,6 +105,7 @@ enum {
 	PERCENT_HITS_LOCAL,
 	PERCENT_HITS_GLOBAL,
 	PERCENT_PERIOD_LOCAL,
+	PERCENT_PERIOD_GLOBAL,
 	PERCENT_MAX,
 };
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH 12/20] perf annotate: Add percent_type to struct annotation_options
  2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
                   ` (10 preceding siblings ...)
  2018-08-04 13:05 ` [PATCH 11/20] perf annotate: Add PERCENT_PERIOD_GLOBAL " Jiri Olsa
@ 2018-08-04 13:05 ` Jiri Olsa
  2018-08-06 15:17   ` Arnaldo Carvalho de Melo
  2018-08-18 11:31   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  2018-08-04 13:05 ` [PATCH 13/20] perf annotate: Pass struct annotation_options to symbol__calc_lines Jiri Olsa
                   ` (7 subsequent siblings)
  19 siblings, 2 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

It will be used to carry user selection of percent
type for annotation output.

Passing the percent_type to the annotation_line__print
function as the first step and making it default to
current percentage type (PERCENT_HITS_LOCAL) value.

Link: http://lkml.kernel.org/n/tip-6ma4jjbxjcbglkkak3clhw97@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/annotate.c | 13 ++++++++-----
 tools/perf/util/annotate.h |  1 +
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index e890164592b0..91528a065768 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -49,6 +49,7 @@ struct annotation_options annotation__default_options = {
 	.jump_arrows    = true,
 	.annotate_src	= true,
 	.offset_level	= ANNOTATION__OFFSET_JUMP_TARGETS,
+	.percent_type	= PERCENT_HITS_LOCAL,
 };
 
 static regex_t	 file_lineno;
@@ -1297,7 +1298,8 @@ static int disasm_line__print(struct disasm_line *dl, u64 start, int addr_fmt_wi
 static int
 annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start,
 		       struct perf_evsel *evsel, u64 len, int min_pcnt, int printed,
-		       int max_lines, struct annotation_line *queue, int addr_fmt_width)
+		       int max_lines, struct annotation_line *queue, int addr_fmt_width,
+		       int percent_type)
 {
 	struct disasm_line *dl = container_of(al, struct disasm_line, al);
 	static const char *prev_line;
@@ -1313,7 +1315,7 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 			double percent;
 
 			percent = annotation_data__percent(&al->data[i],
-							   PERCENT_HITS_LOCAL);
+							   percent_type);
 
 			if (percent > max_percent)
 				max_percent = percent;
@@ -1333,7 +1335,8 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 				if (queue == al)
 					break;
 				annotation_line__print(queue, sym, start, evsel, len,
-						       0, 0, 1, NULL, addr_fmt_width);
+						       0, 0, 1, NULL, addr_fmt_width,
+						       percent_type);
 			}
 		}
 
@@ -1357,7 +1360,7 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 			struct annotation_data *data = &al->data[i];
 			double percent;
 
-			percent = annotation_data__percent(data, PERCENT_HITS_LOCAL);
+			percent = annotation_data__percent(data, percent_type);
 			color = get_percent_color(percent);
 
 			if (symbol_conf.show_total_period)
@@ -2075,7 +2078,7 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map,
 
 		err = annotation_line__print(pos, sym, start, evsel, len,
 					     opts->min_pcnt, printed, opts->max_lines,
-					     queue, addr_fmt_width);
+					     queue, addr_fmt_width, opts->percent_type);
 
 		switch (err) {
 		case 0:
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 48fe2aa6b5a8..145dec845f33 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -82,6 +82,7 @@ struct annotation_options {
 	int  context;
 	const char *objdump_path;
 	const char *disassembler_style;
+	unsigned int percent_type;
 };
 
 enum {
-- 
2.17.1


^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH 13/20] perf annotate: Pass struct annotation_options to symbol__calc_lines
  2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
                   ` (11 preceding siblings ...)
  2018-08-04 13:05 ` [PATCH 12/20] perf annotate: Add percent_type to struct annotation_options Jiri Olsa
@ 2018-08-04 13:05 ` Jiri Olsa
  2018-08-06 15:18   ` Arnaldo Carvalho de Melo
  2018-08-18 11:32   ` [tip:perf/urgent] perf annotate: Pass struct annotation_options to symbol__calc_lines() tip-bot for Jiri Olsa
  2018-08-04 13:05 ` [PATCH 14/20] perf annotate: Pass struct annotation_options to map_symbol__annotation_dump Jiri Olsa
                   ` (6 subsequent siblings)
  19 siblings, 2 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Passing struct annotation_options to symbol__calc_lines,
to carry on and pass the percent_type value.

Link: http://lkml.kernel.org/n/tip-hsutsg6zepd5o9dxdz0di4pb@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/annotate.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 91528a065768..2b06476c79c2 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1868,7 +1868,8 @@ int symbol__annotate(struct symbol *sym, struct map *map,
 	return symbol__disassemble(sym, &args);
 }
 
-static void insert_source_line(struct rb_root *root, struct annotation_line *al)
+static void insert_source_line(struct rb_root *root, struct annotation_line *al,
+			       struct annotation_options *opts)
 {
 	struct annotation_line *iter;
 	struct rb_node **p = &root->rb_node;
@@ -1883,7 +1884,7 @@ static void insert_source_line(struct rb_root *root, struct annotation_line *al)
 		if (ret == 0) {
 			for (i = 0; i < al->data_nr; i++) {
 				iter->data[i].percent_sum += annotation_data__percent(&al->data[i],
-										      PERCENT_HITS_LOCAL);
+										      opts->percent_type);
 			}
 			return;
 		}
@@ -1896,7 +1897,7 @@ static void insert_source_line(struct rb_root *root, struct annotation_line *al)
 
 	for (i = 0; i < al->data_nr; i++) {
 		al->data[i].percent_sum = annotation_data__percent(&al->data[i],
-								   PERCENT_HITS_LOCAL);
+								   opts->percent_type);
 	}
 
 	rb_link_node(&al->rb_node, parent, p);
@@ -2372,7 +2373,8 @@ void annotation__update_column_widths(struct annotation *notes)
 }
 
 static void annotation__calc_lines(struct annotation *notes, struct map *map,
-				  struct rb_root *root)
+				   struct rb_root *root,
+				   struct annotation_options *opts)
 {
 	struct annotation_line *al;
 	struct rb_root tmp_root = RB_ROOT;
@@ -2385,7 +2387,7 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map,
 			double percent;
 
 			percent = annotation_data__percent(&al->data[i],
-							   PERCENT_HITS_LOCAL);
+							   opts->percent_type);
 
 			if (percent > percent_max)
 				percent_max = percent;
@@ -2396,18 +2398,19 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map,
 
 		al->path = get_srcline(map->dso, notes->start + al->offset, NULL,
 				       false, true, notes->start + al->offset);
-		insert_source_line(&tmp_root, al);
+		insert_source_line(&tmp_root, al, opts);
 	}
 
 	resort_source_line(root, &tmp_root);
 }
 
 static void symbol__calc_lines(struct symbol *sym, struct map *map,
-			      struct rb_root *root)
+			       struct rb_root *root,
+			       struct annotation_options *opts)
 {
 	struct annotation *notes = symbol__annotation(sym);
 
-	annotation__calc_lines(notes, map, root);
+	annotation__calc_lines(notes, map, root, opts);
 }
 
 int symbol__tty_annotate2(struct symbol *sym, struct map *map,
@@ -2424,7 +2427,7 @@ int symbol__tty_annotate2(struct symbol *sym, struct map *map,
 
 	if (opts->print_lines) {
 		srcline_full_filename = opts->full_path;
-		symbol__calc_lines(sym, map, &source_line);
+		symbol__calc_lines(sym, map, &source_line, opts);
 		print_summary(&source_line, dso->long_name);
 	}
 
@@ -2451,7 +2454,7 @@ int symbol__tty_annotate(struct symbol *sym, struct map *map,
 
 	if (opts->print_lines) {
 		srcline_full_filename = opts->full_path;
-		symbol__calc_lines(sym, map, &source_line);
+		symbol__calc_lines(sym, map, &source_line, opts);
 		print_summary(&source_line, dso->long_name);
 	}
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH 14/20] perf annotate: Pass struct annotation_options to map_symbol__annotation_dump
  2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
                   ` (12 preceding siblings ...)
  2018-08-04 13:05 ` [PATCH 13/20] perf annotate: Pass struct annotation_options to symbol__calc_lines Jiri Olsa
@ 2018-08-04 13:05 ` Jiri Olsa
  2018-08-06 13:45   ` Namhyung Kim
  2018-08-18 11:32   ` [tip:perf/urgent] perf annotate: Pass 'struct annotation_options' to map_symbol__annotation_dump() tip-bot for Jiri Olsa
  2018-08-04 13:05 ` [PATCH 15/20] perf annotate: Pass browser percent_type in annotate_browser__calc_percent Jiri Olsa
                   ` (5 subsequent siblings)
  19 siblings, 2 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Passing struct annotation_options to map_symbol__annotation_dump,
to carry on and pass the percent_type value.

Link: http://lkml.kernel.org/n/tip-5toohgdkgpk3vn6zebusr3bb@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/ui/browsers/annotate.c |  4 +--
 tools/perf/util/annotate.c        | 42 +++++++++++++++++--------------
 tools/perf/util/annotate.h        |  6 +++--
 3 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 81876c3923d2..cfe611c28987 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -115,7 +115,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
 	if (!browser->navkeypressed)
 		ops.width += 1;
 
-	annotation_line__write(al, notes, &ops);
+	annotation_line__write(al, notes, &ops, ab->opts);
 
 	if (ops.current_entry)
 		ab->selection = al;
@@ -783,7 +783,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
 			continue;
 		}
 		case 'P':
-			map_symbol__annotation_dump(ms, evsel);
+			map_symbol__annotation_dump(ms, evsel, browser->opts);
 			continue;
 		case 't':
 			if (notes->options->show_total_period) {
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 2b06476c79c2..850958bb613a 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2156,10 +2156,11 @@ static void FILE__write_graph(void *fp, int graph)
 	fputs(s, fp);
 }
 
-static int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp)
+static int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp,
+				     struct annotation_options *opts)
 {
 	struct annotation *notes = symbol__annotation(sym);
-	struct annotation_write_ops ops = {
+	struct annotation_write_ops wops = {
 		.first_line		 = true,
 		.obj			 = fp,
 		.set_color		 = FILE__set_color,
@@ -2173,15 +2174,16 @@ static int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp)
 	list_for_each_entry(al, &notes->src->source, node) {
 		if (annotation_line__filter(al, notes))
 			continue;
-		annotation_line__write(al, notes, &ops);
+		annotation_line__write(al, notes, &wops, opts);
 		fputc('\n', fp);
-		ops.first_line = false;
+		wops.first_line = false;
 	}
 
 	return 0;
 }
 
-int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel)
+int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel,
+				struct annotation_options *opts)
 {
 	const char *ev_name = perf_evsel__name(evsel);
 	char buf[1024];
@@ -2203,7 +2205,7 @@ int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel)
 
 	fprintf(fp, "%s() %s\nEvent: %s\n\n",
 		ms->sym->name, ms->map->dso->long_name, ev_name);
-	symbol__annotate_fprintf2(ms->sym, fp);
+	symbol__annotate_fprintf2(ms->sym, fp, opts);
 
 	fclose(fp);
 	err = 0;
@@ -2433,7 +2435,7 @@ int symbol__tty_annotate2(struct symbol *sym, struct map *map,
 
 	hists__scnprintf_title(hists, buf, sizeof(buf));
 	fprintf(stdout, "%s\n%s() %s\n", buf, sym->name, dso->long_name);
-	symbol__annotate_fprintf2(sym, stdout);
+	symbol__annotate_fprintf2(sym, stdout, opts);
 
 	annotated_source__purge(symbol__annotation(sym)->src);
 
@@ -2472,7 +2474,8 @@ bool ui__has_annotation(void)
 
 
 static double annotation_line__max_percent(struct annotation_line *al,
-					   struct annotation *notes)
+					   struct annotation *notes,
+					   unsigned int percent_type)
 {
 	double percent_max = 0.0;
 	int i;
@@ -2481,7 +2484,7 @@ static double annotation_line__max_percent(struct annotation_line *al,
 		double percent;
 
 		percent = annotation_data__percent(&al->data[i],
-						   PERCENT_HITS_LOCAL);
+						   percent_type);
 
 		if (percent > percent_max)
 			percent_max = percent;
@@ -2523,7 +2526,7 @@ static void disasm_line__write(struct disasm_line *dl, struct annotation *notes,
 
 static void __annotation_line__write(struct annotation_line *al, struct annotation *notes,
 				     bool first_line, bool current_entry, bool change_color, int width,
-				     void *obj,
+				     void *obj, unsigned int percent_type,
 				     int  (*obj__set_color)(void *obj, int color),
 				     void (*obj__set_percent_color)(void *obj, double percent, bool current),
 				     int  (*obj__set_jumps_percent_color)(void *obj, int nr, bool current),
@@ -2531,7 +2534,7 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
 				     void (*obj__write_graph)(void *obj, int graph))
 
 {
-	double percent_max = annotation_line__max_percent(al, notes);
+	double percent_max = annotation_line__max_percent(al, notes, percent_type);
 	int pcnt_width = annotation__pcnt_width(notes),
 	    cycles_width = annotation__cycles_width(notes);
 	bool show_title = false;
@@ -2552,8 +2555,7 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
 		for (i = 0; i < notes->nr_events; i++) {
 			double percent;
 
-			percent = annotation_data__percent(&al->data[i],
-							   PERCENT_HITS_LOCAL);
+			percent = annotation_data__percent(&al->data[i], percent_type);
 
 			obj__set_percent_color(obj, percent, current_entry);
 			if (notes->options->show_total_period) {
@@ -2680,13 +2682,15 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
 }
 
 void annotation_line__write(struct annotation_line *al, struct annotation *notes,
-			    struct annotation_write_ops *ops)
+			    struct annotation_write_ops *wops,
+			    struct annotation_options *opts)
 {
-	__annotation_line__write(al, notes, ops->first_line, ops->current_entry,
-				 ops->change_color, ops->width, ops->obj,
-				 ops->set_color, ops->set_percent_color,
-				 ops->set_jumps_percent_color, ops->printf,
-				 ops->write_graph);
+	__annotation_line__write(al, notes, wops->first_line, wops->current_entry,
+				 wops->change_color, wops->width, wops->obj,
+				 opts->percent_type,
+				 wops->set_color, wops->set_percent_color,
+				 wops->set_jumps_percent_color, wops->printf,
+				 wops->write_graph);
 }
 
 int symbol__annotate2(struct symbol *sym, struct map *map, struct perf_evsel *evsel,
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 145dec845f33..3d4579e68d28 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -185,7 +185,8 @@ struct annotation_write_ops {
 };
 
 void annotation_line__write(struct annotation_line *al, struct annotation *notes,
-			    struct annotation_write_ops *ops);
+			    struct annotation_write_ops *ops,
+			    struct annotation_options *opts);
 
 int __annotation__scnprintf_samples_period(struct annotation *notes,
 					   char *bf, size_t size,
@@ -351,7 +352,8 @@ void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
 void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
 void annotated_source__purge(struct annotated_source *as);
 
-int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel);
+int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel,
+				struct annotation_options *opts);
 
 bool ui__has_annotation(void);
 
-- 
2.17.1


^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH 15/20] perf annotate: Pass browser percent_type in annotate_browser__calc_percent
  2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
                   ` (13 preceding siblings ...)
  2018-08-04 13:05 ` [PATCH 14/20] perf annotate: Pass struct annotation_options to map_symbol__annotation_dump Jiri Olsa
@ 2018-08-04 13:05 ` Jiri Olsa
  2018-08-06 15:23   ` Arnaldo Carvalho de Melo
  2018-08-18 11:33   ` [tip:perf/urgent] perf annotate: Pass browser percent_type in annotate_browser__calc_percent() tip-bot for Jiri Olsa
  2018-08-04 13:05 ` [PATCH 16/20] perf annotate: Add support to togle percent type Jiri Olsa
                   ` (4 subsequent siblings)
  19 siblings, 2 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Passing browser percent_type in annotate_browser__calc_percent.

Link: http://lkml.kernel.org/n/tip-7hqr2hyuv4yaqqtzxithrt3b@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/ui/browsers/annotate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index cfe611c28987..2a3a34d450d5 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -318,7 +318,7 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
 			double percent;
 
 			percent = annotation_data__percent(&pos->al.data[i],
-							   PERCENT_HITS_LOCAL);
+							   browser->opts->percent_type);
 
 			if (max_percent < percent)
 				max_percent = percent;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH 16/20] perf annotate: Add support to togle percent type
  2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
                   ` (14 preceding siblings ...)
  2018-08-04 13:05 ` [PATCH 15/20] perf annotate: Pass browser percent_type in annotate_browser__calc_percent Jiri Olsa
@ 2018-08-04 13:05 ` Jiri Olsa
  2018-08-06 18:24   ` Arnaldo Carvalho de Melo
  2018-08-18 11:33   ` [tip:perf/urgent] perf annotate: Add support to toggle " tip-bot for Jiri Olsa
  2018-08-04 13:05 ` [PATCH 17/20] perf annotate: Make local period the default " Jiri Olsa
                   ` (3 subsequent siblings)
  19 siblings, 2 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Adding new key bindings to togle percent type/base
in annotation UI browser:

 'p' to switch between local and global percent type
 'b' to switch between hits and perdio percent base

Adding following help messages to the UI browser '?' window:

  ...
  p             Toggle percent type [local/global]
  b             Toggle percent base [period/hits]
  ...

Link: http://lkml.kernel.org/n/tip-4czhcopnki8vn6pzbdl5k437@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/ui/browsers/annotate.c | 57 ++++++++++++++++++++++++++++---
 tools/perf/util/annotate.h        | 16 +++++++++
 2 files changed, 68 insertions(+), 5 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 2a3a34d450d5..11ce40f9c241 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -15,6 +15,7 @@
 #include <linux/kernel.h>
 #include <linux/string.h>
 #include <sys/ttydefaults.h>
+#include <asm/bug.h>
 
 struct disasm_line_samples {
 	double		      percent;
@@ -382,10 +383,13 @@ static void ui_browser__init_asm_mode(struct ui_browser *browser)
 
 #define SYM_TITLE_MAX_SIZE (PATH_MAX + 64)
 
-static int sym_title(struct symbol *sym, struct map *map, char *title,
-		     size_t sz)
+static int
+sym_title(struct symbol *sym, struct map *map, unsigned int percent_type,
+	  char *title, size_t sz)
 {
-	return snprintf(title, sz, "%s  %s", sym->name, map->dso->long_name);
+	return snprintf(title, sz, "%s  %s [Percent: %s]",
+			sym->name, map->dso->long_name,
+			percent_type_str(percent_type));
 }
 
 /*
@@ -423,7 +427,7 @@ static bool annotate_browser__callq(struct annotate_browser *browser,
 
 	pthread_mutex_unlock(&notes->lock);
 	symbol__tui_annotate(dl->ops.target.sym, ms->map, evsel, hbt, browser->opts);
-	sym_title(ms->sym, ms->map, title, sizeof(title));
+	sym_title(ms->sym, ms->map, browser->opts->percent_type, title, sizeof(title));
 	ui_browser__show_title(&browser->b, title);
 	return true;
 }
@@ -598,6 +602,7 @@ bool annotate_browser__continue_search_reverse(struct annotate_browser *browser,
 
 static int annotate_browser__show(struct ui_browser *browser, char *title, const char *help)
 {
+	struct annotate_browser *ab = container_of(browser, struct annotate_browser, b);
 	struct map_symbol *ms = browser->priv;
 	struct symbol *sym = ms->sym;
 	char symbol_dso[SYM_TITLE_MAX_SIZE];
@@ -605,7 +610,8 @@ static int annotate_browser__show(struct ui_browser *browser, char *title, const
 	if (ui_browser__show(browser, title, help) < 0)
 		return -1;
 
-	sym_title(sym, ms->map, symbol_dso, sizeof(symbol_dso));
+	sym_title(sym, ms->map, ab->opts->percent_type,
+		  symbol_dso, sizeof(symbol_dso));
 
 	ui_browser__gotorc_title(browser, 0, 0);
 	ui_browser__set_color(browser, HE_COLORSET_ROOT);
@@ -613,6 +619,39 @@ static int annotate_browser__show(struct ui_browser *browser, char *title, const
 	return 0;
 }
 
+static void
+switch_percent_type(struct annotation_options *opts, bool base)
+{
+	switch (opts->percent_type) {
+	case PERCENT_HITS_LOCAL:
+		if (base)
+			opts->percent_type = PERCENT_PERIOD_LOCAL;
+		else
+			opts->percent_type = PERCENT_HITS_GLOBAL;
+		break;
+	case PERCENT_HITS_GLOBAL:
+		if (base)
+			opts->percent_type = PERCENT_PERIOD_GLOBAL;
+		else
+			opts->percent_type = PERCENT_HITS_LOCAL;
+		break;
+	case PERCENT_PERIOD_LOCAL:
+		if (base)
+			opts->percent_type = PERCENT_HITS_LOCAL;
+		else
+			opts->percent_type = PERCENT_PERIOD_GLOBAL;
+		break;
+	case PERCENT_PERIOD_GLOBAL:
+		if (base)
+			opts->percent_type = PERCENT_HITS_GLOBAL;
+		else
+			opts->percent_type = PERCENT_PERIOD_LOCAL;
+		break;
+	default:
+		WARN_ON(1);
+	}
+}
+
 static int annotate_browser__run(struct annotate_browser *browser,
 				 struct perf_evsel *evsel,
 				 struct hist_browser_timer *hbt)
@@ -703,6 +742,8 @@ static int annotate_browser__run(struct annotate_browser *browser,
 		"k             Toggle line numbers\n"
 		"P             Print to [symbol_name].annotation file.\n"
 		"r             Run available scripts\n"
+		"p             Toggle percent type [local/global]\n"
+		"b             Toggle percent base [period/hits]\n"
 		"?             Search string backwards\n");
 			continue;
 		case 'r':
@@ -802,6 +843,12 @@ static int annotate_browser__run(struct annotate_browser *browser,
 				notes->options->show_minmax_cycle = true;
 			annotation__update_column_widths(notes);
 			continue;
+		case 'p':
+		case 'b':
+			switch_percent_type(browser->opts, key == 'b');
+			hists__scnprintf_title(hists, title, sizeof(title));
+			annotate_browser__show(&browser->b, title, help);
+			continue;
 		case K_LEFT:
 		case K_ESC:
 		case 'q':
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 3d4579e68d28..760a6678edff 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -11,6 +11,7 @@
 #include <linux/list.h>
 #include <linux/rbtree.h>
 #include <pthread.h>
+#include <asm/bug.h>
 
 struct ins_ops;
 
@@ -149,6 +150,21 @@ static inline double annotation_data__percent(struct annotation_data *data,
 	return which < PERCENT_MAX ? data->percent[which] : -1;
 }
 
+static inline const char *percent_type_str(unsigned int type)
+{
+	static const char *str[PERCENT_MAX] = {
+		"local hits",
+		"global hits",
+		"local period",
+		"global period",
+	};
+
+	if (WARN_ON(type >= PERCENT_MAX))
+		return "N/A";
+
+	return str[type];
+}
+
 static inline struct disasm_line *disasm_line(struct annotation_line *al)
 {
 	return al ? container_of(al, struct disasm_line, al) : NULL;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH 17/20] perf annotate: Make local period the default percent type
  2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
                   ` (15 preceding siblings ...)
  2018-08-04 13:05 ` [PATCH 16/20] perf annotate: Add support to togle percent type Jiri Olsa
@ 2018-08-04 13:05 ` Jiri Olsa
  2018-08-06 18:26   ` Arnaldo Carvalho de Melo
  2018-08-18 11:34   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  2018-08-04 13:05 ` [PATCH 18/20] perf annotate: Display percent type in stdio output Jiri Olsa
                   ` (2 subsequent siblings)
  19 siblings, 2 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Currently we display the percentages in annotation output
based on number of samples hits. Switching it to period
based percentage by default, because it corresponds more
to the time spent on the line.

Link: http://lkml.kernel.org/n/tip-so91zbhsjblu1g3867lfvymd@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/annotate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 850958bb613a..05d15629afd0 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -49,7 +49,7 @@ struct annotation_options annotation__default_options = {
 	.jump_arrows    = true,
 	.annotate_src	= true,
 	.offset_level	= ANNOTATION__OFFSET_JUMP_TARGETS,
-	.percent_type	= PERCENT_HITS_LOCAL,
+	.percent_type	= PERCENT_PERIOD_LOCAL,
 };
 
 static regex_t	 file_lineno;
-- 
2.17.1


^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH 18/20] perf annotate: Display percent type in stdio output
  2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
                   ` (16 preceding siblings ...)
  2018-08-04 13:05 ` [PATCH 17/20] perf annotate: Make local period the default " Jiri Olsa
@ 2018-08-04 13:05 ` Jiri Olsa
  2018-08-06 18:27   ` Arnaldo Carvalho de Melo
  2018-08-18 11:34   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  2018-08-04 13:05 ` [PATCH 19/20] perf annotate: Add --percent-type option Jiri Olsa
  2018-08-04 13:05 ` [PATCH 20/20] perf report: " Jiri Olsa
  19 siblings, 2 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

In following patches we will allow to switch percent type
even for stdio annotation outputs. Adding the percent type
value into the annotation outputs title.

  $ perf annotate --stdio
   Percent         |      Sou ... instructions:u } (2805 samples, percent: local period)
  --------------------------- ... ------------------------------------------------------
  ...

  $ perf annotate --stdio2
  Samples: 2K of events 'anon ...  count (approx.): 156525487, [percent: local period]
  safe_write.c() /usr/bin/yes
  Percent
  ...

Link: http://lkml.kernel.org/n/tip-6r6t568p4m4c3bmw3urr7o3z@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/annotate.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 05d15629afd0..6316fa96d984 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2056,10 +2056,12 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map,
 		evsel_name = buf;
 	}
 
-	graph_dotted_len = printf(" %-*.*s|	Source code & Disassembly of %s for %s (%" PRIu64 " samples)\n",
+	graph_dotted_len = printf(" %-*.*s|	Source code & Disassembly of %s for %s (%" PRIu64 " samples, "
+				  "percent: %s)\n",
 				  width, width, symbol_conf.show_total_period ? "Period" :
 				  symbol_conf.show_nr_samples ? "Samples" : "Percent",
-				  d_filename, evsel_name, h->nr_samples);
+				  d_filename, evsel_name, h->nr_samples,
+				  percent_type_str(opts->percent_type));
 
 	printf("%-*.*s----\n",
 	       graph_dotted_len, graph_dotted_len, graph_dotted_line);
@@ -2434,7 +2436,8 @@ int symbol__tty_annotate2(struct symbol *sym, struct map *map,
 	}
 
 	hists__scnprintf_title(hists, buf, sizeof(buf));
-	fprintf(stdout, "%s\n%s() %s\n", buf, sym->name, dso->long_name);
+	fprintf(stdout, "%s, [percent: %s]\n%s() %s\n",
+		buf, percent_type_str(opts->percent_type), sym->name, dso->long_name);
 	symbol__annotate_fprintf2(sym, stdout, opts);
 
 	annotated_source__purge(symbol__annotation(sym)->src);
-- 
2.17.1


^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH 19/20] perf annotate: Add --percent-type option
  2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
                   ` (17 preceding siblings ...)
  2018-08-04 13:05 ` [PATCH 18/20] perf annotate: Display percent type in stdio output Jiri Olsa
@ 2018-08-04 13:05 ` Jiri Olsa
  2018-08-06 13:49   ` Namhyung Kim
                     ` (2 more replies)
  2018-08-04 13:05 ` [PATCH 20/20] perf report: " Jiri Olsa
  19 siblings, 3 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Adding --percent-type option to set annotation percent type
from following choices:
  global-period, local-period, global-hits, local-hits

Examples:
  $ perf annotate --percent-type period-local --stdio | head -1
   Percent         |      Source code ... es, percent: local period)
  $ perf annotate --percent-type hits-local --stdio | head -1
   Percent         |      Source code ... es, percent: local hits)
  $ perf annotate --percent-type hits-global --stdio | head -1
   Percent         |      Source code ... es, percent: global hits)
  $ perf annotate --percent-type period-global --stdio | head -1
   Percent         |      Source code ... es, percent: global period)

The local/global keywords set if the percentage is computed
in the scope of the function (local) or the whole data (global).

The period/hits keywords set the base the percentage is computed
on - the samples period or the number of samples (hits).

Link: http://lkml.kernel.org/n/tip-ahnswy1p9rnjlkudhl2ig3gc@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/Documentation/perf-annotate.txt |  9 ++++
 tools/perf/builtin-annotate.c              |  4 ++
 tools/perf/util/annotate.c                 | 53 ++++++++++++++++++++++
 tools/perf/util/annotate.h                 |  3 ++
 4 files changed, 69 insertions(+)

diff --git a/tools/perf/Documentation/perf-annotate.txt b/tools/perf/Documentation/perf-annotate.txt
index 749cc6055dac..e8c972f89357 100644
--- a/tools/perf/Documentation/perf-annotate.txt
+++ b/tools/perf/Documentation/perf-annotate.txt
@@ -118,6 +118,15 @@ OPTIONS
 --group::
 	Show event group information together
 
+--percent-type::
+	Set annotation percent type from following choices:
+	  global-period, local-period, global-hits, local-hits
+
+	The local/global keywords set if the percentage is computed
+	in the scope of the function (local) or the whole data (global).
+	The period/hits keywords set the base the percentage is computed
+	on - the samples period or the number of samples (hits).
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-report[1]
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 8180319285af..830481b8db26 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -542,6 +542,10 @@ int cmd_annotate(int argc, const char **argv)
 	OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode",
 			     "'always' (default), 'never' or 'auto' only applicable to --stdio mode",
 			     stdio__config_color, "always"),
+	OPT_CALLBACK(0, "percent-type", &annotate.opts, "local-period",
+		     "Set percent type local/global-period/hits",
+		     annotate_parse_percent_type),
+
 	OPT_END()
 	};
 	int ret;
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 6316fa96d984..f68636c0d95a 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2799,3 +2799,56 @@ void annotation_config__init(void)
 	annotation__default_options.show_total_period = symbol_conf.show_total_period;
 	annotation__default_options.show_nr_samples   = symbol_conf.show_nr_samples;
 }
+
+static unsigned int parse_percent_type(char *str1, char *str2)
+{
+	unsigned int type = (unsigned int) -1;
+
+	if (!strcmp("period", str1)) {
+		if (!strcmp("local", str2))
+			type = PERCENT_PERIOD_LOCAL;
+		else if (!strcmp("global", str2))
+			type = PERCENT_PERIOD_GLOBAL;
+	}
+
+	if (!strcmp("hits", str1)) {
+		if (!strcmp("local", str2))
+			type = PERCENT_HITS_LOCAL;
+		else if (!strcmp("global", str2))
+			type = PERCENT_HITS_GLOBAL;
+	}
+
+	return type;
+}
+
+int
+annotate_parse_percent_type(const struct option *opt, const char *_str,
+			    int unset __maybe_unused)
+{
+	struct annotation_options *opts = opt->value;
+	unsigned int type;
+	char *str1, *str2;
+	int err = -1;
+
+	str1 = strdup(_str);
+	if (!str1)
+		return -ENOMEM;
+
+	str2 = strchr(str1, '-');
+	if (!str2)
+		goto out;
+
+	*str2++ = 0;
+
+	type = parse_percent_type(str1, str2);
+	if (type == (unsigned int) -1)
+		type = parse_percent_type(str2, str1);
+	if (type != (unsigned int) -1) {
+		opts->percent_type = type;
+		err = 0;
+	}
+
+out:
+	free(str1);
+	return err;
+}
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 760a6678edff..c7337f0a1823 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -397,4 +397,7 @@ static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused,
 
 void annotation_config__init(void);
 
+int
+annotate_parse_percent_type(const struct option *opt, const char *_str,
+			    int unset);
 #endif	/* __PERF_ANNOTATE_H */
-- 
2.17.1


^ permalink raw reply	[flat|nested] 67+ messages in thread

* [PATCH 20/20] perf report: Add --percent-type option
  2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
                   ` (18 preceding siblings ...)
  2018-08-04 13:05 ` [PATCH 19/20] perf annotate: Add --percent-type option Jiri Olsa
@ 2018-08-04 13:05 ` Jiri Olsa
  2018-08-06 18:48   ` Arnaldo Carvalho de Melo
  2018-08-18 11:35   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  19 siblings, 2 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-04 13:05 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Set annotation percent type from following choices:
  global-period, local-period, global-hits, local-hits

With following report option setup the percent type will be
passed to annotation browser:

  $ perf report --percent-type period-local

The local/global keywords set if the percentage is computed
in the scope of the function (local) or the whole data (global).
The period/hits keywords set the base the percentage is computed
on - the samples period or the number of samples (hits).

Link: http://lkml.kernel.org/n/tip-ahnswy1p9rnjlkudhl2ig3gc@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/Documentation/perf-report.txt | 9 +++++++++
 tools/perf/builtin-report.c              | 3 +++
 2 files changed, 12 insertions(+)

diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 917e36fde6d8..474a4941f65d 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -477,6 +477,15 @@ include::itrace.txt[]
 	Display monitored tasks stored in perf data. Displaying pid/tid/ppid
 	plus the command string aligned to distinguish parent and child tasks.
 
+--percent-type::
+	Set annotation percent type from following choices:
+	  global-period, local-period, global-hits, local-hits
+
+	The local/global keywords set if the percentage is computed
+	in the scope of the function (local) or the whole data (global).
+	The period/hits keywords set the base the percentage is computed
+	on - the samples period or the number of samples (hits).
+
 include::callchain-overhead-calculation.txt[]
 
 SEE ALSO
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 02f7a3c27761..143542ffac20 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -1124,6 +1124,9 @@ int cmd_report(int argc, const char **argv)
 		   "Time span of interest (start,stop)"),
 	OPT_BOOLEAN(0, "inline", &symbol_conf.inline_name,
 		    "Show inline function"),
+	OPT_CALLBACK(0, "percent-type", &report.annotation_opts, "local-period",
+		     "Set percent type local/global-period/hits",
+		     annotate_parse_percent_type),
 	OPT_END()
 	};
 	struct perf_data data = {
-- 
2.17.1


^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 14/20] perf annotate: Pass struct annotation_options to map_symbol__annotation_dump
  2018-08-04 13:05 ` [PATCH 14/20] perf annotate: Pass struct annotation_options to map_symbol__annotation_dump Jiri Olsa
@ 2018-08-06 13:45   ` Namhyung Kim
  2018-08-06 14:24     ` Jiri Olsa
  2018-08-18 11:32   ` [tip:perf/urgent] perf annotate: Pass 'struct annotation_options' to map_symbol__annotation_dump() tip-bot for Jiri Olsa
  1 sibling, 1 reply; 67+ messages in thread
From: Namhyung Kim @ 2018-08-06 13:45 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Arnaldo Carvalho de Melo, lkml, Ingo Molnar, David Ahern,
	Alexander Shishkin, Peter Zijlstra, Stephane Eranian,
	kernel-team

Hi Jiri,

On Sat, Aug 04, 2018 at 03:05:15PM +0200, Jiri Olsa wrote:
> Passing struct annotation_options to map_symbol__annotation_dump,
> to carry on and pass the percent_type value.
> 
> Link: http://lkml.kernel.org/n/tip-5toohgdkgpk3vn6zebusr3bb@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---

[SNIP]
> @@ -2523,7 +2526,7 @@ static void disasm_line__write(struct disasm_line *dl, struct annotation *notes,
>  
>  static void __annotation_line__write(struct annotation_line *al, struct annotation *notes,
>  				     bool first_line, bool current_entry, bool change_color, int width,
> -				     void *obj,
> +				     void *obj, unsigned int percent_type,
>  				     int  (*obj__set_color)(void *obj, int color),
>  				     void (*obj__set_percent_color)(void *obj, double percent, bool current),
>  				     int  (*obj__set_jumps_percent_color)(void *obj, int nr, bool current),
> @@ -2531,7 +2534,7 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
>  				     void (*obj__write_graph)(void *obj, int graph))
>  
>  {
> -	double percent_max = annotation_line__max_percent(al, notes);
> +	double percent_max = annotation_line__max_percent(al, notes, percent_type);
>  	int pcnt_width = annotation__pcnt_width(notes),
>  	    cycles_width = annotation__cycles_width(notes);
>  	bool show_title = false;
> @@ -2552,8 +2555,7 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
>  		for (i = 0; i < notes->nr_events; i++) {
>  			double percent;
>  
> -			percent = annotation_data__percent(&al->data[i],
> -							   PERCENT_HITS_LOCAL);
> +			percent = annotation_data__percent(&al->data[i], percent_type);
>  
>  			obj__set_percent_color(obj, percent, current_entry);
>  			if (notes->options->show_total_period) {
> @@ -2680,13 +2682,15 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
>  }
>  
>  void annotation_line__write(struct annotation_line *al, struct annotation *notes,
> -			    struct annotation_write_ops *ops)
> +			    struct annotation_write_ops *wops,
> +			    struct annotation_options *opts)
>  {
> -	__annotation_line__write(al, notes, ops->first_line, ops->current_entry,
> -				 ops->change_color, ops->width, ops->obj,
> -				 ops->set_color, ops->set_percent_color,
> -				 ops->set_jumps_percent_color, ops->printf,
> -				 ops->write_graph);
> +	__annotation_line__write(al, notes, wops->first_line, wops->current_entry,
> +				 wops->change_color, wops->width, wops->obj,
> +				 opts->percent_type,
> +				 wops->set_color, wops->set_percent_color,
> +				 wops->set_jumps_percent_color, wops->printf,
> +				 wops->write_graph);

This doesn't look good.  Why not just passing a pointer to wops
instead of each fields separately?

Thanks,
Namhyung


>  }
>  
>  int symbol__annotate2(struct symbol *sym, struct map *map, struct perf_evsel *evsel,
> diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
> index 145dec845f33..3d4579e68d28 100644
> --- a/tools/perf/util/annotate.h
> +++ b/tools/perf/util/annotate.h
> @@ -185,7 +185,8 @@ struct annotation_write_ops {
>  };
>  
>  void annotation_line__write(struct annotation_line *al, struct annotation *notes,
> -			    struct annotation_write_ops *ops);
> +			    struct annotation_write_ops *ops,
> +			    struct annotation_options *opts);
>  
>  int __annotation__scnprintf_samples_period(struct annotation *notes,
>  					   char *bf, size_t size,
> @@ -351,7 +352,8 @@ void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
>  void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
>  void annotated_source__purge(struct annotated_source *as);
>  
> -int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel);
> +int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel,
> +				struct annotation_options *opts);
>  
>  bool ui__has_annotation(void);
>  
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 19/20] perf annotate: Add --percent-type option
  2018-08-04 13:05 ` [PATCH 19/20] perf annotate: Add --percent-type option Jiri Olsa
@ 2018-08-06 13:49   ` Namhyung Kim
  2018-08-06 14:26     ` Jiri Olsa
  2018-08-06 18:32   ` Arnaldo Carvalho de Melo
  2018-08-18 11:35   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  2 siblings, 1 reply; 67+ messages in thread
From: Namhyung Kim @ 2018-08-06 13:49 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Arnaldo Carvalho de Melo, lkml, Ingo Molnar, David Ahern,
	Alexander Shishkin, Peter Zijlstra, Stephane Eranian,
	kernel-team

On Sat, Aug 04, 2018 at 03:05:20PM +0200, Jiri Olsa wrote:
> Adding --percent-type option to set annotation percent type
> from following choices:
>   global-period, local-period, global-hits, local-hits
> 
> Examples:
>   $ perf annotate --percent-type period-local --stdio | head -1
>    Percent         |      Source code ... es, percent: local period)
>   $ perf annotate --percent-type hits-local --stdio | head -1
>    Percent         |      Source code ... es, percent: local hits)
>   $ perf annotate --percent-type hits-global --stdio | head -1
>    Percent         |      Source code ... es, percent: global hits)
>   $ perf annotate --percent-type period-global --stdio | head -1
>    Percent         |      Source code ... es, percent: global period)
> 
> The local/global keywords set if the percentage is computed
> in the scope of the function (local) or the whole data (global).
> 
> The period/hits keywords set the base the percentage is computed
> on - the samples period or the number of samples (hits).

What about adding "period" as an alias to "local-period" (and same for
"hits" as well)?

Thanks,
Namhyung


> 
> Link: http://lkml.kernel.org/n/tip-ahnswy1p9rnjlkudhl2ig3gc@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/perf/Documentation/perf-annotate.txt |  9 ++++
>  tools/perf/builtin-annotate.c              |  4 ++
>  tools/perf/util/annotate.c                 | 53 ++++++++++++++++++++++
>  tools/perf/util/annotate.h                 |  3 ++
>  4 files changed, 69 insertions(+)
> 
> diff --git a/tools/perf/Documentation/perf-annotate.txt b/tools/perf/Documentation/perf-annotate.txt
> index 749cc6055dac..e8c972f89357 100644
> --- a/tools/perf/Documentation/perf-annotate.txt
> +++ b/tools/perf/Documentation/perf-annotate.txt
> @@ -118,6 +118,15 @@ OPTIONS
>  --group::
>  	Show event group information together
>  
> +--percent-type::
> +	Set annotation percent type from following choices:
> +	  global-period, local-period, global-hits, local-hits
> +
> +	The local/global keywords set if the percentage is computed
> +	in the scope of the function (local) or the whole data (global).
> +	The period/hits keywords set the base the percentage is computed
> +	on - the samples period or the number of samples (hits).
> +
>  SEE ALSO
>  --------
>  linkperf:perf-record[1], linkperf:perf-report[1]
> diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
> index 8180319285af..830481b8db26 100644
> --- a/tools/perf/builtin-annotate.c
> +++ b/tools/perf/builtin-annotate.c
> @@ -542,6 +542,10 @@ int cmd_annotate(int argc, const char **argv)
>  	OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode",
>  			     "'always' (default), 'never' or 'auto' only applicable to --stdio mode",
>  			     stdio__config_color, "always"),
> +	OPT_CALLBACK(0, "percent-type", &annotate.opts, "local-period",
> +		     "Set percent type local/global-period/hits",
> +		     annotate_parse_percent_type),
> +
>  	OPT_END()
>  	};
>  	int ret;
> diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
> index 6316fa96d984..f68636c0d95a 100644
> --- a/tools/perf/util/annotate.c
> +++ b/tools/perf/util/annotate.c
> @@ -2799,3 +2799,56 @@ void annotation_config__init(void)
>  	annotation__default_options.show_total_period = symbol_conf.show_total_period;
>  	annotation__default_options.show_nr_samples   = symbol_conf.show_nr_samples;
>  }
> +
> +static unsigned int parse_percent_type(char *str1, char *str2)
> +{
> +	unsigned int type = (unsigned int) -1;
> +
> +	if (!strcmp("period", str1)) {
> +		if (!strcmp("local", str2))
> +			type = PERCENT_PERIOD_LOCAL;
> +		else if (!strcmp("global", str2))
> +			type = PERCENT_PERIOD_GLOBAL;
> +	}
> +
> +	if (!strcmp("hits", str1)) {
> +		if (!strcmp("local", str2))
> +			type = PERCENT_HITS_LOCAL;
> +		else if (!strcmp("global", str2))
> +			type = PERCENT_HITS_GLOBAL;
> +	}
> +
> +	return type;
> +}
> +
> +int
> +annotate_parse_percent_type(const struct option *opt, const char *_str,
> +			    int unset __maybe_unused)
> +{
> +	struct annotation_options *opts = opt->value;
> +	unsigned int type;
> +	char *str1, *str2;
> +	int err = -1;
> +
> +	str1 = strdup(_str);
> +	if (!str1)
> +		return -ENOMEM;
> +
> +	str2 = strchr(str1, '-');
> +	if (!str2)
> +		goto out;
> +
> +	*str2++ = 0;
> +
> +	type = parse_percent_type(str1, str2);
> +	if (type == (unsigned int) -1)
> +		type = parse_percent_type(str2, str1);
> +	if (type != (unsigned int) -1) {
> +		opts->percent_type = type;
> +		err = 0;
> +	}
> +
> +out:
> +	free(str1);
> +	return err;
> +}
> diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
> index 760a6678edff..c7337f0a1823 100644
> --- a/tools/perf/util/annotate.h
> +++ b/tools/perf/util/annotate.h
> @@ -397,4 +397,7 @@ static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused,
>  
>  void annotation_config__init(void);
>  
> +int
> +annotate_parse_percent_type(const struct option *opt, const char *_str,
> +			    int unset);
>  #endif	/* __PERF_ANNOTATE_H */
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 14/20] perf annotate: Pass struct annotation_options to map_symbol__annotation_dump
  2018-08-06 13:45   ` Namhyung Kim
@ 2018-08-06 14:24     ` Jiri Olsa
  2018-08-06 15:22       ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 67+ messages in thread
From: Jiri Olsa @ 2018-08-06 14:24 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Jiri Olsa, Arnaldo Carvalho de Melo, lkml, Ingo Molnar,
	David Ahern, Alexander Shishkin, Peter Zijlstra,
	Stephane Eranian, kernel-team

On Mon, Aug 06, 2018 at 10:45:07PM +0900, Namhyung Kim wrote:
> Hi Jiri,
> 
> On Sat, Aug 04, 2018 at 03:05:15PM +0200, Jiri Olsa wrote:
> > Passing struct annotation_options to map_symbol__annotation_dump,
> > to carry on and pass the percent_type value.
> > 
> > Link: http://lkml.kernel.org/n/tip-5toohgdkgpk3vn6zebusr3bb@git.kernel.org
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> 
> [SNIP]
> > @@ -2523,7 +2526,7 @@ static void disasm_line__write(struct disasm_line *dl, struct annotation *notes,
> >  
> >  static void __annotation_line__write(struct annotation_line *al, struct annotation *notes,
> >  				     bool first_line, bool current_entry, bool change_color, int width,
> > -				     void *obj,
> > +				     void *obj, unsigned int percent_type,
> >  				     int  (*obj__set_color)(void *obj, int color),
> >  				     void (*obj__set_percent_color)(void *obj, double percent, bool current),
> >  				     int  (*obj__set_jumps_percent_color)(void *obj, int nr, bool current),
> > @@ -2531,7 +2534,7 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
> >  				     void (*obj__write_graph)(void *obj, int graph))
> >  
> >  {
> > -	double percent_max = annotation_line__max_percent(al, notes);
> > +	double percent_max = annotation_line__max_percent(al, notes, percent_type);
> >  	int pcnt_width = annotation__pcnt_width(notes),
> >  	    cycles_width = annotation__cycles_width(notes);
> >  	bool show_title = false;
> > @@ -2552,8 +2555,7 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
> >  		for (i = 0; i < notes->nr_events; i++) {
> >  			double percent;
> >  
> > -			percent = annotation_data__percent(&al->data[i],
> > -							   PERCENT_HITS_LOCAL);
> > +			percent = annotation_data__percent(&al->data[i], percent_type);
> >  
> >  			obj__set_percent_color(obj, percent, current_entry);
> >  			if (notes->options->show_total_period) {
> > @@ -2680,13 +2682,15 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
> >  }
> >  
> >  void annotation_line__write(struct annotation_line *al, struct annotation *notes,
> > -			    struct annotation_write_ops *ops)
> > +			    struct annotation_write_ops *wops,
> > +			    struct annotation_options *opts)
> >  {
> > -	__annotation_line__write(al, notes, ops->first_line, ops->current_entry,
> > -				 ops->change_color, ops->width, ops->obj,
> > -				 ops->set_color, ops->set_percent_color,
> > -				 ops->set_jumps_percent_color, ops->printf,
> > -				 ops->write_graph);
> > +	__annotation_line__write(al, notes, wops->first_line, wops->current_entry,
> > +				 wops->change_color, wops->width, wops->obj,
> > +				 opts->percent_type,
> > +				 wops->set_color, wops->set_percent_color,
> > +				 wops->set_jumps_percent_color, wops->printf,
> > +				 wops->write_graph);
> 
> This doesn't look good.  Why not just passing a pointer to wops
> instead of each fields separately?

yep, my thoughts exactly when I saw this ;-) we probably had some
other caller..  however I only wanted to add one more param ;-)

I'll check what we can do with this in v2

jirka

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 19/20] perf annotate: Add --percent-type option
  2018-08-06 13:49   ` Namhyung Kim
@ 2018-08-06 14:26     ` Jiri Olsa
  2018-08-06 18:33       ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 67+ messages in thread
From: Jiri Olsa @ 2018-08-06 14:26 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Jiri Olsa, Arnaldo Carvalho de Melo, lkml, Ingo Molnar,
	David Ahern, Alexander Shishkin, Peter Zijlstra,
	Stephane Eranian, kernel-team

On Mon, Aug 06, 2018 at 10:49:12PM +0900, Namhyung Kim wrote:
> On Sat, Aug 04, 2018 at 03:05:20PM +0200, Jiri Olsa wrote:
> > Adding --percent-type option to set annotation percent type
> > from following choices:
> >   global-period, local-period, global-hits, local-hits
> > 
> > Examples:
> >   $ perf annotate --percent-type period-local --stdio | head -1
> >    Percent         |      Source code ... es, percent: local period)
> >   $ perf annotate --percent-type hits-local --stdio | head -1
> >    Percent         |      Source code ... es, percent: local hits)
> >   $ perf annotate --percent-type hits-global --stdio | head -1
> >    Percent         |      Source code ... es, percent: global hits)
> >   $ perf annotate --percent-type period-global --stdio | head -1
> >    Percent         |      Source code ... es, percent: global period)
> > 
> > The local/global keywords set if the percentage is computed
> > in the scope of the function (local) or the whole data (global).
> > 
> > The period/hits keywords set the base the percentage is computed
> > on - the samples period or the number of samples (hits).
> 
> What about adding "period" as an alias to "local-period" (and same for
> "hits" as well)?

I dont mind that.. will add to v2 if there are no objections

thanks,
jirka

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 01/20] perf annotate: Make symbol__annotate_fprintf2 local
  2018-08-04 13:05 ` [PATCH 01/20] " Jiri Olsa
@ 2018-08-06 15:00   ` Arnaldo Carvalho de Melo
  2018-08-18 11:25   ` [tip:perf/urgent] perf annotate: Make symbol__annotate_fprintf2() local tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 15:00 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Em Sat, Aug 04, 2018 at 03:05:02PM +0200, Jiri Olsa escreveu:
> There's no outside user of it.

Thanks, applied.

- Arnaldo

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 02/20] perf annotate: Make annotation_line__max_percent static
  2018-08-04 13:05 ` [PATCH 02/20] perf annotate: Make annotation_line__max_percent static Jiri Olsa
@ 2018-08-06 15:01   ` Arnaldo Carvalho de Melo
  2018-08-18 11:26   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 15:01 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Em Sat, Aug 04, 2018 at 03:05:03PM +0200, Jiri Olsa escreveu:
> There's no outside user of it.

Applied

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 03/20] perf annotate: Get rid of annotation__scnprintf_samples_period
  2018-08-04 13:05 ` [PATCH 03/20] perf annotate: Get rid of annotation__scnprintf_samples_period Jiri Olsa
@ 2018-08-06 15:07   ` Arnaldo Carvalho de Melo
  2018-08-18 11:26   ` [tip:perf/urgent] perf annotate: Get rid of annotation__scnprintf_samples_period() tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 15:07 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Em Sat, Aug 04, 2018 at 03:05:04PM +0200, Jiri Olsa escreveu:
> We have more current function tto get the title for annotation,
> which is hists__scnprintf_title. They both have same output as
> far as the annotation's header line goes.
> 
> They differ in counting of the nr_samples, hists__scnprintf_title
> provides more accurate number based on the setup of the
> symbol_conf.filter_relative variable.
> 
> Plus it also displays any uid/thread/dso/socket filters/zooms
> if there are set any, which annotation__scnprintf_samples_period
> does not.

Thanks, tested and applied.

- Arnaldo

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 04/20] perf annotate: Rename struct annotation_line::samples* to data*
  2018-08-04 13:05 ` [PATCH 04/20] perf annotate: Rename struct annotation_line::samples* to data* Jiri Olsa
@ 2018-08-06 15:08   ` Arnaldo Carvalho de Melo
  2018-08-18 11:27   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 15:08 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Em Sat, Aug 04, 2018 at 03:05:05PM +0200, Jiri Olsa escreveu:
> The name 'samples*' is little confusing because we have
> nested 'struct sym_hist_entry' under annotation_line struct,
> which holds 'nr_samples' as well.
> 
> Also the holding struct name is 'annotation_data' so the
> 'data' name fits better.

Applied,

- Arnaldo

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 05/20] perf annotate: Rename local sample variables to data
  2018-08-04 13:05 ` [PATCH 05/20] perf annotate: Rename local sample variables to data Jiri Olsa
@ 2018-08-06 15:09   ` Arnaldo Carvalho de Melo
  2018-08-18 11:27   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 15:09 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Em Sat, Aug 04, 2018 at 03:05:06PM +0200, Jiri Olsa escreveu:
> Based on previous rename, changing also the local
> variable names to fit properly.

Applied.

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 06/20] perf annotate: Rename hist to sym_hist in annotation__calc_percent
  2018-08-04 13:05 ` [PATCH 06/20] perf annotate: Rename hist to sym_hist in annotation__calc_percent Jiri Olsa
@ 2018-08-06 15:10   ` Arnaldo Carvalho de Melo
  2018-08-18 11:28   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 15:10 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Em Sat, Aug 04, 2018 at 03:05:07PM +0200, Jiri Olsa escreveu:
> We will need to bring in 'struct hists' variable in this scope,
> so it's better we do this rename first.

Applied.

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 07/20] perf annotate: Loop group events directly in annotation__calc_percent
  2018-08-04 13:05 ` [PATCH 07/20] perf annotate: Loop group events directly " Jiri Olsa
@ 2018-08-06 15:12   ` Arnaldo Carvalho de Melo
  2018-08-18 11:28   ` [tip:perf/urgent] perf annotate: Loop group events directly in annotation__calc_percent() tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 15:12 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Em Sat, Aug 04, 2018 at 03:05:08PM +0200, Jiri Olsa escreveu:
> We need to bring in 'struct hists' object and for that
> we need 'struct perf_evsel' object in the scope.
> 
> Switching the group data loop with the evsel group loop.
> It does the same thing, but it brings evsel object, that
> we can use later get the 'struct hists' object.

Applied.

- Arnaldo

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 08/20] perf annotate: Switch struct annotation_data::percent to array
  2018-08-04 13:05 ` [PATCH 08/20] perf annotate: Switch struct annotation_data::percent to array Jiri Olsa
@ 2018-08-06 15:14   ` Arnaldo Carvalho de Melo
  2018-08-18 11:29   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 15:14 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Em Sat, Aug 04, 2018 at 03:05:09PM +0200, Jiri Olsa escreveu:
> So we can hold multiple percent values for annotation line.
> 
> The first member of this array is current local hits percent
> value (PERCENT_HITS_LOCAL index), so no functional change is
> expected.
> 
> Adding annotation_data__percent function to return requested
> percent value from struct annotation_data.

thanks, applied.

- Arnaldo

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 09/20] perf annotate: Add PERCENT_HITS_GLOBAL percent value
  2018-08-04 13:05 ` [PATCH 09/20] perf annotate: Add PERCENT_HITS_GLOBAL percent value Jiri Olsa
@ 2018-08-06 15:15   ` Arnaldo Carvalho de Melo
  2018-08-18 11:29   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 15:15 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Em Sat, Aug 04, 2018 at 03:05:10PM +0200, Jiri Olsa escreveu:
> Adding and computing global hits percent value for
> annotation line. Storing it in struct annotation_data
> percent array under new PERCENT_HITS_GLOBAL index.
> 
> At the moment it's not displayed, it's coming in
> following patches.

Applied.

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 10/20] perf annotate: Add PERCENT_PERIOD_LOCAL percent value
  2018-08-04 13:05 ` [PATCH 10/20] perf annotate: Add PERCENT_PERIOD_LOCAL " Jiri Olsa
@ 2018-08-06 15:16   ` Arnaldo Carvalho de Melo
  2018-08-18 11:30   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 15:16 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Em Sat, Aug 04, 2018 at 03:05:11PM +0200, Jiri Olsa escreveu:
> Adding and computing local period percent value for
> annotation line. Storing it in struct annotation_data
> percent array under new PERCENT_PERIOD_LOCAL index.
> 
> At the moment it's not displayed, it's coming in
> following patches.

Applied

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 11/20] perf annotate: Add PERCENT_PERIOD_GLOBAL percent value
  2018-08-04 13:05 ` [PATCH 11/20] perf annotate: Add PERCENT_PERIOD_GLOBAL " Jiri Olsa
@ 2018-08-06 15:16   ` Arnaldo Carvalho de Melo
  2018-08-18 11:30   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 15:16 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Em Sat, Aug 04, 2018 at 03:05:12PM +0200, Jiri Olsa escreveu:
> Adding and computing global period percent value for
> annotation line.  Storing it in struct annotation_data
> percent array under new PERCENT_PERIOD_GLOBAL index.
> 
> At the moment it's not displayed, it's coming in
> following patches.

applied

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 12/20] perf annotate: Add percent_type to struct annotation_options
  2018-08-04 13:05 ` [PATCH 12/20] perf annotate: Add percent_type to struct annotation_options Jiri Olsa
@ 2018-08-06 15:17   ` Arnaldo Carvalho de Melo
  2018-08-18 11:31   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 15:17 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Em Sat, Aug 04, 2018 at 03:05:13PM +0200, Jiri Olsa escreveu:
> It will be used to carry user selection of percent
> type for annotation output.
> 
> Passing the percent_type to the annotation_line__print
> function as the first step and making it default to
> current percentage type (PERCENT_HITS_LOCAL) value.

Applied.

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 13/20] perf annotate: Pass struct annotation_options to symbol__calc_lines
  2018-08-04 13:05 ` [PATCH 13/20] perf annotate: Pass struct annotation_options to symbol__calc_lines Jiri Olsa
@ 2018-08-06 15:18   ` Arnaldo Carvalho de Melo
  2018-08-18 11:32   ` [tip:perf/urgent] perf annotate: Pass struct annotation_options to symbol__calc_lines() tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 15:18 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Em Sat, Aug 04, 2018 at 03:05:14PM +0200, Jiri Olsa escreveu:
> Passing struct annotation_options to symbol__calc_lines,
> to carry on and pass the percent_type value.

Applied.

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 14/20] perf annotate: Pass struct annotation_options to map_symbol__annotation_dump
  2018-08-06 14:24     ` Jiri Olsa
@ 2018-08-06 15:22       ` Arnaldo Carvalho de Melo
  2018-08-06 15:29         ` Jiri Olsa
  0 siblings, 1 reply; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 15:22 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Namhyung Kim, Jiri Olsa, lkml, Ingo Molnar, David Ahern,
	Alexander Shishkin, Peter Zijlstra, Stephane Eranian,
	kernel-team

Em Mon, Aug 06, 2018 at 04:24:47PM +0200, Jiri Olsa escreveu:
> On Mon, Aug 06, 2018 at 10:45:07PM +0900, Namhyung Kim wrote:
> > Hi Jiri,
> > 
> > On Sat, Aug 04, 2018 at 03:05:15PM +0200, Jiri Olsa wrote:
> > > Passing struct annotation_options to map_symbol__annotation_dump,
> > > to carry on and pass the percent_type value.
> > > 
> > > Link: http://lkml.kernel.org/n/tip-5toohgdkgpk3vn6zebusr3bb@git.kernel.org
> > > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > > ---
> > 
> > [SNIP]
> > > @@ -2523,7 +2526,7 @@ static void disasm_line__write(struct disasm_line *dl, struct annotation *notes,
> > >  
> > >  static void __annotation_line__write(struct annotation_line *al, struct annotation *notes,
> > >  				     bool first_line, bool current_entry, bool change_color, int width,
> > > -				     void *obj,
> > > +				     void *obj, unsigned int percent_type,
> > >  				     int  (*obj__set_color)(void *obj, int color),
> > >  				     void (*obj__set_percent_color)(void *obj, double percent, bool current),
> > >  				     int  (*obj__set_jumps_percent_color)(void *obj, int nr, bool current),
> > > @@ -2531,7 +2534,7 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
> > >  				     void (*obj__write_graph)(void *obj, int graph))
> > >  
> > >  {
> > > -	double percent_max = annotation_line__max_percent(al, notes);
> > > +	double percent_max = annotation_line__max_percent(al, notes, percent_type);
> > >  	int pcnt_width = annotation__pcnt_width(notes),
> > >  	    cycles_width = annotation__cycles_width(notes);
> > >  	bool show_title = false;
> > > @@ -2552,8 +2555,7 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
> > >  		for (i = 0; i < notes->nr_events; i++) {
> > >  			double percent;
> > >  
> > > -			percent = annotation_data__percent(&al->data[i],
> > > -							   PERCENT_HITS_LOCAL);
> > > +			percent = annotation_data__percent(&al->data[i], percent_type);
> > >  
> > >  			obj__set_percent_color(obj, percent, current_entry);
> > >  			if (notes->options->show_total_period) {
> > > @@ -2680,13 +2682,15 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
> > >  }
> > >  
> > >  void annotation_line__write(struct annotation_line *al, struct annotation *notes,
> > > -			    struct annotation_write_ops *ops)
> > > +			    struct annotation_write_ops *wops,
> > > +			    struct annotation_options *opts)
> > >  {
> > > -	__annotation_line__write(al, notes, ops->first_line, ops->current_entry,
> > > -				 ops->change_color, ops->width, ops->obj,
> > > -				 ops->set_color, ops->set_percent_color,
> > > -				 ops->set_jumps_percent_color, ops->printf,
> > > -				 ops->write_graph);
> > > +	__annotation_line__write(al, notes, wops->first_line, wops->current_entry,
> > > +				 wops->change_color, wops->width, wops->obj,
> > > +				 opts->percent_type,
> > > +				 wops->set_color, wops->set_percent_color,
> > > +				 wops->set_jumps_percent_color, wops->printf,
> > > +				 wops->write_graph);
> > 
> > This doesn't look good.  Why not just passing a pointer to wops
> > instead of each fields separately?
> 
> yep, my thoughts exactly when I saw this ;-) we probably had some

But then, while this is a valid observation, it is not related to this
patchkit, that is just adding an extra config variable, percent_type, at
some point one can try to shorten that function signature, looking at
why it was done this way originally to see if there was any reason or if
its just something to improve by shortening the function signature.

Applying Jiri's patch,

> other caller..  however I only wanted to add one more param ;-)

Right
 
> I'll check what we can do with this in v2

I'm going thru v2 already, so far its an uncontrovertial, trivial, so
I think you better just wait a teeny bit for this to be applied and then
get on over with followup patches, ok?

- Arnaldo

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 15/20] perf annotate: Pass browser percent_type in annotate_browser__calc_percent
  2018-08-04 13:05 ` [PATCH 15/20] perf annotate: Pass browser percent_type in annotate_browser__calc_percent Jiri Olsa
@ 2018-08-06 15:23   ` Arnaldo Carvalho de Melo
  2018-08-18 11:33   ` [tip:perf/urgent] perf annotate: Pass browser percent_type in annotate_browser__calc_percent() tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 15:23 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Em Sat, Aug 04, 2018 at 03:05:16PM +0200, Jiri Olsa escreveu:
> Passing browser percent_type in annotate_browser__calc_percent.

applied

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 14/20] perf annotate: Pass struct annotation_options to map_symbol__annotation_dump
  2018-08-06 15:22       ` Arnaldo Carvalho de Melo
@ 2018-08-06 15:29         ` Jiri Olsa
  0 siblings, 0 replies; 67+ messages in thread
From: Jiri Olsa @ 2018-08-06 15:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Namhyung Kim, Jiri Olsa, lkml, Ingo Molnar, David Ahern,
	Alexander Shishkin, Peter Zijlstra, Stephane Eranian,
	kernel-team

On Mon, Aug 06, 2018 at 12:22:19PM -0300, Arnaldo Carvalho de Melo wrote:

SNIP

> > > > -				 ops->set_jumps_percent_color, ops->printf,
> > > > -				 ops->write_graph);
> > > > +	__annotation_line__write(al, notes, wops->first_line, wops->current_entry,
> > > > +				 wops->change_color, wops->width, wops->obj,
> > > > +				 opts->percent_type,
> > > > +				 wops->set_color, wops->set_percent_color,
> > > > +				 wops->set_jumps_percent_color, wops->printf,
> > > > +				 wops->write_graph);
> > > 
> > > This doesn't look good.  Why not just passing a pointer to wops
> > > instead of each fields separately?
> > 
> > yep, my thoughts exactly when I saw this ;-) we probably had some
> 
> But then, while this is a valid observation, it is not related to this
> patchkit, that is just adding an extra config variable, percent_type, at
> some point one can try to shorten that function signature, looking at
> why it was done this way originally to see if there was any reason or if
> its just something to improve by shortening the function signature.
> 
> Applying Jiri's patch,
> 
> > other caller..  however I only wanted to add one more param ;-)
> 
> Right
>  
> > I'll check what we can do with this in v2
> 
> I'm going thru v2 already, so far its an uncontrovertial, trivial, so
> I think you better just wait a teeny bit for this to be applied and then
> get on over with followup patches, ok?

sure, np

jirka

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 16/20] perf annotate: Add support to togle percent type
  2018-08-04 13:05 ` [PATCH 16/20] perf annotate: Add support to togle percent type Jiri Olsa
@ 2018-08-06 18:24   ` Arnaldo Carvalho de Melo
  2018-08-18 11:33   ` [tip:perf/urgent] perf annotate: Add support to toggle " tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 18:24 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Em Sat, Aug 04, 2018 at 03:05:17PM +0200, Jiri Olsa escreveu:
> Adding new key bindings to togle percent type/base
> in annotation UI browser:

Thanks, tested, nice! Applied.

- Arnaldo

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 17/20] perf annotate: Make local period the default percent type
  2018-08-04 13:05 ` [PATCH 17/20] perf annotate: Make local period the default " Jiri Olsa
@ 2018-08-06 18:26   ` Arnaldo Carvalho de Melo
  2018-08-18 11:34   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 18:26 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Em Sat, Aug 04, 2018 at 03:05:18PM +0200, Jiri Olsa escreveu:
> Currently we display the percentages in annotation output
> based on number of samples hits. Switching it to period
> based percentage by default, because it corresponds more
> to the time spent on the line.

Thanks, tested, applied.

- Arnaldo

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 18/20] perf annotate: Display percent type in stdio output
  2018-08-04 13:05 ` [PATCH 18/20] perf annotate: Display percent type in stdio output Jiri Olsa
@ 2018-08-06 18:27   ` Arnaldo Carvalho de Melo
  2018-08-18 11:34   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 18:27 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Em Sat, Aug 04, 2018 at 03:05:19PM +0200, Jiri Olsa escreveu:
> In following patches we will allow to switch percent type
> even for stdio annotation outputs. Adding the percent type
> value into the annotation outputs title.
> 
>   $ perf annotate --stdio
>    Percent         |      Sou ... instructions:u } (2805 samples, percent: local period)
>   --------------------------- ... ------------------------------------------------------
>   ...
> 
>   $ perf annotate --stdio2
>   Samples: 2K of events 'anon ...  count (approx.): 156525487, [percent: local period]
>   safe_write.c() /usr/bin/yes
>   Percent
>   ...

Thanks, tested, applied.

- Arnaldo

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 19/20] perf annotate: Add --percent-type option
  2018-08-04 13:05 ` [PATCH 19/20] perf annotate: Add --percent-type option Jiri Olsa
  2018-08-06 13:49   ` Namhyung Kim
@ 2018-08-06 18:32   ` Arnaldo Carvalho de Melo
  2018-08-18 11:35   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  2 siblings, 0 replies; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 18:32 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Em Sat, Aug 04, 2018 at 03:05:20PM +0200, Jiri Olsa escreveu:
> Adding --percent-type option to set annotation percent type
> from following choices:
>   global-period, local-period, global-hits, local-hits
> 
> Examples:
>   $ perf annotate --percent-type period-local --stdio | head -1
>    Percent         |      Source code ... es, percent: local period)
>   $ perf annotate --percent-type hits-local --stdio | head -1
>    Percent         |      Source code ... es, percent: local hits)
>   $ perf annotate --percent-type hits-global --stdio | head -1
>    Percent         |      Source code ... es, percent: global hits)
>   $ perf annotate --percent-type period-global --stdio | head -1
>    Percent         |      Source code ... es, percent: global period)
> 
> The local/global keywords set if the percentage is computed
> in the scope of the function (local) or the whole data (global).
> 
> The period/hits keywords set the base the percentage is computed
> on - the samples period or the number of samples (hits).

Thanks, tested, applied.

- Arnaldo

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 19/20] perf annotate: Add --percent-type option
  2018-08-06 14:26     ` Jiri Olsa
@ 2018-08-06 18:33       ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 18:33 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Namhyung Kim, Jiri Olsa, lkml, Ingo Molnar, David Ahern,
	Alexander Shishkin, Peter Zijlstra, Stephane Eranian,
	kernel-team

Em Mon, Aug 06, 2018 at 04:26:25PM +0200, Jiri Olsa escreveu:
> On Mon, Aug 06, 2018 at 10:49:12PM +0900, Namhyung Kim wrote:
> > On Sat, Aug 04, 2018 at 03:05:20PM +0200, Jiri Olsa wrote:
> > > The local/global keywords set if the percentage is computed
> > > in the scope of the function (local) or the whole data (global).

> > > The period/hits keywords set the base the percentage is computed
> > > on - the samples period or the number of samples (hits).

> > What about adding "period" as an alias to "local-period" (and same for
> > "hits" as well)?

> I dont mind that.. will add to v2 if there are no objections

Please add this on top of this, I'm finishing processing this now.

- Arnaldo

^ permalink raw reply	[flat|nested] 67+ messages in thread

* Re: [PATCH 20/20] perf report: Add --percent-type option
  2018-08-04 13:05 ` [PATCH 20/20] perf report: " Jiri Olsa
@ 2018-08-06 18:48   ` Arnaldo Carvalho de Melo
  2018-08-18 11:35   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: Arnaldo Carvalho de Melo @ 2018-08-06 18:48 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, David Ahern, Alexander Shishkin,
	Peter Zijlstra, Stephane Eranian

Em Sat, Aug 04, 2018 at 03:05:21PM +0200, Jiri Olsa escreveu:
> Set annotation percent type from following choices:
>   global-period, local-period, global-hits, local-hits
> 
> With following report option setup the percent type will be
> passed to annotation browser:
> 
>   $ perf report --percent-type period-local
> 
> The local/global keywords set if the percentage is computed
> in the scope of the function (local) or the whole data (global).
> The period/hits keywords set the base the percentage is computed
> on - the samples period or the number of samples (hits).

Tested, applied,

- Arnaldo

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [tip:perf/urgent] perf annotate: Make symbol__annotate_fprintf2() local
  2018-08-04 13:05 ` [PATCH 01/20] " Jiri Olsa
  2018-08-06 15:00   ` Arnaldo Carvalho de Melo
@ 2018-08-18 11:25   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-08-18 11:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: dsahern, linux-kernel, alexander.shishkin, peterz, jolsa,
	namhyung, acme, hpa, eranian, tglx, mingo

Commit-ID:  7a3e71e0d806070071f53271705b0c511c0359fc
Gitweb:     https://git.kernel.org/tip/7a3e71e0d806070071f53271705b0c511c0359fc
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sat, 4 Aug 2018 15:05:02 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Aug 2018 15:55:45 -0300

perf annotate: Make symbol__annotate_fprintf2() local

There's no outside user of it.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lkml.kernel.org/r/20180804130521.11408-2-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/annotate.c | 2 +-
 tools/perf/util/annotate.h | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index f91775b4bc3c..b6e7d0d56622 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2129,7 +2129,7 @@ static void FILE__write_graph(void *fp, int graph)
 	fputs(s, fp);
 }
 
-int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp)
+static int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp)
 {
 	struct annotation *notes = symbol__annotation(sym);
 	struct annotation_write_ops ops = {
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index a4c0d91907e6..5f24fc9dcc7c 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -340,7 +340,6 @@ int symbol__strerror_disassemble(struct symbol *sym, struct map *map,
 int symbol__annotate_printf(struct symbol *sym, struct map *map,
 			    struct perf_evsel *evsel,
 			    struct annotation_options *options);
-int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp);
 void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
 void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
 void annotated_source__purge(struct annotated_source *as);

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [tip:perf/urgent] perf annotate: Make annotation_line__max_percent static
  2018-08-04 13:05 ` [PATCH 02/20] perf annotate: Make annotation_line__max_percent static Jiri Olsa
  2018-08-06 15:01   ` Arnaldo Carvalho de Melo
@ 2018-08-18 11:26   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-08-18 11:26 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: jolsa, alexander.shishkin, mingo, hpa, linux-kernel, dsahern,
	acme, eranian, peterz, namhyung, tglx

Commit-ID:  5ecf7d30eb4f9c046f5284f20133d7b69729c315
Gitweb:     https://git.kernel.org/tip/5ecf7d30eb4f9c046f5284f20133d7b69729c315
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sat, 4 Aug 2018 15:05:03 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Aug 2018 15:55:45 -0300

perf annotate: Make annotation_line__max_percent static

There's no outside user of it.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20180804130521.11408-3-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/annotate.c | 3 ++-
 tools/perf/util/annotate.h | 1 -
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index b6e7d0d56622..956c9b19d81c 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2441,7 +2441,8 @@ bool ui__has_annotation(void)
 }
 
 
-double annotation_line__max_percent(struct annotation_line *al, struct annotation *notes)
+static double annotation_line__max_percent(struct annotation_line *al,
+					   struct annotation *notes)
 {
 	double percent_max = 0.0;
 	int i;
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 5f24fc9dcc7c..a93502d0c582 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -169,7 +169,6 @@ struct annotation_write_ops {
 	void (*write_graph)(void *obj, int graph);
 };
 
-double annotation_line__max_percent(struct annotation_line *al, struct annotation *notes);
 void annotation_line__write(struct annotation_line *al, struct annotation *notes,
 			    struct annotation_write_ops *ops);
 

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [tip:perf/urgent] perf annotate: Get rid of annotation__scnprintf_samples_period()
  2018-08-04 13:05 ` [PATCH 03/20] perf annotate: Get rid of annotation__scnprintf_samples_period Jiri Olsa
  2018-08-06 15:07   ` Arnaldo Carvalho de Melo
@ 2018-08-18 11:26   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-08-18 11:26 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, peterz, alexander.shishkin, hpa, namhyung, acme,
	linux-kernel, eranian, dsahern, mingo, jolsa

Commit-ID:  0683d13c1afbf5cca147b6f578d1463be132b11b
Gitweb:     https://git.kernel.org/tip/0683d13c1afbf5cca147b6f578d1463be132b11b
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sat, 4 Aug 2018 15:05:04 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Aug 2018 15:55:46 -0300

perf annotate: Get rid of annotation__scnprintf_samples_period()

We have more current function tto get the title for annotation,
which is hists__scnprintf_title. They both have same output as
far as the annotation's header line goes.

They differ in counting of the nr_samples, hists__scnprintf_title
provides more accurate number based on the setup of the
symbol_conf.filter_relative variable.

Plus it also displays any uid/thread/dso/socket filters/zooms
if there are set any, which annotation__scnprintf_samples_period
does not.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20180804130521.11408-4-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/ui/browsers/annotate.c |  3 +--
 tools/perf/util/annotate.c        | 44 ++-------------------------------------
 tools/perf/util/annotate.h        |  7 -------
 3 files changed, 3 insertions(+), 51 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 3b4f1c10ff57..d264916d2648 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -624,8 +624,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
 	char title[256];
 	int key;
 
-	annotation__scnprintf_samples_period(notes, title, sizeof(title), evsel);
-
+	hists__scnprintf_title(hists, title, sizeof(title));
 	if (annotate_browser__show(&browser->b, title, help) < 0)
 		return -1;
 
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 956c9b19d81c..0d40cee13f6b 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2389,7 +2389,7 @@ int symbol__tty_annotate2(struct symbol *sym, struct map *map,
 {
 	struct dso *dso = map->dso;
 	struct rb_root source_line = RB_ROOT;
-	struct annotation *notes = symbol__annotation(sym);
+	struct hists *hists = evsel__hists(evsel);
 	char buf[1024];
 
 	if (symbol__annotate2(sym, map, evsel, opts, NULL) < 0)
@@ -2401,7 +2401,7 @@ int symbol__tty_annotate2(struct symbol *sym, struct map *map,
 		print_summary(&source_line, dso->long_name);
 	}
 
-	annotation__scnprintf_samples_period(notes, buf, sizeof(buf), evsel);
+	hists__scnprintf_title(hists, buf, sizeof(buf));
 	fprintf(stdout, "%s\n%s() %s\n", buf, sym->name, dso->long_name);
 	symbol__annotate_fprintf2(sym, stdout);
 
@@ -2689,46 +2689,6 @@ out_free_offsets:
 	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 buf[1024], 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)) {
-		perf_evsel__group_desc(evsel, buf, sizeof(buf));
-		ev_name = buf;
-                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 a93502d0c582..d06f14c656c6 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -177,13 +177,6 @@ int __annotation__scnprintf_samples_period(struct annotation *notes,
 					   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);

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [tip:perf/urgent] perf annotate: Rename struct annotation_line::samples* to data*
  2018-08-04 13:05 ` [PATCH 04/20] perf annotate: Rename struct annotation_line::samples* to data* Jiri Olsa
  2018-08-06 15:08   ` Arnaldo Carvalho de Melo
@ 2018-08-18 11:27   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-08-18 11:27 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: dsahern, mingo, alexander.shishkin, hpa, tglx, jolsa, peterz,
	linux-kernel, acme, eranian, namhyung

Commit-ID:  c2f938ba5aa61ba60e9217848e666c783cbcce1c
Gitweb:     https://git.kernel.org/tip/c2f938ba5aa61ba60e9217848e666c783cbcce1c
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sat, 4 Aug 2018 15:05:05 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Aug 2018 15:55:46 -0300

perf annotate: Rename struct annotation_line::samples* to data*

The name 'samples*' is little confusing because we have nested 'struct
sym_hist_entry' under annotation_line struct, which holds 'nr_samples'
as well.

Also the holding struct name is 'annotation_data' so the 'data' name
fits better.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20180804130521.11408-5-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/ui/browsers/annotate.c | 10 ++++----
 tools/perf/util/annotate.c        | 52 +++++++++++++++++++--------------------
 tools/perf/util/annotate.h        |  4 +--
 3 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index d264916d2648..d648d1e153f3 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -227,10 +227,10 @@ static int disasm__cmp(struct annotation_line *a, struct annotation_line *b)
 {
 	int i;
 
-	for (i = 0; i < a->samples_nr; i++) {
-		if (a->samples[i].percent == b->samples[i].percent)
+	for (i = 0; i < a->data_nr; i++) {
+		if (a->data[i].percent == b->data[i].percent)
 			continue;
-		return a->samples[i].percent < b->samples[i].percent;
+		return a->data[i].percent < b->data[i].percent;
 	}
 	return 0;
 }
@@ -314,8 +314,8 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
 			continue;
 		}
 
-		for (i = 0; i < pos->al.samples_nr; i++) {
-			struct annotation_data *sample = &pos->al.samples[i];
+		for (i = 0; i < pos->al.data_nr; i++) {
+			struct annotation_data *sample = &pos->al.data[i];
 
 			if (max_percent < sample->percent)
 				max_percent = sample->percent;
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 0d40cee13f6b..e4cb8963db1a 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1108,7 +1108,7 @@ annotation_line__new(struct annotate_args *args, size_t privsize)
 	if (perf_evsel__is_group_event(evsel))
 		nr = evsel->nr_members;
 
-	size += sizeof(al->samples[0]) * nr;
+	size += sizeof(al->data[0]) * nr;
 
 	al = zalloc(size);
 	if (al) {
@@ -1117,7 +1117,7 @@ annotation_line__new(struct annotate_args *args, size_t privsize)
 		al->offset     = args->offset;
 		al->line       = strdup(args->line);
 		al->line_nr    = args->line_nr;
-		al->samples_nr = nr;
+		al->data_nr    = nr;
 	}
 
 	return al;
@@ -1309,15 +1309,15 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 		const char *color;
 		struct annotation *notes = symbol__annotation(sym);
 
-		for (i = 0; i < al->samples_nr; i++) {
-			struct annotation_data *sample = &al->samples[i];
+		for (i = 0; i < al->data_nr; i++) {
+			struct annotation_data *sample = &al->data[i];
 
 			if (sample->percent > max_percent)
 				max_percent = sample->percent;
 		}
 
-		if (al->samples_nr > nr_percent)
-			nr_percent = al->samples_nr;
+		if (al->data_nr > nr_percent)
+			nr_percent = al->data_nr;
 
 		if (max_percent < min_pcnt)
 			return -1;
@@ -1351,7 +1351,7 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 		}
 
 		for (i = 0; i < nr_percent; i++) {
-			struct annotation_data *sample = &al->samples[i];
+			struct annotation_data *sample = &al->data[i];
 
 			color = get_percent_color(sample->percent);
 
@@ -1788,12 +1788,12 @@ static void annotation__calc_percent(struct annotation *notes,
 		next = annotation_line__next(al, &notes->src->source);
 		end  = next ? next->offset : len;
 
-		for (i = 0; i < al->samples_nr; i++) {
+		for (i = 0; i < al->data_nr; i++) {
 			struct annotation_data *sample;
 			struct sym_hist *hist;
 
 			hist   = annotation__histogram(notes, evsel->idx + i);
-			sample = &al->samples[i];
+			sample = &al->data[i];
 
 			calc_percent(hist, sample, al->offset, end);
 		}
@@ -1859,8 +1859,8 @@ static void insert_source_line(struct rb_root *root, struct annotation_line *al)
 
 		ret = strcmp(iter->path, al->path);
 		if (ret == 0) {
-			for (i = 0; i < al->samples_nr; i++)
-				iter->samples[i].percent_sum += al->samples[i].percent;
+			for (i = 0; i < al->data_nr; i++)
+				iter->data[i].percent_sum += al->data[i].percent;
 			return;
 		}
 
@@ -1870,8 +1870,8 @@ static void insert_source_line(struct rb_root *root, struct annotation_line *al)
 			p = &(*p)->rb_right;
 	}
 
-	for (i = 0; i < al->samples_nr; i++)
-		al->samples[i].percent_sum = al->samples[i].percent;
+	for (i = 0; i < al->data_nr; i++)
+		al->data[i].percent_sum = al->data[i].percent;
 
 	rb_link_node(&al->rb_node, parent, p);
 	rb_insert_color(&al->rb_node, root);
@@ -1881,10 +1881,10 @@ static int cmp_source_line(struct annotation_line *a, struct annotation_line *b)
 {
 	int i;
 
-	for (i = 0; i < a->samples_nr; i++) {
-		if (a->samples[i].percent_sum == b->samples[i].percent_sum)
+	for (i = 0; i < a->data_nr; i++) {
+		if (a->data[i].percent_sum == b->data[i].percent_sum)
 			continue;
-		return a->samples[i].percent_sum > b->samples[i].percent_sum;
+		return a->data[i].percent_sum > b->data[i].percent_sum;
 	}
 
 	return 0;
@@ -1949,8 +1949,8 @@ static void print_summary(struct rb_root *root, const char *filename)
 		int i;
 
 		al = rb_entry(node, struct annotation_line, rb_node);
-		for (i = 0; i < al->samples_nr; i++) {
-			percent = al->samples[i].percent_sum;
+		for (i = 0; i < al->data_nr; i++) {
+			percent = al->data[i].percent_sum;
 			color = get_percent_color(percent);
 			color_fprintf(stdout, color, " %7.2f", percent);
 
@@ -2355,10 +2355,10 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map,
 		double percent_max = 0.0;
 		int i;
 
-		for (i = 0; i < al->samples_nr; i++) {
+		for (i = 0; i < al->data_nr; i++) {
 			struct annotation_data *sample;
 
-			sample = &al->samples[i];
+			sample = &al->data[i];
 
 			if (sample->percent > percent_max)
 				percent_max = sample->percent;
@@ -2448,8 +2448,8 @@ static double annotation_line__max_percent(struct annotation_line *al,
 	int i;
 
 	for (i = 0; i < notes->nr_events; i++) {
-		if (al->samples[i].percent > percent_max)
-			percent_max = al->samples[i].percent;
+		if (al->data[i].percent > percent_max)
+			percent_max = al->data[i].percent;
 	}
 
 	return percent_max;
@@ -2515,15 +2515,15 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
 		int i;
 
 		for (i = 0; i < notes->nr_events; i++) {
-			obj__set_percent_color(obj, al->samples[i].percent, current_entry);
+			obj__set_percent_color(obj, al->data[i].percent, current_entry);
 			if (notes->options->show_total_period) {
-				obj__printf(obj, "%11" PRIu64 " ", al->samples[i].he.period);
+				obj__printf(obj, "%11" PRIu64 " ", al->data[i].he.period);
 			} else if (notes->options->show_nr_samples) {
 				obj__printf(obj, "%6" PRIu64 " ",
-						   al->samples[i].he.nr_samples);
+						   al->data[i].he.nr_samples);
 			} else {
 				obj__printf(obj, "%6.2f ",
-						   al->samples[i].percent);
+						   al->data[i].percent);
 			}
 		}
 	} else {
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index d06f14c656c6..58aa14c55bab 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -122,8 +122,8 @@ struct annotation_line {
 	char			*path;
 	u32			 idx;
 	int			 idx_asm;
-	int			 samples_nr;
-	struct annotation_data	 samples[0];
+	int			 data_nr;
+	struct annotation_data	 data[0];
 };
 
 struct disasm_line {

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [tip:perf/urgent] perf annotate: Rename local sample variables to data
  2018-08-04 13:05 ` [PATCH 05/20] perf annotate: Rename local sample variables to data Jiri Olsa
  2018-08-06 15:09   ` Arnaldo Carvalho de Melo
@ 2018-08-18 11:27   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-08-18 11:27 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, jolsa, eranian, acme, alexander.shishkin, peterz,
	dsahern, mingo, namhyung, tglx, hpa

Commit-ID:  0440af74dcd0f32b134b1c4d47dc25f0bb539ded
Gitweb:     https://git.kernel.org/tip/0440af74dcd0f32b134b1c4d47dc25f0bb539ded
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sat, 4 Aug 2018 15:05:06 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Aug 2018 15:55:47 -0300

perf annotate: Rename local sample variables to data

Based on previous rename, changing also the local variable names to fit
properly.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20180804130521.11408-6-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/annotate.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index e4cb8963db1a..8bd278a71004 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1310,10 +1310,10 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 		struct annotation *notes = symbol__annotation(sym);
 
 		for (i = 0; i < al->data_nr; i++) {
-			struct annotation_data *sample = &al->data[i];
+			struct annotation_data *data = &al->data[i];
 
-			if (sample->percent > max_percent)
-				max_percent = sample->percent;
+			if (data->percent > max_percent)
+				max_percent = data->percent;
 		}
 
 		if (al->data_nr > nr_percent)
@@ -1351,18 +1351,18 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 		}
 
 		for (i = 0; i < nr_percent; i++) {
-			struct annotation_data *sample = &al->data[i];
+			struct annotation_data *data = &al->data[i];
 
-			color = get_percent_color(sample->percent);
+			color = get_percent_color(data->percent);
 
 			if (symbol_conf.show_total_period)
 				color_fprintf(stdout, color, " %11" PRIu64,
-					      sample->he.period);
+					      data->he.period);
 			else if (symbol_conf.show_nr_samples)
 				color_fprintf(stdout, color, " %7" PRIu64,
-					      sample->he.nr_samples);
+					      data->he.nr_samples);
 			else
-				color_fprintf(stdout, color, " %7.2f", sample->percent);
+				color_fprintf(stdout, color, " %7.2f", data->percent);
 		}
 
 		printf(" : ");
@@ -1754,7 +1754,7 @@ out_close_stdout:
 }
 
 static void calc_percent(struct sym_hist *hist,
-			 struct annotation_data *sample,
+			 struct annotation_data *data,
 			 s64 offset, s64 end)
 {
 	unsigned int hits = 0;
@@ -1767,9 +1767,9 @@ static void calc_percent(struct sym_hist *hist,
 	}
 
 	if (hist->nr_samples) {
-		sample->he.period     = period;
-		sample->he.nr_samples = hits;
-		sample->percent = 100.0 * hits / hist->nr_samples;
+		data->he.period     = period;
+		data->he.nr_samples = hits;
+		data->percent = 100.0 * hits / hist->nr_samples;
 	}
 }
 
@@ -1789,13 +1789,13 @@ static void annotation__calc_percent(struct annotation *notes,
 		end  = next ? next->offset : len;
 
 		for (i = 0; i < al->data_nr; i++) {
-			struct annotation_data *sample;
+			struct annotation_data *data;
 			struct sym_hist *hist;
 
-			hist   = annotation__histogram(notes, evsel->idx + i);
-			sample = &al->data[i];
+			hist = annotation__histogram(notes, evsel->idx + i);
+			data = &al->data[i];
 
-			calc_percent(hist, sample, al->offset, end);
+			calc_percent(hist, data, al->offset, end);
 		}
 	}
 }
@@ -2356,12 +2356,12 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map,
 		int i;
 
 		for (i = 0; i < al->data_nr; i++) {
-			struct annotation_data *sample;
+			struct annotation_data *data;
 
-			sample = &al->data[i];
+			data = &al->data[i];
 
-			if (sample->percent > percent_max)
-				percent_max = sample->percent;
+			if (data->percent > percent_max)
+				percent_max = data->percent;
 		}
 
 		if (percent_max <= 0.5)

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [tip:perf/urgent] perf annotate: Rename hist to sym_hist in annotation__calc_percent
  2018-08-04 13:05 ` [PATCH 06/20] perf annotate: Rename hist to sym_hist in annotation__calc_percent Jiri Olsa
  2018-08-06 15:10   ` Arnaldo Carvalho de Melo
@ 2018-08-18 11:28   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-08-18 11:28 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: peterz, tglx, mingo, namhyung, eranian, acme, dsahern,
	alexander.shishkin, linux-kernel, jolsa, hpa

Commit-ID:  48a1e4f2381387a097ea9f7897c5c32e9aaa708d
Gitweb:     https://git.kernel.org/tip/48a1e4f2381387a097ea9f7897c5c32e9aaa708d
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sat, 4 Aug 2018 15:05:07 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Aug 2018 15:55:47 -0300

perf annotate: Rename hist to sym_hist in annotation__calc_percent

We will need to bring in 'struct hists' variable in this scope, so it's
better we do this rename first.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20180804130521.11408-7-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/annotate.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 8bd278a71004..728603636adc 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1753,7 +1753,7 @@ out_close_stdout:
 	goto out_free_command;
 }
 
-static void calc_percent(struct sym_hist *hist,
+static void calc_percent(struct sym_hist *sym_hist,
 			 struct annotation_data *data,
 			 s64 offset, s64 end)
 {
@@ -1761,15 +1761,15 @@ static void calc_percent(struct sym_hist *hist,
 	u64 period = 0;
 
 	while (offset < end) {
-		hits   += hist->addr[offset].nr_samples;
-		period += hist->addr[offset].period;
+		hits   += sym_hist->addr[offset].nr_samples;
+		period += sym_hist->addr[offset].period;
 		++offset;
 	}
 
-	if (hist->nr_samples) {
+	if (sym_hist->nr_samples) {
 		data->he.period     = period;
 		data->he.nr_samples = hits;
-		data->percent = 100.0 * hits / hist->nr_samples;
+		data->percent = 100.0 * hits / sym_hist->nr_samples;
 	}
 }
 
@@ -1790,12 +1790,12 @@ static void annotation__calc_percent(struct annotation *notes,
 
 		for (i = 0; i < al->data_nr; i++) {
 			struct annotation_data *data;
-			struct sym_hist *hist;
+			struct sym_hist *sym_hist;
 
-			hist = annotation__histogram(notes, evsel->idx + i);
+			sym_hist = annotation__histogram(notes, evsel->idx + i);
 			data = &al->data[i];
 
-			calc_percent(hist, data, al->offset, end);
+			calc_percent(sym_hist, data, al->offset, end);
 		}
 	}
 }

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [tip:perf/urgent] perf annotate: Loop group events directly in annotation__calc_percent()
  2018-08-04 13:05 ` [PATCH 07/20] perf annotate: Loop group events directly " Jiri Olsa
  2018-08-06 15:12   ` Arnaldo Carvalho de Melo
@ 2018-08-18 11:28   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-08-18 11:28 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, alexander.shishkin, dsahern, hpa, linux-kernel, namhyung,
	eranian, tglx, peterz, mingo, jolsa

Commit-ID:  2bcf73069b0722c92a84c0fd57df542890a74904
Gitweb:     https://git.kernel.org/tip/2bcf73069b0722c92a84c0fd57df542890a74904
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sat, 4 Aug 2018 15:05:08 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Aug 2018 15:55:47 -0300

perf annotate: Loop group events directly in annotation__calc_percent()

We need to bring in 'struct hists' object and for that we need 'struct
perf_evsel' object in the scope.

Switching the group data loop with the evsel group loop.  It does the
same thing, but it brings evsel object, that we can use later get the
'struct hists' object.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20180804130521.11408-8-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/annotate.c | 13 ++++++++-----
 tools/perf/util/evsel.h    |  7 +++++++
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 728603636adc..34d4bb73aa84 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1774,13 +1774,14 @@ static void calc_percent(struct sym_hist *sym_hist,
 }
 
 static void annotation__calc_percent(struct annotation *notes,
-				     struct perf_evsel *evsel, s64 len)
+				     struct perf_evsel *leader, s64 len)
 {
 	struct annotation_line *al, *next;
+	struct perf_evsel *evsel;
 
 	list_for_each_entry(al, &notes->src->source, node) {
 		s64 end;
-		int i;
+		int i = 0;
 
 		if (al->offset == -1)
 			continue;
@@ -1788,12 +1789,14 @@ static void annotation__calc_percent(struct annotation *notes,
 		next = annotation_line__next(al, &notes->src->source);
 		end  = next ? next->offset : len;
 
-		for (i = 0; i < al->data_nr; i++) {
+		for_each_group_evsel(evsel, leader) {
 			struct annotation_data *data;
 			struct sym_hist *sym_hist;
 
-			sym_hist = annotation__histogram(notes, evsel->idx + i);
-			data = &al->data[i];
+			BUG_ON(i >= al->data_nr);
+
+			sym_hist = annotation__histogram(notes, evsel->idx);
+			data = &al->data[i++];
 
 			calc_percent(sym_hist, data, al->offset, end);
 		}
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 973c03167947..163c960614d3 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -452,11 +452,18 @@ static inline int perf_evsel__group_idx(struct perf_evsel *evsel)
 	return evsel->idx - evsel->leader->idx;
 }
 
+/* Iterates group WITHOUT the leader. */
 #define for_each_group_member(_evsel, _leader) 					\
 for ((_evsel) = list_entry((_leader)->node.next, struct perf_evsel, node); 	\
      (_evsel) && (_evsel)->leader == (_leader);					\
      (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node))
 
+/* Iterates group WITH the leader. */
+#define for_each_group_evsel(_evsel, _leader) 					\
+for ((_evsel) = _leader; 							\
+     (_evsel) && (_evsel)->leader == (_leader);					\
+     (_evsel) = list_entry((_evsel)->node.next, struct perf_evsel, node))
+
 static inline bool perf_evsel__has_branch_callstack(const struct perf_evsel *evsel)
 {
 	return evsel->attr.branch_sample_type & PERF_SAMPLE_BRANCH_CALL_STACK;

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [tip:perf/urgent] perf annotate: Switch struct annotation_data::percent to array
  2018-08-04 13:05 ` [PATCH 08/20] perf annotate: Switch struct annotation_data::percent to array Jiri Olsa
  2018-08-06 15:14   ` Arnaldo Carvalho de Melo
@ 2018-08-18 11:29   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-08-18 11:29 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: eranian, alexander.shishkin, tglx, dsahern, mingo, hpa, peterz,
	acme, jolsa, namhyung, linux-kernel

Commit-ID:  6d9f0c2d5ef7568c29fa5927748c4915a9c7760a
Gitweb:     https://git.kernel.org/tip/6d9f0c2d5ef7568c29fa5927748c4915a9c7760a
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sat, 4 Aug 2018 15:05:09 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Aug 2018 15:55:48 -0300

perf annotate: Switch struct annotation_data::percent to array

So we can hold multiple percent values for annotation line.

The first member of this array is current local hits percent value
(PERCENT_HITS_LOCAL index), so no functional change is expected.

Adding annotation_data__percent function to return requested percent
value from struct annotation_data.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20180804130521.11408-9-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/ui/browsers/annotate.c |  9 ++++---
 tools/perf/util/annotate.c        | 57 ++++++++++++++++++++++++++-------------
 tools/perf/util/annotate.h        | 13 ++++++++-
 3 files changed, 56 insertions(+), 23 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index d648d1e153f3..81876c3923d2 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -315,10 +315,13 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
 		}
 
 		for (i = 0; i < pos->al.data_nr; i++) {
-			struct annotation_data *sample = &pos->al.data[i];
+			double percent;
 
-			if (max_percent < sample->percent)
-				max_percent = sample->percent;
+			percent = annotation_data__percent(&pos->al.data[i],
+							   PERCENT_HITS_LOCAL);
+
+			if (max_percent < percent)
+				max_percent = percent;
 		}
 
 		if (max_percent < 0.01 && pos->al.ipc == 0) {
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 34d4bb73aa84..074adb2a831e 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1310,10 +1310,13 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 		struct annotation *notes = symbol__annotation(sym);
 
 		for (i = 0; i < al->data_nr; i++) {
-			struct annotation_data *data = &al->data[i];
+			double percent;
+
+			percent = annotation_data__percent(&al->data[i],
+							   PERCENT_HITS_LOCAL);
 
-			if (data->percent > max_percent)
-				max_percent = data->percent;
+			if (percent > max_percent)
+				max_percent = percent;
 		}
 
 		if (al->data_nr > nr_percent)
@@ -1352,8 +1355,10 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 
 		for (i = 0; i < nr_percent; i++) {
 			struct annotation_data *data = &al->data[i];
+			double percent;
 
-			color = get_percent_color(data->percent);
+			percent = annotation_data__percent(data, PERCENT_HITS_LOCAL);
+			color = get_percent_color(percent);
 
 			if (symbol_conf.show_total_period)
 				color_fprintf(stdout, color, " %11" PRIu64,
@@ -1362,7 +1367,7 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 				color_fprintf(stdout, color, " %7" PRIu64,
 					      data->he.nr_samples);
 			else
-				color_fprintf(stdout, color, " %7.2f", data->percent);
+				color_fprintf(stdout, color, " %7.2f", percent);
 		}
 
 		printf(" : ");
@@ -1769,7 +1774,7 @@ static void calc_percent(struct sym_hist *sym_hist,
 	if (sym_hist->nr_samples) {
 		data->he.period     = period;
 		data->he.nr_samples = hits;
-		data->percent = 100.0 * hits / sym_hist->nr_samples;
+		data->percent[PERCENT_HITS_LOCAL] = 100.0 * hits / sym_hist->nr_samples;
 	}
 }
 
@@ -1862,8 +1867,10 @@ static void insert_source_line(struct rb_root *root, struct annotation_line *al)
 
 		ret = strcmp(iter->path, al->path);
 		if (ret == 0) {
-			for (i = 0; i < al->data_nr; i++)
-				iter->data[i].percent_sum += al->data[i].percent;
+			for (i = 0; i < al->data_nr; i++) {
+				iter->data[i].percent_sum += annotation_data__percent(&al->data[i],
+										      PERCENT_HITS_LOCAL);
+			}
 			return;
 		}
 
@@ -1873,8 +1880,10 @@ static void insert_source_line(struct rb_root *root, struct annotation_line *al)
 			p = &(*p)->rb_right;
 	}
 
-	for (i = 0; i < al->data_nr; i++)
-		al->data[i].percent_sum = al->data[i].percent;
+	for (i = 0; i < al->data_nr; i++) {
+		al->data[i].percent_sum = annotation_data__percent(&al->data[i],
+								   PERCENT_HITS_LOCAL);
+	}
 
 	rb_link_node(&al->rb_node, parent, p);
 	rb_insert_color(&al->rb_node, root);
@@ -2359,12 +2368,13 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map,
 		int i;
 
 		for (i = 0; i < al->data_nr; i++) {
-			struct annotation_data *data;
+			double percent;
 
-			data = &al->data[i];
+			percent = annotation_data__percent(&al->data[i],
+							   PERCENT_HITS_LOCAL);
 
-			if (data->percent > percent_max)
-				percent_max = data->percent;
+			if (percent > percent_max)
+				percent_max = percent;
 		}
 
 		if (percent_max <= 0.5)
@@ -2451,8 +2461,13 @@ static double annotation_line__max_percent(struct annotation_line *al,
 	int i;
 
 	for (i = 0; i < notes->nr_events; i++) {
-		if (al->data[i].percent > percent_max)
-			percent_max = al->data[i].percent;
+		double percent;
+
+		percent = annotation_data__percent(&al->data[i],
+						   PERCENT_HITS_LOCAL);
+
+		if (percent > percent_max)
+			percent_max = percent;
 	}
 
 	return percent_max;
@@ -2518,15 +2533,19 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
 		int i;
 
 		for (i = 0; i < notes->nr_events; i++) {
-			obj__set_percent_color(obj, al->data[i].percent, current_entry);
+			double percent;
+
+			percent = annotation_data__percent(&al->data[i],
+							   PERCENT_HITS_LOCAL);
+
+			obj__set_percent_color(obj, percent, current_entry);
 			if (notes->options->show_total_period) {
 				obj__printf(obj, "%11" PRIu64 " ", al->data[i].he.period);
 			} else if (notes->options->show_nr_samples) {
 				obj__printf(obj, "%6" PRIu64 " ",
 						   al->data[i].he.nr_samples);
 			} else {
-				obj__printf(obj, "%6.2f ",
-						   al->data[i].percent);
+				obj__printf(obj, "%6.2f ", percent);
 			}
 		}
 	} else {
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 58aa14c55bab..0afbf8075fca 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -101,8 +101,13 @@ struct sym_hist_entry {
 	u64		period;
 };
 
+enum {
+	PERCENT_HITS_LOCAL,
+	PERCENT_MAX,
+};
+
 struct annotation_data {
-	double			 percent;
+	double			 percent[PERCENT_MAX];
 	double			 percent_sum;
 	struct sym_hist_entry	 he;
 };
@@ -134,6 +139,12 @@ struct disasm_line {
 	struct annotation_line	 al;
 };
 
+static inline double annotation_data__percent(struct annotation_data *data,
+					      unsigned int which)
+{
+	return which < PERCENT_MAX ? data->percent[which] : -1;
+}
+
 static inline struct disasm_line *disasm_line(struct annotation_line *al)
 {
 	return al ? container_of(al, struct disasm_line, al) : NULL;

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [tip:perf/urgent] perf annotate: Add PERCENT_HITS_GLOBAL percent value
  2018-08-04 13:05 ` [PATCH 09/20] perf annotate: Add PERCENT_HITS_GLOBAL percent value Jiri Olsa
  2018-08-06 15:15   ` Arnaldo Carvalho de Melo
@ 2018-08-18 11:29   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-08-18 11:29 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: alexander.shishkin, acme, jolsa, peterz, mingo, tglx, dsahern,
	eranian, linux-kernel, hpa, namhyung

Commit-ID:  75a8c1ff287b2a949b50c1c1e58a6492e21a3ac5
Gitweb:     https://git.kernel.org/tip/75a8c1ff287b2a949b50c1c1e58a6492e21a3ac5
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sat, 4 Aug 2018 15:05:10 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Aug 2018 15:55:48 -0300

perf annotate: Add PERCENT_HITS_GLOBAL percent value

Adding and computing global hits percent value for annotation line.
Storing it in struct annotation_data percent array under new
PERCENT_HITS_GLOBAL index.

At the moment it's not displayed, it's coming in following patches.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20180804130521.11408-10-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/annotate.c | 8 +++++++-
 tools/perf/util/annotate.h | 1 +
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 074adb2a831e..b7485a512da1 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1759,6 +1759,7 @@ out_close_stdout:
 }
 
 static void calc_percent(struct sym_hist *sym_hist,
+			 struct hists *hists,
 			 struct annotation_data *data,
 			 s64 offset, s64 end)
 {
@@ -1776,6 +1777,10 @@ static void calc_percent(struct sym_hist *sym_hist,
 		data->he.nr_samples = hits;
 		data->percent[PERCENT_HITS_LOCAL] = 100.0 * hits / sym_hist->nr_samples;
 	}
+
+	if (hists->stats.nr_non_filtered_samples)
+		data->percent[PERCENT_HITS_GLOBAL] = 100.0 * hits / hists->stats.nr_non_filtered_samples;
+
 }
 
 static void annotation__calc_percent(struct annotation *notes,
@@ -1795,6 +1800,7 @@ static void annotation__calc_percent(struct annotation *notes,
 		end  = next ? next->offset : len;
 
 		for_each_group_evsel(evsel, leader) {
+			struct hists *hists = evsel__hists(evsel);
 			struct annotation_data *data;
 			struct sym_hist *sym_hist;
 
@@ -1803,7 +1809,7 @@ static void annotation__calc_percent(struct annotation *notes,
 			sym_hist = annotation__histogram(notes, evsel->idx);
 			data = &al->data[i++];
 
-			calc_percent(sym_hist, data, al->offset, end);
+			calc_percent(sym_hist, hists, data, al->offset, end);
 		}
 	}
 }
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 0afbf8075fca..3a06cb2b6e28 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -103,6 +103,7 @@ struct sym_hist_entry {
 
 enum {
 	PERCENT_HITS_LOCAL,
+	PERCENT_HITS_GLOBAL,
 	PERCENT_MAX,
 };
 

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [tip:perf/urgent] perf annotate: Add PERCENT_PERIOD_LOCAL percent value
  2018-08-04 13:05 ` [PATCH 10/20] perf annotate: Add PERCENT_PERIOD_LOCAL " Jiri Olsa
  2018-08-06 15:16   ` Arnaldo Carvalho de Melo
@ 2018-08-18 11:30   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-08-18 11:30 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: alexander.shishkin, mingo, linux-kernel, namhyung, acme, tglx,
	peterz, jolsa, eranian, hpa, dsahern

Commit-ID:  ab371169fb7db9587f09137e93a49c6afeab16f7
Gitweb:     https://git.kernel.org/tip/ab371169fb7db9587f09137e93a49c6afeab16f7
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sat, 4 Aug 2018 15:05:11 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Aug 2018 15:55:49 -0300

perf annotate: Add PERCENT_PERIOD_LOCAL percent value

Adding and computing local period percent value for annotation line.
Storing it in struct annotation_data percent array under new
PERCENT_PERIOD_LOCAL index.

At the moment it's not displayed, it's coming in following patches.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20180804130521.11408-11-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/annotate.c | 2 ++
 tools/perf/util/annotate.h | 1 +
 2 files changed, 3 insertions(+)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index b7485a512da1..b37e8cc18668 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1781,6 +1781,8 @@ static void calc_percent(struct sym_hist *sym_hist,
 	if (hists->stats.nr_non_filtered_samples)
 		data->percent[PERCENT_HITS_GLOBAL] = 100.0 * hits / hists->stats.nr_non_filtered_samples;
 
+	if (sym_hist->period)
+		data->percent[PERCENT_PERIOD_LOCAL] = 100.0 * period / sym_hist->period;
 }
 
 static void annotation__calc_percent(struct annotation *notes,
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 3a06cb2b6e28..890b6869caa9 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -104,6 +104,7 @@ struct sym_hist_entry {
 enum {
 	PERCENT_HITS_LOCAL,
 	PERCENT_HITS_GLOBAL,
+	PERCENT_PERIOD_LOCAL,
 	PERCENT_MAX,
 };
 

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [tip:perf/urgent] perf annotate: Add PERCENT_PERIOD_GLOBAL percent value
  2018-08-04 13:05 ` [PATCH 11/20] perf annotate: Add PERCENT_PERIOD_GLOBAL " Jiri Olsa
  2018-08-06 15:16   ` Arnaldo Carvalho de Melo
@ 2018-08-18 11:30   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-08-18 11:30 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, eranian, dsahern, mingo, tglx, peterz, alexander.shishkin,
	acme, namhyung, jolsa, linux-kernel

Commit-ID:  e58684df912906d944967e2ce0f3ed5d5140d1e5
Gitweb:     https://git.kernel.org/tip/e58684df912906d944967e2ce0f3ed5d5140d1e5
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sat, 4 Aug 2018 15:05:12 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Aug 2018 15:55:49 -0300

perf annotate: Add PERCENT_PERIOD_GLOBAL percent value

Adding and computing global period percent value for annotation line.
Storing it in struct annotation_data percent array under new
PERCENT_PERIOD_GLOBAL index.

At the moment it's not displayed, it's coming in following patches.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20180804130521.11408-12-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/annotate.c | 3 +++
 tools/perf/util/annotate.h | 1 +
 2 files changed, 4 insertions(+)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index b37e8cc18668..e890164592b0 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1783,6 +1783,9 @@ static void calc_percent(struct sym_hist *sym_hist,
 
 	if (sym_hist->period)
 		data->percent[PERCENT_PERIOD_LOCAL] = 100.0 * period / sym_hist->period;
+
+	if (hists->stats.total_period)
+		data->percent[PERCENT_PERIOD_GLOBAL] = 100.0 * period / hists->stats.total_period;
 }
 
 static void annotation__calc_percent(struct annotation *notes,
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 890b6869caa9..48fe2aa6b5a8 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -105,6 +105,7 @@ enum {
 	PERCENT_HITS_LOCAL,
 	PERCENT_HITS_GLOBAL,
 	PERCENT_PERIOD_LOCAL,
+	PERCENT_PERIOD_GLOBAL,
 	PERCENT_MAX,
 };
 

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [tip:perf/urgent] perf annotate: Add percent_type to struct annotation_options
  2018-08-04 13:05 ` [PATCH 12/20] perf annotate: Add percent_type to struct annotation_options Jiri Olsa
  2018-08-06 15:17   ` Arnaldo Carvalho de Melo
@ 2018-08-18 11:31   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-08-18 11:31 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: alexander.shishkin, dsahern, peterz, acme, linux-kernel, eranian,
	mingo, jolsa, tglx, namhyung, hpa

Commit-ID:  796ca33d5ceb621f238021c34cff8cfaa1100623
Gitweb:     https://git.kernel.org/tip/796ca33d5ceb621f238021c34cff8cfaa1100623
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sat, 4 Aug 2018 15:05:13 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Aug 2018 15:55:50 -0300

perf annotate: Add percent_type to struct annotation_options

It will be used to carry user selection of percent type for annotation
output.

Passing the percent_type to the annotation_line__print function as the
first step and making it default to current percentage type
(PERCENT_HITS_LOCAL) value.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20180804130521.11408-13-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/annotate.c | 13 ++++++++-----
 tools/perf/util/annotate.h |  1 +
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index e890164592b0..91528a065768 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -49,6 +49,7 @@ struct annotation_options annotation__default_options = {
 	.jump_arrows    = true,
 	.annotate_src	= true,
 	.offset_level	= ANNOTATION__OFFSET_JUMP_TARGETS,
+	.percent_type	= PERCENT_HITS_LOCAL,
 };
 
 static regex_t	 file_lineno;
@@ -1297,7 +1298,8 @@ static int disasm_line__print(struct disasm_line *dl, u64 start, int addr_fmt_wi
 static int
 annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start,
 		       struct perf_evsel *evsel, u64 len, int min_pcnt, int printed,
-		       int max_lines, struct annotation_line *queue, int addr_fmt_width)
+		       int max_lines, struct annotation_line *queue, int addr_fmt_width,
+		       int percent_type)
 {
 	struct disasm_line *dl = container_of(al, struct disasm_line, al);
 	static const char *prev_line;
@@ -1313,7 +1315,7 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 			double percent;
 
 			percent = annotation_data__percent(&al->data[i],
-							   PERCENT_HITS_LOCAL);
+							   percent_type);
 
 			if (percent > max_percent)
 				max_percent = percent;
@@ -1333,7 +1335,8 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 				if (queue == al)
 					break;
 				annotation_line__print(queue, sym, start, evsel, len,
-						       0, 0, 1, NULL, addr_fmt_width);
+						       0, 0, 1, NULL, addr_fmt_width,
+						       percent_type);
 			}
 		}
 
@@ -1357,7 +1360,7 @@ annotation_line__print(struct annotation_line *al, struct symbol *sym, u64 start
 			struct annotation_data *data = &al->data[i];
 			double percent;
 
-			percent = annotation_data__percent(data, PERCENT_HITS_LOCAL);
+			percent = annotation_data__percent(data, percent_type);
 			color = get_percent_color(percent);
 
 			if (symbol_conf.show_total_period)
@@ -2075,7 +2078,7 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map,
 
 		err = annotation_line__print(pos, sym, start, evsel, len,
 					     opts->min_pcnt, printed, opts->max_lines,
-					     queue, addr_fmt_width);
+					     queue, addr_fmt_width, opts->percent_type);
 
 		switch (err) {
 		case 0:
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 48fe2aa6b5a8..145dec845f33 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -82,6 +82,7 @@ struct annotation_options {
 	int  context;
 	const char *objdump_path;
 	const char *disassembler_style;
+	unsigned int percent_type;
 };
 
 enum {

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [tip:perf/urgent] perf annotate: Pass struct annotation_options to symbol__calc_lines()
  2018-08-04 13:05 ` [PATCH 13/20] perf annotate: Pass struct annotation_options to symbol__calc_lines Jiri Olsa
  2018-08-06 15:18   ` Arnaldo Carvalho de Melo
@ 2018-08-18 11:32   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-08-18 11:32 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, alexander.shishkin, mingo, dsahern, hpa, linux-kernel,
	jolsa, namhyung, peterz, eranian, tglx

Commit-ID:  c849c12cf344e4b99dbf98df642b622b6c91bbfd
Gitweb:     https://git.kernel.org/tip/c849c12cf344e4b99dbf98df642b622b6c91bbfd
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sat, 4 Aug 2018 15:05:14 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Aug 2018 15:55:50 -0300

perf annotate: Pass struct annotation_options to symbol__calc_lines()

Pass struct annotation_options to symbol__calc_lines(), to carry on and
pass the percent_type value.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20180804130521.11408-14-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/annotate.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 91528a065768..2b06476c79c2 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -1868,7 +1868,8 @@ int symbol__annotate(struct symbol *sym, struct map *map,
 	return symbol__disassemble(sym, &args);
 }
 
-static void insert_source_line(struct rb_root *root, struct annotation_line *al)
+static void insert_source_line(struct rb_root *root, struct annotation_line *al,
+			       struct annotation_options *opts)
 {
 	struct annotation_line *iter;
 	struct rb_node **p = &root->rb_node;
@@ -1883,7 +1884,7 @@ static void insert_source_line(struct rb_root *root, struct annotation_line *al)
 		if (ret == 0) {
 			for (i = 0; i < al->data_nr; i++) {
 				iter->data[i].percent_sum += annotation_data__percent(&al->data[i],
-										      PERCENT_HITS_LOCAL);
+										      opts->percent_type);
 			}
 			return;
 		}
@@ -1896,7 +1897,7 @@ static void insert_source_line(struct rb_root *root, struct annotation_line *al)
 
 	for (i = 0; i < al->data_nr; i++) {
 		al->data[i].percent_sum = annotation_data__percent(&al->data[i],
-								   PERCENT_HITS_LOCAL);
+								   opts->percent_type);
 	}
 
 	rb_link_node(&al->rb_node, parent, p);
@@ -2372,7 +2373,8 @@ void annotation__update_column_widths(struct annotation *notes)
 }
 
 static void annotation__calc_lines(struct annotation *notes, struct map *map,
-				  struct rb_root *root)
+				   struct rb_root *root,
+				   struct annotation_options *opts)
 {
 	struct annotation_line *al;
 	struct rb_root tmp_root = RB_ROOT;
@@ -2385,7 +2387,7 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map,
 			double percent;
 
 			percent = annotation_data__percent(&al->data[i],
-							   PERCENT_HITS_LOCAL);
+							   opts->percent_type);
 
 			if (percent > percent_max)
 				percent_max = percent;
@@ -2396,18 +2398,19 @@ static void annotation__calc_lines(struct annotation *notes, struct map *map,
 
 		al->path = get_srcline(map->dso, notes->start + al->offset, NULL,
 				       false, true, notes->start + al->offset);
-		insert_source_line(&tmp_root, al);
+		insert_source_line(&tmp_root, al, opts);
 	}
 
 	resort_source_line(root, &tmp_root);
 }
 
 static void symbol__calc_lines(struct symbol *sym, struct map *map,
-			      struct rb_root *root)
+			       struct rb_root *root,
+			       struct annotation_options *opts)
 {
 	struct annotation *notes = symbol__annotation(sym);
 
-	annotation__calc_lines(notes, map, root);
+	annotation__calc_lines(notes, map, root, opts);
 }
 
 int symbol__tty_annotate2(struct symbol *sym, struct map *map,
@@ -2424,7 +2427,7 @@ int symbol__tty_annotate2(struct symbol *sym, struct map *map,
 
 	if (opts->print_lines) {
 		srcline_full_filename = opts->full_path;
-		symbol__calc_lines(sym, map, &source_line);
+		symbol__calc_lines(sym, map, &source_line, opts);
 		print_summary(&source_line, dso->long_name);
 	}
 
@@ -2451,7 +2454,7 @@ int symbol__tty_annotate(struct symbol *sym, struct map *map,
 
 	if (opts->print_lines) {
 		srcline_full_filename = opts->full_path;
-		symbol__calc_lines(sym, map, &source_line);
+		symbol__calc_lines(sym, map, &source_line, opts);
 		print_summary(&source_line, dso->long_name);
 	}
 

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [tip:perf/urgent] perf annotate: Pass 'struct annotation_options' to map_symbol__annotation_dump()
  2018-08-04 13:05 ` [PATCH 14/20] perf annotate: Pass struct annotation_options to map_symbol__annotation_dump Jiri Olsa
  2018-08-06 13:45   ` Namhyung Kim
@ 2018-08-18 11:32   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-08-18 11:32 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: alexander.shishkin, tglx, hpa, acme, eranian, linux-kernel,
	peterz, dsahern, namhyung, mingo, jolsa

Commit-ID:  4c650ddc2e9e8f1d8dc46f13b30b1b9a6017fb02
Gitweb:     https://git.kernel.org/tip/4c650ddc2e9e8f1d8dc46f13b30b1b9a6017fb02
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sat, 4 Aug 2018 15:05:15 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Aug 2018 15:55:51 -0300

perf annotate: Pass 'struct annotation_options' to map_symbol__annotation_dump()

Pass 'struct annotation_options' to map_symbol__annotation_dump(), to
carry on and pass the percent_type value.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20180804130521.11408-15-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/ui/browsers/annotate.c |  4 ++--
 tools/perf/util/annotate.c        | 42 +++++++++++++++++++++------------------
 tools/perf/util/annotate.h        |  6 ++++--
 3 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 81876c3923d2..cfe611c28987 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -115,7 +115,7 @@ static void annotate_browser__write(struct ui_browser *browser, void *entry, int
 	if (!browser->navkeypressed)
 		ops.width += 1;
 
-	annotation_line__write(al, notes, &ops);
+	annotation_line__write(al, notes, &ops, ab->opts);
 
 	if (ops.current_entry)
 		ab->selection = al;
@@ -783,7 +783,7 @@ show_sup_ins:
 			continue;
 		}
 		case 'P':
-			map_symbol__annotation_dump(ms, evsel);
+			map_symbol__annotation_dump(ms, evsel, browser->opts);
 			continue;
 		case 't':
 			if (notes->options->show_total_period) {
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 2b06476c79c2..850958bb613a 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2156,10 +2156,11 @@ static void FILE__write_graph(void *fp, int graph)
 	fputs(s, fp);
 }
 
-static int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp)
+static int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp,
+				     struct annotation_options *opts)
 {
 	struct annotation *notes = symbol__annotation(sym);
-	struct annotation_write_ops ops = {
+	struct annotation_write_ops wops = {
 		.first_line		 = true,
 		.obj			 = fp,
 		.set_color		 = FILE__set_color,
@@ -2173,15 +2174,16 @@ static int symbol__annotate_fprintf2(struct symbol *sym, FILE *fp)
 	list_for_each_entry(al, &notes->src->source, node) {
 		if (annotation_line__filter(al, notes))
 			continue;
-		annotation_line__write(al, notes, &ops);
+		annotation_line__write(al, notes, &wops, opts);
 		fputc('\n', fp);
-		ops.first_line = false;
+		wops.first_line = false;
 	}
 
 	return 0;
 }
 
-int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel)
+int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel,
+				struct annotation_options *opts)
 {
 	const char *ev_name = perf_evsel__name(evsel);
 	char buf[1024];
@@ -2203,7 +2205,7 @@ int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel)
 
 	fprintf(fp, "%s() %s\nEvent: %s\n\n",
 		ms->sym->name, ms->map->dso->long_name, ev_name);
-	symbol__annotate_fprintf2(ms->sym, fp);
+	symbol__annotate_fprintf2(ms->sym, fp, opts);
 
 	fclose(fp);
 	err = 0;
@@ -2433,7 +2435,7 @@ int symbol__tty_annotate2(struct symbol *sym, struct map *map,
 
 	hists__scnprintf_title(hists, buf, sizeof(buf));
 	fprintf(stdout, "%s\n%s() %s\n", buf, sym->name, dso->long_name);
-	symbol__annotate_fprintf2(sym, stdout);
+	symbol__annotate_fprintf2(sym, stdout, opts);
 
 	annotated_source__purge(symbol__annotation(sym)->src);
 
@@ -2472,7 +2474,8 @@ bool ui__has_annotation(void)
 
 
 static double annotation_line__max_percent(struct annotation_line *al,
-					   struct annotation *notes)
+					   struct annotation *notes,
+					   unsigned int percent_type)
 {
 	double percent_max = 0.0;
 	int i;
@@ -2481,7 +2484,7 @@ static double annotation_line__max_percent(struct annotation_line *al,
 		double percent;
 
 		percent = annotation_data__percent(&al->data[i],
-						   PERCENT_HITS_LOCAL);
+						   percent_type);
 
 		if (percent > percent_max)
 			percent_max = percent;
@@ -2523,7 +2526,7 @@ call_like:
 
 static void __annotation_line__write(struct annotation_line *al, struct annotation *notes,
 				     bool first_line, bool current_entry, bool change_color, int width,
-				     void *obj,
+				     void *obj, unsigned int percent_type,
 				     int  (*obj__set_color)(void *obj, int color),
 				     void (*obj__set_percent_color)(void *obj, double percent, bool current),
 				     int  (*obj__set_jumps_percent_color)(void *obj, int nr, bool current),
@@ -2531,7 +2534,7 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
 				     void (*obj__write_graph)(void *obj, int graph))
 
 {
-	double percent_max = annotation_line__max_percent(al, notes);
+	double percent_max = annotation_line__max_percent(al, notes, percent_type);
 	int pcnt_width = annotation__pcnt_width(notes),
 	    cycles_width = annotation__cycles_width(notes);
 	bool show_title = false;
@@ -2552,8 +2555,7 @@ static void __annotation_line__write(struct annotation_line *al, struct annotati
 		for (i = 0; i < notes->nr_events; i++) {
 			double percent;
 
-			percent = annotation_data__percent(&al->data[i],
-							   PERCENT_HITS_LOCAL);
+			percent = annotation_data__percent(&al->data[i], percent_type);
 
 			obj__set_percent_color(obj, percent, current_entry);
 			if (notes->options->show_total_period) {
@@ -2680,13 +2682,15 @@ print_addr:
 }
 
 void annotation_line__write(struct annotation_line *al, struct annotation *notes,
-			    struct annotation_write_ops *ops)
+			    struct annotation_write_ops *wops,
+			    struct annotation_options *opts)
 {
-	__annotation_line__write(al, notes, ops->first_line, ops->current_entry,
-				 ops->change_color, ops->width, ops->obj,
-				 ops->set_color, ops->set_percent_color,
-				 ops->set_jumps_percent_color, ops->printf,
-				 ops->write_graph);
+	__annotation_line__write(al, notes, wops->first_line, wops->current_entry,
+				 wops->change_color, wops->width, wops->obj,
+				 opts->percent_type,
+				 wops->set_color, wops->set_percent_color,
+				 wops->set_jumps_percent_color, wops->printf,
+				 wops->write_graph);
 }
 
 int symbol__annotate2(struct symbol *sym, struct map *map, struct perf_evsel *evsel,
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 145dec845f33..3d4579e68d28 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -185,7 +185,8 @@ struct annotation_write_ops {
 };
 
 void annotation_line__write(struct annotation_line *al, struct annotation *notes,
-			    struct annotation_write_ops *ops);
+			    struct annotation_write_ops *ops,
+			    struct annotation_options *opts);
 
 int __annotation__scnprintf_samples_period(struct annotation *notes,
 					   char *bf, size_t size,
@@ -351,7 +352,8 @@ void symbol__annotate_zero_histogram(struct symbol *sym, int evidx);
 void symbol__annotate_decay_histogram(struct symbol *sym, int evidx);
 void annotated_source__purge(struct annotated_source *as);
 
-int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel);
+int map_symbol__annotation_dump(struct map_symbol *ms, struct perf_evsel *evsel,
+				struct annotation_options *opts);
 
 bool ui__has_annotation(void);
 

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [tip:perf/urgent] perf annotate: Pass browser percent_type in annotate_browser__calc_percent()
  2018-08-04 13:05 ` [PATCH 15/20] perf annotate: Pass browser percent_type in annotate_browser__calc_percent Jiri Olsa
  2018-08-06 15:23   ` Arnaldo Carvalho de Melo
@ 2018-08-18 11:33   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-08-18 11:33 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, linux-kernel, acme, mingo, hpa, jolsa, dsahern, namhyung,
	eranian, alexander.shishkin, peterz

Commit-ID:  d4265b1a1b9b58df9c3bc0a3a7aa5b72c079c77a
Gitweb:     https://git.kernel.org/tip/d4265b1a1b9b58df9c3bc0a3a7aa5b72c079c77a
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sat, 4 Aug 2018 15:05:16 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Aug 2018 15:55:51 -0300

perf annotate: Pass browser percent_type in annotate_browser__calc_percent()

Pass browser percent_type in annotate_browser__calc_percent().

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20180804130521.11408-16-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/ui/browsers/annotate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index cfe611c28987..2a3a34d450d5 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -318,7 +318,7 @@ static void annotate_browser__calc_percent(struct annotate_browser *browser,
 			double percent;
 
 			percent = annotation_data__percent(&pos->al.data[i],
-							   PERCENT_HITS_LOCAL);
+							   browser->opts->percent_type);
 
 			if (max_percent < percent)
 				max_percent = percent;

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [tip:perf/urgent] perf annotate: Add support to toggle percent type
  2018-08-04 13:05 ` [PATCH 16/20] perf annotate: Add support to togle percent type Jiri Olsa
  2018-08-06 18:24   ` Arnaldo Carvalho de Melo
@ 2018-08-18 11:33   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-08-18 11:33 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, acme, eranian, dsahern, peterz, mingo, namhyung,
	jolsa, alexander.shishkin, hpa, tglx

Commit-ID:  3e0d79531984c731951d9a8a5be406df3a78ac97
Gitweb:     https://git.kernel.org/tip/3e0d79531984c731951d9a8a5be406df3a78ac97
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sat, 4 Aug 2018 15:05:17 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Aug 2018 15:55:52 -0300

perf annotate: Add support to toggle percent type

Add new key bindings to toggle percent type/base in annotation UI browser:

 'p' to switch between local and global percent type
 'b' to switch between hits and perdio percent base

Add the following help messages to the UI browser '?' window:

  ...
  p             Toggle percent type [local/global]
  b             Toggle percent base [period/hits]
  ...

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20180804130521.11408-17-jolsa@kernel.org
[ Moved percent_type to be the last arg to sym_title(), its an arg to what is being formmated (buf, size) ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/ui/browsers/annotate.c | 52 ++++++++++++++++++++++++++++++++++++---
 tools/perf/util/annotate.h        | 16 ++++++++++++
 2 files changed, 64 insertions(+), 4 deletions(-)

diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 2a3a34d450d5..1d00e5ec7906 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -15,6 +15,7 @@
 #include <linux/kernel.h>
 #include <linux/string.h>
 #include <sys/ttydefaults.h>
+#include <asm/bug.h>
 
 struct disasm_line_samples {
 	double		      percent;
@@ -383,9 +384,10 @@ static void ui_browser__init_asm_mode(struct ui_browser *browser)
 #define SYM_TITLE_MAX_SIZE (PATH_MAX + 64)
 
 static int sym_title(struct symbol *sym, struct map *map, char *title,
-		     size_t sz)
+		     size_t sz, int percent_type)
 {
-	return snprintf(title, sz, "%s  %s", sym->name, map->dso->long_name);
+	return snprintf(title, sz, "%s  %s [Percent: %s]", sym->name, map->dso->long_name,
+			percent_type_str(percent_type));
 }
 
 /*
@@ -423,7 +425,7 @@ static bool annotate_browser__callq(struct annotate_browser *browser,
 
 	pthread_mutex_unlock(&notes->lock);
 	symbol__tui_annotate(dl->ops.target.sym, ms->map, evsel, hbt, browser->opts);
-	sym_title(ms->sym, ms->map, title, sizeof(title));
+	sym_title(ms->sym, ms->map, title, sizeof(title), browser->opts->percent_type);
 	ui_browser__show_title(&browser->b, title);
 	return true;
 }
@@ -598,6 +600,7 @@ bool annotate_browser__continue_search_reverse(struct annotate_browser *browser,
 
 static int annotate_browser__show(struct ui_browser *browser, char *title, const char *help)
 {
+	struct annotate_browser *ab = container_of(browser, struct annotate_browser, b);
 	struct map_symbol *ms = browser->priv;
 	struct symbol *sym = ms->sym;
 	char symbol_dso[SYM_TITLE_MAX_SIZE];
@@ -605,7 +608,7 @@ static int annotate_browser__show(struct ui_browser *browser, char *title, const
 	if (ui_browser__show(browser, title, help) < 0)
 		return -1;
 
-	sym_title(sym, ms->map, symbol_dso, sizeof(symbol_dso));
+	sym_title(sym, ms->map, symbol_dso, sizeof(symbol_dso), ab->opts->percent_type);
 
 	ui_browser__gotorc_title(browser, 0, 0);
 	ui_browser__set_color(browser, HE_COLORSET_ROOT);
@@ -613,6 +616,39 @@ static int annotate_browser__show(struct ui_browser *browser, char *title, const
 	return 0;
 }
 
+static void
+switch_percent_type(struct annotation_options *opts, bool base)
+{
+	switch (opts->percent_type) {
+	case PERCENT_HITS_LOCAL:
+		if (base)
+			opts->percent_type = PERCENT_PERIOD_LOCAL;
+		else
+			opts->percent_type = PERCENT_HITS_GLOBAL;
+		break;
+	case PERCENT_HITS_GLOBAL:
+		if (base)
+			opts->percent_type = PERCENT_PERIOD_GLOBAL;
+		else
+			opts->percent_type = PERCENT_HITS_LOCAL;
+		break;
+	case PERCENT_PERIOD_LOCAL:
+		if (base)
+			opts->percent_type = PERCENT_HITS_LOCAL;
+		else
+			opts->percent_type = PERCENT_PERIOD_GLOBAL;
+		break;
+	case PERCENT_PERIOD_GLOBAL:
+		if (base)
+			opts->percent_type = PERCENT_HITS_GLOBAL;
+		else
+			opts->percent_type = PERCENT_PERIOD_LOCAL;
+		break;
+	default:
+		WARN_ON(1);
+	}
+}
+
 static int annotate_browser__run(struct annotate_browser *browser,
 				 struct perf_evsel *evsel,
 				 struct hist_browser_timer *hbt)
@@ -703,6 +739,8 @@ static int annotate_browser__run(struct annotate_browser *browser,
 		"k             Toggle line numbers\n"
 		"P             Print to [symbol_name].annotation file.\n"
 		"r             Run available scripts\n"
+		"p             Toggle percent type [local/global]\n"
+		"b             Toggle percent base [period/hits]\n"
 		"?             Search string backwards\n");
 			continue;
 		case 'r':
@@ -802,6 +840,12 @@ show_sup_ins:
 				notes->options->show_minmax_cycle = true;
 			annotation__update_column_widths(notes);
 			continue;
+		case 'p':
+		case 'b':
+			switch_percent_type(browser->opts, key == 'b');
+			hists__scnprintf_title(hists, title, sizeof(title));
+			annotate_browser__show(&browser->b, title, help);
+			continue;
 		case K_LEFT:
 		case K_ESC:
 		case 'q':
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 3d4579e68d28..760a6678edff 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -11,6 +11,7 @@
 #include <linux/list.h>
 #include <linux/rbtree.h>
 #include <pthread.h>
+#include <asm/bug.h>
 
 struct ins_ops;
 
@@ -149,6 +150,21 @@ static inline double annotation_data__percent(struct annotation_data *data,
 	return which < PERCENT_MAX ? data->percent[which] : -1;
 }
 
+static inline const char *percent_type_str(unsigned int type)
+{
+	static const char *str[PERCENT_MAX] = {
+		"local hits",
+		"global hits",
+		"local period",
+		"global period",
+	};
+
+	if (WARN_ON(type >= PERCENT_MAX))
+		return "N/A";
+
+	return str[type];
+}
+
 static inline struct disasm_line *disasm_line(struct annotation_line *al)
 {
 	return al ? container_of(al, struct disasm_line, al) : NULL;

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [tip:perf/urgent] perf annotate: Make local period the default percent type
  2018-08-04 13:05 ` [PATCH 17/20] perf annotate: Make local period the default " Jiri Olsa
  2018-08-06 18:26   ` Arnaldo Carvalho de Melo
@ 2018-08-18 11:34   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-08-18 11:34 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: alexander.shishkin, hpa, mingo, eranian, peterz, jolsa, acme,
	linux-kernel, namhyung, tglx, dsahern

Commit-ID:  addba8b66f9101b0e55a151fc543ff35990bc8ef
Gitweb:     https://git.kernel.org/tip/addba8b66f9101b0e55a151fc543ff35990bc8ef
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sat, 4 Aug 2018 15:05:18 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Aug 2018 15:55:52 -0300

perf annotate: Make local period the default percent type

Currently we display the percentages in annotation output based on
number of samples hits. Switching it to period based percentage by
default, because it corresponds more to the time spent on the line.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20180804130521.11408-18-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/annotate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 850958bb613a..05d15629afd0 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -49,7 +49,7 @@ struct annotation_options annotation__default_options = {
 	.jump_arrows    = true,
 	.annotate_src	= true,
 	.offset_level	= ANNOTATION__OFFSET_JUMP_TARGETS,
-	.percent_type	= PERCENT_HITS_LOCAL,
+	.percent_type	= PERCENT_PERIOD_LOCAL,
 };
 
 static regex_t	 file_lineno;

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [tip:perf/urgent] perf annotate: Display percent type in stdio output
  2018-08-04 13:05 ` [PATCH 18/20] perf annotate: Display percent type in stdio output Jiri Olsa
  2018-08-06 18:27   ` Arnaldo Carvalho de Melo
@ 2018-08-18 11:34   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-08-18 11:34 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: alexander.shishkin, dsahern, jolsa, tglx, peterz, mingo, hpa,
	eranian, linux-kernel, acme, namhyung

Commit-ID:  4c04868fbe931ec315ad34bb7e28e5cf725f88e4
Gitweb:     https://git.kernel.org/tip/4c04868fbe931ec315ad34bb7e28e5cf725f88e4
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sat, 4 Aug 2018 15:05:19 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Aug 2018 15:55:53 -0300

perf annotate: Display percent type in stdio output

In following patches we will allow to switch percent type even for stdio
annotation outputs. Adding the percent type value into the annotation
outputs title.

  $ perf annotate --stdio
   Percent         |      Sou ... instructions:u } (2805 samples, percent: local period)
  --------------------------- ... ------------------------------------------------------
  ...

  $ perf annotate --stdio2
  Samples: 2K of events 'anon ...  count (approx.): 156525487, [percent: local period]
  safe_write.c() /usr/bin/yes
  Percent
  ...

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20180804130521.11408-19-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/annotate.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 05d15629afd0..6316fa96d984 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2056,10 +2056,12 @@ int symbol__annotate_printf(struct symbol *sym, struct map *map,
 		evsel_name = buf;
 	}
 
-	graph_dotted_len = printf(" %-*.*s|	Source code & Disassembly of %s for %s (%" PRIu64 " samples)\n",
+	graph_dotted_len = printf(" %-*.*s|	Source code & Disassembly of %s for %s (%" PRIu64 " samples, "
+				  "percent: %s)\n",
 				  width, width, symbol_conf.show_total_period ? "Period" :
 				  symbol_conf.show_nr_samples ? "Samples" : "Percent",
-				  d_filename, evsel_name, h->nr_samples);
+				  d_filename, evsel_name, h->nr_samples,
+				  percent_type_str(opts->percent_type));
 
 	printf("%-*.*s----\n",
 	       graph_dotted_len, graph_dotted_len, graph_dotted_line);
@@ -2434,7 +2436,8 @@ int symbol__tty_annotate2(struct symbol *sym, struct map *map,
 	}
 
 	hists__scnprintf_title(hists, buf, sizeof(buf));
-	fprintf(stdout, "%s\n%s() %s\n", buf, sym->name, dso->long_name);
+	fprintf(stdout, "%s, [percent: %s]\n%s() %s\n",
+		buf, percent_type_str(opts->percent_type), sym->name, dso->long_name);
 	symbol__annotate_fprintf2(sym, stdout, opts);
 
 	annotated_source__purge(symbol__annotation(sym)->src);

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [tip:perf/urgent] perf annotate: Add --percent-type option
  2018-08-04 13:05 ` [PATCH 19/20] perf annotate: Add --percent-type option Jiri Olsa
  2018-08-06 13:49   ` Namhyung Kim
  2018-08-06 18:32   ` Arnaldo Carvalho de Melo
@ 2018-08-18 11:35   ` tip-bot for Jiri Olsa
  2 siblings, 0 replies; 67+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-08-18 11:35 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, dsahern, hpa, alexander.shishkin, eranian, linux-kernel,
	peterz, namhyung, mingo, acme, jolsa

Commit-ID:  88c211907720f9eb23308401305aefa25392417f
Gitweb:     https://git.kernel.org/tip/88c211907720f9eb23308401305aefa25392417f
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sat, 4 Aug 2018 15:05:20 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Aug 2018 15:55:53 -0300

perf annotate: Add --percent-type option

Add --percent-type option to set annotation percent type from following
choices:

  global-period, local-period, global-hits, local-hits

Examples:

  $ perf annotate --percent-type period-local --stdio | head -1
   Percent         |      Source code ... es, percent: local period)
  $ perf annotate --percent-type hits-local --stdio | head -1
   Percent         |      Source code ... es, percent: local hits)
  $ perf annotate --percent-type hits-global --stdio | head -1
   Percent         |      Source code ... es, percent: global hits)
  $ perf annotate --percent-type period-global --stdio | head -1
   Percent         |      Source code ... es, percent: global period)

The local/global keywords set if the percentage is computed in the scope
of the function (local) or the whole data (global).

The period/hits keywords set the base the percentage is computed on -
the samples period or the number of samples (hits).

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20180804130521.11408-20-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-annotate.txt |  9 ++++++
 tools/perf/builtin-annotate.c              |  4 +++
 tools/perf/util/annotate.c                 | 52 ++++++++++++++++++++++++++++++
 tools/perf/util/annotate.h                 |  2 ++
 4 files changed, 67 insertions(+)

diff --git a/tools/perf/Documentation/perf-annotate.txt b/tools/perf/Documentation/perf-annotate.txt
index 749cc6055dac..e8c972f89357 100644
--- a/tools/perf/Documentation/perf-annotate.txt
+++ b/tools/perf/Documentation/perf-annotate.txt
@@ -118,6 +118,15 @@ OPTIONS
 --group::
 	Show event group information together
 
+--percent-type::
+	Set annotation percent type from following choices:
+	  global-period, local-period, global-hits, local-hits
+
+	The local/global keywords set if the percentage is computed
+	in the scope of the function (local) or the whole data (global).
+	The period/hits keywords set the base the percentage is computed
+	on - the samples period or the number of samples (hits).
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-report[1]
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c
index 8180319285af..830481b8db26 100644
--- a/tools/perf/builtin-annotate.c
+++ b/tools/perf/builtin-annotate.c
@@ -542,6 +542,10 @@ int cmd_annotate(int argc, const char **argv)
 	OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode",
 			     "'always' (default), 'never' or 'auto' only applicable to --stdio mode",
 			     stdio__config_color, "always"),
+	OPT_CALLBACK(0, "percent-type", &annotate.opts, "local-period",
+		     "Set percent type local/global-period/hits",
+		     annotate_parse_percent_type),
+
 	OPT_END()
 	};
 	int ret;
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 6316fa96d984..e4268b948e0e 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -2799,3 +2799,55 @@ void annotation_config__init(void)
 	annotation__default_options.show_total_period = symbol_conf.show_total_period;
 	annotation__default_options.show_nr_samples   = symbol_conf.show_nr_samples;
 }
+
+static unsigned int parse_percent_type(char *str1, char *str2)
+{
+	unsigned int type = (unsigned int) -1;
+
+	if (!strcmp("period", str1)) {
+		if (!strcmp("local", str2))
+			type = PERCENT_PERIOD_LOCAL;
+		else if (!strcmp("global", str2))
+			type = PERCENT_PERIOD_GLOBAL;
+	}
+
+	if (!strcmp("hits", str1)) {
+		if (!strcmp("local", str2))
+			type = PERCENT_HITS_LOCAL;
+		else if (!strcmp("global", str2))
+			type = PERCENT_HITS_GLOBAL;
+	}
+
+	return type;
+}
+
+int annotate_parse_percent_type(const struct option *opt, const char *_str,
+				int unset __maybe_unused)
+{
+	struct annotation_options *opts = opt->value;
+	unsigned int type;
+	char *str1, *str2;
+	int err = -1;
+
+	str1 = strdup(_str);
+	if (!str1)
+		return -ENOMEM;
+
+	str2 = strchr(str1, '-');
+	if (!str2)
+		goto out;
+
+	*str2++ = 0;
+
+	type = parse_percent_type(str1, str2);
+	if (type == (unsigned int) -1)
+		type = parse_percent_type(str2, str1);
+	if (type != (unsigned int) -1) {
+		opts->percent_type = type;
+		err = 0;
+	}
+
+out:
+	free(str1);
+	return err;
+}
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index 760a6678edff..005a5fe8a8c6 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -397,4 +397,6 @@ static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused,
 
 void annotation_config__init(void);
 
+int annotate_parse_percent_type(const struct option *opt, const char *_str,
+				int unset);
 #endif	/* __PERF_ANNOTATE_H */

^ permalink raw reply	[flat|nested] 67+ messages in thread

* [tip:perf/urgent] perf report: Add --percent-type option
  2018-08-04 13:05 ` [PATCH 20/20] perf report: " Jiri Olsa
  2018-08-06 18:48   ` Arnaldo Carvalho de Melo
@ 2018-08-18 11:35   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 67+ messages in thread
From: tip-bot for Jiri Olsa @ 2018-08-18 11:35 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, alexander.shishkin, peterz, mingo, linux-kernel, jolsa,
	dsahern, acme, hpa, eranian, namhyung

Commit-ID:  e6902d1b7326149952abf8e7f07513e254668e52
Gitweb:     https://git.kernel.org/tip/e6902d1b7326149952abf8e7f07513e254668e52
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Sat, 4 Aug 2018 15:05:21 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 8 Aug 2018 15:55:54 -0300

perf report: Add --percent-type option

Set annotation percent type from following choices:

  global-period, local-period, global-hits, local-hits

With following report option setup the percent type will be passed to
annotation browser:

  $ perf report --percent-type period-local

The local/global keywords set if the percentage is computed in the scope
of the function (local) or the whole data (global).  The period/hits
keywords set the base the percentage is computed on - the samples period
or the number of samples (hits).

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20180804130521.11408-21-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-report.txt | 9 +++++++++
 tools/perf/builtin-report.c              | 3 +++
 2 files changed, 12 insertions(+)

diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index 917e36fde6d8..474a4941f65d 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -477,6 +477,15 @@ include::itrace.txt[]
 	Display monitored tasks stored in perf data. Displaying pid/tid/ppid
 	plus the command string aligned to distinguish parent and child tasks.
 
+--percent-type::
+	Set annotation percent type from following choices:
+	  global-period, local-period, global-hits, local-hits
+
+	The local/global keywords set if the percentage is computed
+	in the scope of the function (local) or the whole data (global).
+	The period/hits keywords set the base the percentage is computed
+	on - the samples period or the number of samples (hits).
+
 include::callchain-overhead-calculation.txt[]
 
 SEE ALSO
diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index 02f7a3c27761..143542ffac20 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -1124,6 +1124,9 @@ int cmd_report(int argc, const char **argv)
 		   "Time span of interest (start,stop)"),
 	OPT_BOOLEAN(0, "inline", &symbol_conf.inline_name,
 		    "Show inline function"),
+	OPT_CALLBACK(0, "percent-type", &report.annotation_opts, "local-period",
+		     "Set percent type local/global-period/hits",
+		     annotate_parse_percent_type),
 	OPT_END()
 	};
 	struct perf_data data = {

^ permalink raw reply	[flat|nested] 67+ messages in thread

end of thread, other threads:[~2018-08-18 11:36 UTC | newest]

Thread overview: 67+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-04 13:05 [PATCH 00/20] perf annotate: Make symbol__annotate_fprintf2 local Jiri Olsa
2018-08-04 13:05 ` [PATCH 01/20] " Jiri Olsa
2018-08-06 15:00   ` Arnaldo Carvalho de Melo
2018-08-18 11:25   ` [tip:perf/urgent] perf annotate: Make symbol__annotate_fprintf2() local tip-bot for Jiri Olsa
2018-08-04 13:05 ` [PATCH 02/20] perf annotate: Make annotation_line__max_percent static Jiri Olsa
2018-08-06 15:01   ` Arnaldo Carvalho de Melo
2018-08-18 11:26   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2018-08-04 13:05 ` [PATCH 03/20] perf annotate: Get rid of annotation__scnprintf_samples_period Jiri Olsa
2018-08-06 15:07   ` Arnaldo Carvalho de Melo
2018-08-18 11:26   ` [tip:perf/urgent] perf annotate: Get rid of annotation__scnprintf_samples_period() tip-bot for Jiri Olsa
2018-08-04 13:05 ` [PATCH 04/20] perf annotate: Rename struct annotation_line::samples* to data* Jiri Olsa
2018-08-06 15:08   ` Arnaldo Carvalho de Melo
2018-08-18 11:27   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2018-08-04 13:05 ` [PATCH 05/20] perf annotate: Rename local sample variables to data Jiri Olsa
2018-08-06 15:09   ` Arnaldo Carvalho de Melo
2018-08-18 11:27   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2018-08-04 13:05 ` [PATCH 06/20] perf annotate: Rename hist to sym_hist in annotation__calc_percent Jiri Olsa
2018-08-06 15:10   ` Arnaldo Carvalho de Melo
2018-08-18 11:28   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2018-08-04 13:05 ` [PATCH 07/20] perf annotate: Loop group events directly " Jiri Olsa
2018-08-06 15:12   ` Arnaldo Carvalho de Melo
2018-08-18 11:28   ` [tip:perf/urgent] perf annotate: Loop group events directly in annotation__calc_percent() tip-bot for Jiri Olsa
2018-08-04 13:05 ` [PATCH 08/20] perf annotate: Switch struct annotation_data::percent to array Jiri Olsa
2018-08-06 15:14   ` Arnaldo Carvalho de Melo
2018-08-18 11:29   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2018-08-04 13:05 ` [PATCH 09/20] perf annotate: Add PERCENT_HITS_GLOBAL percent value Jiri Olsa
2018-08-06 15:15   ` Arnaldo Carvalho de Melo
2018-08-18 11:29   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2018-08-04 13:05 ` [PATCH 10/20] perf annotate: Add PERCENT_PERIOD_LOCAL " Jiri Olsa
2018-08-06 15:16   ` Arnaldo Carvalho de Melo
2018-08-18 11:30   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2018-08-04 13:05 ` [PATCH 11/20] perf annotate: Add PERCENT_PERIOD_GLOBAL " Jiri Olsa
2018-08-06 15:16   ` Arnaldo Carvalho de Melo
2018-08-18 11:30   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2018-08-04 13:05 ` [PATCH 12/20] perf annotate: Add percent_type to struct annotation_options Jiri Olsa
2018-08-06 15:17   ` Arnaldo Carvalho de Melo
2018-08-18 11:31   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2018-08-04 13:05 ` [PATCH 13/20] perf annotate: Pass struct annotation_options to symbol__calc_lines Jiri Olsa
2018-08-06 15:18   ` Arnaldo Carvalho de Melo
2018-08-18 11:32   ` [tip:perf/urgent] perf annotate: Pass struct annotation_options to symbol__calc_lines() tip-bot for Jiri Olsa
2018-08-04 13:05 ` [PATCH 14/20] perf annotate: Pass struct annotation_options to map_symbol__annotation_dump Jiri Olsa
2018-08-06 13:45   ` Namhyung Kim
2018-08-06 14:24     ` Jiri Olsa
2018-08-06 15:22       ` Arnaldo Carvalho de Melo
2018-08-06 15:29         ` Jiri Olsa
2018-08-18 11:32   ` [tip:perf/urgent] perf annotate: Pass 'struct annotation_options' to map_symbol__annotation_dump() tip-bot for Jiri Olsa
2018-08-04 13:05 ` [PATCH 15/20] perf annotate: Pass browser percent_type in annotate_browser__calc_percent Jiri Olsa
2018-08-06 15:23   ` Arnaldo Carvalho de Melo
2018-08-18 11:33   ` [tip:perf/urgent] perf annotate: Pass browser percent_type in annotate_browser__calc_percent() tip-bot for Jiri Olsa
2018-08-04 13:05 ` [PATCH 16/20] perf annotate: Add support to togle percent type Jiri Olsa
2018-08-06 18:24   ` Arnaldo Carvalho de Melo
2018-08-18 11:33   ` [tip:perf/urgent] perf annotate: Add support to toggle " tip-bot for Jiri Olsa
2018-08-04 13:05 ` [PATCH 17/20] perf annotate: Make local period the default " Jiri Olsa
2018-08-06 18:26   ` Arnaldo Carvalho de Melo
2018-08-18 11:34   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2018-08-04 13:05 ` [PATCH 18/20] perf annotate: Display percent type in stdio output Jiri Olsa
2018-08-06 18:27   ` Arnaldo Carvalho de Melo
2018-08-18 11:34   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2018-08-04 13:05 ` [PATCH 19/20] perf annotate: Add --percent-type option Jiri Olsa
2018-08-06 13:49   ` Namhyung Kim
2018-08-06 14:26     ` Jiri Olsa
2018-08-06 18:33       ` Arnaldo Carvalho de Melo
2018-08-06 18:32   ` Arnaldo Carvalho de Melo
2018-08-18 11:35   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2018-08-04 13:05 ` [PATCH 20/20] perf report: " Jiri Olsa
2018-08-06 18:48   ` Arnaldo Carvalho de Melo
2018-08-18 11:35   ` [tip:perf/urgent] " tip-bot for Jiri Olsa

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox