perf evlist: Default to syswide target when no thread/cpu maps set
tip-bot for Arnaldo Carvalho de Melo
merge botCommit-ID: 4112eb1899c0e711b2ab1491f51215359cf94d74 Gitweb: http://git.kernel.org/tip/4112eb1899c0e711b2ab1491f51215359cf94d74 Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Fri, 10 Oct 2014 15:55:15 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 14 Oct 2014 17:32:53 -0300
perf evlist: Default to syswide target when no thread/cpu maps set
If all a tool wants is to do system wide event monitoring, there is no more the need to setup thread_map and cpu_map objects, just call perf_evlist__open() and it will do create one fd per CPU monitoring all threads.
Cc Adrian Hunter <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc David Ahern <[email protected]>
Cc Don Zickus <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Jean Pihet <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/util/evlist.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
tools/perf/util/evlist.c +40 -0
@@ -1175,11 +1175,51 @@ void perf_evlist__close(struct perf_evlist *evlist) } } +static int perf_evlist__create_syswide_maps (struct perf_evlist *evlist) +{ +int err = -ENOMEM ; + +/* +* Try reading /sys/devices/system/cpu/online to get +* an all cpus map. +* +* FIXME: -ENOMEM is the best we can do here, the cpu_map +* code needs an overhaul to properly forward the +* error, and we may not want to do that fallback to a +* default cpu identity map :-\ +*/ + evlist->cpus =cpu_map__new (NULL ); +if (evlist->cpus ==NULL ) + goto out; + + evlist->threads =thread_map__new_dummy (); +if (evlist->threads ==NULL ) + goto out_free_cpus; + + err =0 ; +out: +return err; +out_free_cpus: +cpu_map__delete (evlist->cpus); + evlist->cpus =NULL ; + goto out; +} +int perf_evlist__open (struct perf_evlist *evlist) {struct perf_evsel *evsel;int err; +/* +* Default: one fd per CPU, all threads, aka systemwide +* as sys_perf_event_open(cpu = -1, thread = -1) is EINVAL +*/ +if (evlist->threads ==NULL && evlist->cpus ==NULL ) { + err =perf_evlist__create_syswide_maps (evlist); +if (err <0 ) + goto out_err; + } +perf_evlist__update_id_pos (evlist);evlist__for_each (evlist, evsel) {