linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Wang Nan <wangnan0@huawei.com>,
	Andi Kleen <ak@linux.intel.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Zefan Li <lizefan@huawei.com>,
	pi3orama@163.com, Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 07/13] perf record: Apply filter to all events in a glob matching
Date: Mon, 20 Jul 2015 17:58:38 -0300	[thread overview]
Message-ID: <1437425924-31064-8-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1437425924-31064-1-git-send-email-acme@kernel.org>

From: Wang Nan <wangnan0@huawei.com>

There is an old problem in perf's filter applying which first posted at
Sep. 2014 at https://lkml.org/lkml/2014/9/9/944 that, if passing
multiple events in a glob matching expression in cmdline then add
'--filter' after them, the filter will be applied on only the last one.

For example:

 # dd if=/dev/zero of=/dev/null &
 [1] 464
 # perf record -a -e 'syscalls:sys_*_read' --filter 'common_pid != 464' sleep 0.1
 [ perf record: Woken up 1 times to write data ]
 [ perf record: Captured and wrote 0.239 MB perf.data (2094 samples) ]
 # perf report --stdio | tee
 ...
 # Samples: 2K of event 'syscalls:sys_enter_read'
 # Event count (approx.): 2092
 ...
 # Samples: 2  of event 'syscalls:sys_exit_read'
 # Event count (approx.): 2
 ...

In this example, filter only applied on 'syscalls:sys_exit_read', and
there's no way to set filter for ''syscalls:sys_enter_read'.

This patch adds a 'cmdline_group_boundary' for 'struct evsel', and
apply filter on all events between two boundary marks.

After applying this patch:

 # perf record -a -e 'syscalls:sys_*_read' --filter 'common_pid != 464' sleep 0.1
 [ perf record: Woken up 1 times to write data ]
 [ perf record: Captured and wrote 0.031 MB perf.data (3 samples) ]
 # perf report --stdio | tee
 ...
 # Samples: 1  of event 'syscalls:sys_enter_read'
 # Event count (approx.): 1
 ...
 # Samples: 2  of event 'syscalls:sys_exit_read'
 # Event count (approx.): 2
 ...

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Reported-by: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1436513770-8896-1-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/evsel.c        |  1 +
 tools/perf/util/evsel.h        |  1 +
 tools/perf/util/parse-events.c | 30 +++++++++++++++++++++---------
 3 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 83c08037e7e2..49fb7b5feb09 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -210,6 +210,7 @@ void perf_evsel__init(struct perf_evsel *evsel,
 	perf_evsel__object.init(evsel);
 	evsel->sample_size = __perf_evsel__sample_size(attr->sample_type);
 	perf_evsel__calc_id_pos(evsel);
+	evsel->cmdline_group_boundary = false;
 }
 
 struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx)
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index fe9f3279632b..1fc263a80d91 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -86,6 +86,7 @@ struct perf_evsel {
 	unsigned long		*per_pkg_mask;
 	struct perf_evsel	*leader;
 	char			*group_name;
+	bool			cmdline_group_boundary;
 };
 
 union u64_swap {
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index a71eeb279ed2..bbb7fbc2857e 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1065,8 +1065,13 @@ int parse_events(struct perf_evlist *evlist, const char *str,
 	perf_pmu__parse_cleanup();
 	if (!ret) {
 		int entries = data.idx - evlist->nr_entries;
+		struct perf_evsel *last;
+
 		perf_evlist__splice_list_tail(evlist, &data.list, entries);
 		evlist->nr_groups += data.nr_groups;
+		last = perf_evlist__last(evlist);
+		last->cmdline_group_boundary = true;
+
 		return 0;
 	}
 
@@ -1171,16 +1176,23 @@ int parse_filter(const struct option *opt, const char *str,
 	if (evlist->nr_entries > 0)
 		last = perf_evlist__last(evlist);
 
-	if (last == NULL || last->attr.type != PERF_TYPE_TRACEPOINT) {
-		fprintf(stderr,
-			"--filter option should follow a -e tracepoint option\n");
-		return -1;
-	}
+	do {
+		if (last == NULL || last->attr.type != PERF_TYPE_TRACEPOINT) {
+			fprintf(stderr,
+				"--filter option should follow a -e tracepoint option\n");
+			return -1;
+		}
 
-	if (perf_evsel__set_filter(last, str) < 0) {
-		fprintf(stderr, "not enough memory to hold filter string\n");
-		return -1;
-	}
+		if (perf_evsel__set_filter(last, str) < 0) {
+			fprintf(stderr,
+				"not enough memory to hold filter string\n");
+			return -1;
+		}
+
+		if (last->node.prev == &evlist->entries)
+			return 0;
+		last = list_entry(last->node.prev, struct perf_evsel, node);
+	} while (!last->cmdline_group_boundary);
 
 	return 0;
 }
-- 
2.1.0


  parent reply	other threads:[~2015-07-20 20:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-20 20:58 [GIT PULL 00/13] perf/core improvements and fixes Arnaldo Carvalho de Melo
2015-07-20 20:58 ` [PATCH 01/13] perf record: Document setting '-e pmu/period=N/' in man page Arnaldo Carvalho de Melo
2015-07-20 20:58 ` [PATCH 02/13] perf strlist: load() should return a negative errno Arnaldo Carvalho de Melo
2015-07-20 20:58 ` [PATCH 03/13] perf strlist: Make dupstr be the default and part of an extensible config parm Arnaldo Carvalho de Melo
2015-07-20 20:58 ` [PATCH 04/13] perf strlist: Allow substitutions from file contents in a given directory Arnaldo Carvalho de Melo
2015-07-20 20:58 ` [PATCH 05/13] perf strlist: Make parse_list() private Arnaldo Carvalho de Melo
2015-07-20 20:58 ` [PATCH 06/13] perf trace: Support 'strace' syscall event groups Arnaldo Carvalho de Melo
2015-07-20 20:58 ` Arnaldo Carvalho de Melo [this message]
2015-07-20 20:58 ` [PATCH 08/13] perf record: Allow filtering perf's pid via --exclude-perf Arnaldo Carvalho de Melo
2015-07-20 20:58 ` [PATCH 09/13] perf probe: Simplify __add_probe_trace_events code Arnaldo Carvalho de Melo
2015-07-20 20:58 ` [PATCH 10/13] perf probe: Move ftrace probe-event operations to probe-file.c Arnaldo Carvalho de Melo
2015-07-20 20:58 ` [PATCH 11/13] perf buildid: Use SBUILD_ID_SIZE macro Arnaldo Carvalho de Melo
2015-07-20 20:58 ` [PATCH 12/13] perf tools: Fix makefile generation under dash Arnaldo Carvalho de Melo
2015-07-20 20:58 ` [PATCH 13/13] perf bench futex: Add lock_pi stresser Arnaldo Carvalho de Melo
2015-07-21  6:00 ` [GIT PULL 00/13] perf/core improvements and fixes Ingo Molnar

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=1437425924-31064-8-git-send-email-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=mingo@kernel.org \
    --cc=pi3orama@163.com \
    --cc=rostedt@goodmis.org \
    --cc=wangnan0@huawei.com \
    /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).