]> git.karo-electronics.de Git - linux-beck.git/commitdiff
perf tools: Add a helper function to probe whether cpu-wide tracing is possible
authorAdrian Hunter <adrian.hunter@intel.com>
Thu, 13 Aug 2015 09:40:56 +0000 (12:40 +0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 17 Aug 2015 14:08:37 +0000 (11:08 -0300)
Add a helper function to probe whether cpu-wide tracing is possible.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/1439458857-30636-2-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/evlist.h
tools/perf/util/record.c

index 397757063da1924fb09778a7cbfcb567fcd58620..436e358300b17d7deec6253b54679d7330d17206 100644 (file)
@@ -115,6 +115,7 @@ void perf_evlist__close(struct perf_evlist *evlist);
 void perf_evlist__set_id_pos(struct perf_evlist *evlist);
 bool perf_can_sample_identifier(void);
 bool perf_can_record_switch_events(void);
+bool perf_can_record_cpu_wide(void);
 void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts);
 int record_opts__config(struct record_opts *opts);
 
index 0d228a29526dded5d329e20ca6fe4f51bb94cf85..0467367dc31551122c47e0274e01ac48378c5a6e 100644 (file)
@@ -105,6 +105,30 @@ bool perf_can_record_switch_events(void)
        return perf_probe_api(perf_probe_context_switch);
 }
 
+bool perf_can_record_cpu_wide(void)
+{
+       struct perf_event_attr attr = {
+               .type = PERF_TYPE_SOFTWARE,
+               .config = PERF_COUNT_SW_CPU_CLOCK,
+               .exclude_kernel = 1,
+       };
+       struct cpu_map *cpus;
+       int cpu, fd;
+
+       cpus = cpu_map__new(NULL);
+       if (!cpus)
+               return false;
+       cpu = cpus->map[0];
+       cpu_map__put(cpus);
+
+       fd = sys_perf_event_open(&attr, -1, cpu, -1, 0);
+       if (fd < 0)
+               return false;
+       close(fd);
+
+       return true;
+}
+
 void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts)
 {
        struct perf_evsel *evsel;