aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util')
-rw-r--r--tools/perf/util/evsel.c52
-rw-r--r--tools/perf/util/evsel.h5
2 files changed, 57 insertions, 0 deletions
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 3f5de5196231..e62cc5e050ab 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1,4 +1,5 @@
1#include "evsel.h" 1#include "evsel.h"
2#include "../perf.h"
2#include "util.h" 3#include "util.h"
3 4
4#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) 5#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
@@ -121,3 +122,54 @@ int __perf_evsel__read(struct perf_evsel *evsel,
121 122
122 return 0; 123 return 0;
123} 124}
125
126int perf_evsel__open_per_cpu(struct perf_evsel *evsel, int ncpus, int *cpu_map)
127{
128 int cpu;
129
130 for (cpu = 0; cpu < ncpus; cpu++) {
131 FD(evsel, cpu, 0) = sys_perf_event_open(&evsel->attr, -1,
132 cpu_map[cpu], -1, 0);
133 if (FD(evsel, cpu, 0) < 0)
134 goto out_close;
135 }
136
137 return 0;
138
139out_close:
140 while (--cpu >= 0) {
141 close(FD(evsel, cpu, 0));
142 FD(evsel, cpu, 0) = -1;
143 }
144 return -1;
145}
146
147int perf_evsel__open_per_thread(struct perf_evsel *evsel, int nthreads, int *thread_map)
148{
149 int thread;
150
151 for (thread = 0; thread < nthreads; thread++) {
152 FD(evsel, 0, thread) = sys_perf_event_open(&evsel->attr,
153 thread_map[thread], -1, -1, 0);
154 if (FD(evsel, 0, thread) < 0)
155 goto out_close;
156 }
157
158 return 0;
159
160out_close:
161 while (--thread >= 0) {
162 close(FD(evsel, 0, thread));
163 FD(evsel, 0, thread) = -1;
164 }
165 return -1;
166}
167
168int perf_evsel__open(struct perf_evsel *evsel, int ncpus, int nthreads,
169 int *cpu_map, int *thread_map)
170{
171 if (nthreads < 0)
172 return perf_evsel__open_per_cpu(evsel, ncpus, cpu_map);
173
174 return perf_evsel__open_per_thread(evsel, nthreads, thread_map);
175}
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 8b48ef1e672c..a62fb55cffa7 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -42,6 +42,11 @@ int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
42void perf_evsel__free_fd(struct perf_evsel *evsel); 42void perf_evsel__free_fd(struct perf_evsel *evsel);
43void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads); 43void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
44 44
45int perf_evsel__open_per_cpu(struct perf_evsel *evsel, int ncpus, int *cpu_map);
46int perf_evsel__open_per_thread(struct perf_evsel *evsel, int nthreads, int *thread_map);
47int perf_evsel__open(struct perf_evsel *evsel, int ncpus, int nthreads,
48 int *cpu_map, int *thread_map);
49
45#define perf_evsel__match(evsel, t, c) \ 50#define perf_evsel__match(evsel, t, c) \
46 (evsel->attr.type == PERF_TYPE_##t && \ 51 (evsel->attr.type == PERF_TYPE_##t && \
47 evsel->attr.config == PERF_COUNT_##c) 52 evsel->attr.config == PERF_COUNT_##c)