All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Andi Kleen <andi@firstfloor.org>
Cc: jolsa@redhat.com, linux-kernel@vger.kernel.org,
	namhyung@kernel.org, mingo@kernel.org, peterz@infradead.org,
	Andi Kleen <ak@linux.intel.com>
Subject: Re: [PATCH] perf, tools: Add PERF_PID
Date: Mon, 15 Sep 2014 16:22:59 -0300	[thread overview]
Message-ID: <20140915192259.GI11199@kernel.org> (raw)
In-Reply-To: <1410307433-12475-1-git-send-email-andi@firstfloor.org>

Em Tue, Sep 09, 2014 at 05:03:53PM -0700, Andi Kleen escreveu:
> From: Andi Kleen <ak@linux.intel.com>
> 
> It's currently difficult to filter out perf itself using a filter.
> This can give cascading effects during IO tracing when the IO
> perf does itself causes more trace output.
> 
> The best way to filter is to use the pid. But it's difficult to get the pid
> of perf without using hacks.
> 
> Add a PERF_PID meta variable to the perf filter that contains the current pid.
> 
> With this patch the following works
> 
> % perf record -e syscalls:sys_enter_write -a --filter 'common_pid != PERF_PID' ...
> 
> This won't work for more complex perf pipe lines with multiple processes,
> but at least solves the problem nicely for a single perf.
 
> @@ -983,6 +984,13 @@ int parse_filter(const struct option *opt, const char *str,
>  		return -1;
>  	}
>  
> +	/* Assume a pid has not more than 8 characters */

> +	pid = strstr(last->filter, "PERF_PID");
> +	if (pid) {
> +		char buf[9];
> +		snprintf(buf, 9, "%8d", getpid());
> +		memcpy(pid, buf, 8);

Can we please remove this assumption?

If the get to be more than 8 chars we'll be just truncating stuff and
possibly filtering some other, unrelated process, no?

       pid_t getpid(void);

typedef __pid_t pid_t;
__STD_TYPE __PID_T_TYPE __pid_t;	/* Type of process identifications.  */
/usr/include/bits/typesizes.h:#define __PID_T_TYPE __S32_TYPE
/usr/include/bits/types.h:#define	__S32_TYPE		int
[acme@zoo linux]$ uname -a
Linux zoo.ghostprotocols.net 3.17.0-rc1+ #2 SMP Thu Aug 21 12:25:42 BRT 2014 x86_64 x86_64 x86_64 GNU/Linux

[acme@zoo ~]$ cat a.c
#include <limits.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
	printf("%8d", INT_MAX);
}
[acme@zoo ~]$ make a
cc     a.c   -o a
[acme@zoo ~]$ ./a | wc -c
10
[acme@zoo ~]$

The feature is needed, no doubt about it, thanks for working on it.

I guess we need the equivalent of (python regexp) s/PERF_PID/("%d" % getpid())/g
to properly implement this.

- Arnaldo

  parent reply	other threads:[~2014-09-15 19:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-10  0:03 [PATCH] perf, tools: Add PERF_PID Andi Kleen
2014-09-10  1:08 ` Brendan Gregg
2014-09-15 19:22 ` Arnaldo Carvalho de Melo [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-09-15 23:17 Andi Kleen
2014-08-19 15:04 Andi Kleen
2014-08-19 12:02 Andi Kleen
2014-08-19 15:02 ` Andi Kleen
2014-08-13 21:12 Andi Kleen
2014-08-19  6:23 ` Namhyung Kim

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=20140915192259.GI11199@kernel.org \
    --to=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=andi@firstfloor.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.