Skip to contentSkip to conversation

perf annotate: Check total period before calculating percent

PATCH In review Taeung Song 1 participant 1 message Jul 27, 2017 perf events

lore
Share & tools
lore
#0 lore raw

PATCH v4 8/9 perf annotate: Check total period before calculating percent

Before calculating percent, checking total period is clear and safer than checking just number of samples. So fix it.

Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
---
 tools/perf/util/annotate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/annotate.c +2 -2
index 7032bdc..522b67b 100644
@@ -967,7 +967,7 @@ double disasm__calc_percent(struct annotation *notes, int evidx, s64 offset,
 			period += h->addr[offset++].period;
 		}
 
-		if (h->nr_samples) {
+		if (h->period) {
 			sample->period	   = period;
 			sample->nr_samples = hits;
 			percent = 100.0 * hits / h->nr_samples;
@@ -1718,7 +1718,7 @@ static int symbol__get_source_line(struct symbol *sym, struct map *map,
 
 			h = annotation__histogram(notes, evidx + k);
 			nr_samples = h->addr[i].nr_samples;
-			if (h->nr_samples)
+			if (h->period)
 				percent = 100.0 * nr_samples / h->nr_samples;
 
 			if (percent > percent_max)
Signature · 1 line
2.7.4