linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: David Ahern <dsahern@gmail.com>
Cc: linux-kernel@vger.kernel.org, Don Zickus <dzickus@redhat.com>,
	Joe Mario <jmario@redhat.com>, Jiri Olsa <jolsa@redhat.com>,
	Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH v2 2/2] perf tool: Fix ppid for synthesized fork events
Date: Mon, 30 Mar 2015 16:40:55 -0300	[thread overview]
Message-ID: <20150330194055.GG32560@kernel.org> (raw)
In-Reply-To: <1427739642-17961-1-git-send-email-dsahern@gmail.com>

Em Mon, Mar 30, 2015 at 12:20:42PM -0600, David Ahern escreveu:

Some nits below:
 
>  tools/perf/util/event.c | 92 ++++++++++++++++++++++++++++++-------------------
>  1 file changed, 57 insertions(+), 35 deletions(-)
> 
> diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
<SNIP>
> @@ -81,6 +84,7 @@ static pid_t perf_event__get_comm_tgid(pid_t pid, char *comm, size_t len)
>  
>  	name = strstr(bf, "Name:");
>  	tgids = strstr(bf, "Tgid:");
> +	ppids = strstr(bf, "PPid:");

can't we make this:

	ppids = strstr(tgids, "PPid:");

To speed it up a teeny little bit? 8-)
  
>  	if (name) {
>  		name += 5;  /* strlen("Name:") */
> @@ -109,32 +113,51 @@ static pid_t perf_event__get_comm_tgid(pid_t pid, char *comm, size_t len)
>  		if (nl)
>  			*nl = '\0';
>  
> -		tgid = atoi(tgids);
> +		*tgid = atoi(tgids);
>  
>  	} else
>  		pr_debug("Tgid: string not found for pid %d\n", pid);
>  
> -	return tgid;
> +	if (ppids) {
> +		ppids += 5;  /* strlen("PPid:") */
> +
> +		while (*ppids && isspace(*ppids))
> +			++ppids;

The above could be simplified to:

		while (isspace(*ppids))
			++ppids;

$ cat isspace.c 
#include <ctype.h>
#include <stdio.h>
int main(void) { return printf("isspace('\\0')=%d\n", isspace('\0')); }
$ ./isspace 
isspace('\0')=0
$ 

> +		nl = strchr(ppids, '\n');
> +		if (nl)
> +			 *nl = '\0';

We also don't need to find and zero this '\n', as:

$ cat atoi.c 
#include <string.h>
#include <stdio.h>
int main(void) { return printf("atoi(\"1234\\n\")=%d\n",
atoi("1234\n")); }
$ ./atoi 
atoi("1234\n")=1234
$

<SNIP>

> +	if (machine__is_host(machine)) {
> +		if (perf_event__get_comm_ids(pid, event->comm.comm,
> +					     sizeof(event->comm.comm),
> +					     tgid, ppid) != 0) {
> +			return -1;
> +		}
> +	} else
> +		*tgid = machine->pid;

Somebody, I think PeterZ and also Ingo, routinely asks for having {} on
the else part of an if that has {}, please do so.

- Arnaldo

  reply	other threads:[~2015-03-30 19:40 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-29 22:30 [PATCH 1/2] perf tool: Refactor comm/tgid lookup David Ahern
2015-03-29 22:30 ` [PATCH 2/2] perf tool: Fix ppid for synthesized fork events David Ahern
2015-03-30  8:04   ` Jiri Olsa
2015-03-30 15:23     ` David Ahern
2015-03-30 15:29       ` Arnaldo Carvalho de Melo
2015-03-30 18:20   ` [PATCH v2 " David Ahern
2015-03-30 19:40     ` Arnaldo Carvalho de Melo [this message]
2015-03-30 19:53       ` David Ahern
2015-03-30 20:00         ` Arnaldo Carvalho de Melo
2015-03-30  8:01 ` [PATCH 1/2] perf tool: Refactor comm/tgid lookup Jiri Olsa
2015-03-30 15:34   ` David Ahern

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=20150330194055.GG32560@kernel.org \
    --to=acme@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=dzickus@redhat.com \
    --cc=jmario@redhat.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.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;
as well as URLs for NNTP newsgroup(s).