mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Namhyung Kim <namhyung.kim@lge.com>
Subject: [PATCH 3/3] perf ui/browser: Fix stale output of sorted result
Date: Fri, 14 Sep 2012 17:35:29 +0900	[thread overview]
Message-ID: <1347611729-16994-3-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1347611729-16994-1-git-send-email-namhyung@kernel.org>

From: Namhyung Kim <namhyung.kim@lge.com>

The hist_entry__sort_snprintf() can return 0 if all of the sort keys
are elided.  In this case a buffer which used for the function would
contain old message or a garbage and printed like below:

  $ perf record -g -e cycles:u abc
  $ perf --report -s comm -c abc
  (...)
  + 100.00%100.00%

Fix it by checking return value.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/ui/browsers/hists.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index a21f40bebbac..75b3898ca651 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -664,8 +664,8 @@ static int hist_browser__show_entry(struct hist_browser *browser,
 		if (!browser->b.navkeypressed)
 			width += 1;
 
-		hist_entry__sort_snprintf(entry, s, sizeof(s), browser->hists);
-		slsmg_write_nstring(s, width);
+		if (hist_entry__sort_snprintf(entry, s, sizeof(s), browser->hists))
+			slsmg_write_nstring(s, width);
 		++row;
 		++printed;
 	} else
@@ -981,7 +981,6 @@ static int hist_browser__fprintf_entry(struct hist_browser *browser,
 	if (symbol_conf.use_callchain)
 		folded_sign = hist_entry__folded(he);
 
-	hist_entry__sort_snprintf(he, s, sizeof(s), browser->hists);
 	percent = (he->period * 100.0) / browser->hists->stats.total_period;
 
 	if (symbol_conf.use_callchain)
@@ -995,7 +994,8 @@ static int hist_browser__fprintf_entry(struct hist_browser *browser,
 	if (symbol_conf.show_total_period)
 		printed += fprintf(fp, " %12" PRIu64, he->period);
 
-	printed += fprintf(fp, "%s\n", rtrim(s));
+	if (hist_entry__sort_snprintf(he, s, sizeof(s), browser->hists))
+		printed += fprintf(fp, "%s\n", rtrim(s));
 
 	if (folded_sign == '-')
 		printed += hist_browser__fprintf_callchain(browser, &he->sorted_chain, 1, fp);
-- 
1.7.11.4


  parent reply	other threads:[~2012-09-14  8:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-14  8:35 [PATCH 1/3] perf tools: Add sort__has_sym Namhyung Kim
2012-09-14  8:35 ` [PATCH 2/3] perf report: Enable itegrated annotation only if possible Namhyung Kim
2012-09-19 15:16   ` [tip:perf/core] perf report: Enable integrated " tip-bot for Namhyung Kim
2012-09-14  8:35 ` Namhyung Kim [this message]
2012-09-25  5:03   ` [PATCH 3/3] perf ui/browser: Fix stale output of sorted result Namhyung Kim
2012-09-19 15:15 ` [tip:perf/core] perf tools: Add sort__has_sym tip-bot for Namhyung Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1347611729-16994-3-git-send-email-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@ghostprotocols.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung.kim@lge.com \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®