Skip to contentSkip to conversation

perf annotate: Use the sample period when calculating the percentage

PATCH Superseded Taeung Song 2 participants 3 messages Jul 13, 2017 – Jul 19, 2017 perf events

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 9/9 perf annotate: Use the sample period when calculating the percentage

Currently the percentages of perf-annotate are calculated with number of samples, not the sample period.
So fix it to correspond with perf-report using the sample period for the calculation.

Cc Namhyung Kim <[email protected]>
Cc Jiri Olsa <[email protected]>
---
 tools/perf/util/annotate.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
tools/perf/util/annotate.c +6 -5
index d9bdedf..28a6d11 100644
@@ -988,7 +988,7 @@ double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset,
 		if (h->total_samples) {
 			sample->nr_samples = hits;
 			sample->period = p;
-			percent = 100.0 * hits / h->total_samples;
+			percent = 100.0 * p / h->total_period;
 		}
 	}
 
@@ -1730,8 +1730,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,15 +1740,15 @@ 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;
+			sample = h->addr[i];
 
 			if (h->total_samples)
-				percent = 100.0 * nr_samples / h->total_samples;
+				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)
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 4 lines · Taeung Song

Currently the percentages of perf-annotate are calculated with number of samples, not the sample period.
So fix it to correspond with perf-report using the sample period for the calculation.

Not sure someone still wants the old behavior. Maybe it'd be better to honor --show-nr-samples option.

Quoted 13 lines
Cc Namhyung Kim <[email protected]>
Cc Jiri Olsa <[email protected]>
---
 tools/perf/util/annotate.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
tools/perf/util/annotate.c +0 -0
index d9bdedf..28a6d11 100644

tools/perf/util/annotate.c double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset, · line 988

Quoted 1 line
tools/perf/util/annotate.c +0 -0
@@ -988,7 +988,7 @@ double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset,
 		if (h->total_samples) {

It seems checking total_period here is clearer and safer. But I guess it would have same effect 99.9% but still..

Quoted 19 lines
tools/perf/util/annotate.c +3 -2
 			sample->nr_samples = hits;
 			sample->period = p;
-			percent = 100.0 * hits / h->total_samples;
+			percent = 100.0 * p / h->total_period;
 		}
 	}
 
@@ -1730,8 +1730,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;
 

tools/perf/util/annotate.c static int symbol__get_source_line(struct symbol *sym, struct map *map, · line 1745

Quoted 7 lines
tools/perf/util/annotate.c +1 -1
@@ -1739,15 +1740,15 @@ 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;
+			sample = h->addr[i];
 
 			if (h->total_samples)

Ditto.

Thanks,
Namhyung

Quoted 14 lines
tools/perf/util/annotate.c +2 -2
-				percent = 100.0 * nr_samples / h->total_samples;
+				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)
Signature · 1 line
2.7.4
#2 lore raw
Quoted 10 lines · Namhyung Kim
Quoted 4 lines · Taeung Song

Currently the percentages of perf-annotate are calculated with number of samples, not the sample period.
So fix it to correspond with perf-report using the sample period for the calculation.

Not sure someone still wants the old behavior. Maybe it'd be better to honor --show-nr-samples option.

You mean that if users use --show-nr-samples option,
we can calculate the percent values with number of samples, right ?

Quoted 8 lines
Quoted 8 lines
Cc Namhyung Kim <[email protected]>
Cc Jiri Olsa <[email protected]>
---
  tools/perf/util/annotate.c | 11 ++++++-----
  1 file changed, 6 insertions(+), 5 deletions(-)
Quoted 11 lines

tools/perf/util/annotate.c double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset, · line 988

Quoted 6 lines
tools/perf/util/annotate.c +0 -0
index d9bdedf..28a6d11 100644
@@ -988,7 +988,7 @@ double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset,
  		if (h->total_samples) {

It seems checking total_period here is clearer and safer. But I guess it would have same effect 99.9% but still..

I got it.

Quoted 25 lines
Quoted 25 lines
tools/perf/util/annotate.c +4 -3
  			sample->nr_samples = hits;
  			sample->period = p;
-			percent = 100.0 * hits / h->total_samples;
+			percent = 100.0 * p / h->total_period;
  		}
  	}
 
@@ -1730,8 +1730,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,15 +1740,15 @@ 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;
+			sample = h->addr[i];
 
Quoted 8 lines

tools/perf/util/annotate.c static int symbol__get_source_line(struct symbol *sym, struct map *map, · line 1745

Quoted 1 line
tools/perf/util/annotate.c +0 -0
  			if (h->total_samples)

Ditto.

Thanks,
Namhyung

ok

Thanks,
Taeung

Quoted 14 lines
Quoted 14 lines
tools/perf/util/annotate.c +2 -2
-				percent = 100.0 * nr_samples / h->total_samples;
+				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)
Signature · 1 line
2.7.4