[PATCH 3/3] perf report: Fix output of 'pid' sort key

From: Namhyung Kim
Date: Tue Sep 20 2016 - 01:30:50 EST


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 <fweisbec@xxxxxxxxx>
Fixes: 4dfced359fbc ("perf tools: Get current comm instead of last one")
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
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