From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753614AbcITFar (ORCPT ); Tue, 20 Sep 2016 01:30:47 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:36862 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751029AbcITFao (ORCPT ); Tue, 20 Sep 2016 01:30:44 -0400 From: Namhyung Kim To: Arnaldo Carvalho de Melo Cc: Ingo Molnar , Peter Zijlstra , Jiri Olsa , LKML , Andi Kleen , Frederic Weisbecker Subject: [PATCH 3/3] perf report: Fix output of 'pid' sort key Date: Tue, 20 Sep 2016 14:30:25 +0900 Message-Id: <20160920053025.13989-3-namhyung@kernel.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160920053025.13989-1-namhyung@kernel.org> References: <20160920053025.13989-1-namhyung@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The thread->comm can be changed during the lifetime due to prctl() or exec(). For this reason each hist entry has a pointer to a comm at the time as well as a pointer to the thread. So it should use the he->comm instead of thread__comm(he->thread) which always returns the latest comm. This can be seen using following example: $ perf report --hierarchy -s comm,pid Before: 3.86% 2.53% sh 1.05% 0.45% 776:sh 0.67% 0.49% 8190:sh 0.65% 0.37% 8194:sh 0.28% 0.21% 8192:awk 0.24% 0.22% 8191:acpi 0.24% 0.21% 8196:awk 0.22% 0.15% 8193:tr 0.21% 0.14% 8195:netctl-auto 0.10% 0.30% 8319:date 0.10% 0.00% 8320:xsetroot 0.09% 0.00% 8321:sleep After: 3.86% 2.53% sh 1.05% 0.45% 776:sh 0.67% 0.49% 8190:sh 0.65% 0.37% 8194:sh 0.28% 0.21% 8192:sh 0.24% 0.22% 8191:sh 0.24% 0.21% 8196:sh 0.22% 0.15% 8193:sh 0.21% 0.14% 8195:sh 0.10% 0.30% 8319:sh 0.10% 0.00% 8320:sh 0.09% 0.00% 8321:sh Cc: Frederic Weisbecker Fixes: 4dfced359fbc ("perf tools: Get current comm instead of last one") Signed-off-by: Namhyung Kim --- tools/perf/util/sort.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c index 1884d7f9b9d2..549dfbdbe9c3 100644 --- a/tools/perf/util/sort.c +++ b/tools/perf/util/sort.c @@ -77,7 +77,7 @@ sort__thread_cmp(struct hist_entry *left, struct hist_entry *right) static int hist_entry__thread_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width) { - const char *comm = thread__comm_str(he->thread); + const char *comm = comm__str(he->comm); width = max(7U, width) - 8; return repsep_snprintf(bf, size, "%7d:%-*.*s", he->thread->tid, -- 2.9.3