Arnaldo Carvalho de Melo | f8a9530 | 2011-01-30 10:46:46 -0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com> |
| 3 | * |
| 4 | * Parts came from builtin-{top,stat,record}.c, see those files for further |
| 5 | * copyright notes. |
| 6 | * |
| 7 | * Released under the GPL v2. (and only v2, not any later version) |
| 8 | */ |
| 9 | |
David Ahern | 936be50 | 2011-09-06 09:12:26 -0600 | [diff] [blame] | 10 | #include <byteswap.h> |
Jiri Olsa | 0f6a301 | 2012-08-07 15:20:45 +0200 | [diff] [blame] | 11 | #include <linux/bitops.h> |
Borislav Petkov | 553873e | 2013-12-09 17:14:23 +0100 | [diff] [blame] | 12 | #include <api/fs/debugfs.h> |
Robert Richter | 4e31902 | 2013-06-11 17:29:18 +0200 | [diff] [blame] | 13 | #include <traceevent/event-parse.h> |
| 14 | #include <linux/hw_breakpoint.h> |
| 15 | #include <linux/perf_event.h> |
Andi Kleen | bec1967 | 2013-08-04 19:41:26 -0700 | [diff] [blame] | 16 | #include <sys/resource.h> |
Robert Richter | 4e31902 | 2013-06-11 17:29:18 +0200 | [diff] [blame] | 17 | #include "asm/bug.h" |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 18 | #include "evsel.h" |
Arnaldo Carvalho de Melo | 70082dd | 2011-01-12 17:03:24 -0200 | [diff] [blame] | 19 | #include "evlist.h" |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 20 | #include "util.h" |
Arnaldo Carvalho de Melo | 86bd5e8 | 2011-01-03 23:09:46 -0200 | [diff] [blame] | 21 | #include "cpumap.h" |
Arnaldo Carvalho de Melo | fd78260 | 2011-01-18 15:15:24 -0200 | [diff] [blame] | 22 | #include "thread_map.h" |
Namhyung Kim | 12864b3 | 2012-04-26 14:15:22 +0900 | [diff] [blame] | 23 | #include "target.h" |
Jiri Olsa | 26d3302 | 2012-08-07 15:20:47 +0200 | [diff] [blame] | 24 | #include "perf_regs.h" |
Adrian Hunter | e3e1a54 | 2013-08-14 15:48:24 +0300 | [diff] [blame] | 25 | #include "debug.h" |
Jiri Olsa | 97978b3 | 2013-12-03 14:09:24 +0100 | [diff] [blame] | 26 | #include "trace-event.h" |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 27 | |
Arnaldo Carvalho de Melo | 594ac61 | 2012-12-13 13:13:07 -0300 | [diff] [blame] | 28 | static struct { |
| 29 | bool sample_id_all; |
| 30 | bool exclude_guest; |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 31 | bool mmap2; |
Yann Droneaud | 57480d2 | 2014-06-30 22:28:47 +0200 | [diff] [blame] | 32 | bool cloexec; |
Arnaldo Carvalho de Melo | 594ac61 | 2012-12-13 13:13:07 -0300 | [diff] [blame] | 33 | } perf_missing_features; |
| 34 | |
Arnaldo Carvalho de Melo | c52b12e | 2011-01-03 17:45:52 -0200 | [diff] [blame] | 35 | #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) |
| 36 | |
Adrian Hunter | 7556257 | 2013-08-27 11:23:09 +0300 | [diff] [blame] | 37 | int __perf_evsel__sample_size(u64 sample_type) |
Arnaldo Carvalho de Melo | c2a7065 | 2011-06-02 11:04:54 -0300 | [diff] [blame] | 38 | { |
| 39 | u64 mask = sample_type & PERF_SAMPLE_MASK; |
| 40 | int size = 0; |
| 41 | int i; |
| 42 | |
| 43 | for (i = 0; i < 64; i++) { |
| 44 | if (mask & (1ULL << i)) |
| 45 | size++; |
| 46 | } |
| 47 | |
| 48 | size *= sizeof(u64); |
| 49 | |
| 50 | return size; |
| 51 | } |
| 52 | |
Adrian Hunter | 7556257 | 2013-08-27 11:23:09 +0300 | [diff] [blame] | 53 | /** |
| 54 | * __perf_evsel__calc_id_pos - calculate id_pos. |
| 55 | * @sample_type: sample type |
| 56 | * |
| 57 | * This function returns the position of the event id (PERF_SAMPLE_ID or |
| 58 | * PERF_SAMPLE_IDENTIFIER) in a sample event i.e. in the array of struct |
| 59 | * sample_event. |
| 60 | */ |
| 61 | static int __perf_evsel__calc_id_pos(u64 sample_type) |
| 62 | { |
| 63 | int idx = 0; |
| 64 | |
| 65 | if (sample_type & PERF_SAMPLE_IDENTIFIER) |
| 66 | return 0; |
| 67 | |
| 68 | if (!(sample_type & PERF_SAMPLE_ID)) |
| 69 | return -1; |
| 70 | |
| 71 | if (sample_type & PERF_SAMPLE_IP) |
| 72 | idx += 1; |
| 73 | |
| 74 | if (sample_type & PERF_SAMPLE_TID) |
| 75 | idx += 1; |
| 76 | |
| 77 | if (sample_type & PERF_SAMPLE_TIME) |
| 78 | idx += 1; |
| 79 | |
| 80 | if (sample_type & PERF_SAMPLE_ADDR) |
| 81 | idx += 1; |
| 82 | |
| 83 | return idx; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * __perf_evsel__calc_is_pos - calculate is_pos. |
| 88 | * @sample_type: sample type |
| 89 | * |
| 90 | * This function returns the position (counting backwards) of the event id |
| 91 | * (PERF_SAMPLE_ID or PERF_SAMPLE_IDENTIFIER) in a non-sample event i.e. if |
| 92 | * sample_id_all is used there is an id sample appended to non-sample events. |
| 93 | */ |
| 94 | static int __perf_evsel__calc_is_pos(u64 sample_type) |
| 95 | { |
| 96 | int idx = 1; |
| 97 | |
| 98 | if (sample_type & PERF_SAMPLE_IDENTIFIER) |
| 99 | return 1; |
| 100 | |
| 101 | if (!(sample_type & PERF_SAMPLE_ID)) |
| 102 | return -1; |
| 103 | |
| 104 | if (sample_type & PERF_SAMPLE_CPU) |
| 105 | idx += 1; |
| 106 | |
| 107 | if (sample_type & PERF_SAMPLE_STREAM_ID) |
| 108 | idx += 1; |
| 109 | |
| 110 | return idx; |
| 111 | } |
| 112 | |
| 113 | void perf_evsel__calc_id_pos(struct perf_evsel *evsel) |
| 114 | { |
| 115 | evsel->id_pos = __perf_evsel__calc_id_pos(evsel->attr.sample_type); |
| 116 | evsel->is_pos = __perf_evsel__calc_is_pos(evsel->attr.sample_type); |
| 117 | } |
| 118 | |
Jiri Olsa | 4bf9ce1 | 2012-03-22 14:37:26 +0100 | [diff] [blame] | 119 | void hists__init(struct hists *hists) |
Arnaldo Carvalho de Melo | 0e2a5f1 | 2011-11-04 08:16:58 -0200 | [diff] [blame] | 120 | { |
| 121 | memset(hists, 0, sizeof(*hists)); |
| 122 | hists->entries_in_array[0] = hists->entries_in_array[1] = RB_ROOT; |
| 123 | hists->entries_in = &hists->entries_in_array[0]; |
| 124 | hists->entries_collapsed = RB_ROOT; |
| 125 | hists->entries = RB_ROOT; |
| 126 | pthread_mutex_init(&hists->lock, NULL); |
| 127 | } |
| 128 | |
Arnaldo Carvalho de Melo | 7be5ebe | 2012-12-10 14:53:43 -0300 | [diff] [blame] | 129 | void __perf_evsel__set_sample_bit(struct perf_evsel *evsel, |
| 130 | enum perf_event_sample_format bit) |
| 131 | { |
| 132 | if (!(evsel->attr.sample_type & bit)) { |
| 133 | evsel->attr.sample_type |= bit; |
| 134 | evsel->sample_size += sizeof(u64); |
Adrian Hunter | 7556257 | 2013-08-27 11:23:09 +0300 | [diff] [blame] | 135 | perf_evsel__calc_id_pos(evsel); |
Arnaldo Carvalho de Melo | 7be5ebe | 2012-12-10 14:53:43 -0300 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
| 139 | void __perf_evsel__reset_sample_bit(struct perf_evsel *evsel, |
| 140 | enum perf_event_sample_format bit) |
| 141 | { |
| 142 | if (evsel->attr.sample_type & bit) { |
| 143 | evsel->attr.sample_type &= ~bit; |
| 144 | evsel->sample_size -= sizeof(u64); |
Adrian Hunter | 7556257 | 2013-08-27 11:23:09 +0300 | [diff] [blame] | 145 | perf_evsel__calc_id_pos(evsel); |
Arnaldo Carvalho de Melo | 7be5ebe | 2012-12-10 14:53:43 -0300 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
Adrian Hunter | 7556257 | 2013-08-27 11:23:09 +0300 | [diff] [blame] | 149 | void perf_evsel__set_sample_id(struct perf_evsel *evsel, |
| 150 | bool can_sample_identifier) |
Arnaldo Carvalho de Melo | 7a5a5ca | 2012-12-10 15:21:30 -0300 | [diff] [blame] | 151 | { |
Adrian Hunter | 7556257 | 2013-08-27 11:23:09 +0300 | [diff] [blame] | 152 | if (can_sample_identifier) { |
| 153 | perf_evsel__reset_sample_bit(evsel, ID); |
| 154 | perf_evsel__set_sample_bit(evsel, IDENTIFIER); |
| 155 | } else { |
| 156 | perf_evsel__set_sample_bit(evsel, ID); |
| 157 | } |
Arnaldo Carvalho de Melo | 7a5a5ca | 2012-12-10 15:21:30 -0300 | [diff] [blame] | 158 | evsel->attr.read_format |= PERF_FORMAT_ID; |
| 159 | } |
| 160 | |
Arnaldo Carvalho de Melo | ef1d1af | 2011-01-18 21:41:45 -0200 | [diff] [blame] | 161 | void perf_evsel__init(struct perf_evsel *evsel, |
| 162 | struct perf_event_attr *attr, int idx) |
| 163 | { |
| 164 | evsel->idx = idx; |
| 165 | evsel->attr = *attr; |
Namhyung Kim | 2cfda56 | 2012-11-29 15:38:29 +0900 | [diff] [blame] | 166 | evsel->leader = evsel; |
Stephane Eranian | 410136f | 2013-11-12 17:58:49 +0100 | [diff] [blame] | 167 | evsel->unit = ""; |
| 168 | evsel->scale = 1.0; |
Arnaldo Carvalho de Melo | ef1d1af | 2011-01-18 21:41:45 -0200 | [diff] [blame] | 169 | INIT_LIST_HEAD(&evsel->node); |
Arnaldo Carvalho de Melo | 1980c2eb | 2011-10-05 17:50:23 -0300 | [diff] [blame] | 170 | hists__init(&evsel->hists); |
Arnaldo Carvalho de Melo | bde0946 | 2012-08-01 18:53:11 -0300 | [diff] [blame] | 171 | evsel->sample_size = __perf_evsel__sample_size(attr->sample_type); |
Adrian Hunter | 7556257 | 2013-08-27 11:23:09 +0300 | [diff] [blame] | 172 | perf_evsel__calc_id_pos(evsel); |
Arnaldo Carvalho de Melo | ef1d1af | 2011-01-18 21:41:45 -0200 | [diff] [blame] | 173 | } |
| 174 | |
Arnaldo Carvalho de Melo | ef50383 | 2013-11-07 16:41:19 -0300 | [diff] [blame] | 175 | struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx) |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 176 | { |
| 177 | struct perf_evsel *evsel = zalloc(sizeof(*evsel)); |
| 178 | |
Arnaldo Carvalho de Melo | ef1d1af | 2011-01-18 21:41:45 -0200 | [diff] [blame] | 179 | if (evsel != NULL) |
| 180 | perf_evsel__init(evsel, attr, idx); |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 181 | |
| 182 | return evsel; |
| 183 | } |
| 184 | |
Arnaldo Carvalho de Melo | ef50383 | 2013-11-07 16:41:19 -0300 | [diff] [blame] | 185 | struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx) |
Arnaldo Carvalho de Melo | efd2b92 | 2012-09-18 11:21:50 -0300 | [diff] [blame] | 186 | { |
| 187 | struct perf_evsel *evsel = zalloc(sizeof(*evsel)); |
| 188 | |
| 189 | if (evsel != NULL) { |
| 190 | struct perf_event_attr attr = { |
Arnaldo Carvalho de Melo | 0b80f8b3 | 2012-09-26 12:28:26 -0300 | [diff] [blame] | 191 | .type = PERF_TYPE_TRACEPOINT, |
| 192 | .sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | |
| 193 | PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD), |
Arnaldo Carvalho de Melo | efd2b92 | 2012-09-18 11:21:50 -0300 | [diff] [blame] | 194 | }; |
| 195 | |
Arnaldo Carvalho de Melo | e48ffe2 | 2012-09-26 17:11:38 -0300 | [diff] [blame] | 196 | if (asprintf(&evsel->name, "%s:%s", sys, name) < 0) |
| 197 | goto out_free; |
| 198 | |
Jiri Olsa | 97978b3 | 2013-12-03 14:09:24 +0100 | [diff] [blame] | 199 | evsel->tp_format = trace_event__tp_format(sys, name); |
Arnaldo Carvalho de Melo | efd2b92 | 2012-09-18 11:21:50 -0300 | [diff] [blame] | 200 | if (evsel->tp_format == NULL) |
| 201 | goto out_free; |
| 202 | |
Arnaldo Carvalho de Melo | 0b80f8b3 | 2012-09-26 12:28:26 -0300 | [diff] [blame] | 203 | event_attr_init(&attr); |
Arnaldo Carvalho de Melo | efd2b92 | 2012-09-18 11:21:50 -0300 | [diff] [blame] | 204 | attr.config = evsel->tp_format->id; |
Arnaldo Carvalho de Melo | 0b80f8b3 | 2012-09-26 12:28:26 -0300 | [diff] [blame] | 205 | attr.sample_period = 1; |
Arnaldo Carvalho de Melo | efd2b92 | 2012-09-18 11:21:50 -0300 | [diff] [blame] | 206 | perf_evsel__init(evsel, &attr, idx); |
Arnaldo Carvalho de Melo | efd2b92 | 2012-09-18 11:21:50 -0300 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | return evsel; |
| 210 | |
| 211 | out_free: |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 212 | zfree(&evsel->name); |
Arnaldo Carvalho de Melo | efd2b92 | 2012-09-18 11:21:50 -0300 | [diff] [blame] | 213 | free(evsel); |
| 214 | return NULL; |
| 215 | } |
| 216 | |
Arnaldo Carvalho de Melo | 8ad7013 | 2012-09-06 13:11:18 -0300 | [diff] [blame] | 217 | const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX] = { |
Arnaldo Carvalho de Melo | c410431 | 2012-05-25 16:38:11 -0300 | [diff] [blame] | 218 | "cycles", |
| 219 | "instructions", |
| 220 | "cache-references", |
| 221 | "cache-misses", |
| 222 | "branches", |
| 223 | "branch-misses", |
| 224 | "bus-cycles", |
| 225 | "stalled-cycles-frontend", |
| 226 | "stalled-cycles-backend", |
| 227 | "ref-cycles", |
| 228 | }; |
| 229 | |
Arnaldo Carvalho de Melo | dd4f522 | 2012-06-13 15:52:42 -0300 | [diff] [blame] | 230 | static const char *__perf_evsel__hw_name(u64 config) |
Arnaldo Carvalho de Melo | c410431 | 2012-05-25 16:38:11 -0300 | [diff] [blame] | 231 | { |
| 232 | if (config < PERF_COUNT_HW_MAX && perf_evsel__hw_names[config]) |
| 233 | return perf_evsel__hw_names[config]; |
| 234 | |
| 235 | return "unknown-hardware"; |
| 236 | } |
| 237 | |
Arnaldo Carvalho de Melo | 27f1861 | 2012-06-11 13:33:09 -0300 | [diff] [blame] | 238 | static int perf_evsel__add_modifiers(struct perf_evsel *evsel, char *bf, size_t size) |
Arnaldo Carvalho de Melo | c410431 | 2012-05-25 16:38:11 -0300 | [diff] [blame] | 239 | { |
Arnaldo Carvalho de Melo | 27f1861 | 2012-06-11 13:33:09 -0300 | [diff] [blame] | 240 | int colon = 0, r = 0; |
Arnaldo Carvalho de Melo | c410431 | 2012-05-25 16:38:11 -0300 | [diff] [blame] | 241 | struct perf_event_attr *attr = &evsel->attr; |
Arnaldo Carvalho de Melo | c410431 | 2012-05-25 16:38:11 -0300 | [diff] [blame] | 242 | bool exclude_guest_default = false; |
| 243 | |
| 244 | #define MOD_PRINT(context, mod) do { \ |
| 245 | if (!attr->exclude_##context) { \ |
Arnaldo Carvalho de Melo | 27f1861 | 2012-06-11 13:33:09 -0300 | [diff] [blame] | 246 | if (!colon) colon = ++r; \ |
Arnaldo Carvalho de Melo | c410431 | 2012-05-25 16:38:11 -0300 | [diff] [blame] | 247 | r += scnprintf(bf + r, size - r, "%c", mod); \ |
| 248 | } } while(0) |
| 249 | |
| 250 | if (attr->exclude_kernel || attr->exclude_user || attr->exclude_hv) { |
| 251 | MOD_PRINT(kernel, 'k'); |
| 252 | MOD_PRINT(user, 'u'); |
| 253 | MOD_PRINT(hv, 'h'); |
| 254 | exclude_guest_default = true; |
| 255 | } |
| 256 | |
| 257 | if (attr->precise_ip) { |
| 258 | if (!colon) |
Arnaldo Carvalho de Melo | 27f1861 | 2012-06-11 13:33:09 -0300 | [diff] [blame] | 259 | colon = ++r; |
Arnaldo Carvalho de Melo | c410431 | 2012-05-25 16:38:11 -0300 | [diff] [blame] | 260 | r += scnprintf(bf + r, size - r, "%.*s", attr->precise_ip, "ppp"); |
| 261 | exclude_guest_default = true; |
| 262 | } |
| 263 | |
| 264 | if (attr->exclude_host || attr->exclude_guest == exclude_guest_default) { |
| 265 | MOD_PRINT(host, 'H'); |
| 266 | MOD_PRINT(guest, 'G'); |
| 267 | } |
| 268 | #undef MOD_PRINT |
| 269 | if (colon) |
Arnaldo Carvalho de Melo | 27f1861 | 2012-06-11 13:33:09 -0300 | [diff] [blame] | 270 | bf[colon - 1] = ':'; |
Arnaldo Carvalho de Melo | c410431 | 2012-05-25 16:38:11 -0300 | [diff] [blame] | 271 | return r; |
| 272 | } |
| 273 | |
Arnaldo Carvalho de Melo | 27f1861 | 2012-06-11 13:33:09 -0300 | [diff] [blame] | 274 | static int perf_evsel__hw_name(struct perf_evsel *evsel, char *bf, size_t size) |
| 275 | { |
| 276 | int r = scnprintf(bf, size, "%s", __perf_evsel__hw_name(evsel->attr.config)); |
| 277 | return r + perf_evsel__add_modifiers(evsel, bf + r, size - r); |
| 278 | } |
| 279 | |
Arnaldo Carvalho de Melo | 8ad7013 | 2012-09-06 13:11:18 -0300 | [diff] [blame] | 280 | const char *perf_evsel__sw_names[PERF_COUNT_SW_MAX] = { |
Arnaldo Carvalho de Melo | 335c2f5 | 2012-06-11 14:36:20 -0300 | [diff] [blame] | 281 | "cpu-clock", |
| 282 | "task-clock", |
| 283 | "page-faults", |
| 284 | "context-switches", |
Arnaldo Carvalho de Melo | 8ad7013 | 2012-09-06 13:11:18 -0300 | [diff] [blame] | 285 | "cpu-migrations", |
Arnaldo Carvalho de Melo | 335c2f5 | 2012-06-11 14:36:20 -0300 | [diff] [blame] | 286 | "minor-faults", |
| 287 | "major-faults", |
| 288 | "alignment-faults", |
| 289 | "emulation-faults", |
Adrian Hunter | d22d1a2 | 2013-08-31 21:50:52 +0300 | [diff] [blame] | 290 | "dummy", |
Arnaldo Carvalho de Melo | 335c2f5 | 2012-06-11 14:36:20 -0300 | [diff] [blame] | 291 | }; |
| 292 | |
Arnaldo Carvalho de Melo | dd4f522 | 2012-06-13 15:52:42 -0300 | [diff] [blame] | 293 | static const char *__perf_evsel__sw_name(u64 config) |
Arnaldo Carvalho de Melo | 335c2f5 | 2012-06-11 14:36:20 -0300 | [diff] [blame] | 294 | { |
| 295 | if (config < PERF_COUNT_SW_MAX && perf_evsel__sw_names[config]) |
| 296 | return perf_evsel__sw_names[config]; |
| 297 | return "unknown-software"; |
| 298 | } |
| 299 | |
| 300 | static int perf_evsel__sw_name(struct perf_evsel *evsel, char *bf, size_t size) |
| 301 | { |
| 302 | int r = scnprintf(bf, size, "%s", __perf_evsel__sw_name(evsel->attr.config)); |
| 303 | return r + perf_evsel__add_modifiers(evsel, bf + r, size - r); |
| 304 | } |
| 305 | |
Jiri Olsa | 287e74a | 2012-06-28 23:18:49 +0200 | [diff] [blame] | 306 | static int __perf_evsel__bp_name(char *bf, size_t size, u64 addr, u64 type) |
| 307 | { |
| 308 | int r; |
| 309 | |
| 310 | r = scnprintf(bf, size, "mem:0x%" PRIx64 ":", addr); |
| 311 | |
| 312 | if (type & HW_BREAKPOINT_R) |
| 313 | r += scnprintf(bf + r, size - r, "r"); |
| 314 | |
| 315 | if (type & HW_BREAKPOINT_W) |
| 316 | r += scnprintf(bf + r, size - r, "w"); |
| 317 | |
| 318 | if (type & HW_BREAKPOINT_X) |
| 319 | r += scnprintf(bf + r, size - r, "x"); |
| 320 | |
| 321 | return r; |
| 322 | } |
| 323 | |
| 324 | static int perf_evsel__bp_name(struct perf_evsel *evsel, char *bf, size_t size) |
| 325 | { |
| 326 | struct perf_event_attr *attr = &evsel->attr; |
| 327 | int r = __perf_evsel__bp_name(bf, size, attr->bp_addr, attr->bp_type); |
| 328 | return r + perf_evsel__add_modifiers(evsel, bf + r, size - r); |
| 329 | } |
| 330 | |
Arnaldo Carvalho de Melo | 0b668bc | 2012-06-11 14:08:07 -0300 | [diff] [blame] | 331 | const char *perf_evsel__hw_cache[PERF_COUNT_HW_CACHE_MAX] |
| 332 | [PERF_EVSEL__MAX_ALIASES] = { |
| 333 | { "L1-dcache", "l1-d", "l1d", "L1-data", }, |
| 334 | { "L1-icache", "l1-i", "l1i", "L1-instruction", }, |
| 335 | { "LLC", "L2", }, |
| 336 | { "dTLB", "d-tlb", "Data-TLB", }, |
| 337 | { "iTLB", "i-tlb", "Instruction-TLB", }, |
| 338 | { "branch", "branches", "bpu", "btb", "bpc", }, |
| 339 | { "node", }, |
| 340 | }; |
| 341 | |
| 342 | const char *perf_evsel__hw_cache_op[PERF_COUNT_HW_CACHE_OP_MAX] |
| 343 | [PERF_EVSEL__MAX_ALIASES] = { |
| 344 | { "load", "loads", "read", }, |
| 345 | { "store", "stores", "write", }, |
| 346 | { "prefetch", "prefetches", "speculative-read", "speculative-load", }, |
| 347 | }; |
| 348 | |
| 349 | const char *perf_evsel__hw_cache_result[PERF_COUNT_HW_CACHE_RESULT_MAX] |
| 350 | [PERF_EVSEL__MAX_ALIASES] = { |
| 351 | { "refs", "Reference", "ops", "access", }, |
| 352 | { "misses", "miss", }, |
| 353 | }; |
| 354 | |
| 355 | #define C(x) PERF_COUNT_HW_CACHE_##x |
| 356 | #define CACHE_READ (1 << C(OP_READ)) |
| 357 | #define CACHE_WRITE (1 << C(OP_WRITE)) |
| 358 | #define CACHE_PREFETCH (1 << C(OP_PREFETCH)) |
| 359 | #define COP(x) (1 << x) |
| 360 | |
| 361 | /* |
| 362 | * cache operartion stat |
| 363 | * L1I : Read and prefetch only |
| 364 | * ITLB and BPU : Read-only |
| 365 | */ |
| 366 | static unsigned long perf_evsel__hw_cache_stat[C(MAX)] = { |
| 367 | [C(L1D)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), |
| 368 | [C(L1I)] = (CACHE_READ | CACHE_PREFETCH), |
| 369 | [C(LL)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), |
| 370 | [C(DTLB)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), |
| 371 | [C(ITLB)] = (CACHE_READ), |
| 372 | [C(BPU)] = (CACHE_READ), |
| 373 | [C(NODE)] = (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH), |
| 374 | }; |
| 375 | |
| 376 | bool perf_evsel__is_cache_op_valid(u8 type, u8 op) |
| 377 | { |
| 378 | if (perf_evsel__hw_cache_stat[type] & COP(op)) |
| 379 | return true; /* valid */ |
| 380 | else |
| 381 | return false; /* invalid */ |
| 382 | } |
| 383 | |
| 384 | int __perf_evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result, |
| 385 | char *bf, size_t size) |
| 386 | { |
| 387 | if (result) { |
| 388 | return scnprintf(bf, size, "%s-%s-%s", perf_evsel__hw_cache[type][0], |
| 389 | perf_evsel__hw_cache_op[op][0], |
| 390 | perf_evsel__hw_cache_result[result][0]); |
| 391 | } |
| 392 | |
| 393 | return scnprintf(bf, size, "%s-%s", perf_evsel__hw_cache[type][0], |
| 394 | perf_evsel__hw_cache_op[op][1]); |
| 395 | } |
| 396 | |
Arnaldo Carvalho de Melo | dd4f522 | 2012-06-13 15:52:42 -0300 | [diff] [blame] | 397 | static int __perf_evsel__hw_cache_name(u64 config, char *bf, size_t size) |
Arnaldo Carvalho de Melo | 0b668bc | 2012-06-11 14:08:07 -0300 | [diff] [blame] | 398 | { |
| 399 | u8 op, result, type = (config >> 0) & 0xff; |
| 400 | const char *err = "unknown-ext-hardware-cache-type"; |
| 401 | |
| 402 | if (type > PERF_COUNT_HW_CACHE_MAX) |
| 403 | goto out_err; |
| 404 | |
| 405 | op = (config >> 8) & 0xff; |
| 406 | err = "unknown-ext-hardware-cache-op"; |
| 407 | if (op > PERF_COUNT_HW_CACHE_OP_MAX) |
| 408 | goto out_err; |
| 409 | |
| 410 | result = (config >> 16) & 0xff; |
| 411 | err = "unknown-ext-hardware-cache-result"; |
| 412 | if (result > PERF_COUNT_HW_CACHE_RESULT_MAX) |
| 413 | goto out_err; |
| 414 | |
| 415 | err = "invalid-cache"; |
| 416 | if (!perf_evsel__is_cache_op_valid(type, op)) |
| 417 | goto out_err; |
| 418 | |
| 419 | return __perf_evsel__hw_cache_type_op_res_name(type, op, result, bf, size); |
| 420 | out_err: |
| 421 | return scnprintf(bf, size, "%s", err); |
| 422 | } |
| 423 | |
| 424 | static int perf_evsel__hw_cache_name(struct perf_evsel *evsel, char *bf, size_t size) |
| 425 | { |
| 426 | int ret = __perf_evsel__hw_cache_name(evsel->attr.config, bf, size); |
| 427 | return ret + perf_evsel__add_modifiers(evsel, bf + ret, size - ret); |
| 428 | } |
| 429 | |
Arnaldo Carvalho de Melo | 6eef3d9 | 2012-06-13 11:53:37 -0300 | [diff] [blame] | 430 | static int perf_evsel__raw_name(struct perf_evsel *evsel, char *bf, size_t size) |
| 431 | { |
| 432 | int ret = scnprintf(bf, size, "raw 0x%" PRIx64, evsel->attr.config); |
| 433 | return ret + perf_evsel__add_modifiers(evsel, bf + ret, size - ret); |
| 434 | } |
| 435 | |
Arnaldo Carvalho de Melo | 7289f83 | 2012-06-12 12:34:58 -0300 | [diff] [blame] | 436 | const char *perf_evsel__name(struct perf_evsel *evsel) |
Arnaldo Carvalho de Melo | a446083 | 2012-06-12 10:29:12 -0300 | [diff] [blame] | 437 | { |
Arnaldo Carvalho de Melo | 7289f83 | 2012-06-12 12:34:58 -0300 | [diff] [blame] | 438 | char bf[128]; |
Arnaldo Carvalho de Melo | a446083 | 2012-06-12 10:29:12 -0300 | [diff] [blame] | 439 | |
Arnaldo Carvalho de Melo | 7289f83 | 2012-06-12 12:34:58 -0300 | [diff] [blame] | 440 | if (evsel->name) |
| 441 | return evsel->name; |
Arnaldo Carvalho de Melo | c410431 | 2012-05-25 16:38:11 -0300 | [diff] [blame] | 442 | |
| 443 | switch (evsel->attr.type) { |
| 444 | case PERF_TYPE_RAW: |
Arnaldo Carvalho de Melo | 6eef3d9 | 2012-06-13 11:53:37 -0300 | [diff] [blame] | 445 | perf_evsel__raw_name(evsel, bf, sizeof(bf)); |
Arnaldo Carvalho de Melo | c410431 | 2012-05-25 16:38:11 -0300 | [diff] [blame] | 446 | break; |
| 447 | |
| 448 | case PERF_TYPE_HARDWARE: |
Arnaldo Carvalho de Melo | 7289f83 | 2012-06-12 12:34:58 -0300 | [diff] [blame] | 449 | perf_evsel__hw_name(evsel, bf, sizeof(bf)); |
Arnaldo Carvalho de Melo | c410431 | 2012-05-25 16:38:11 -0300 | [diff] [blame] | 450 | break; |
Arnaldo Carvalho de Melo | 0b668bc | 2012-06-11 14:08:07 -0300 | [diff] [blame] | 451 | |
| 452 | case PERF_TYPE_HW_CACHE: |
Arnaldo Carvalho de Melo | 7289f83 | 2012-06-12 12:34:58 -0300 | [diff] [blame] | 453 | perf_evsel__hw_cache_name(evsel, bf, sizeof(bf)); |
Arnaldo Carvalho de Melo | 0b668bc | 2012-06-11 14:08:07 -0300 | [diff] [blame] | 454 | break; |
| 455 | |
Arnaldo Carvalho de Melo | 335c2f5 | 2012-06-11 14:36:20 -0300 | [diff] [blame] | 456 | case PERF_TYPE_SOFTWARE: |
Arnaldo Carvalho de Melo | 7289f83 | 2012-06-12 12:34:58 -0300 | [diff] [blame] | 457 | perf_evsel__sw_name(evsel, bf, sizeof(bf)); |
Arnaldo Carvalho de Melo | 335c2f5 | 2012-06-11 14:36:20 -0300 | [diff] [blame] | 458 | break; |
| 459 | |
Arnaldo Carvalho de Melo | a446083 | 2012-06-12 10:29:12 -0300 | [diff] [blame] | 460 | case PERF_TYPE_TRACEPOINT: |
Arnaldo Carvalho de Melo | 7289f83 | 2012-06-12 12:34:58 -0300 | [diff] [blame] | 461 | scnprintf(bf, sizeof(bf), "%s", "unknown tracepoint"); |
Arnaldo Carvalho de Melo | a446083 | 2012-06-12 10:29:12 -0300 | [diff] [blame] | 462 | break; |
| 463 | |
Jiri Olsa | 287e74a | 2012-06-28 23:18:49 +0200 | [diff] [blame] | 464 | case PERF_TYPE_BREAKPOINT: |
| 465 | perf_evsel__bp_name(evsel, bf, sizeof(bf)); |
| 466 | break; |
| 467 | |
Arnaldo Carvalho de Melo | c410431 | 2012-05-25 16:38:11 -0300 | [diff] [blame] | 468 | default: |
Robert Richter | ca1b145 | 2012-08-16 21:10:18 +0200 | [diff] [blame] | 469 | scnprintf(bf, sizeof(bf), "unknown attr type: %d", |
| 470 | evsel->attr.type); |
Arnaldo Carvalho de Melo | a446083 | 2012-06-12 10:29:12 -0300 | [diff] [blame] | 471 | break; |
Arnaldo Carvalho de Melo | c410431 | 2012-05-25 16:38:11 -0300 | [diff] [blame] | 472 | } |
| 473 | |
Arnaldo Carvalho de Melo | 7289f83 | 2012-06-12 12:34:58 -0300 | [diff] [blame] | 474 | evsel->name = strdup(bf); |
| 475 | |
| 476 | return evsel->name ?: "unknown"; |
Arnaldo Carvalho de Melo | c410431 | 2012-05-25 16:38:11 -0300 | [diff] [blame] | 477 | } |
| 478 | |
Namhyung Kim | 717e263 | 2013-01-22 18:09:44 +0900 | [diff] [blame] | 479 | const char *perf_evsel__group_name(struct perf_evsel *evsel) |
| 480 | { |
| 481 | return evsel->group_name ?: "anon group"; |
| 482 | } |
| 483 | |
| 484 | int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size) |
| 485 | { |
| 486 | int ret; |
| 487 | struct perf_evsel *pos; |
| 488 | const char *group_name = perf_evsel__group_name(evsel); |
| 489 | |
| 490 | ret = scnprintf(buf, size, "%s", group_name); |
| 491 | |
| 492 | ret += scnprintf(buf + ret, size - ret, " { %s", |
| 493 | perf_evsel__name(evsel)); |
| 494 | |
| 495 | for_each_group_member(pos, evsel) |
| 496 | ret += scnprintf(buf + ret, size - ret, ", %s", |
| 497 | perf_evsel__name(pos)); |
| 498 | |
| 499 | ret += scnprintf(buf + ret, size - ret, " }"); |
| 500 | |
| 501 | return ret; |
| 502 | } |
| 503 | |
Jiri Olsa | 6bedfab | 2014-03-02 16:56:40 +0100 | [diff] [blame] | 504 | static void |
| 505 | perf_evsel__config_callgraph(struct perf_evsel *evsel, |
| 506 | struct record_opts *opts) |
| 507 | { |
| 508 | bool function = perf_evsel__is_function_event(evsel); |
| 509 | struct perf_event_attr *attr = &evsel->attr; |
| 510 | |
| 511 | perf_evsel__set_sample_bit(evsel, CALLCHAIN); |
| 512 | |
| 513 | if (opts->call_graph == CALLCHAIN_DWARF) { |
| 514 | if (!function) { |
| 515 | perf_evsel__set_sample_bit(evsel, REGS_USER); |
| 516 | perf_evsel__set_sample_bit(evsel, STACK_USER); |
| 517 | attr->sample_regs_user = PERF_REGS_MASK; |
| 518 | attr->sample_stack_user = opts->stack_dump_size; |
| 519 | attr->exclude_callchain_user = 1; |
| 520 | } else { |
| 521 | pr_info("Cannot use DWARF unwind for function trace event," |
| 522 | " falling back to framepointers.\n"); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | if (function) { |
| 527 | pr_info("Disabling user space callchains for function trace event.\n"); |
| 528 | attr->exclude_callchain_user = 1; |
| 529 | } |
| 530 | } |
| 531 | |
Jiri Olsa | 774cb49 | 2012-11-12 18:34:01 +0100 | [diff] [blame] | 532 | /* |
| 533 | * The enable_on_exec/disabled value strategy: |
| 534 | * |
| 535 | * 1) For any type of traced program: |
| 536 | * - all independent events and group leaders are disabled |
| 537 | * - all group members are enabled |
| 538 | * |
| 539 | * Group members are ruled by group leaders. They need to |
| 540 | * be enabled, because the group scheduling relies on that. |
| 541 | * |
| 542 | * 2) For traced programs executed by perf: |
| 543 | * - all independent events and group leaders have |
| 544 | * enable_on_exec set |
| 545 | * - we don't specifically enable or disable any event during |
| 546 | * the record command |
| 547 | * |
| 548 | * Independent events and group leaders are initially disabled |
| 549 | * and get enabled by exec. Group members are ruled by group |
| 550 | * leaders as stated in 1). |
| 551 | * |
| 552 | * 3) For traced programs attached by perf (pid/tid): |
| 553 | * - we specifically enable or disable all events during |
| 554 | * the record command |
| 555 | * |
| 556 | * When attaching events to already running traced we |
| 557 | * enable/disable events specifically, as there's no |
| 558 | * initial traced exec call. |
| 559 | */ |
Arnaldo Carvalho de Melo | b400679 | 2013-12-19 14:43:45 -0300 | [diff] [blame] | 560 | void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts) |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 561 | { |
Jiri Olsa | 3c17631 | 2012-10-10 17:39:03 +0200 | [diff] [blame] | 562 | struct perf_evsel *leader = evsel->leader; |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 563 | struct perf_event_attr *attr = &evsel->attr; |
| 564 | int track = !evsel->idx; /* only the first counter needs these */ |
Adrian Hunter | 3aa5939 | 2013-11-15 15:52:29 +0200 | [diff] [blame] | 565 | bool per_cpu = opts->target.default_per_cpu && !opts->target.per_thread; |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 566 | |
Arnaldo Carvalho de Melo | 594ac61 | 2012-12-13 13:13:07 -0300 | [diff] [blame] | 567 | attr->sample_id_all = perf_missing_features.sample_id_all ? 0 : 1; |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 568 | attr->inherit = !opts->no_inherit; |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 569 | |
Arnaldo Carvalho de Melo | 7be5ebe | 2012-12-10 14:53:43 -0300 | [diff] [blame] | 570 | perf_evsel__set_sample_bit(evsel, IP); |
| 571 | perf_evsel__set_sample_bit(evsel, TID); |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 572 | |
Jiri Olsa | 3c17631 | 2012-10-10 17:39:03 +0200 | [diff] [blame] | 573 | if (evsel->sample_read) { |
| 574 | perf_evsel__set_sample_bit(evsel, READ); |
| 575 | |
| 576 | /* |
| 577 | * We need ID even in case of single event, because |
| 578 | * PERF_SAMPLE_READ process ID specific data. |
| 579 | */ |
Adrian Hunter | 7556257 | 2013-08-27 11:23:09 +0300 | [diff] [blame] | 580 | perf_evsel__set_sample_id(evsel, false); |
Jiri Olsa | 3c17631 | 2012-10-10 17:39:03 +0200 | [diff] [blame] | 581 | |
| 582 | /* |
| 583 | * Apply group format only if we belong to group |
| 584 | * with more than one members. |
| 585 | */ |
| 586 | if (leader->nr_members > 1) { |
| 587 | attr->read_format |= PERF_FORMAT_GROUP; |
| 588 | attr->inherit = 0; |
| 589 | } |
| 590 | } |
| 591 | |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 592 | /* |
Namhyung Kim | 17314e2 | 2014-06-09 14:43:37 +0900 | [diff] [blame] | 593 | * We default some events to have a default interval. But keep |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 594 | * it a weak assumption overridable by the user. |
| 595 | */ |
Namhyung Kim | 17314e2 | 2014-06-09 14:43:37 +0900 | [diff] [blame] | 596 | if (!attr->sample_period || (opts->user_freq != UINT_MAX || |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 597 | opts->user_interval != ULLONG_MAX)) { |
| 598 | if (opts->freq) { |
Arnaldo Carvalho de Melo | 7be5ebe | 2012-12-10 14:53:43 -0300 | [diff] [blame] | 599 | perf_evsel__set_sample_bit(evsel, PERIOD); |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 600 | attr->freq = 1; |
| 601 | attr->sample_freq = opts->freq; |
| 602 | } else { |
| 603 | attr->sample_period = opts->default_interval; |
| 604 | } |
| 605 | } |
| 606 | |
Jiri Olsa | 3c17631 | 2012-10-10 17:39:03 +0200 | [diff] [blame] | 607 | /* |
| 608 | * Disable sampling for all group members other |
| 609 | * than leader in case leader 'leads' the sampling. |
| 610 | */ |
| 611 | if ((leader != evsel) && leader->sample_read) { |
| 612 | attr->sample_freq = 0; |
| 613 | attr->sample_period = 0; |
| 614 | } |
| 615 | |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 616 | if (opts->no_samples) |
| 617 | attr->sample_freq = 0; |
| 618 | |
| 619 | if (opts->inherit_stat) |
| 620 | attr->inherit_stat = 1; |
| 621 | |
| 622 | if (opts->sample_address) { |
Arnaldo Carvalho de Melo | 7be5ebe | 2012-12-10 14:53:43 -0300 | [diff] [blame] | 623 | perf_evsel__set_sample_bit(evsel, ADDR); |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 624 | attr->mmap_data = track; |
| 625 | } |
| 626 | |
Adrian Hunter | 6ff1ce7 | 2014-07-14 13:02:56 +0300 | [diff] [blame] | 627 | if (opts->call_graph_enabled && !evsel->no_aux_samples) |
Jiri Olsa | 6bedfab | 2014-03-02 16:56:40 +0100 | [diff] [blame] | 628 | perf_evsel__config_callgraph(evsel, opts); |
Jiri Olsa | 26d3302 | 2012-08-07 15:20:47 +0200 | [diff] [blame] | 629 | |
Adrian Hunter | 3aa5939 | 2013-11-15 15:52:29 +0200 | [diff] [blame] | 630 | if (target__has_cpu(&opts->target)) |
Arnaldo Carvalho de Melo | 7be5ebe | 2012-12-10 14:53:43 -0300 | [diff] [blame] | 631 | perf_evsel__set_sample_bit(evsel, CPU); |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 632 | |
Andrew Vagin | 3e76ac7 | 2011-12-20 17:32:45 +0300 | [diff] [blame] | 633 | if (opts->period) |
Arnaldo Carvalho de Melo | 7be5ebe | 2012-12-10 14:53:43 -0300 | [diff] [blame] | 634 | perf_evsel__set_sample_bit(evsel, PERIOD); |
Andrew Vagin | 3e76ac7 | 2011-12-20 17:32:45 +0300 | [diff] [blame] | 635 | |
Andi Kleen | 8affc2b | 2014-07-31 14:45:04 +0800 | [diff] [blame] | 636 | /* |
| 637 | * When the user explicitely disabled time don't force it here. |
| 638 | */ |
| 639 | if (opts->sample_time && |
| 640 | (!perf_missing_features.sample_id_all && |
| 641 | (!opts->no_inherit || target__has_cpu(&opts->target) || per_cpu))) |
Arnaldo Carvalho de Melo | 7be5ebe | 2012-12-10 14:53:43 -0300 | [diff] [blame] | 642 | perf_evsel__set_sample_bit(evsel, TIME); |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 643 | |
Adrian Hunter | 6ff1ce7 | 2014-07-14 13:02:56 +0300 | [diff] [blame] | 644 | if (opts->raw_samples && !evsel->no_aux_samples) { |
Arnaldo Carvalho de Melo | 7be5ebe | 2012-12-10 14:53:43 -0300 | [diff] [blame] | 645 | perf_evsel__set_sample_bit(evsel, TIME); |
| 646 | perf_evsel__set_sample_bit(evsel, RAW); |
| 647 | perf_evsel__set_sample_bit(evsel, CPU); |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 648 | } |
| 649 | |
Stephane Eranian | ccf49bf | 2013-01-24 16:10:37 +0100 | [diff] [blame] | 650 | if (opts->sample_address) |
Adrian Hunter | 1e7ed5e | 2013-11-01 15:51:35 +0200 | [diff] [blame] | 651 | perf_evsel__set_sample_bit(evsel, DATA_SRC); |
Stephane Eranian | ccf49bf | 2013-01-24 16:10:37 +0100 | [diff] [blame] | 652 | |
Arnaldo Carvalho de Melo | 509051e | 2014-01-14 17:52:14 -0300 | [diff] [blame] | 653 | if (opts->no_buffering) { |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 654 | attr->watermark = 0; |
| 655 | attr->wakeup_events = 1; |
| 656 | } |
Adrian Hunter | 6ff1ce7 | 2014-07-14 13:02:56 +0300 | [diff] [blame] | 657 | if (opts->branch_stack && !evsel->no_aux_samples) { |
Arnaldo Carvalho de Melo | 7be5ebe | 2012-12-10 14:53:43 -0300 | [diff] [blame] | 658 | perf_evsel__set_sample_bit(evsel, BRANCH_STACK); |
Roberto Agostino Vitillo | bdfebd8 | 2012-02-09 23:21:02 +0100 | [diff] [blame] | 659 | attr->branch_sample_type = opts->branch_stack; |
| 660 | } |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 661 | |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 662 | if (opts->sample_weight) |
Adrian Hunter | 1e7ed5e | 2013-11-01 15:51:35 +0200 | [diff] [blame] | 663 | perf_evsel__set_sample_bit(evsel, WEIGHT); |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 664 | |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 665 | attr->mmap = track; |
Don Zickus | a5a5ba7 | 2014-05-30 10:49:42 -0400 | [diff] [blame] | 666 | attr->mmap2 = track && !perf_missing_features.mmap2; |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 667 | attr->comm = track; |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 668 | |
Andi Kleen | 475eeab | 2013-09-20 07:40:43 -0700 | [diff] [blame] | 669 | if (opts->sample_transaction) |
Adrian Hunter | 1e7ed5e | 2013-11-01 15:51:35 +0200 | [diff] [blame] | 670 | perf_evsel__set_sample_bit(evsel, TRANSACTION); |
Andi Kleen | 475eeab | 2013-09-20 07:40:43 -0700 | [diff] [blame] | 671 | |
Jiri Olsa | 774cb49 | 2012-11-12 18:34:01 +0100 | [diff] [blame] | 672 | /* |
| 673 | * XXX see the function comment above |
| 674 | * |
| 675 | * Disabling only independent events or group leaders, |
| 676 | * keeping group members enabled. |
| 677 | */ |
Namhyung Kim | 823254e | 2012-11-29 15:38:30 +0900 | [diff] [blame] | 678 | if (perf_evsel__is_group_leader(evsel)) |
Jiri Olsa | 774cb49 | 2012-11-12 18:34:01 +0100 | [diff] [blame] | 679 | attr->disabled = 1; |
| 680 | |
| 681 | /* |
| 682 | * Setting enable_on_exec for independent events and |
| 683 | * group leaders for traced executed by perf. |
| 684 | */ |
Andi Kleen | 6619a53 | 2014-01-11 13:38:27 -0800 | [diff] [blame] | 685 | if (target__none(&opts->target) && perf_evsel__is_group_leader(evsel) && |
| 686 | !opts->initial_delay) |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 687 | attr->enable_on_exec = 1; |
Adrian Hunter | 2afd2bc | 2014-07-14 13:02:57 +0300 | [diff] [blame] | 688 | |
| 689 | if (evsel->immediate) { |
| 690 | attr->disabled = 0; |
| 691 | attr->enable_on_exec = 0; |
| 692 | } |
Arnaldo Carvalho de Melo | 0f82ebc | 2011-11-08 14:41:57 -0200 | [diff] [blame] | 693 | } |
| 694 | |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 695 | int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads) |
| 696 | { |
David Ahern | 4af4c95 | 2011-05-27 09:58:34 -0600 | [diff] [blame] | 697 | int cpu, thread; |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 698 | evsel->fd = xyarray__new(ncpus, nthreads, sizeof(int)); |
David Ahern | 4af4c95 | 2011-05-27 09:58:34 -0600 | [diff] [blame] | 699 | |
| 700 | if (evsel->fd) { |
| 701 | for (cpu = 0; cpu < ncpus; cpu++) { |
| 702 | for (thread = 0; thread < nthreads; thread++) { |
| 703 | FD(evsel, cpu, thread) = -1; |
| 704 | } |
| 705 | } |
| 706 | } |
| 707 | |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 708 | return evsel->fd != NULL ? 0 : -ENOMEM; |
| 709 | } |
| 710 | |
Andi Kleen | e2407be | 2013-08-02 17:41:10 -0700 | [diff] [blame] | 711 | static int perf_evsel__run_ioctl(struct perf_evsel *evsel, int ncpus, int nthreads, |
| 712 | int ioc, void *arg) |
Arnaldo Carvalho de Melo | 745cefc | 2012-09-26 15:07:39 -0300 | [diff] [blame] | 713 | { |
| 714 | int cpu, thread; |
| 715 | |
| 716 | for (cpu = 0; cpu < ncpus; cpu++) { |
| 717 | for (thread = 0; thread < nthreads; thread++) { |
| 718 | int fd = FD(evsel, cpu, thread), |
Andi Kleen | e2407be | 2013-08-02 17:41:10 -0700 | [diff] [blame] | 719 | err = ioctl(fd, ioc, arg); |
Arnaldo Carvalho de Melo | 745cefc | 2012-09-26 15:07:39 -0300 | [diff] [blame] | 720 | |
| 721 | if (err) |
| 722 | return err; |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | return 0; |
| 727 | } |
| 728 | |
Andi Kleen | e2407be | 2013-08-02 17:41:10 -0700 | [diff] [blame] | 729 | int perf_evsel__set_filter(struct perf_evsel *evsel, int ncpus, int nthreads, |
| 730 | const char *filter) |
| 731 | { |
| 732 | return perf_evsel__run_ioctl(evsel, ncpus, nthreads, |
| 733 | PERF_EVENT_IOC_SET_FILTER, |
| 734 | (void *)filter); |
| 735 | } |
| 736 | |
| 737 | int perf_evsel__enable(struct perf_evsel *evsel, int ncpus, int nthreads) |
| 738 | { |
| 739 | return perf_evsel__run_ioctl(evsel, ncpus, nthreads, |
| 740 | PERF_EVENT_IOC_ENABLE, |
| 741 | 0); |
| 742 | } |
| 743 | |
Arnaldo Carvalho de Melo | 70db753 | 2011-01-12 22:39:13 -0200 | [diff] [blame] | 744 | int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads) |
| 745 | { |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 746 | evsel->sample_id = xyarray__new(ncpus, nthreads, sizeof(struct perf_sample_id)); |
| 747 | if (evsel->sample_id == NULL) |
| 748 | return -ENOMEM; |
| 749 | |
| 750 | evsel->id = zalloc(ncpus * nthreads * sizeof(u64)); |
| 751 | if (evsel->id == NULL) { |
| 752 | xyarray__delete(evsel->sample_id); |
| 753 | evsel->sample_id = NULL; |
| 754 | return -ENOMEM; |
| 755 | } |
| 756 | |
| 757 | return 0; |
Arnaldo Carvalho de Melo | 70db753 | 2011-01-12 22:39:13 -0200 | [diff] [blame] | 758 | } |
| 759 | |
Frederik Deweerdt | a7e191c | 2013-03-01 13:02:27 -0500 | [diff] [blame] | 760 | void perf_evsel__reset_counts(struct perf_evsel *evsel, int ncpus) |
| 761 | { |
| 762 | memset(evsel->counts, 0, (sizeof(*evsel->counts) + |
| 763 | (ncpus * sizeof(struct perf_counts_values)))); |
| 764 | } |
| 765 | |
Arnaldo Carvalho de Melo | c52b12e | 2011-01-03 17:45:52 -0200 | [diff] [blame] | 766 | int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus) |
| 767 | { |
| 768 | evsel->counts = zalloc((sizeof(*evsel->counts) + |
| 769 | (ncpus * sizeof(struct perf_counts_values)))); |
| 770 | return evsel->counts != NULL ? 0 : -ENOMEM; |
| 771 | } |
| 772 | |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 773 | void perf_evsel__free_fd(struct perf_evsel *evsel) |
| 774 | { |
| 775 | xyarray__delete(evsel->fd); |
| 776 | evsel->fd = NULL; |
| 777 | } |
| 778 | |
Arnaldo Carvalho de Melo | 70db753 | 2011-01-12 22:39:13 -0200 | [diff] [blame] | 779 | void perf_evsel__free_id(struct perf_evsel *evsel) |
| 780 | { |
Arnaldo Carvalho de Melo | a91e543 | 2011-03-10 11:15:54 -0300 | [diff] [blame] | 781 | xyarray__delete(evsel->sample_id); |
| 782 | evsel->sample_id = NULL; |
Arnaldo Carvalho de Melo | 0466252 | 2013-12-26 17:41:15 -0300 | [diff] [blame] | 783 | zfree(&evsel->id); |
Arnaldo Carvalho de Melo | 70db753 | 2011-01-12 22:39:13 -0200 | [diff] [blame] | 784 | } |
| 785 | |
Arnaldo Carvalho de Melo | c52b12e | 2011-01-03 17:45:52 -0200 | [diff] [blame] | 786 | void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads) |
| 787 | { |
| 788 | int cpu, thread; |
| 789 | |
| 790 | for (cpu = 0; cpu < ncpus; cpu++) |
| 791 | for (thread = 0; thread < nthreads; ++thread) { |
| 792 | close(FD(evsel, cpu, thread)); |
| 793 | FD(evsel, cpu, thread) = -1; |
| 794 | } |
| 795 | } |
| 796 | |
Namhyung Kim | 43f8e76 | 2013-01-25 10:44:44 +0900 | [diff] [blame] | 797 | void perf_evsel__free_counts(struct perf_evsel *evsel) |
| 798 | { |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 799 | zfree(&evsel->counts); |
Namhyung Kim | 43f8e76 | 2013-01-25 10:44:44 +0900 | [diff] [blame] | 800 | } |
| 801 | |
Arnaldo Carvalho de Melo | ef1d1af | 2011-01-18 21:41:45 -0200 | [diff] [blame] | 802 | void perf_evsel__exit(struct perf_evsel *evsel) |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 803 | { |
| 804 | assert(list_empty(&evsel->node)); |
Namhyung Kim | 736b05a | 2013-03-15 14:48:49 +0900 | [diff] [blame] | 805 | perf_evsel__free_fd(evsel); |
| 806 | perf_evsel__free_id(evsel); |
Arnaldo Carvalho de Melo | ef1d1af | 2011-01-18 21:41:45 -0200 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | void perf_evsel__delete(struct perf_evsel *evsel) |
| 810 | { |
| 811 | perf_evsel__exit(evsel); |
Stephane Eranian | 023695d | 2011-02-14 11:20:01 +0200 | [diff] [blame] | 812 | close_cgroup(evsel->cgrp); |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 813 | zfree(&evsel->group_name); |
Arnaldo Carvalho de Melo | e48ffe2 | 2012-09-26 17:11:38 -0300 | [diff] [blame] | 814 | if (evsel->tp_format) |
Arnaldo Carvalho de Melo | efd2b92 | 2012-09-18 11:21:50 -0300 | [diff] [blame] | 815 | pevent_free_format(evsel->tp_format); |
Arnaldo Carvalho de Melo | 74cf249 | 2013-12-27 16:55:14 -0300 | [diff] [blame] | 816 | zfree(&evsel->name); |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 817 | free(evsel); |
| 818 | } |
Arnaldo Carvalho de Melo | c52b12e | 2011-01-03 17:45:52 -0200 | [diff] [blame] | 819 | |
Stephane Eranian | c7a79c4 | 2013-01-29 12:47:43 +0100 | [diff] [blame] | 820 | static inline void compute_deltas(struct perf_evsel *evsel, |
| 821 | int cpu, |
| 822 | struct perf_counts_values *count) |
| 823 | { |
| 824 | struct perf_counts_values tmp; |
| 825 | |
| 826 | if (!evsel->prev_raw_counts) |
| 827 | return; |
| 828 | |
| 829 | if (cpu == -1) { |
| 830 | tmp = evsel->prev_raw_counts->aggr; |
| 831 | evsel->prev_raw_counts->aggr = *count; |
| 832 | } else { |
| 833 | tmp = evsel->prev_raw_counts->cpu[cpu]; |
| 834 | evsel->prev_raw_counts->cpu[cpu] = *count; |
| 835 | } |
| 836 | |
| 837 | count->val = count->val - tmp.val; |
| 838 | count->ena = count->ena - tmp.ena; |
| 839 | count->run = count->run - tmp.run; |
| 840 | } |
| 841 | |
Arnaldo Carvalho de Melo | c52b12e | 2011-01-03 17:45:52 -0200 | [diff] [blame] | 842 | int __perf_evsel__read_on_cpu(struct perf_evsel *evsel, |
| 843 | int cpu, int thread, bool scale) |
| 844 | { |
| 845 | struct perf_counts_values count; |
| 846 | size_t nv = scale ? 3 : 1; |
| 847 | |
| 848 | if (FD(evsel, cpu, thread) < 0) |
| 849 | return -EINVAL; |
| 850 | |
Arnaldo Carvalho de Melo | 4eed11d | 2011-01-04 00:13:17 -0200 | [diff] [blame] | 851 | if (evsel->counts == NULL && perf_evsel__alloc_counts(evsel, cpu + 1) < 0) |
| 852 | return -ENOMEM; |
| 853 | |
Arnaldo Carvalho de Melo | c52b12e | 2011-01-03 17:45:52 -0200 | [diff] [blame] | 854 | if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) < 0) |
| 855 | return -errno; |
| 856 | |
Stephane Eranian | c7a79c4 | 2013-01-29 12:47:43 +0100 | [diff] [blame] | 857 | compute_deltas(evsel, cpu, &count); |
| 858 | |
Arnaldo Carvalho de Melo | c52b12e | 2011-01-03 17:45:52 -0200 | [diff] [blame] | 859 | if (scale) { |
| 860 | if (count.run == 0) |
| 861 | count.val = 0; |
| 862 | else if (count.run < count.ena) |
| 863 | count.val = (u64)((double)count.val * count.ena / count.run + 0.5); |
| 864 | } else |
| 865 | count.ena = count.run = 0; |
| 866 | |
| 867 | evsel->counts->cpu[cpu] = count; |
| 868 | return 0; |
| 869 | } |
| 870 | |
| 871 | int __perf_evsel__read(struct perf_evsel *evsel, |
| 872 | int ncpus, int nthreads, bool scale) |
| 873 | { |
| 874 | size_t nv = scale ? 3 : 1; |
| 875 | int cpu, thread; |
| 876 | struct perf_counts_values *aggr = &evsel->counts->aggr, count; |
| 877 | |
Arnaldo Carvalho de Melo | 52bcd994 | 2011-02-03 17:26:06 -0200 | [diff] [blame] | 878 | aggr->val = aggr->ena = aggr->run = 0; |
Arnaldo Carvalho de Melo | c52b12e | 2011-01-03 17:45:52 -0200 | [diff] [blame] | 879 | |
| 880 | for (cpu = 0; cpu < ncpus; cpu++) { |
| 881 | for (thread = 0; thread < nthreads; thread++) { |
| 882 | if (FD(evsel, cpu, thread) < 0) |
| 883 | continue; |
| 884 | |
| 885 | if (readn(FD(evsel, cpu, thread), |
| 886 | &count, nv * sizeof(u64)) < 0) |
| 887 | return -errno; |
| 888 | |
| 889 | aggr->val += count.val; |
| 890 | if (scale) { |
| 891 | aggr->ena += count.ena; |
| 892 | aggr->run += count.run; |
| 893 | } |
| 894 | } |
| 895 | } |
| 896 | |
Stephane Eranian | c7a79c4 | 2013-01-29 12:47:43 +0100 | [diff] [blame] | 897 | compute_deltas(evsel, -1, aggr); |
| 898 | |
Arnaldo Carvalho de Melo | c52b12e | 2011-01-03 17:45:52 -0200 | [diff] [blame] | 899 | evsel->counts->scaled = 0; |
| 900 | if (scale) { |
| 901 | if (aggr->run == 0) { |
| 902 | evsel->counts->scaled = -1; |
| 903 | aggr->val = 0; |
| 904 | return 0; |
| 905 | } |
| 906 | |
| 907 | if (aggr->run < aggr->ena) { |
| 908 | evsel->counts->scaled = 1; |
| 909 | aggr->val = (u64)((double)aggr->val * aggr->ena / aggr->run + 0.5); |
| 910 | } |
| 911 | } else |
| 912 | aggr->ena = aggr->run = 0; |
| 913 | |
| 914 | return 0; |
| 915 | } |
Arnaldo Carvalho de Melo | 4829060 | 2011-01-03 17:48:12 -0200 | [diff] [blame] | 916 | |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 917 | static int get_group_fd(struct perf_evsel *evsel, int cpu, int thread) |
| 918 | { |
| 919 | struct perf_evsel *leader = evsel->leader; |
| 920 | int fd; |
| 921 | |
Namhyung Kim | 823254e | 2012-11-29 15:38:30 +0900 | [diff] [blame] | 922 | if (perf_evsel__is_group_leader(evsel)) |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 923 | return -1; |
| 924 | |
| 925 | /* |
| 926 | * Leader must be already processed/open, |
| 927 | * if not it's a bug. |
| 928 | */ |
| 929 | BUG_ON(!leader->fd); |
| 930 | |
| 931 | fd = FD(leader, cpu, thread); |
| 932 | BUG_ON(fd == -1); |
| 933 | |
| 934 | return fd; |
| 935 | } |
| 936 | |
Adrian Hunter | e3e1a54 | 2013-08-14 15:48:24 +0300 | [diff] [blame] | 937 | #define __PRINT_ATTR(fmt, cast, field) \ |
| 938 | fprintf(fp, " %-19s "fmt"\n", #field, cast attr->field) |
| 939 | |
| 940 | #define PRINT_ATTR_U32(field) __PRINT_ATTR("%u" , , field) |
| 941 | #define PRINT_ATTR_X32(field) __PRINT_ATTR("%#x", , field) |
| 942 | #define PRINT_ATTR_U64(field) __PRINT_ATTR("%" PRIu64, (uint64_t), field) |
| 943 | #define PRINT_ATTR_X64(field) __PRINT_ATTR("%#"PRIx64, (uint64_t), field) |
| 944 | |
| 945 | #define PRINT_ATTR2N(name1, field1, name2, field2) \ |
| 946 | fprintf(fp, " %-19s %u %-19s %u\n", \ |
| 947 | name1, attr->field1, name2, attr->field2) |
| 948 | |
| 949 | #define PRINT_ATTR2(field1, field2) \ |
| 950 | PRINT_ATTR2N(#field1, field1, #field2, field2) |
| 951 | |
| 952 | static size_t perf_event_attr__fprintf(struct perf_event_attr *attr, FILE *fp) |
| 953 | { |
| 954 | size_t ret = 0; |
| 955 | |
| 956 | ret += fprintf(fp, "%.60s\n", graph_dotted_line); |
| 957 | ret += fprintf(fp, "perf_event_attr:\n"); |
| 958 | |
| 959 | ret += PRINT_ATTR_U32(type); |
| 960 | ret += PRINT_ATTR_U32(size); |
| 961 | ret += PRINT_ATTR_X64(config); |
| 962 | ret += PRINT_ATTR_U64(sample_period); |
| 963 | ret += PRINT_ATTR_U64(sample_freq); |
| 964 | ret += PRINT_ATTR_X64(sample_type); |
| 965 | ret += PRINT_ATTR_X64(read_format); |
| 966 | |
| 967 | ret += PRINT_ATTR2(disabled, inherit); |
| 968 | ret += PRINT_ATTR2(pinned, exclusive); |
| 969 | ret += PRINT_ATTR2(exclude_user, exclude_kernel); |
| 970 | ret += PRINT_ATTR2(exclude_hv, exclude_idle); |
| 971 | ret += PRINT_ATTR2(mmap, comm); |
Adrian Hunter | 022c50d | 2014-07-14 13:02:27 +0300 | [diff] [blame] | 972 | ret += PRINT_ATTR2(mmap2, comm_exec); |
Adrian Hunter | e3e1a54 | 2013-08-14 15:48:24 +0300 | [diff] [blame] | 973 | ret += PRINT_ATTR2(freq, inherit_stat); |
| 974 | ret += PRINT_ATTR2(enable_on_exec, task); |
| 975 | ret += PRINT_ATTR2(watermark, precise_ip); |
| 976 | ret += PRINT_ATTR2(mmap_data, sample_id_all); |
| 977 | ret += PRINT_ATTR2(exclude_host, exclude_guest); |
| 978 | ret += PRINT_ATTR2N("excl.callchain_kern", exclude_callchain_kernel, |
| 979 | "excl.callchain_user", exclude_callchain_user); |
| 980 | |
| 981 | ret += PRINT_ATTR_U32(wakeup_events); |
| 982 | ret += PRINT_ATTR_U32(wakeup_watermark); |
| 983 | ret += PRINT_ATTR_X32(bp_type); |
| 984 | ret += PRINT_ATTR_X64(bp_addr); |
| 985 | ret += PRINT_ATTR_X64(config1); |
| 986 | ret += PRINT_ATTR_U64(bp_len); |
| 987 | ret += PRINT_ATTR_X64(config2); |
| 988 | ret += PRINT_ATTR_X64(branch_sample_type); |
| 989 | ret += PRINT_ATTR_X64(sample_regs_user); |
| 990 | ret += PRINT_ATTR_U32(sample_stack_user); |
| 991 | |
| 992 | ret += fprintf(fp, "%.60s\n", graph_dotted_line); |
| 993 | |
| 994 | return ret; |
| 995 | } |
| 996 | |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 997 | static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 998 | struct thread_map *threads) |
Arnaldo Carvalho de Melo | 4829060 | 2011-01-03 17:48:12 -0200 | [diff] [blame] | 999 | { |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 1000 | int cpu, thread; |
Yann Droneaud | 57480d2 | 2014-06-30 22:28:47 +0200 | [diff] [blame] | 1001 | unsigned long flags = PERF_FLAG_FD_CLOEXEC; |
Arnaldo Carvalho de Melo | 727ab04 | 2011-10-25 10:42:19 -0200 | [diff] [blame] | 1002 | int pid = -1, err; |
Andi Kleen | bec1967 | 2013-08-04 19:41:26 -0700 | [diff] [blame] | 1003 | enum { NO_CHANGE, SET_TO_MAX, INCREASED_MAX } set_rlimit = NO_CHANGE; |
Arnaldo Carvalho de Melo | 4829060 | 2011-01-03 17:48:12 -0200 | [diff] [blame] | 1004 | |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 1005 | if (evsel->fd == NULL && |
| 1006 | perf_evsel__alloc_fd(evsel, cpus->nr, threads->nr) < 0) |
Arnaldo Carvalho de Melo | 727ab04 | 2011-10-25 10:42:19 -0200 | [diff] [blame] | 1007 | return -ENOMEM; |
Arnaldo Carvalho de Melo | 4eed11d | 2011-01-04 00:13:17 -0200 | [diff] [blame] | 1008 | |
Stephane Eranian | 023695d | 2011-02-14 11:20:01 +0200 | [diff] [blame] | 1009 | if (evsel->cgrp) { |
Yann Droneaud | 57480d2 | 2014-06-30 22:28:47 +0200 | [diff] [blame] | 1010 | flags |= PERF_FLAG_PID_CGROUP; |
Stephane Eranian | 023695d | 2011-02-14 11:20:01 +0200 | [diff] [blame] | 1011 | pid = evsel->cgrp->fd; |
| 1012 | } |
| 1013 | |
Arnaldo Carvalho de Melo | 594ac61 | 2012-12-13 13:13:07 -0300 | [diff] [blame] | 1014 | fallback_missing_features: |
Yann Droneaud | 57480d2 | 2014-06-30 22:28:47 +0200 | [diff] [blame] | 1015 | if (perf_missing_features.cloexec) |
| 1016 | flags &= ~(unsigned long)PERF_FLAG_FD_CLOEXEC; |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 1017 | if (perf_missing_features.mmap2) |
| 1018 | evsel->attr.mmap2 = 0; |
Arnaldo Carvalho de Melo | 594ac61 | 2012-12-13 13:13:07 -0300 | [diff] [blame] | 1019 | if (perf_missing_features.exclude_guest) |
| 1020 | evsel->attr.exclude_guest = evsel->attr.exclude_host = 0; |
| 1021 | retry_sample_id: |
| 1022 | if (perf_missing_features.sample_id_all) |
| 1023 | evsel->attr.sample_id_all = 0; |
| 1024 | |
Adrian Hunter | e3e1a54 | 2013-08-14 15:48:24 +0300 | [diff] [blame] | 1025 | if (verbose >= 2) |
| 1026 | perf_event_attr__fprintf(&evsel->attr, stderr); |
| 1027 | |
Arnaldo Carvalho de Melo | 86bd5e8 | 2011-01-03 23:09:46 -0200 | [diff] [blame] | 1028 | for (cpu = 0; cpu < cpus->nr; cpu++) { |
Arnaldo Carvalho de Melo | 9d04f17 | 2011-01-12 00:08:18 -0200 | [diff] [blame] | 1029 | |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 1030 | for (thread = 0; thread < threads->nr; thread++) { |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 1031 | int group_fd; |
Stephane Eranian | 023695d | 2011-02-14 11:20:01 +0200 | [diff] [blame] | 1032 | |
| 1033 | if (!evsel->cgrp) |
| 1034 | pid = threads->map[thread]; |
| 1035 | |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 1036 | group_fd = get_group_fd(evsel, cpu, thread); |
Andi Kleen | bec1967 | 2013-08-04 19:41:26 -0700 | [diff] [blame] | 1037 | retry_open: |
Ramkumar Ramachandra | a33f6ef | 2014-03-18 15:10:42 -0400 | [diff] [blame] | 1038 | pr_debug2("sys_perf_event_open: pid %d cpu %d group_fd %d flags %#lx\n", |
Adrian Hunter | e3e1a54 | 2013-08-14 15:48:24 +0300 | [diff] [blame] | 1039 | pid, cpus->map[cpu], group_fd, flags); |
| 1040 | |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 1041 | FD(evsel, cpu, thread) = sys_perf_event_open(&evsel->attr, |
Stephane Eranian | 023695d | 2011-02-14 11:20:01 +0200 | [diff] [blame] | 1042 | pid, |
Arnaldo Carvalho de Melo | f08199d | 2011-01-11 23:42:19 -0200 | [diff] [blame] | 1043 | cpus->map[cpu], |
Stephane Eranian | 023695d | 2011-02-14 11:20:01 +0200 | [diff] [blame] | 1044 | group_fd, flags); |
Arnaldo Carvalho de Melo | 727ab04 | 2011-10-25 10:42:19 -0200 | [diff] [blame] | 1045 | if (FD(evsel, cpu, thread) < 0) { |
| 1046 | err = -errno; |
Ramkumar Ramachandra | a33f6ef | 2014-03-18 15:10:42 -0400 | [diff] [blame] | 1047 | pr_debug2("sys_perf_event_open failed, error %d\n", |
Adrian Hunter | f852fd6 | 2013-11-01 15:51:29 +0200 | [diff] [blame] | 1048 | err); |
Arnaldo Carvalho de Melo | 594ac61 | 2012-12-13 13:13:07 -0300 | [diff] [blame] | 1049 | goto try_fallback; |
Arnaldo Carvalho de Melo | 727ab04 | 2011-10-25 10:42:19 -0200 | [diff] [blame] | 1050 | } |
Andi Kleen | bec1967 | 2013-08-04 19:41:26 -0700 | [diff] [blame] | 1051 | set_rlimit = NO_CHANGE; |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 1052 | } |
Arnaldo Carvalho de Melo | 4829060 | 2011-01-03 17:48:12 -0200 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | return 0; |
| 1056 | |
Arnaldo Carvalho de Melo | 594ac61 | 2012-12-13 13:13:07 -0300 | [diff] [blame] | 1057 | try_fallback: |
Andi Kleen | bec1967 | 2013-08-04 19:41:26 -0700 | [diff] [blame] | 1058 | /* |
| 1059 | * perf stat needs between 5 and 22 fds per CPU. When we run out |
| 1060 | * of them try to increase the limits. |
| 1061 | */ |
| 1062 | if (err == -EMFILE && set_rlimit < INCREASED_MAX) { |
| 1063 | struct rlimit l; |
| 1064 | int old_errno = errno; |
| 1065 | |
| 1066 | if (getrlimit(RLIMIT_NOFILE, &l) == 0) { |
| 1067 | if (set_rlimit == NO_CHANGE) |
| 1068 | l.rlim_cur = l.rlim_max; |
| 1069 | else { |
| 1070 | l.rlim_cur = l.rlim_max + 1000; |
| 1071 | l.rlim_max = l.rlim_cur; |
| 1072 | } |
| 1073 | if (setrlimit(RLIMIT_NOFILE, &l) == 0) { |
| 1074 | set_rlimit++; |
| 1075 | errno = old_errno; |
| 1076 | goto retry_open; |
| 1077 | } |
| 1078 | } |
| 1079 | errno = old_errno; |
| 1080 | } |
| 1081 | |
Arnaldo Carvalho de Melo | 594ac61 | 2012-12-13 13:13:07 -0300 | [diff] [blame] | 1082 | if (err != -EINVAL || cpu > 0 || thread > 0) |
| 1083 | goto out_close; |
| 1084 | |
Yann Droneaud | 57480d2 | 2014-06-30 22:28:47 +0200 | [diff] [blame] | 1085 | if (!perf_missing_features.cloexec && (flags & PERF_FLAG_FD_CLOEXEC)) { |
| 1086 | perf_missing_features.cloexec = true; |
| 1087 | goto fallback_missing_features; |
| 1088 | } else if (!perf_missing_features.mmap2 && evsel->attr.mmap2) { |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 1089 | perf_missing_features.mmap2 = true; |
| 1090 | goto fallback_missing_features; |
| 1091 | } else if (!perf_missing_features.exclude_guest && |
| 1092 | (evsel->attr.exclude_guest || evsel->attr.exclude_host)) { |
Arnaldo Carvalho de Melo | 594ac61 | 2012-12-13 13:13:07 -0300 | [diff] [blame] | 1093 | perf_missing_features.exclude_guest = true; |
| 1094 | goto fallback_missing_features; |
| 1095 | } else if (!perf_missing_features.sample_id_all) { |
| 1096 | perf_missing_features.sample_id_all = true; |
| 1097 | goto retry_sample_id; |
| 1098 | } |
| 1099 | |
Arnaldo Carvalho de Melo | 4829060 | 2011-01-03 17:48:12 -0200 | [diff] [blame] | 1100 | out_close: |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 1101 | do { |
| 1102 | while (--thread >= 0) { |
| 1103 | close(FD(evsel, cpu, thread)); |
| 1104 | FD(evsel, cpu, thread) = -1; |
| 1105 | } |
| 1106 | thread = threads->nr; |
| 1107 | } while (--cpu >= 0); |
Arnaldo Carvalho de Melo | 727ab04 | 2011-10-25 10:42:19 -0200 | [diff] [blame] | 1108 | return err; |
| 1109 | } |
| 1110 | |
| 1111 | void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads) |
| 1112 | { |
| 1113 | if (evsel->fd == NULL) |
| 1114 | return; |
| 1115 | |
| 1116 | perf_evsel__close_fd(evsel, ncpus, nthreads); |
| 1117 | perf_evsel__free_fd(evsel); |
Arnaldo Carvalho de Melo | 4829060 | 2011-01-03 17:48:12 -0200 | [diff] [blame] | 1118 | } |
| 1119 | |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 1120 | static struct { |
| 1121 | struct cpu_map map; |
| 1122 | int cpus[1]; |
| 1123 | } empty_cpu_map = { |
| 1124 | .map.nr = 1, |
| 1125 | .cpus = { -1, }, |
| 1126 | }; |
| 1127 | |
| 1128 | static struct { |
| 1129 | struct thread_map map; |
| 1130 | int threads[1]; |
| 1131 | } empty_thread_map = { |
| 1132 | .map.nr = 1, |
| 1133 | .threads = { -1, }, |
| 1134 | }; |
| 1135 | |
Arnaldo Carvalho de Melo | f08199d | 2011-01-11 23:42:19 -0200 | [diff] [blame] | 1136 | int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 1137 | struct thread_map *threads) |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 1138 | { |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 1139 | if (cpus == NULL) { |
| 1140 | /* Work around old compiler warnings about strict aliasing */ |
| 1141 | cpus = &empty_cpu_map.map; |
| 1142 | } |
| 1143 | |
| 1144 | if (threads == NULL) |
| 1145 | threads = &empty_thread_map.map; |
| 1146 | |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 1147 | return __perf_evsel__open(evsel, cpus, threads); |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 1148 | } |
| 1149 | |
Arnaldo Carvalho de Melo | f08199d | 2011-01-11 23:42:19 -0200 | [diff] [blame] | 1150 | int perf_evsel__open_per_cpu(struct perf_evsel *evsel, |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 1151 | struct cpu_map *cpus) |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 1152 | { |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 1153 | return __perf_evsel__open(evsel, cpus, &empty_thread_map.map); |
Arnaldo Carvalho de Melo | 0252208 | 2011-01-04 11:55:27 -0200 | [diff] [blame] | 1154 | } |
| 1155 | |
Arnaldo Carvalho de Melo | f08199d | 2011-01-11 23:42:19 -0200 | [diff] [blame] | 1156 | int perf_evsel__open_per_thread(struct perf_evsel *evsel, |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 1157 | struct thread_map *threads) |
Arnaldo Carvalho de Melo | 4829060 | 2011-01-03 17:48:12 -0200 | [diff] [blame] | 1158 | { |
Jiri Olsa | 6a4bb04 | 2012-08-08 12:22:36 +0200 | [diff] [blame] | 1159 | return __perf_evsel__open(evsel, &empty_cpu_map.map, threads); |
Arnaldo Carvalho de Melo | 4829060 | 2011-01-03 17:48:12 -0200 | [diff] [blame] | 1160 | } |
Arnaldo Carvalho de Melo | 70082dd | 2011-01-12 17:03:24 -0200 | [diff] [blame] | 1161 | |
Arnaldo Carvalho de Melo | 0807d2d | 2012-09-26 12:48:18 -0300 | [diff] [blame] | 1162 | static int perf_evsel__parse_id_sample(const struct perf_evsel *evsel, |
| 1163 | const union perf_event *event, |
| 1164 | struct perf_sample *sample) |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1165 | { |
Arnaldo Carvalho de Melo | 0807d2d | 2012-09-26 12:48:18 -0300 | [diff] [blame] | 1166 | u64 type = evsel->attr.sample_type; |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1167 | const u64 *array = event->sample.array; |
Arnaldo Carvalho de Melo | 0807d2d | 2012-09-26 12:48:18 -0300 | [diff] [blame] | 1168 | bool swapped = evsel->needs_swap; |
Jiri Olsa | 37073f9 | 2012-05-30 14:23:44 +0200 | [diff] [blame] | 1169 | union u64_swap u; |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1170 | |
| 1171 | array += ((event->header.size - |
| 1172 | sizeof(event->header)) / sizeof(u64)) - 1; |
| 1173 | |
Adrian Hunter | 7556257 | 2013-08-27 11:23:09 +0300 | [diff] [blame] | 1174 | if (type & PERF_SAMPLE_IDENTIFIER) { |
| 1175 | sample->id = *array; |
| 1176 | array--; |
| 1177 | } |
| 1178 | |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1179 | if (type & PERF_SAMPLE_CPU) { |
Jiri Olsa | 37073f9 | 2012-05-30 14:23:44 +0200 | [diff] [blame] | 1180 | u.val64 = *array; |
| 1181 | if (swapped) { |
| 1182 | /* undo swap of u64, then swap on individual u32s */ |
| 1183 | u.val64 = bswap_64(u.val64); |
| 1184 | u.val32[0] = bswap_32(u.val32[0]); |
| 1185 | } |
| 1186 | |
| 1187 | sample->cpu = u.val32[0]; |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1188 | array--; |
| 1189 | } |
| 1190 | |
| 1191 | if (type & PERF_SAMPLE_STREAM_ID) { |
| 1192 | sample->stream_id = *array; |
| 1193 | array--; |
| 1194 | } |
| 1195 | |
| 1196 | if (type & PERF_SAMPLE_ID) { |
| 1197 | sample->id = *array; |
| 1198 | array--; |
| 1199 | } |
| 1200 | |
| 1201 | if (type & PERF_SAMPLE_TIME) { |
| 1202 | sample->time = *array; |
| 1203 | array--; |
| 1204 | } |
| 1205 | |
| 1206 | if (type & PERF_SAMPLE_TID) { |
Jiri Olsa | 37073f9 | 2012-05-30 14:23:44 +0200 | [diff] [blame] | 1207 | u.val64 = *array; |
| 1208 | if (swapped) { |
| 1209 | /* undo swap of u64, then swap on individual u32s */ |
| 1210 | u.val64 = bswap_64(u.val64); |
| 1211 | u.val32[0] = bswap_32(u.val32[0]); |
| 1212 | u.val32[1] = bswap_32(u.val32[1]); |
| 1213 | } |
| 1214 | |
| 1215 | sample->pid = u.val32[0]; |
| 1216 | sample->tid = u.val32[1]; |
Adrian Hunter | dd44bc6 | 2013-10-18 15:29:01 +0300 | [diff] [blame] | 1217 | array--; |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | return 0; |
| 1221 | } |
| 1222 | |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1223 | static inline bool overflow(const void *endp, u16 max_size, const void *offset, |
| 1224 | u64 size) |
Frederic Weisbecker | 98e1da9 | 2011-05-21 20:08:15 +0200 | [diff] [blame] | 1225 | { |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1226 | return size > max_size || offset + size > endp; |
Frederic Weisbecker | 98e1da9 | 2011-05-21 20:08:15 +0200 | [diff] [blame] | 1227 | } |
| 1228 | |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1229 | #define OVERFLOW_CHECK(offset, size, max_size) \ |
| 1230 | do { \ |
| 1231 | if (overflow(endp, (max_size), (offset), (size))) \ |
| 1232 | return -EFAULT; \ |
| 1233 | } while (0) |
| 1234 | |
| 1235 | #define OVERFLOW_CHECK_u64(offset) \ |
| 1236 | OVERFLOW_CHECK(offset, sizeof(u64), sizeof(u64)) |
| 1237 | |
Arnaldo Carvalho de Melo | a3f698f | 2012-08-02 12:23:46 -0300 | [diff] [blame] | 1238 | int perf_evsel__parse_sample(struct perf_evsel *evsel, union perf_event *event, |
Arnaldo Carvalho de Melo | 0807d2d | 2012-09-26 12:48:18 -0300 | [diff] [blame] | 1239 | struct perf_sample *data) |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1240 | { |
Arnaldo Carvalho de Melo | a3f698f | 2012-08-02 12:23:46 -0300 | [diff] [blame] | 1241 | u64 type = evsel->attr.sample_type; |
Arnaldo Carvalho de Melo | 0807d2d | 2012-09-26 12:48:18 -0300 | [diff] [blame] | 1242 | bool swapped = evsel->needs_swap; |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1243 | const u64 *array; |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1244 | u16 max_size = event->header.size; |
| 1245 | const void *endp = (void *)event + max_size; |
| 1246 | u64 sz; |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1247 | |
David Ahern | 936be50 | 2011-09-06 09:12:26 -0600 | [diff] [blame] | 1248 | /* |
| 1249 | * used for cross-endian analysis. See git commit 65014ab3 |
| 1250 | * for why this goofiness is needed. |
| 1251 | */ |
Jiri Olsa | 6a11f92 | 2012-05-16 08:59:04 +0200 | [diff] [blame] | 1252 | union u64_swap u; |
David Ahern | 936be50 | 2011-09-06 09:12:26 -0600 | [diff] [blame] | 1253 | |
Robert Richter | f3bda2c | 2011-12-15 17:32:39 +0100 | [diff] [blame] | 1254 | memset(data, 0, sizeof(*data)); |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1255 | data->cpu = data->pid = data->tid = -1; |
| 1256 | data->stream_id = data->id = data->time = -1ULL; |
Jiri Olsa | bc52908 | 2014-02-03 12:44:41 +0100 | [diff] [blame] | 1257 | data->period = evsel->attr.sample_period; |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 1258 | data->weight = 0; |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1259 | |
| 1260 | if (event->header.type != PERF_RECORD_SAMPLE) { |
Arnaldo Carvalho de Melo | a3f698f | 2012-08-02 12:23:46 -0300 | [diff] [blame] | 1261 | if (!evsel->attr.sample_id_all) |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1262 | return 0; |
Arnaldo Carvalho de Melo | 0807d2d | 2012-09-26 12:48:18 -0300 | [diff] [blame] | 1263 | return perf_evsel__parse_id_sample(evsel, event, data); |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | array = event->sample.array; |
| 1267 | |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1268 | /* |
| 1269 | * The evsel's sample_size is based on PERF_SAMPLE_MASK which includes |
| 1270 | * up to PERF_SAMPLE_PERIOD. After that overflow() must be used to |
| 1271 | * check the format does not go past the end of the event. |
| 1272 | */ |
Arnaldo Carvalho de Melo | a3f698f | 2012-08-02 12:23:46 -0300 | [diff] [blame] | 1273 | if (evsel->sample_size + sizeof(event->header) > event->header.size) |
Frederic Weisbecker | a285412 | 2011-05-21 19:33:04 +0200 | [diff] [blame] | 1274 | return -EFAULT; |
| 1275 | |
Adrian Hunter | 7556257 | 2013-08-27 11:23:09 +0300 | [diff] [blame] | 1276 | data->id = -1ULL; |
| 1277 | if (type & PERF_SAMPLE_IDENTIFIER) { |
| 1278 | data->id = *array; |
| 1279 | array++; |
| 1280 | } |
| 1281 | |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1282 | if (type & PERF_SAMPLE_IP) { |
Adrian Hunter | ef89325 | 2013-08-27 11:23:06 +0300 | [diff] [blame] | 1283 | data->ip = *array; |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1284 | array++; |
| 1285 | } |
| 1286 | |
| 1287 | if (type & PERF_SAMPLE_TID) { |
David Ahern | 936be50 | 2011-09-06 09:12:26 -0600 | [diff] [blame] | 1288 | u.val64 = *array; |
| 1289 | if (swapped) { |
| 1290 | /* undo swap of u64, then swap on individual u32s */ |
| 1291 | u.val64 = bswap_64(u.val64); |
| 1292 | u.val32[0] = bswap_32(u.val32[0]); |
| 1293 | u.val32[1] = bswap_32(u.val32[1]); |
| 1294 | } |
| 1295 | |
| 1296 | data->pid = u.val32[0]; |
| 1297 | data->tid = u.val32[1]; |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1298 | array++; |
| 1299 | } |
| 1300 | |
| 1301 | if (type & PERF_SAMPLE_TIME) { |
| 1302 | data->time = *array; |
| 1303 | array++; |
| 1304 | } |
| 1305 | |
David Ahern | 7cec092 | 2011-05-30 13:08:23 -0600 | [diff] [blame] | 1306 | data->addr = 0; |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1307 | if (type & PERF_SAMPLE_ADDR) { |
| 1308 | data->addr = *array; |
| 1309 | array++; |
| 1310 | } |
| 1311 | |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1312 | if (type & PERF_SAMPLE_ID) { |
| 1313 | data->id = *array; |
| 1314 | array++; |
| 1315 | } |
| 1316 | |
| 1317 | if (type & PERF_SAMPLE_STREAM_ID) { |
| 1318 | data->stream_id = *array; |
| 1319 | array++; |
| 1320 | } |
| 1321 | |
| 1322 | if (type & PERF_SAMPLE_CPU) { |
David Ahern | 936be50 | 2011-09-06 09:12:26 -0600 | [diff] [blame] | 1323 | |
| 1324 | u.val64 = *array; |
| 1325 | if (swapped) { |
| 1326 | /* undo swap of u64, then swap on individual u32s */ |
| 1327 | u.val64 = bswap_64(u.val64); |
| 1328 | u.val32[0] = bswap_32(u.val32[0]); |
| 1329 | } |
| 1330 | |
| 1331 | data->cpu = u.val32[0]; |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1332 | array++; |
| 1333 | } |
| 1334 | |
| 1335 | if (type & PERF_SAMPLE_PERIOD) { |
| 1336 | data->period = *array; |
| 1337 | array++; |
| 1338 | } |
| 1339 | |
| 1340 | if (type & PERF_SAMPLE_READ) { |
Jiri Olsa | 9ede473 | 2012-10-10 17:38:13 +0200 | [diff] [blame] | 1341 | u64 read_format = evsel->attr.read_format; |
| 1342 | |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1343 | OVERFLOW_CHECK_u64(array); |
Jiri Olsa | 9ede473 | 2012-10-10 17:38:13 +0200 | [diff] [blame] | 1344 | if (read_format & PERF_FORMAT_GROUP) |
| 1345 | data->read.group.nr = *array; |
| 1346 | else |
| 1347 | data->read.one.value = *array; |
| 1348 | |
| 1349 | array++; |
| 1350 | |
| 1351 | if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) { |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1352 | OVERFLOW_CHECK_u64(array); |
Jiri Olsa | 9ede473 | 2012-10-10 17:38:13 +0200 | [diff] [blame] | 1353 | data->read.time_enabled = *array; |
| 1354 | array++; |
| 1355 | } |
| 1356 | |
| 1357 | if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) { |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1358 | OVERFLOW_CHECK_u64(array); |
Jiri Olsa | 9ede473 | 2012-10-10 17:38:13 +0200 | [diff] [blame] | 1359 | data->read.time_running = *array; |
| 1360 | array++; |
| 1361 | } |
| 1362 | |
| 1363 | /* PERF_FORMAT_ID is forced for PERF_SAMPLE_READ */ |
| 1364 | if (read_format & PERF_FORMAT_GROUP) { |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1365 | const u64 max_group_nr = UINT64_MAX / |
| 1366 | sizeof(struct sample_read_value); |
| 1367 | |
| 1368 | if (data->read.group.nr > max_group_nr) |
| 1369 | return -EFAULT; |
| 1370 | sz = data->read.group.nr * |
| 1371 | sizeof(struct sample_read_value); |
| 1372 | OVERFLOW_CHECK(array, sz, max_size); |
| 1373 | data->read.group.values = |
| 1374 | (struct sample_read_value *)array; |
| 1375 | array = (void *)array + sz; |
Jiri Olsa | 9ede473 | 2012-10-10 17:38:13 +0200 | [diff] [blame] | 1376 | } else { |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1377 | OVERFLOW_CHECK_u64(array); |
Jiri Olsa | 9ede473 | 2012-10-10 17:38:13 +0200 | [diff] [blame] | 1378 | data->read.one.id = *array; |
| 1379 | array++; |
| 1380 | } |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | if (type & PERF_SAMPLE_CALLCHAIN) { |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1384 | const u64 max_callchain_nr = UINT64_MAX / sizeof(u64); |
| 1385 | |
| 1386 | OVERFLOW_CHECK_u64(array); |
| 1387 | data->callchain = (struct ip_callchain *)array++; |
| 1388 | if (data->callchain->nr > max_callchain_nr) |
Frederic Weisbecker | 98e1da9 | 2011-05-21 20:08:15 +0200 | [diff] [blame] | 1389 | return -EFAULT; |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1390 | sz = data->callchain->nr * sizeof(u64); |
| 1391 | OVERFLOW_CHECK(array, sz, max_size); |
| 1392 | array = (void *)array + sz; |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | if (type & PERF_SAMPLE_RAW) { |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1396 | OVERFLOW_CHECK_u64(array); |
David Ahern | 936be50 | 2011-09-06 09:12:26 -0600 | [diff] [blame] | 1397 | u.val64 = *array; |
| 1398 | if (WARN_ONCE(swapped, |
| 1399 | "Endianness of raw data not corrected!\n")) { |
| 1400 | /* undo swap of u64, then swap on individual u32s */ |
| 1401 | u.val64 = bswap_64(u.val64); |
| 1402 | u.val32[0] = bswap_32(u.val32[0]); |
| 1403 | u.val32[1] = bswap_32(u.val32[1]); |
| 1404 | } |
David Ahern | 936be50 | 2011-09-06 09:12:26 -0600 | [diff] [blame] | 1405 | data->raw_size = u.val32[0]; |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1406 | array = (void *)array + sizeof(u32); |
Frederic Weisbecker | 98e1da9 | 2011-05-21 20:08:15 +0200 | [diff] [blame] | 1407 | |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1408 | OVERFLOW_CHECK(array, data->raw_size, max_size); |
| 1409 | data->raw_data = (void *)array; |
| 1410 | array = (void *)array + data->raw_size; |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1411 | } |
| 1412 | |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 1413 | if (type & PERF_SAMPLE_BRANCH_STACK) { |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1414 | const u64 max_branch_nr = UINT64_MAX / |
| 1415 | sizeof(struct branch_entry); |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 1416 | |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1417 | OVERFLOW_CHECK_u64(array); |
| 1418 | data->branch_stack = (struct branch_stack *)array++; |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 1419 | |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1420 | if (data->branch_stack->nr > max_branch_nr) |
| 1421 | return -EFAULT; |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 1422 | sz = data->branch_stack->nr * sizeof(struct branch_entry); |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1423 | OVERFLOW_CHECK(array, sz, max_size); |
| 1424 | array = (void *)array + sz; |
Roberto Agostino Vitillo | b538752 | 2012-02-09 23:21:01 +0100 | [diff] [blame] | 1425 | } |
Jiri Olsa | 0f6a301 | 2012-08-07 15:20:45 +0200 | [diff] [blame] | 1426 | |
| 1427 | if (type & PERF_SAMPLE_REGS_USER) { |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1428 | OVERFLOW_CHECK_u64(array); |
Adrian Hunter | 5b95a4a3 | 2013-08-27 11:23:10 +0300 | [diff] [blame] | 1429 | data->user_regs.abi = *array; |
| 1430 | array++; |
Jiri Olsa | 0f6a301 | 2012-08-07 15:20:45 +0200 | [diff] [blame] | 1431 | |
Adrian Hunter | 5b95a4a3 | 2013-08-27 11:23:10 +0300 | [diff] [blame] | 1432 | if (data->user_regs.abi) { |
Jiri Olsa | 352ea45 | 2014-01-07 13:47:25 +0100 | [diff] [blame] | 1433 | u64 mask = evsel->attr.sample_regs_user; |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1434 | |
Jiri Olsa | 352ea45 | 2014-01-07 13:47:25 +0100 | [diff] [blame] | 1435 | sz = hweight_long(mask) * sizeof(u64); |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1436 | OVERFLOW_CHECK(array, sz, max_size); |
Jiri Olsa | 352ea45 | 2014-01-07 13:47:25 +0100 | [diff] [blame] | 1437 | data->user_regs.mask = mask; |
Jiri Olsa | 0f6a301 | 2012-08-07 15:20:45 +0200 | [diff] [blame] | 1438 | data->user_regs.regs = (u64 *)array; |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1439 | array = (void *)array + sz; |
Jiri Olsa | 0f6a301 | 2012-08-07 15:20:45 +0200 | [diff] [blame] | 1440 | } |
| 1441 | } |
| 1442 | |
| 1443 | if (type & PERF_SAMPLE_STACK_USER) { |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1444 | OVERFLOW_CHECK_u64(array); |
| 1445 | sz = *array++; |
Jiri Olsa | 0f6a301 | 2012-08-07 15:20:45 +0200 | [diff] [blame] | 1446 | |
| 1447 | data->user_stack.offset = ((char *)(array - 1) |
| 1448 | - (char *) event); |
| 1449 | |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1450 | if (!sz) { |
Jiri Olsa | 0f6a301 | 2012-08-07 15:20:45 +0200 | [diff] [blame] | 1451 | data->user_stack.size = 0; |
| 1452 | } else { |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1453 | OVERFLOW_CHECK(array, sz, max_size); |
Jiri Olsa | 0f6a301 | 2012-08-07 15:20:45 +0200 | [diff] [blame] | 1454 | data->user_stack.data = (char *)array; |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1455 | array = (void *)array + sz; |
| 1456 | OVERFLOW_CHECK_u64(array); |
Adrian Hunter | 54bd269 | 2013-07-04 16:20:34 +0300 | [diff] [blame] | 1457 | data->user_stack.size = *array++; |
Jiri Olsa | a65cb4b | 2013-10-02 15:46:39 +0200 | [diff] [blame] | 1458 | if (WARN_ONCE(data->user_stack.size > sz, |
| 1459 | "user stack dump failure\n")) |
| 1460 | return -EFAULT; |
Jiri Olsa | 0f6a301 | 2012-08-07 15:20:45 +0200 | [diff] [blame] | 1461 | } |
| 1462 | } |
| 1463 | |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 1464 | data->weight = 0; |
| 1465 | if (type & PERF_SAMPLE_WEIGHT) { |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1466 | OVERFLOW_CHECK_u64(array); |
Andi Kleen | 0548429 | 2013-01-24 16:10:29 +0100 | [diff] [blame] | 1467 | data->weight = *array; |
| 1468 | array++; |
| 1469 | } |
| 1470 | |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 1471 | data->data_src = PERF_MEM_DATA_SRC_NONE; |
| 1472 | if (type & PERF_SAMPLE_DATA_SRC) { |
Adrian Hunter | 03b6ea9 | 2013-08-27 11:23:04 +0300 | [diff] [blame] | 1473 | OVERFLOW_CHECK_u64(array); |
Stephane Eranian | 98a3b32 | 2013-01-24 16:10:35 +0100 | [diff] [blame] | 1474 | data->data_src = *array; |
| 1475 | array++; |
| 1476 | } |
| 1477 | |
Andi Kleen | 475eeab | 2013-09-20 07:40:43 -0700 | [diff] [blame] | 1478 | data->transaction = 0; |
| 1479 | if (type & PERF_SAMPLE_TRANSACTION) { |
Adrian Hunter | 87b9552 | 2013-11-01 15:51:36 +0200 | [diff] [blame] | 1480 | OVERFLOW_CHECK_u64(array); |
Andi Kleen | 475eeab | 2013-09-20 07:40:43 -0700 | [diff] [blame] | 1481 | data->transaction = *array; |
| 1482 | array++; |
| 1483 | } |
| 1484 | |
Arnaldo Carvalho de Melo | d0dd74e | 2011-01-21 13:46:41 -0200 | [diff] [blame] | 1485 | return 0; |
| 1486 | } |
Andrew Vagin | 74eec26 | 2011-11-28 12:03:31 +0300 | [diff] [blame] | 1487 | |
Adrian Hunter | b1cf6f6 | 2013-08-27 11:23:12 +0300 | [diff] [blame] | 1488 | size_t perf_event__sample_event_size(const struct perf_sample *sample, u64 type, |
Jiri Olsa | 352ea45 | 2014-01-07 13:47:25 +0100 | [diff] [blame] | 1489 | u64 read_format) |
Adrian Hunter | b1cf6f6 | 2013-08-27 11:23:12 +0300 | [diff] [blame] | 1490 | { |
| 1491 | size_t sz, result = sizeof(struct sample_event); |
| 1492 | |
| 1493 | if (type & PERF_SAMPLE_IDENTIFIER) |
| 1494 | result += sizeof(u64); |
| 1495 | |
| 1496 | if (type & PERF_SAMPLE_IP) |
| 1497 | result += sizeof(u64); |
| 1498 | |
| 1499 | if (type & PERF_SAMPLE_TID) |
| 1500 | result += sizeof(u64); |
| 1501 | |
| 1502 | if (type & PERF_SAMPLE_TIME) |
| 1503 | result += sizeof(u64); |
| 1504 | |
| 1505 | if (type & PERF_SAMPLE_ADDR) |
| 1506 | result += sizeof(u64); |
| 1507 | |
| 1508 | if (type & PERF_SAMPLE_ID) |
| 1509 | result += sizeof(u64); |
| 1510 | |
| 1511 | if (type & PERF_SAMPLE_STREAM_ID) |
| 1512 | result += sizeof(u64); |
| 1513 | |
| 1514 | if (type & PERF_SAMPLE_CPU) |
| 1515 | result += sizeof(u64); |
| 1516 | |
| 1517 | if (type & PERF_SAMPLE_PERIOD) |
| 1518 | result += sizeof(u64); |
| 1519 | |
| 1520 | if (type & PERF_SAMPLE_READ) { |
| 1521 | result += sizeof(u64); |
| 1522 | if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) |
| 1523 | result += sizeof(u64); |
| 1524 | if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) |
| 1525 | result += sizeof(u64); |
| 1526 | /* PERF_FORMAT_ID is forced for PERF_SAMPLE_READ */ |
| 1527 | if (read_format & PERF_FORMAT_GROUP) { |
| 1528 | sz = sample->read.group.nr * |
| 1529 | sizeof(struct sample_read_value); |
| 1530 | result += sz; |
| 1531 | } else { |
| 1532 | result += sizeof(u64); |
| 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | if (type & PERF_SAMPLE_CALLCHAIN) { |
| 1537 | sz = (sample->callchain->nr + 1) * sizeof(u64); |
| 1538 | result += sz; |
| 1539 | } |
| 1540 | |
| 1541 | if (type & PERF_SAMPLE_RAW) { |
| 1542 | result += sizeof(u32); |
| 1543 | result += sample->raw_size; |
| 1544 | } |
| 1545 | |
| 1546 | if (type & PERF_SAMPLE_BRANCH_STACK) { |
| 1547 | sz = sample->branch_stack->nr * sizeof(struct branch_entry); |
| 1548 | sz += sizeof(u64); |
| 1549 | result += sz; |
| 1550 | } |
| 1551 | |
| 1552 | if (type & PERF_SAMPLE_REGS_USER) { |
| 1553 | if (sample->user_regs.abi) { |
| 1554 | result += sizeof(u64); |
Jiri Olsa | 352ea45 | 2014-01-07 13:47:25 +0100 | [diff] [blame] | 1555 | sz = hweight_long(sample->user_regs.mask) * sizeof(u64); |
Adrian Hunter | b1cf6f6 | 2013-08-27 11:23:12 +0300 | [diff] [blame] | 1556 | result += sz; |
| 1557 | } else { |
| 1558 | result += sizeof(u64); |
| 1559 | } |
| 1560 | } |
| 1561 | |
| 1562 | if (type & PERF_SAMPLE_STACK_USER) { |
| 1563 | sz = sample->user_stack.size; |
| 1564 | result += sizeof(u64); |
| 1565 | if (sz) { |
| 1566 | result += sz; |
| 1567 | result += sizeof(u64); |
| 1568 | } |
| 1569 | } |
| 1570 | |
| 1571 | if (type & PERF_SAMPLE_WEIGHT) |
| 1572 | result += sizeof(u64); |
| 1573 | |
| 1574 | if (type & PERF_SAMPLE_DATA_SRC) |
| 1575 | result += sizeof(u64); |
| 1576 | |
Adrian Hunter | 42d8891 | 2013-11-01 15:51:38 +0200 | [diff] [blame] | 1577 | if (type & PERF_SAMPLE_TRANSACTION) |
| 1578 | result += sizeof(u64); |
| 1579 | |
Adrian Hunter | b1cf6f6 | 2013-08-27 11:23:12 +0300 | [diff] [blame] | 1580 | return result; |
| 1581 | } |
| 1582 | |
Andrew Vagin | 74eec26 | 2011-11-28 12:03:31 +0300 | [diff] [blame] | 1583 | int perf_event__synthesize_sample(union perf_event *event, u64 type, |
Jiri Olsa | 352ea45 | 2014-01-07 13:47:25 +0100 | [diff] [blame] | 1584 | u64 read_format, |
Andrew Vagin | 74eec26 | 2011-11-28 12:03:31 +0300 | [diff] [blame] | 1585 | const struct perf_sample *sample, |
| 1586 | bool swapped) |
| 1587 | { |
| 1588 | u64 *array; |
Adrian Hunter | d03f217 | 2013-08-27 11:23:11 +0300 | [diff] [blame] | 1589 | size_t sz; |
Andrew Vagin | 74eec26 | 2011-11-28 12:03:31 +0300 | [diff] [blame] | 1590 | /* |
| 1591 | * used for cross-endian analysis. See git commit 65014ab3 |
| 1592 | * for why this goofiness is needed. |
| 1593 | */ |
Jiri Olsa | 6a11f92 | 2012-05-16 08:59:04 +0200 | [diff] [blame] | 1594 | union u64_swap u; |
Andrew Vagin | 74eec26 | 2011-11-28 12:03:31 +0300 | [diff] [blame] | 1595 | |
| 1596 | array = event->sample.array; |
| 1597 | |
Adrian Hunter | 7556257 | 2013-08-27 11:23:09 +0300 | [diff] [blame] | 1598 | if (type & PERF_SAMPLE_IDENTIFIER) { |
| 1599 | *array = sample->id; |
| 1600 | array++; |
| 1601 | } |
| 1602 | |
Andrew Vagin | 74eec26 | 2011-11-28 12:03:31 +0300 | [diff] [blame] | 1603 | if (type & PERF_SAMPLE_IP) { |
Adrian Hunter | ef89325 | 2013-08-27 11:23:06 +0300 | [diff] [blame] | 1604 | *array = sample->ip; |
Andrew Vagin | 74eec26 | 2011-11-28 12:03:31 +0300 | [diff] [blame] | 1605 | array++; |
| 1606 | } |
| 1607 | |
| 1608 | if (type & PERF_SAMPLE_TID) { |
| 1609 | u.val32[0] = sample->pid; |
| 1610 | u.val32[1] = sample->tid; |
| 1611 | if (swapped) { |
| 1612 | /* |
Arnaldo Carvalho de Melo | a3f698f | 2012-08-02 12:23:46 -0300 | [diff] [blame] | 1613 | * Inverse of what is done in perf_evsel__parse_sample |
Andrew Vagin | 74eec26 | 2011-11-28 12:03:31 +0300 | [diff] [blame] | 1614 | */ |
| 1615 | u.val32[0] = bswap_32(u.val32[0]); |
| 1616 | u.val32[1] = bswap_32(u.val32[1]); |
| 1617 | u.val64 = bswap_64(u.val64); |
| 1618 | } |
| 1619 | |
| 1620 | *array = u.val64; |
| 1621 | array++; |
| 1622 | } |
| 1623 | |
| 1624 | if (type & PERF_SAMPLE_TIME) { |
| 1625 | *array = sample->time; |
| 1626 | array++; |
| 1627 | } |
| 1628 | |
| 1629 | if (type & PERF_SAMPLE_ADDR) { |
| 1630 | *array = sample->addr; |
| 1631 | array++; |
| 1632 | } |
| 1633 | |
| 1634 | if (type & PERF_SAMPLE_ID) { |
| 1635 | *array = sample->id; |
| 1636 | array++; |
| 1637 | } |
| 1638 | |
| 1639 | if (type & PERF_SAMPLE_STREAM_ID) { |
| 1640 | *array = sample->stream_id; |
| 1641 | array++; |
| 1642 | } |
| 1643 | |
| 1644 | if (type & PERF_SAMPLE_CPU) { |
| 1645 | u.val32[0] = sample->cpu; |
| 1646 | if (swapped) { |
| 1647 | /* |
Arnaldo Carvalho de Melo | a3f698f | 2012-08-02 12:23:46 -0300 | [diff] [blame] | 1648 | * Inverse of what is done in perf_evsel__parse_sample |
Andrew Vagin | 74eec26 | 2011-11-28 12:03:31 +0300 | [diff] [blame] | 1649 | */ |
| 1650 | u.val32[0] = bswap_32(u.val32[0]); |
| 1651 | u.val64 = bswap_64(u.val64); |
| 1652 | } |
| 1653 | *array = u.val64; |
| 1654 | array++; |
| 1655 | } |
| 1656 | |
| 1657 | if (type & PERF_SAMPLE_PERIOD) { |
| 1658 | *array = sample->period; |
| 1659 | array++; |
| 1660 | } |
| 1661 | |
Adrian Hunter | d03f217 | 2013-08-27 11:23:11 +0300 | [diff] [blame] | 1662 | if (type & PERF_SAMPLE_READ) { |
| 1663 | if (read_format & PERF_FORMAT_GROUP) |
| 1664 | *array = sample->read.group.nr; |
| 1665 | else |
| 1666 | *array = sample->read.one.value; |
| 1667 | array++; |
| 1668 | |
| 1669 | if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) { |
| 1670 | *array = sample->read.time_enabled; |
| 1671 | array++; |
| 1672 | } |
| 1673 | |
| 1674 | if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) { |
| 1675 | *array = sample->read.time_running; |
| 1676 | array++; |
| 1677 | } |
| 1678 | |
| 1679 | /* PERF_FORMAT_ID is forced for PERF_SAMPLE_READ */ |
| 1680 | if (read_format & PERF_FORMAT_GROUP) { |
| 1681 | sz = sample->read.group.nr * |
| 1682 | sizeof(struct sample_read_value); |
| 1683 | memcpy(array, sample->read.group.values, sz); |
| 1684 | array = (void *)array + sz; |
| 1685 | } else { |
| 1686 | *array = sample->read.one.id; |
| 1687 | array++; |
| 1688 | } |
| 1689 | } |
| 1690 | |
| 1691 | if (type & PERF_SAMPLE_CALLCHAIN) { |
| 1692 | sz = (sample->callchain->nr + 1) * sizeof(u64); |
| 1693 | memcpy(array, sample->callchain, sz); |
| 1694 | array = (void *)array + sz; |
| 1695 | } |
| 1696 | |
| 1697 | if (type & PERF_SAMPLE_RAW) { |
| 1698 | u.val32[0] = sample->raw_size; |
| 1699 | if (WARN_ONCE(swapped, |
| 1700 | "Endianness of raw data not corrected!\n")) { |
| 1701 | /* |
| 1702 | * Inverse of what is done in perf_evsel__parse_sample |
| 1703 | */ |
| 1704 | u.val32[0] = bswap_32(u.val32[0]); |
| 1705 | u.val32[1] = bswap_32(u.val32[1]); |
| 1706 | u.val64 = bswap_64(u.val64); |
| 1707 | } |
| 1708 | *array = u.val64; |
| 1709 | array = (void *)array + sizeof(u32); |
| 1710 | |
| 1711 | memcpy(array, sample->raw_data, sample->raw_size); |
| 1712 | array = (void *)array + sample->raw_size; |
| 1713 | } |
| 1714 | |
| 1715 | if (type & PERF_SAMPLE_BRANCH_STACK) { |
| 1716 | sz = sample->branch_stack->nr * sizeof(struct branch_entry); |
| 1717 | sz += sizeof(u64); |
| 1718 | memcpy(array, sample->branch_stack, sz); |
| 1719 | array = (void *)array + sz; |
| 1720 | } |
| 1721 | |
| 1722 | if (type & PERF_SAMPLE_REGS_USER) { |
| 1723 | if (sample->user_regs.abi) { |
| 1724 | *array++ = sample->user_regs.abi; |
Jiri Olsa | 352ea45 | 2014-01-07 13:47:25 +0100 | [diff] [blame] | 1725 | sz = hweight_long(sample->user_regs.mask) * sizeof(u64); |
Adrian Hunter | d03f217 | 2013-08-27 11:23:11 +0300 | [diff] [blame] | 1726 | memcpy(array, sample->user_regs.regs, sz); |
| 1727 | array = (void *)array + sz; |
| 1728 | } else { |
| 1729 | *array++ = 0; |
| 1730 | } |
| 1731 | } |
| 1732 | |
| 1733 | if (type & PERF_SAMPLE_STACK_USER) { |
| 1734 | sz = sample->user_stack.size; |
| 1735 | *array++ = sz; |
| 1736 | if (sz) { |
| 1737 | memcpy(array, sample->user_stack.data, sz); |
| 1738 | array = (void *)array + sz; |
| 1739 | *array++ = sz; |
| 1740 | } |
| 1741 | } |
| 1742 | |
| 1743 | if (type & PERF_SAMPLE_WEIGHT) { |
| 1744 | *array = sample->weight; |
| 1745 | array++; |
| 1746 | } |
| 1747 | |
| 1748 | if (type & PERF_SAMPLE_DATA_SRC) { |
| 1749 | *array = sample->data_src; |
| 1750 | array++; |
| 1751 | } |
| 1752 | |
Adrian Hunter | 42d8891 | 2013-11-01 15:51:38 +0200 | [diff] [blame] | 1753 | if (type & PERF_SAMPLE_TRANSACTION) { |
| 1754 | *array = sample->transaction; |
| 1755 | array++; |
| 1756 | } |
| 1757 | |
Andrew Vagin | 74eec26 | 2011-11-28 12:03:31 +0300 | [diff] [blame] | 1758 | return 0; |
| 1759 | } |
Arnaldo Carvalho de Melo | 5555ded | 2012-09-11 19:24:23 -0300 | [diff] [blame] | 1760 | |
Arnaldo Carvalho de Melo | efd2b92 | 2012-09-18 11:21:50 -0300 | [diff] [blame] | 1761 | struct format_field *perf_evsel__field(struct perf_evsel *evsel, const char *name) |
| 1762 | { |
| 1763 | return pevent_find_field(evsel->tp_format, name); |
| 1764 | } |
| 1765 | |
Arnaldo Carvalho de Melo | 5d2074e | 2012-09-26 20:22:00 -0300 | [diff] [blame] | 1766 | void *perf_evsel__rawptr(struct perf_evsel *evsel, struct perf_sample *sample, |
Arnaldo Carvalho de Melo | 5555ded | 2012-09-11 19:24:23 -0300 | [diff] [blame] | 1767 | const char *name) |
| 1768 | { |
Arnaldo Carvalho de Melo | efd2b92 | 2012-09-18 11:21:50 -0300 | [diff] [blame] | 1769 | struct format_field *field = perf_evsel__field(evsel, name); |
Arnaldo Carvalho de Melo | 5555ded | 2012-09-11 19:24:23 -0300 | [diff] [blame] | 1770 | int offset; |
| 1771 | |
Arnaldo Carvalho de Melo | efd2b92 | 2012-09-18 11:21:50 -0300 | [diff] [blame] | 1772 | if (!field) |
| 1773 | return NULL; |
Arnaldo Carvalho de Melo | 5555ded | 2012-09-11 19:24:23 -0300 | [diff] [blame] | 1774 | |
| 1775 | offset = field->offset; |
| 1776 | |
| 1777 | if (field->flags & FIELD_IS_DYNAMIC) { |
| 1778 | offset = *(int *)(sample->raw_data + field->offset); |
| 1779 | offset &= 0xffff; |
| 1780 | } |
| 1781 | |
| 1782 | return sample->raw_data + offset; |
| 1783 | } |
| 1784 | |
| 1785 | u64 perf_evsel__intval(struct perf_evsel *evsel, struct perf_sample *sample, |
| 1786 | const char *name) |
| 1787 | { |
Arnaldo Carvalho de Melo | efd2b92 | 2012-09-18 11:21:50 -0300 | [diff] [blame] | 1788 | struct format_field *field = perf_evsel__field(evsel, name); |
Arnaldo Carvalho de Melo | e6b6f67 | 2012-09-26 13:13:04 -0300 | [diff] [blame] | 1789 | void *ptr; |
| 1790 | u64 value; |
Arnaldo Carvalho de Melo | 5555ded | 2012-09-11 19:24:23 -0300 | [diff] [blame] | 1791 | |
Arnaldo Carvalho de Melo | efd2b92 | 2012-09-18 11:21:50 -0300 | [diff] [blame] | 1792 | if (!field) |
| 1793 | return 0; |
Arnaldo Carvalho de Melo | 5555ded | 2012-09-11 19:24:23 -0300 | [diff] [blame] | 1794 | |
Arnaldo Carvalho de Melo | e6b6f67 | 2012-09-26 13:13:04 -0300 | [diff] [blame] | 1795 | ptr = sample->raw_data + field->offset; |
Arnaldo Carvalho de Melo | 5555ded | 2012-09-11 19:24:23 -0300 | [diff] [blame] | 1796 | |
Arnaldo Carvalho de Melo | e6b6f67 | 2012-09-26 13:13:04 -0300 | [diff] [blame] | 1797 | switch (field->size) { |
| 1798 | case 1: |
| 1799 | return *(u8 *)ptr; |
| 1800 | case 2: |
| 1801 | value = *(u16 *)ptr; |
| 1802 | break; |
| 1803 | case 4: |
| 1804 | value = *(u32 *)ptr; |
| 1805 | break; |
| 1806 | case 8: |
| 1807 | value = *(u64 *)ptr; |
| 1808 | break; |
| 1809 | default: |
| 1810 | return 0; |
| 1811 | } |
| 1812 | |
| 1813 | if (!evsel->needs_swap) |
| 1814 | return value; |
| 1815 | |
| 1816 | switch (field->size) { |
| 1817 | case 2: |
| 1818 | return bswap_16(value); |
| 1819 | case 4: |
| 1820 | return bswap_32(value); |
| 1821 | case 8: |
| 1822 | return bswap_64(value); |
| 1823 | default: |
| 1824 | return 0; |
| 1825 | } |
| 1826 | |
| 1827 | return 0; |
Arnaldo Carvalho de Melo | 5555ded | 2012-09-11 19:24:23 -0300 | [diff] [blame] | 1828 | } |
Arnaldo Carvalho de Melo | 0698aed | 2012-12-10 18:17:08 -0300 | [diff] [blame] | 1829 | |
| 1830 | static int comma_fprintf(FILE *fp, bool *first, const char *fmt, ...) |
| 1831 | { |
| 1832 | va_list args; |
| 1833 | int ret = 0; |
| 1834 | |
| 1835 | if (!*first) { |
| 1836 | ret += fprintf(fp, ","); |
| 1837 | } else { |
| 1838 | ret += fprintf(fp, ":"); |
| 1839 | *first = false; |
| 1840 | } |
| 1841 | |
| 1842 | va_start(args, fmt); |
| 1843 | ret += vfprintf(fp, fmt, args); |
| 1844 | va_end(args); |
| 1845 | return ret; |
| 1846 | } |
| 1847 | |
| 1848 | static int __if_fprintf(FILE *fp, bool *first, const char *field, u64 value) |
| 1849 | { |
| 1850 | if (value == 0) |
| 1851 | return 0; |
| 1852 | |
| 1853 | return comma_fprintf(fp, first, " %s: %" PRIu64, field, value); |
| 1854 | } |
| 1855 | |
| 1856 | #define if_print(field) printed += __if_fprintf(fp, &first, #field, evsel->attr.field) |
| 1857 | |
Arnaldo Carvalho de Melo | c79a439 | 2012-12-11 10:54:12 -0300 | [diff] [blame] | 1858 | struct bit_names { |
| 1859 | int bit; |
| 1860 | const char *name; |
| 1861 | }; |
| 1862 | |
| 1863 | static int bits__fprintf(FILE *fp, const char *field, u64 value, |
| 1864 | struct bit_names *bits, bool *first) |
| 1865 | { |
| 1866 | int i = 0, printed = comma_fprintf(fp, first, " %s: ", field); |
| 1867 | bool first_bit = true; |
| 1868 | |
| 1869 | do { |
| 1870 | if (value & bits[i].bit) { |
| 1871 | printed += fprintf(fp, "%s%s", first_bit ? "" : "|", bits[i].name); |
| 1872 | first_bit = false; |
| 1873 | } |
| 1874 | } while (bits[++i].name != NULL); |
| 1875 | |
| 1876 | return printed; |
| 1877 | } |
| 1878 | |
| 1879 | static int sample_type__fprintf(FILE *fp, bool *first, u64 value) |
| 1880 | { |
| 1881 | #define bit_name(n) { PERF_SAMPLE_##n, #n } |
| 1882 | struct bit_names bits[] = { |
| 1883 | bit_name(IP), bit_name(TID), bit_name(TIME), bit_name(ADDR), |
| 1884 | bit_name(READ), bit_name(CALLCHAIN), bit_name(ID), bit_name(CPU), |
| 1885 | bit_name(PERIOD), bit_name(STREAM_ID), bit_name(RAW), |
| 1886 | bit_name(BRANCH_STACK), bit_name(REGS_USER), bit_name(STACK_USER), |
Adrian Hunter | 7556257 | 2013-08-27 11:23:09 +0300 | [diff] [blame] | 1887 | bit_name(IDENTIFIER), |
Arnaldo Carvalho de Melo | c79a439 | 2012-12-11 10:54:12 -0300 | [diff] [blame] | 1888 | { .name = NULL, } |
| 1889 | }; |
| 1890 | #undef bit_name |
| 1891 | return bits__fprintf(fp, "sample_type", value, bits, first); |
| 1892 | } |
| 1893 | |
| 1894 | static int read_format__fprintf(FILE *fp, bool *first, u64 value) |
| 1895 | { |
| 1896 | #define bit_name(n) { PERF_FORMAT_##n, #n } |
| 1897 | struct bit_names bits[] = { |
| 1898 | bit_name(TOTAL_TIME_ENABLED), bit_name(TOTAL_TIME_RUNNING), |
| 1899 | bit_name(ID), bit_name(GROUP), |
| 1900 | { .name = NULL, } |
| 1901 | }; |
| 1902 | #undef bit_name |
| 1903 | return bits__fprintf(fp, "read_format", value, bits, first); |
| 1904 | } |
| 1905 | |
Arnaldo Carvalho de Melo | 0698aed | 2012-12-10 18:17:08 -0300 | [diff] [blame] | 1906 | int perf_evsel__fprintf(struct perf_evsel *evsel, |
| 1907 | struct perf_attr_details *details, FILE *fp) |
| 1908 | { |
| 1909 | bool first = true; |
Namhyung Kim | e6ab07d | 2013-01-22 18:09:47 +0900 | [diff] [blame] | 1910 | int printed = 0; |
| 1911 | |
Arnaldo Carvalho de Melo | e35ef355 | 2013-02-06 17:20:02 -0300 | [diff] [blame] | 1912 | if (details->event_group) { |
Namhyung Kim | e6ab07d | 2013-01-22 18:09:47 +0900 | [diff] [blame] | 1913 | struct perf_evsel *pos; |
| 1914 | |
| 1915 | if (!perf_evsel__is_group_leader(evsel)) |
| 1916 | return 0; |
| 1917 | |
| 1918 | if (evsel->nr_members > 1) |
| 1919 | printed += fprintf(fp, "%s{", evsel->group_name ?: ""); |
| 1920 | |
| 1921 | printed += fprintf(fp, "%s", perf_evsel__name(evsel)); |
| 1922 | for_each_group_member(pos, evsel) |
| 1923 | printed += fprintf(fp, ",%s", perf_evsel__name(pos)); |
| 1924 | |
| 1925 | if (evsel->nr_members > 1) |
| 1926 | printed += fprintf(fp, "}"); |
| 1927 | goto out; |
| 1928 | } |
| 1929 | |
| 1930 | printed += fprintf(fp, "%s", perf_evsel__name(evsel)); |
Arnaldo Carvalho de Melo | 0698aed | 2012-12-10 18:17:08 -0300 | [diff] [blame] | 1931 | |
| 1932 | if (details->verbose || details->freq) { |
| 1933 | printed += comma_fprintf(fp, &first, " sample_freq=%" PRIu64, |
| 1934 | (u64)evsel->attr.sample_freq); |
| 1935 | } |
| 1936 | |
| 1937 | if (details->verbose) { |
| 1938 | if_print(type); |
| 1939 | if_print(config); |
| 1940 | if_print(config1); |
| 1941 | if_print(config2); |
| 1942 | if_print(size); |
Arnaldo Carvalho de Melo | c79a439 | 2012-12-11 10:54:12 -0300 | [diff] [blame] | 1943 | printed += sample_type__fprintf(fp, &first, evsel->attr.sample_type); |
| 1944 | if (evsel->attr.read_format) |
| 1945 | printed += read_format__fprintf(fp, &first, evsel->attr.read_format); |
Arnaldo Carvalho de Melo | 0698aed | 2012-12-10 18:17:08 -0300 | [diff] [blame] | 1946 | if_print(disabled); |
| 1947 | if_print(inherit); |
| 1948 | if_print(pinned); |
| 1949 | if_print(exclusive); |
| 1950 | if_print(exclude_user); |
| 1951 | if_print(exclude_kernel); |
| 1952 | if_print(exclude_hv); |
| 1953 | if_print(exclude_idle); |
| 1954 | if_print(mmap); |
Stephane Eranian | 5c5e854 | 2013-08-21 12:10:25 +0200 | [diff] [blame] | 1955 | if_print(mmap2); |
Arnaldo Carvalho de Melo | 0698aed | 2012-12-10 18:17:08 -0300 | [diff] [blame] | 1956 | if_print(comm); |
Adrian Hunter | 022c50d | 2014-07-14 13:02:27 +0300 | [diff] [blame] | 1957 | if_print(comm_exec); |
Arnaldo Carvalho de Melo | 0698aed | 2012-12-10 18:17:08 -0300 | [diff] [blame] | 1958 | if_print(freq); |
| 1959 | if_print(inherit_stat); |
| 1960 | if_print(enable_on_exec); |
| 1961 | if_print(task); |
| 1962 | if_print(watermark); |
| 1963 | if_print(precise_ip); |
| 1964 | if_print(mmap_data); |
| 1965 | if_print(sample_id_all); |
| 1966 | if_print(exclude_host); |
| 1967 | if_print(exclude_guest); |
| 1968 | if_print(__reserved_1); |
| 1969 | if_print(wakeup_events); |
| 1970 | if_print(bp_type); |
| 1971 | if_print(branch_sample_type); |
| 1972 | } |
Namhyung Kim | e6ab07d | 2013-01-22 18:09:47 +0900 | [diff] [blame] | 1973 | out: |
Arnaldo Carvalho de Melo | 0698aed | 2012-12-10 18:17:08 -0300 | [diff] [blame] | 1974 | fputc('\n', fp); |
| 1975 | return ++printed; |
| 1976 | } |
Arnaldo Carvalho de Melo | c0a5434 | 2012-12-13 14:16:30 -0300 | [diff] [blame] | 1977 | |
| 1978 | bool perf_evsel__fallback(struct perf_evsel *evsel, int err, |
| 1979 | char *msg, size_t msgsize) |
| 1980 | { |
David Ahern | 2b821cc | 2013-07-18 17:27:59 -0600 | [diff] [blame] | 1981 | if ((err == ENOENT || err == ENXIO || err == ENODEV) && |
Arnaldo Carvalho de Melo | c0a5434 | 2012-12-13 14:16:30 -0300 | [diff] [blame] | 1982 | evsel->attr.type == PERF_TYPE_HARDWARE && |
| 1983 | evsel->attr.config == PERF_COUNT_HW_CPU_CYCLES) { |
| 1984 | /* |
| 1985 | * If it's cycles then fall back to hrtimer based |
| 1986 | * cpu-clock-tick sw counter, which is always available even if |
| 1987 | * no PMU support. |
| 1988 | * |
| 1989 | * PPC returns ENXIO until 2.6.37 (behavior changed with commit |
| 1990 | * b0a873e). |
| 1991 | */ |
| 1992 | scnprintf(msg, msgsize, "%s", |
| 1993 | "The cycles event is not supported, trying to fall back to cpu-clock-ticks"); |
| 1994 | |
| 1995 | evsel->attr.type = PERF_TYPE_SOFTWARE; |
| 1996 | evsel->attr.config = PERF_COUNT_SW_CPU_CLOCK; |
| 1997 | |
Arnaldo Carvalho de Melo | 0466252 | 2013-12-26 17:41:15 -0300 | [diff] [blame] | 1998 | zfree(&evsel->name); |
Arnaldo Carvalho de Melo | c0a5434 | 2012-12-13 14:16:30 -0300 | [diff] [blame] | 1999 | return true; |
| 2000 | } |
| 2001 | |
| 2002 | return false; |
| 2003 | } |
Arnaldo Carvalho de Melo | 56e52e8 | 2012-12-13 15:10:58 -0300 | [diff] [blame] | 2004 | |
Arnaldo Carvalho de Melo | 602ad87 | 2013-11-12 16:46:16 -0300 | [diff] [blame] | 2005 | int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target, |
Arnaldo Carvalho de Melo | 56e52e8 | 2012-12-13 15:10:58 -0300 | [diff] [blame] | 2006 | int err, char *msg, size_t size) |
| 2007 | { |
| 2008 | switch (err) { |
| 2009 | case EPERM: |
| 2010 | case EACCES: |
David Ahern | b69e63a | 2013-05-25 17:54:00 -0600 | [diff] [blame] | 2011 | return scnprintf(msg, size, |
Arnaldo Carvalho de Melo | 56e52e8 | 2012-12-13 15:10:58 -0300 | [diff] [blame] | 2012 | "You may not have permission to collect %sstats.\n" |
| 2013 | "Consider tweaking /proc/sys/kernel/perf_event_paranoid:\n" |
| 2014 | " -1 - Not paranoid at all\n" |
| 2015 | " 0 - Disallow raw tracepoint access for unpriv\n" |
| 2016 | " 1 - Disallow cpu events for unpriv\n" |
| 2017 | " 2 - Disallow kernel profiling for unpriv", |
| 2018 | target->system_wide ? "system-wide " : ""); |
| 2019 | case ENOENT: |
| 2020 | return scnprintf(msg, size, "The %s event is not supported.", |
| 2021 | perf_evsel__name(evsel)); |
| 2022 | case EMFILE: |
| 2023 | return scnprintf(msg, size, "%s", |
| 2024 | "Too many events are opened.\n" |
| 2025 | "Try again after reducing the number of events."); |
| 2026 | case ENODEV: |
| 2027 | if (target->cpu_list) |
| 2028 | return scnprintf(msg, size, "%s", |
| 2029 | "No such device - did you specify an out-of-range profile CPU?\n"); |
| 2030 | break; |
| 2031 | case EOPNOTSUPP: |
| 2032 | if (evsel->attr.precise_ip) |
| 2033 | return scnprintf(msg, size, "%s", |
| 2034 | "\'precise\' request may not be supported. Try removing 'p' modifier."); |
| 2035 | #if defined(__i386__) || defined(__x86_64__) |
| 2036 | if (evsel->attr.type == PERF_TYPE_HARDWARE) |
| 2037 | return scnprintf(msg, size, "%s", |
| 2038 | "No hardware sampling interrupt available.\n" |
| 2039 | "No APIC? If so then you can boot the kernel with the \"lapic\" boot parameter to force-enable it."); |
| 2040 | #endif |
| 2041 | break; |
Jiri Olsa | 63914ac | 2014-08-01 17:46:54 +0200 | [diff] [blame] | 2042 | case EBUSY: |
| 2043 | if (find_process("oprofiled")) |
| 2044 | return scnprintf(msg, size, |
| 2045 | "The PMU counters are busy/taken by another profiler.\n" |
| 2046 | "We found oprofile daemon running, please stop it and try again."); |
| 2047 | break; |
Arnaldo Carvalho de Melo | 56e52e8 | 2012-12-13 15:10:58 -0300 | [diff] [blame] | 2048 | default: |
| 2049 | break; |
| 2050 | } |
| 2051 | |
| 2052 | return scnprintf(msg, size, |
| 2053 | "The sys_perf_event_open() syscall returned with %d (%s) for event (%s). \n" |
| 2054 | "/bin/dmesg may provide additional information.\n" |
| 2055 | "No CONFIG_PERF_EVENTS=y kernel support configured?\n", |
| 2056 | err, strerror(err), perf_evsel__name(evsel)); |
| 2057 | } |