From: Andi Kleen <andi@firstfloor.org>
To: jolsa@redhat.com
Cc: linux-kernel@vger.kernel.org, namhyung@kernel.org,
acme@kernel.org, Andi Kleen <ak@linux.intel.com>,
brendan.d.gregg@gmail.com
Subject: [PATCH 2/2] perf tools: apply -F filter to all previous events
Date: Wed, 24 Sep 2014 13:51:09 -0700 [thread overview]
Message-ID: <1411591869-325-2-git-send-email-andi@firstfloor.org> (raw)
In-Reply-To: <1411591869-325-1-git-send-email-andi@firstfloor.org>
From: Andi Kleen <ak@linux.intel.com>
Right now you would need to duplicate the filter definition
for every trace point event. Instead apply it to each previous
one that did not have its own filter. If you have some tracepoint
events you don't want to give filter you can put them after the
last one.
Cc: brendan.d.gregg@gmail.com
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
tools/perf/util/parse-events.c | 48 +++++++++++++++++++++++++++---------------
1 file changed, 31 insertions(+), 17 deletions(-)
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 9c4bab8..9bf4173 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -962,23 +962,12 @@ int parse_events_option(const struct option *opt, const char *str,
return ret;
}
-int parse_filter(const struct option *opt, const char *str,
- int unset __maybe_unused)
+static char *gen_filter(const char *str)
{
- struct perf_evlist *evlist = *(struct perf_evlist **)opt->value;
- struct perf_evsel *last = NULL;
char *pid, buf[30], *o;
int len, plen;
const char *p;
-
- if (evlist->nr_entries > 0)
- last = perf_evlist__last(evlist);
-
- if (last == NULL || last->attr.type != PERF_TYPE_TRACEPOINT) {
- fprintf(stderr,
- "-F option should follow a -e tracepoint option\n");
- return -1;
- }
+ char *filter;
plen = sprintf(buf, "%d", getpid());
len = strlen(str) + 1;
@@ -987,13 +976,13 @@ int parse_filter(const struct option *opt, const char *str,
len += plen - 8;
}
- last->filter = malloc(len);
- if (last->filter == NULL) {
+ filter = malloc(len);
+ if (filter == NULL) {
fprintf(stderr, "not enough memory to hold filter string\n");
- return -1;
+ return NULL;
}
- o = last->filter;
+ o = filter;
for (p = str; *p; ) {
if (*p == 'P' && !strncmp(p, "PERF_PID", 8)) {
strcpy(o, buf);
@@ -1002,6 +991,31 @@ int parse_filter(const struct option *opt, const char *str,
} else
*o++ = *p++;
}
+ return filter;
+}
+
+int parse_filter(const struct option *opt, const char *str,
+ int unset __maybe_unused)
+{
+ struct perf_evlist *evlist = *(struct perf_evlist **)opt->value;
+ struct perf_evsel *evsel;
+ int nr_tp = 0;
+
+ evlist__for_each(evlist, evsel) {
+ if (evsel->attr.type == PERF_TYPE_TRACEPOINT &&
+ !evsel->filter) {
+ evsel->filter = gen_filter(str);
+ if (!evsel->filter)
+ return -1;
+ nr_tp++;
+ }
+ }
+
+ if (nr_tp == 0) {
+ fprintf(stderr,
+ "-F option should follow a -e tracepoint option\n");
+ return -1;
+ }
return 0;
}
--
1.9.3
next prev parent reply other threads:[~2014-09-24 20:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-24 20:51 [PATCH 1/2] perf, tools: Add PERF_PID Andi Kleen
2014-09-24 20:51 ` Andi Kleen [this message]
2014-10-01 18:03 ` Adding a filter to events (instead of replacing one) was " Arnaldo Carvalho de Melo
2014-10-01 22:02 ` Andi Kleen
2014-10-01 22:13 ` Arnaldo Carvalho de Melo
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=1411591869-325-2-git-send-email-andi@firstfloor.org \
--to=andi@firstfloor.org \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=brendan.d.gregg@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=namhyung@kernel.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
Powered by JetHome