mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RESEND PATCH v3 9/9] perf annotate: Calculate the percentage with period or number of samples
@ 2017-07-19 21:46 Taeung Song
  0 siblings, 0 replies; only message in thread
From: Taeung Song @ 2017-07-19 21:46 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: linux-kernel, Namhyung Kim, Jiri Olsa

To correspond with perf-report using the sample period
for the percentage calculation, calculate the percentage with period.
But if --show-nr-samples was used,
figure out the percentage by number of samples.

Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
---
 tools/perf/util/annotate.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 1cda47e..4cbd124 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -985,10 +985,14 @@ double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset,
 			p += h->addr[offset++].period;
 		}
 
-		if (h->total_samples) {
+		if (h->total_period) {
 			sample->nr_samples = hits;
 			sample->period = p;
-			percent = 100.0 * hits / h->total_samples;
+
+			if (symbol_conf.show_nr_samples)
+				percent = 100.0 * hits / h->total_samples;
+			else
+				percent = 100.0 * p / h->total_period;
 		}
 	}
 
@@ -1730,8 +1734,9 @@ static int symbol__get_source_line(struct symbol *sym, struct map *map,
 	start = map__rip_2objdump(map, sym->start);
 
 	for (i = 0; i < len; i++) {
-		u64 offset, nr_samples;
+		u64 offset;
 		double percent_max = 0.0;
+		struct sym_hist_entry sample;
 
 		src_line->nr_pcnt = nr_pcnt;
 
@@ -1739,14 +1744,18 @@ static int symbol__get_source_line(struct symbol *sym, struct map *map,
 			double percent = 0.0;
 
 			h = annotation__histogram(notes, evidx + k);
-			nr_samples = h->addr[i].nr_samples;
-			if (h->total_samples)
-				percent = 100.0 * nr_samples / h->total_samples;
+			sample = h->addr[i];
+			if (h->total_period) {
+				if (symbol_conf.show_nr_samples)
+					percent = 100.0 * sample.nr_samples / h->total_samples;
+				else
+					percent = 100.0 * sample.period / h->total_period;
+			}
 
 			if (percent > percent_max)
 				percent_max = percent;
 			src_line->samples[k].percent = percent;
-			src_line->samples[k].nr = nr_samples;
+			src_line->samples[k].nr = sample.nr_samples;
 		}
 
 		if (percent_max <= 0.5)
-- 
2.7.4

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-07-19 21:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-19 21:46 [RESEND PATCH v3 9/9] perf annotate: Calculate the percentage with period or number of samples Taeung Song

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

all inboxes | Powered by JetHome®