diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-26 14:07:39 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-26 14:08:43 -0400 |
commit | 745cefc5fba4350243bcb63cd6f75fb47ca77725 (patch) | |
tree | 19fe0919c5d7efcd948e280b96c47c5da9cb91f7 /tools | |
parent | 1491a63218d0fd764e7fab13aa6b82164bfc14d6 (diff) |
perf evlist: Introduce set_filter() method
To apply a filter to all the evsels in an evlist.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-v9x3q9rv4caxtox7wtjpchq5@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/evlist.c | 43 | ||||
-rw-r--r-- | tools/perf/util/evlist.h | 2 | ||||
-rw-r--r-- | tools/perf/util/evsel.c | 18 | ||||
-rw-r--r-- | tools/perf/util/evsel.h | 3 |
4 files changed, 48 insertions, 18 deletions
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index c3ec7878985..ae89686102f 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -668,30 +668,37 @@ void perf_evlist__delete_maps(struct perf_evlist *evlist) | |||
668 | 668 | ||
669 | int perf_evlist__apply_filters(struct perf_evlist *evlist) | 669 | int perf_evlist__apply_filters(struct perf_evlist *evlist) |
670 | { | 670 | { |
671 | const struct thread_map *threads = evlist->threads; | ||
672 | const struct cpu_map *cpus = evlist->cpus; | ||
673 | struct perf_evsel *evsel; | 671 | struct perf_evsel *evsel; |
674 | char *filter; | 672 | int err = 0; |
675 | int thread; | 673 | const int ncpus = cpu_map__nr(evlist->cpus), |
676 | int cpu; | 674 | nthreads = evlist->threads->nr; |
677 | int err; | ||
678 | int fd; | ||
679 | 675 | ||
680 | list_for_each_entry(evsel, &evlist->entries, node) { | 676 | list_for_each_entry(evsel, &evlist->entries, node) { |
681 | filter = evsel->filter; | 677 | if (evsel->filter == NULL) |
682 | if (!filter) | ||
683 | continue; | 678 | continue; |
684 | for (cpu = 0; cpu < cpus->nr; cpu++) { | 679 | |
685 | for (thread = 0; thread < threads->nr; thread++) { | 680 | err = perf_evsel__set_filter(evsel, ncpus, nthreads, evsel->filter); |
686 | fd = FD(evsel, cpu, thread); | 681 | if (err) |
687 | err = ioctl(fd, PERF_EVENT_IOC_SET_FILTER, filter); | 682 | break; |
688 | if (err) | ||
689 | return err; | ||
690 | } | ||
691 | } | ||
692 | } | 683 | } |
693 | 684 | ||
694 | return 0; | 685 | return err; |
686 | } | ||
687 | |||
688 | int perf_evlist__set_filter(struct perf_evlist *evlist, const char *filter) | ||
689 | { | ||
690 | struct perf_evsel *evsel; | ||
691 | int err = 0; | ||
692 | const int ncpus = cpu_map__nr(evlist->cpus), | ||
693 | nthreads = evlist->threads->nr; | ||
694 | |||
695 | list_for_each_entry(evsel, &evlist->entries, node) { | ||
696 | err = perf_evsel__set_filter(evsel, ncpus, nthreads, filter); | ||
697 | if (err) | ||
698 | break; | ||
699 | } | ||
700 | |||
701 | return err; | ||
695 | } | 702 | } |
696 | 703 | ||
697 | bool perf_evlist__valid_sample_type(struct perf_evlist *evlist) | 704 | bool perf_evlist__valid_sample_type(struct perf_evlist *evlist) |
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 25e49e02810..3f1fb66be02 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h | |||
@@ -72,6 +72,8 @@ int perf_evlist__set_tracepoints_handlers(struct perf_evlist *evlist, | |||
72 | #define perf_evlist__set_tracepoints_handlers_array(evlist, array) \ | 72 | #define perf_evlist__set_tracepoints_handlers_array(evlist, array) \ |
73 | perf_evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array)) | 73 | perf_evlist__set_tracepoints_handlers(evlist, array, ARRAY_SIZE(array)) |
74 | 74 | ||
75 | int perf_evlist__set_filter(struct perf_evlist *evlist, const char *filter); | ||
76 | |||
75 | struct perf_evsel * | 77 | struct perf_evsel * |
76 | perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id); | 78 | perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id); |
77 | 79 | ||
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index c78e42ab977..6022daaa741 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
@@ -505,6 +505,24 @@ int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads) | |||
505 | return evsel->fd != NULL ? 0 : -ENOMEM; | 505 | return evsel->fd != NULL ? 0 : -ENOMEM; |
506 | } | 506 | } |
507 | 507 | ||
508 | int perf_evsel__set_filter(struct perf_evsel *evsel, int ncpus, int nthreads, | ||
509 | const char *filter) | ||
510 | { | ||
511 | int cpu, thread; | ||
512 | |||
513 | for (cpu = 0; cpu < ncpus; cpu++) { | ||
514 | for (thread = 0; thread < nthreads; thread++) { | ||
515 | int fd = FD(evsel, cpu, thread), | ||
516 | err = ioctl(fd, PERF_EVENT_IOC_SET_FILTER, filter); | ||
517 | |||
518 | if (err) | ||
519 | return err; | ||
520 | } | ||
521 | } | ||
522 | |||
523 | return 0; | ||
524 | } | ||
525 | |||
508 | int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads) | 526 | int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads) |
509 | { | 527 | { |
510 | evsel->sample_id = xyarray__new(ncpus, nthreads, sizeof(struct perf_sample_id)); | 528 | evsel->sample_id = xyarray__new(ncpus, nthreads, sizeof(struct perf_sample_id)); |
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 60d28853748..25043ff17fd 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h | |||
@@ -115,6 +115,9 @@ void perf_evsel__free_fd(struct perf_evsel *evsel); | |||
115 | void perf_evsel__free_id(struct perf_evsel *evsel); | 115 | void perf_evsel__free_id(struct perf_evsel *evsel); |
116 | void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads); | 116 | void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads); |
117 | 117 | ||
118 | int perf_evsel__set_filter(struct perf_evsel *evsel, int ncpus, int nthreads, | ||
119 | const char *filter); | ||
120 | |||
118 | int perf_evsel__open_per_cpu(struct perf_evsel *evsel, | 121 | int perf_evsel__open_per_cpu(struct perf_evsel *evsel, |
119 | struct cpu_map *cpus); | 122 | struct cpu_map *cpus); |
120 | int perf_evsel__open_per_thread(struct perf_evsel *evsel, | 123 | int perf_evsel__open_per_thread(struct perf_evsel *evsel, |