lkml.org 
[lkml]   [2017]   [Apr]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[tip:perf/core] perf tools: Refactor the code to strip command name with {l,r}trim()
Commit-ID:  bdd97ca63faa374c98314d53c0bcaedb473c5a33
Gitweb: http://git.kernel.org/tip/bdd97ca63faa374c98314d53c0bcaedb473c5a33
Author: Taeung Song <treeze.taeung@gmail.com>
AuthorDate: Fri, 7 Apr 2017 23:24:21 +0900
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 11 Apr 2017 15:23:26 -0300

perf tools: Refactor the code to strip command name with {l,r}trim()

After reading command name from /proc/<pid>/status, use ltrim() and
rtrim() to strip command name, not using just while loop, isspace() and
etc.

Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1491575061-704-6-git-send-email-treeze.taeung@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/event.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 76b9c6b..8255a26 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -106,7 +106,7 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len,
int fd;
size_t size = 0;
ssize_t n;
- char *nl, *name, *tgids, *ppids;
+ char *name, *tgids, *ppids;

*tgid = -1;
*ppid = -1;
@@ -134,14 +134,7 @@ static int perf_event__get_comm_ids(pid_t pid, char *comm, size_t len,

if (name) {
name += 5; /* strlen("Name:") */
-
- while (*name && isspace(*name))
- ++name;
-
- nl = strchr(name, '\n');
- if (nl)
- *nl = '\0';
-
+ name = rtrim(ltrim(name));
size = strlen(name);
if (size >= len)
size = len - 1;
\
 
 \ /
  Last update: 2017-04-12 07:42    [W:0.088 / U:0.300 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site