aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2015-08-13 05:40:56 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-08-17 10:08:37 -0400
commit835095653ebfe4b16596a30db1c4e7c414014b5e (patch)
tree4afc6f2ac74109a8952745cb1c0748c3bad9de6f /tools/perf
parentf0ee3b467ab7a74ffce75190259eb59dbf30ecad (diff)
perf tools: Add a helper function to probe whether cpu-wide tracing is possible
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>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/util/evlist.h1
-rw-r--r--tools/perf/util/record.c24
2 files changed, 25 insertions, 0 deletions
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 397757063da1..436e358300b1 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -115,6 +115,7 @@ void perf_evlist__close(struct perf_evlist *evlist);
115void perf_evlist__set_id_pos(struct perf_evlist *evlist); 115void perf_evlist__set_id_pos(struct perf_evlist *evlist);
116bool perf_can_sample_identifier(void); 116bool perf_can_sample_identifier(void);
117bool perf_can_record_switch_events(void); 117bool perf_can_record_switch_events(void);
118bool perf_can_record_cpu_wide(void);
118void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts); 119void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts);
119int record_opts__config(struct record_opts *opts); 120int record_opts__config(struct record_opts *opts);
120 121
diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
index 0d228a29526d..0467367dc315 100644
--- a/tools/perf/util/record.c
+++ b/tools/perf/util/record.c
@@ -105,6 +105,30 @@ bool perf_can_record_switch_events(void)
105 return perf_probe_api(perf_probe_context_switch); 105 return perf_probe_api(perf_probe_context_switch);
106} 106}
107 107
108bool perf_can_record_cpu_wide(void)
109{
110 struct perf_event_attr attr = {
111 .type = PERF_TYPE_SOFTWARE,
112 .config = PERF_COUNT_SW_CPU_CLOCK,
113 .exclude_kernel = 1,
114 };
115 struct cpu_map *cpus;
116 int cpu, fd;
117
118 cpus = cpu_map__new(NULL);
119 if (!cpus)
120 return false;
121 cpu = cpus->map[0];
122 cpu_map__put(cpus);
123
124 fd = sys_perf_event_open(&attr, -1, cpu, -1, 0);
125 if (fd < 0)
126 return false;
127 close(fd);
128
129 return true;
130}
131
108void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts) 132void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts)
109{ 133{
110 struct perf_evsel *evsel; 134 struct perf_evsel *evsel;