Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1629932 > unrolled thread

[PATCH 22/22] perf tools: Fix the code to strip command name

Started byArnaldo Carvalho de Melo <acme@kernel.org>
First post2017-04-24 22:00 +0200
Last post2017-04-24 22:10 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 22/22] perf tools: Fix the code to strip command name Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-04-24 22:00 +0200
    Re: [PATCH 22/22] perf tools: Fix the code to strip command name David Ahern <dsahern@gmail.com> - 2017-04-24 22:10 +0200

#1629932 — [PATCH 22/22] perf tools: Fix the code to strip command name

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2017-04-24 22:00 +0200
Subject[PATCH 22/22] perf tools: Fix the code to strip command name
Message-ID<tzSjp-2Lp-41@gated-at.bofh.it>
From: Jiri Olsa <jolsa@kernel.org>

Recent commit broke command name strip in perf_event__get_comm_ids
function. It replaced left to right search for '\n' with rtrim, which
actually does right to left search. It occasionally caught earlier '\n'
and kept trash in the command name.

Keeping the ltrim, but moving back the left to right '\n' search
instead of the rtrim.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Taeung Song <treeze.taeung@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Yao Jin <yao.jin@linux.intel.com>
Fixes: bdd97ca63faa ("perf tools: Refactor the code to strip command name with {l,r}trim()")
Link: http://lkml.kernel.org/r/20170420092430.29657-1-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/event.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 2e829ac0f615..142835c0ca0a 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -141,8 +141,15 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len,
 	ppids = strstr(bf, "PPid:");
 
 	if (name) {
+		char *nl;
+
 		name += 5;  /* strlen("Name:") */
-		name = rtrim(ltrim(name));
+		name = ltrim(name);
+
+		nl = strchr(name, '\n');
+		if (nl)
+			*nl = '\0';
+
 		size = strlen(name);
 		if (size >= len)
 			size = len - 1;
-- 
2.9.3

[toc] | [next] | [standalone]


#1629957

FromDavid Ahern <dsahern@gmail.com>
Date2017-04-24 22:10 +0200
Message-ID<tzSt4-33H-27@gated-at.bofh.it>
In reply to#1629932
On 4/24/17 1:54 PM, Arnaldo Carvalho de Melo wrote:
> From: Jiri Olsa <jolsa@kernel.org>
> 
> Recent commit broke command name strip in perf_event__get_comm_ids
> function. It replaced left to right search for '\n' with rtrim, which
> actually does right to left search. It occasionally caught earlier '\n'
> and kept trash in the command name.
> 

interesting. When I reviewed that patch it didn't cross my mind that a
comm Name could have a newline in it. seems very odd to do so.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web