Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751997AbdG0QQr (ORCPT ); Thu, 27 Jul 2017 12:16:47 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:33202 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751754AbdG0QQn (ORCPT ); Thu, 27 Jul 2017 12:16:43 -0400 From: Taeung Song To: Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, Jiri Olsa , Namhyung Kim Subject: [PATCH v4 8/9] perf annotate: Check total period before calculating percent Date: Fri, 28 Jul 2017 01:16:36 +0900 Message-Id: <1501172196-6940-1-git-send-email-treeze.taeung@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1116 Lines: 35 Before calculating percent, checking total period is clear and safer than checking just number of samples. So fix it. Cc: Jiri Olsa Cc: Namhyung Kim Signed-off-by: Taeung Song --- tools/perf/util/annotate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index 7032bdc..522b67b 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -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) -- 2.7.4