From: tip-bot for Wang Nan <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: wangnan0@huawei.com, brendan.d.gregg@gmail.com,
ak@linux.intel.com, linux-kernel@vger.kernel.org,
rostedt@goodmis.org, lizefan@huawei.com, tglx@linutronix.de,
hpa@zytor.com, acme@redhat.com, mingo@kernel.org
Subject: [tip:perf/core] perf record: Apply filter to all events in a glob matching
Date: Tue, 21 Jul 2015 02:34:09 -0700 [thread overview]
Message-ID: <tip-15bfd2cc107a9971ac8aeb4b7724ced581a2ed30@git.kernel.org> (raw)
In-Reply-To: <1436513770-8896-1-git-send-email-wangnan0@huawei.com>
Commit-ID: 15bfd2cc107a9971ac8aeb4b7724ced581a2ed30
Gitweb: http://git.kernel.org/tip/15bfd2cc107a9971ac8aeb4b7724ced581a2ed30
Author: Wang Nan <wangnan0@huawei.com>
AuthorDate: Fri, 10 Jul 2015 07:36:09 +0000
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 20 Jul 2015 15:28:33 -0300
perf record: Apply filter to all events in a glob matching
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 83c0803..49fb7b5 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 fe9f327..1fc263a 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 a71eeb2..bbb7fbc 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;
}
prev parent reply other threads:[~2015-07-21 9:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-10 7:36 [PATCH 1/2] " Wang Nan
2015-07-10 7:36 ` [PATCH 2/2] perf record: Allow passing perf's own pid to '--filter' Wang Nan
2015-07-21 9:34 ` [tip:perf/core] perf record: Allow filtering perf' s pid via --exclude-perf tip-bot for Wang Nan
2015-07-20 18:30 ` [PATCH 1/2] perf record: Apply filter to all events in a glob matching Arnaldo Carvalho de Melo
2015-07-21 9:34 ` tip-bot for Wang Nan [this message]
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=tip-15bfd2cc107a9971ac8aeb4b7724ced581a2ed30@git.kernel.org \
--to=tipbot@zytor.com \
--cc=acme@redhat.com \
--cc=ak@linux.intel.com \
--cc=brendan.d.gregg@gmail.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=mingo@kernel.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--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
Powered by JetHome