All of lore.kernel.org
 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,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Borislav Petkov <bp@suse.de>, David Ahern <dsahern@gmail.com>,
	Don Zickus <dzickus@redhat.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	Stephane Eranian <eranian@google.com>
Subject: [PATCH 06/11] perf evlist: Make perf_evlist__set_filter use perf_evsel__set_filter
Date: Mon,  6 Jul 2015 12:41:26 -0300	[thread overview]
Message-ID: <1436197291-21625-7-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1436197291-21625-1-git-send-email-acme@kernel.org>

From: Arnaldo Carvalho de Melo <acme@redhat.com>

Instead of calling perf_evsel__apply_filter straight away, so that
we can, in the next patches, expand the filter with more conditions
before actually calling the ioctl to pass the end result filter to
the kernel.

Now we need to call perf_evlist__apply_filters() after the filter
is completely setup, i.e. do the ioctl calls.

The perf_evlist__apply_filters() method was already in place, because
that is the model for the other tools that receives filters in the
command line: go on setting then in the evsel->filter and only at
the end, after parsing the whole command line, apply them.

We get, as a bonus, a more expressive message that states which
event, if any, failed to have the filter applied to, with an
error message stating what happened.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-f429pgz75ryz7tpe6v74etre@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-trace.c | 18 ++++++++++++++----
 tools/perf/util/evlist.c   |  4 +---
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index b10608680c01..c02b65a72410 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -2314,6 +2314,7 @@ out_delete_sys_enter:
 static int trace__run(struct trace *trace, int argc, const char **argv)
 {
 	struct perf_evlist *evlist = trace->evlist;
+	struct perf_evsel *evsel;
 	int err = -1, i;
 	unsigned long before;
 	const bool forks = argc > 0;
@@ -2382,10 +2383,12 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
 	else if (thread_map__pid(evlist->threads, 0) == -1)
 		err = perf_evlist__set_filter_pid(evlist, getpid());
 
-	if (err < 0) {
-		printf("err=%d,%s\n", -err, strerror(-err));
-		exit(1);
-	}
+	if (err < 0)
+		goto out_error_mem;
+
+	err = perf_evlist__apply_filters(evlist, &evsel);
+	if (err < 0)
+		goto out_error_apply_filters;
 
 	err = perf_evlist__mmap(evlist, trace->opts.mmap_pages, false);
 	if (err < 0)
@@ -2488,6 +2491,13 @@ out_error_open:
 out_error:
 	fprintf(trace->output, "%s\n", errbuf);
 	goto out_delete_evlist;
+
+out_error_apply_filters:
+	fprintf(trace->output,
+		"Failed to set filter \"%s\" on event %s with %d (%s)\n",
+		evsel->filter, perf_evsel__name(evsel), errno,
+		strerror_r(errno, errbuf, sizeof(errbuf)));
+	goto out_delete_evlist;
 }
 out_error_mem:
 	fprintf(trace->output, "Not enough memory to run!\n");
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 51913284e8e3..f7d9c77ee31b 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1175,11 +1175,9 @@ int perf_evlist__set_filter(struct perf_evlist *evlist, const char *filter)
 {
 	struct perf_evsel *evsel;
 	int err = 0;
-	const int ncpus = cpu_map__nr(evlist->cpus),
-		  nthreads = thread_map__nr(evlist->threads);
 
 	evlist__for_each(evlist, evsel) {
-		err = perf_evsel__apply_filter(evsel, ncpus, nthreads, filter);
+		err = perf_evsel__set_filter(evsel, filter);
 		if (err)
 			break;
 	}
-- 
2.1.0


  parent reply	other threads:[~2015-07-06 15:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-06 15:41 [GIT PULL 00/11] perf/core improvements and fixes Arnaldo Carvalho de Melo
2015-07-06 15:41 ` Arnaldo Carvalho de Melo
2015-07-06 15:41 ` [PATCH 01/11] perf tools: Asprintf like functions to format integer filter expression Arnaldo Carvalho de Melo
2015-07-06 15:41 ` [PATCH 02/11] perf trace: Remember what are the syscalls tracepoint evsels Arnaldo Carvalho de Melo
2015-07-06 15:41 ` [PATCH 03/11] perf trace: Store the syscall ids for the event qualifiers in a table Arnaldo Carvalho de Melo
2015-07-06 15:41 ` [PATCH 04/11] perf evsel: Rename set_filter to apply_filter Arnaldo Carvalho de Melo
2015-07-06 15:41 ` [PATCH 05/11] perf evsel: Introduce set_filter method Arnaldo Carvalho de Melo
2015-07-06 15:41 ` Arnaldo Carvalho de Melo [this message]
2015-07-06 15:41 ` [PATCH 07/11] perf evsel: Introduce append_filter() method Arnaldo Carvalho de Melo
2015-07-06 15:41 ` [PATCH 08/11] perf trace: Use event filters for the event qualifier list Arnaldo Carvalho de Melo
2015-07-06 15:41 ` [PATCH 09/11] perf probe: Delete an unnecessary check before the function call "strfilter__delete" Arnaldo Carvalho de Melo
2015-07-06 15:41   ` Arnaldo Carvalho de Melo
2015-07-06 15:41 ` [PATCH 10/11] perf record: Let user have timestamps with per-thread recording Arnaldo Carvalho de Melo
2015-07-06 15:41 ` [PATCH 11/11] tools lib api debugfs: Check for tracefs when reporting errors Arnaldo Carvalho de Melo
2015-07-06 15:47 ` [GIT PULL 00/11] perf/core improvements and fixes Ingo Molnar
2015-07-06 15:47   ` 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=1436197291-21625-7-git-send-email-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=bp@suse.de \
    --cc=dsahern@gmail.com \
    --cc=dzickus@redhat.com \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@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 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.