Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
83509565 f0ee3b46

+25
+1
tools/perf/util/evlist.h
··· 115 115 void perf_evlist__set_id_pos(struct perf_evlist *evlist); 116 116 bool perf_can_sample_identifier(void); 117 117 bool perf_can_record_switch_events(void); 118 + bool perf_can_record_cpu_wide(void); 118 119 void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts); 119 120 int record_opts__config(struct record_opts *opts); 120 121
+24
tools/perf/util/record.c
··· 105 105 return perf_probe_api(perf_probe_context_switch); 106 106 } 107 107 108 + bool 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 + 108 132 void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts) 109 133 { 110 134 struct perf_evsel *evsel;