diff options
author | Adrian Hunter <adrian.hunter@intel.com> | 2013-12-11 07:36:29 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2013-12-13 08:30:20 -0500 |
commit | c09ec622629eeb4b7877646a42852e7156363425 (patch) | |
tree | 02c90a8cb6a9e74ef5367c9b183ad1591f18ab9d /tools/perf | |
parent | d645c442e68d24e64c46845bc8bb5d5a0a70b249 (diff) |
perf evlist: Add can_select_event() method
Add a function to determine whether an event can be selected.
This function is needed to allow a tool to automatically select
additional events, but only if they are available.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@redhat.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 <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1386765443-26966-18-git-send-email-alexander.shishkin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/util/evlist.h | 2 | ||||
-rw-r--r-- | tools/perf/util/record.c | 37 |
2 files changed, 39 insertions, 0 deletions
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 649d6ea98a84..8a04aae95a18 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h | |||
@@ -193,4 +193,6 @@ static inline void perf_mmap__write_tail(struct perf_mmap *md, | |||
193 | pc->data_tail = tail; | 193 | pc->data_tail = tail; |
194 | } | 194 | } |
195 | 195 | ||
196 | bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str); | ||
197 | |||
196 | #endif /* __PERF_EVLIST_H */ | 198 | #endif /* __PERF_EVLIST_H */ |
diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c index c8845b107f60..e5104538c354 100644 --- a/tools/perf/util/record.c +++ b/tools/perf/util/record.c | |||
@@ -177,3 +177,40 @@ int perf_record_opts__config(struct perf_record_opts *opts) | |||
177 | { | 177 | { |
178 | return perf_record_opts__config_freq(opts); | 178 | return perf_record_opts__config_freq(opts); |
179 | } | 179 | } |
180 | |||
181 | bool perf_evlist__can_select_event(struct perf_evlist *evlist, const char *str) | ||
182 | { | ||
183 | struct perf_evlist *temp_evlist; | ||
184 | struct perf_evsel *evsel; | ||
185 | int err, fd, cpu; | ||
186 | bool ret = false; | ||
187 | |||
188 | temp_evlist = perf_evlist__new(); | ||
189 | if (!temp_evlist) | ||
190 | return false; | ||
191 | |||
192 | err = parse_events(temp_evlist, str); | ||
193 | if (err) | ||
194 | goto out_delete; | ||
195 | |||
196 | evsel = perf_evlist__last(temp_evlist); | ||
197 | |||
198 | if (!evlist || cpu_map__empty(evlist->cpus)) { | ||
199 | struct cpu_map *cpus = cpu_map__new(NULL); | ||
200 | |||
201 | cpu = cpus ? cpus->map[0] : 0; | ||
202 | cpu_map__delete(cpus); | ||
203 | } else { | ||
204 | cpu = evlist->cpus->map[0]; | ||
205 | } | ||
206 | |||
207 | fd = sys_perf_event_open(&evsel->attr, -1, cpu, -1, 0); | ||
208 | if (fd >= 0) { | ||
209 | close(fd); | ||
210 | ret = true; | ||
211 | } | ||
212 | |||
213 | out_delete: | ||
214 | perf_evlist__delete(temp_evlist); | ||
215 | return ret; | ||
216 | } | ||