Lines Matching refs:evsel
25 #include <perf/evsel.h>
32 #include "evsel.h"
96 static int evsel__no_extra_init(struct evsel *evsel __maybe_unused)
103 static void evsel__no_extra_fini(struct evsel *evsel __maybe_unused)
109 int (*init)(struct evsel *evsel);
110 void (*fini)(struct evsel *evsel);
112 .size = sizeof(struct evsel),
117 int evsel__object_config(size_t object_size, int (*init)(struct evsel *evsel),
118 void (*fini)(struct evsel *evsel))
217 void evsel__calc_id_pos(struct evsel *evsel)
219 evsel->id_pos = __perf_evsel__calc_id_pos(evsel->core.attr.sample_type);
220 evsel->is_pos = __perf_evsel__calc_is_pos(evsel->core.attr.sample_type);
223 void __evsel__set_sample_bit(struct evsel *evsel,
226 if (!(evsel->core.attr.sample_type & bit)) {
227 evsel->core.attr.sample_type |= bit;
228 evsel->sample_size += sizeof(u64);
229 evsel__calc_id_pos(evsel);
233 void __evsel__reset_sample_bit(struct evsel *evsel,
236 if (evsel->core.attr.sample_type & bit) {
237 evsel->core.attr.sample_type &= ~bit;
238 evsel->sample_size -= sizeof(u64);
239 evsel__calc_id_pos(evsel);
243 void evsel__set_sample_id(struct evsel *evsel,
247 evsel__reset_sample_bit(evsel, ID);
248 evsel__set_sample_bit(evsel, IDENTIFIER);
250 evsel__set_sample_bit(evsel, ID);
252 evsel->core.attr.read_format |= PERF_FORMAT_ID;
256 * evsel__is_function_event - Return whether given evsel is a function
259 * @evsel - evsel selector to be tested
263 bool evsel__is_function_event(struct evsel *evsel)
267 return evsel->name &&
268 !strncmp(FUNCTION_EVENT, evsel->name, sizeof(FUNCTION_EVENT));
273 void evsel__init(struct evsel *evsel,
276 perf_evsel__init(&evsel->core, attr, idx);
277 evsel->tracking = !idx;
278 evsel->unit = strdup("");
279 evsel->scale = 1.0;
280 evsel->max_events = ULONG_MAX;
281 evsel->evlist = NULL;
282 evsel->bpf_obj = NULL;
283 evsel->bpf_fd = -1;
284 INIT_LIST_HEAD(&evsel->config_terms);
285 INIT_LIST_HEAD(&evsel->bpf_counter_list);
286 INIT_LIST_HEAD(&evsel->bpf_filters);
287 perf_evsel__object.init(evsel);
288 evsel->sample_size = __evsel__sample_size(attr->sample_type);
289 evsel__calc_id_pos(evsel);
290 evsel->cmdline_group_boundary = false;
291 evsel->metric_events = NULL;
292 evsel->per_pkg_mask = NULL;
293 evsel->collect_stat = false;
294 evsel->pmu_name = NULL;
295 evsel->group_pmu_name = NULL;
296 evsel->skippable = false;
299 struct evsel *evsel__new_idx(struct perf_event_attr *attr, int idx)
301 struct evsel *evsel = zalloc(perf_evsel__object.size);
303 if (!evsel)
305 evsel__init(evsel, attr, idx);
307 if (evsel__is_bpf_output(evsel) && !attr->sample_type) {
308 evsel->core.attr.sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME |
310 evsel->core.attr.sample_period = 1;
313 if (evsel__is_clock(evsel)) {
314 free((char *)evsel->unit);
315 evsel->unit = strdup("msec");
316 evsel->scale = 1e-6;
319 return evsel;
344 static int evsel__copy_config_terms(struct evsel *dst, struct evsel *src)
350 * evsel__clone - create a new evsel copied from @orig
351 * @orig: original evsel
356 struct evsel *evsel__clone(struct evsel *orig)
358 struct evsel *evsel;
369 evsel = evsel__new(&orig->core.attr);
370 if (evsel == NULL)
373 evsel->core.cpus = perf_cpu_map__get(orig->core.cpus);
374 evsel->core.own_cpus = perf_cpu_map__get(orig->core.own_cpus);
375 evsel->core.threads = perf_thread_map__get(orig->core.threads);
376 evsel->core.nr_members = orig->core.nr_members;
377 evsel->core.system_wide = orig->core.system_wide;
378 evsel->core.requires_cpu = orig->core.requires_cpu;
379 evsel->core.is_pmu_core = orig->core.is_pmu_core;
382 evsel->name = strdup(orig->name);
383 if (evsel->name == NULL)
387 evsel->group_name = strdup(orig->group_name);
388 if (evsel->group_name == NULL)
392 evsel->pmu_name = strdup(orig->pmu_name);
393 if (evsel->pmu_name == NULL)
397 evsel->group_pmu_name = strdup(orig->group_pmu_name);
398 if (evsel->group_pmu_name == NULL)
402 evsel->filter = strdup(orig->filter);
403 if (evsel->filter == NULL)
407 evsel->metric_id = strdup(orig->metric_id);
408 if (evsel->metric_id == NULL)
411 evsel->cgrp = cgroup__get(orig->cgrp);
413 evsel->tp_format = orig->tp_format;
415 evsel->handler = orig->handler;
416 evsel->core.leader = orig->core.leader;
418 evsel->max_events = orig->max_events;
419 evsel->tool_event = orig->tool_event;
420 free((char *)evsel->unit);
421 evsel->unit = strdup(orig->unit);
422 if (evsel->unit == NULL)
425 evsel->scale = orig->scale;
426 evsel->snapshot = orig->snapshot;
427 evsel->per_pkg = orig->per_pkg;
428 evsel->percore = orig->percore;
429 evsel->precise_max = orig->precise_max;
430 evsel->is_libpfm_event = orig->is_libpfm_event;
432 evsel->exclude_GH = orig->exclude_GH;
433 evsel->sample_read = orig->sample_read;
434 evsel->auto_merge_stats = orig->auto_merge_stats;
435 evsel->collect_stat = orig->collect_stat;
436 evsel->weak_group = orig->weak_group;
437 evsel->use_config_name = orig->use_config_name;
438 evsel->pmu = orig->pmu;
440 if (evsel__copy_config_terms(evsel, orig) < 0)
443 return evsel;
446 evsel__delete(evsel);
454 struct evsel *evsel__newtp_idx(const char *sys, const char *name, int idx)
456 struct evsel *evsel = zalloc(perf_evsel__object.size);
459 if (evsel == NULL) {
468 if (asprintf(&evsel->name, "%s:%s", sys, name) < 0)
471 evsel->tp_format = trace_event__tp_format(sys, name);
472 if (IS_ERR(evsel->tp_format)) {
473 err = PTR_ERR(evsel->tp_format);
478 attr.config = evsel->tp_format->id;
480 evsel__init(evsel, &attr, idx);
483 return evsel;
486 zfree(&evsel->name);
487 free(evsel);
536 static int evsel__add_modifiers(struct evsel *evsel, char *bf, size_t size)
539 struct perf_event_attr *attr = &evsel->core.attr;
572 int __weak arch_evsel__hw_name(struct evsel *evsel, char *bf, size_t size)
574 return scnprintf(bf, size, "%s", __evsel__hw_name(evsel->core.attr.config));
577 static int evsel__hw_name(struct evsel *evsel, char *bf, size_t size)
579 int r = arch_evsel__hw_name(evsel, bf, size);
580 return r + evsel__add_modifiers(evsel, bf + r, size - r);
603 static int evsel__sw_name(struct evsel *evsel, char *bf, size_t size)
605 int r = scnprintf(bf, size, "%s", __evsel__sw_name(evsel->core.attr.config));
606 return r + evsel__add_modifiers(evsel, bf + r, size - r);
632 static int evsel__bp_name(struct evsel *evsel, char *bf, size_t size)
634 struct perf_event_attr *attr = &evsel->core.attr;
636 return r + evsel__add_modifiers(evsel, bf + r, size - r);
728 static int evsel__hw_cache_name(struct evsel *evsel, char *bf, size_t size)
730 int ret = __evsel__hw_cache_name(evsel->core.attr.config, bf, size);
731 return ret + evsel__add_modifiers(evsel, bf + ret, size - ret);
734 static int evsel__raw_name(struct evsel *evsel, char *bf, size_t size)
736 int ret = scnprintf(bf, size, "raw 0x%" PRIx64, evsel->core.attr.config);
737 return ret + evsel__add_modifiers(evsel, bf + ret, size - ret);
740 const char *evsel__name(struct evsel *evsel)
744 if (!evsel)
747 if (evsel->name)
748 return evsel->name;
750 switch (evsel->core.attr.type) {
752 evsel__raw_name(evsel, bf, sizeof(bf));
756 evsel__hw_name(evsel, bf, sizeof(bf));
760 evsel__hw_cache_name(evsel, bf, sizeof(bf));
764 if (evsel__is_tool(evsel))
765 evsel__tool_name(evsel->tool_event, bf, sizeof(bf));
767 evsel__sw_name(evsel, bf, sizeof(bf));
775 evsel__bp_name(evsel, bf, sizeof(bf));
780 evsel->core.attr.type);
784 evsel->name = strdup(bf);
786 if (evsel->name)
787 return evsel->name;
792 bool evsel__name_is(struct evsel *evsel, const char *name)
794 return !strcmp(evsel__name(evsel), name);
797 const char *evsel__metric_id(const struct evsel *evsel)
799 if (evsel->metric_id)
800 return evsel->metric_id;
802 if (evsel__is_tool(evsel))
803 return perf_tool_event__to_str(evsel->tool_event);
808 const char *evsel__group_name(struct evsel *evsel)
810 return evsel->group_name ?: "anon group";
823 int evsel__group_desc(struct evsel *evsel, char *buf, size_t size)
826 struct evsel *pos;
827 const char *group_name = evsel__group_name(evsel);
829 if (!evsel->forced_leader)
832 ret += scnprintf(buf + ret, size - ret, "%s", evsel__name(evsel));
834 for_each_group_member(pos, evsel)
837 if (!evsel->forced_leader)
843 static void __evsel__config_callchain(struct evsel *evsel, struct record_opts *opts,
846 bool function = evsel__is_function_event(evsel);
847 struct perf_event_attr *attr = &evsel->core.attr;
848 const char *arch = perf_env__arch(evsel__env(evsel));
850 evsel__set_sample_bit(evsel, CALLCHAIN);
865 evsel__set_sample_bit(evsel, BRANCH_STACK);
879 evsel__set_sample_bit(evsel, REGS_USER);
880 evsel__set_sample_bit(evsel, STACK_USER);
904 void evsel__config_callchain(struct evsel *evsel, struct record_opts *opts,
908 return __evsel__config_callchain(evsel, opts, param);
911 static void evsel__reset_callgraph(struct evsel *evsel, struct callchain_param *param)
913 struct perf_event_attr *attr = &evsel->core.attr;
915 evsel__reset_sample_bit(evsel, CALLCHAIN);
917 evsel__reset_sample_bit(evsel, BRANCH_STACK);
923 evsel__reset_sample_bit(evsel, REGS_USER);
924 evsel__reset_sample_bit(evsel, STACK_USER);
928 static void evsel__apply_config_terms(struct evsel *evsel,
932 struct list_head *config_terms = &evsel->config_terms;
933 struct perf_event_attr *attr = &evsel->core.attr;
948 evsel__reset_sample_bit(evsel, PERIOD);
955 evsel__set_sample_bit(evsel, PERIOD);
960 evsel__set_sample_bit(evsel, TIME);
962 evsel__reset_sample_bit(evsel, TIME);
969 evsel__set_sample_bit(evsel, BRANCH_STACK);
973 evsel__reset_sample_bit(evsel, BRANCH_STACK);
982 evsel->max_events = term->val.max_events;
1033 evsel->name);
1047 evsel__reset_callgraph(evsel, &callchain_param);
1052 evsel__set_sample_bit(evsel, ADDR);
1053 evsel__set_sample_bit(evsel, DATA_SRC);
1054 evsel->core.attr.mmap_data = track;
1056 evsel__config_callchain(evsel, opts, ¶m);
1061 struct evsel_config_term *__evsel__get_config_term(struct evsel *evsel, enum evsel_term_type type)
1065 list_for_each_entry(term, &evsel->config_terms, list) {
1073 void __weak arch_evsel__set_sample_weight(struct evsel *evsel)
1075 evsel__set_sample_bit(evsel, WEIGHT);
1078 void __weak arch__post_evsel_config(struct evsel *evsel __maybe_unused,
1094 static bool evsel__is_offcpu_event(struct evsel *evsel)
1096 return evsel__is_bpf_output(evsel) && evsel__name_is(evsel, OFFCPU_EVENT);
1127 void evsel__config(struct evsel *evsel, struct record_opts *opts,
1130 struct evsel *leader = evsel__leader(evsel);
1131 struct perf_event_attr *attr = &evsel->core.attr;
1132 int track = evsel->tracking;
1140 evsel__set_sample_bit(evsel, IP);
1141 evsel__set_sample_bit(evsel, TID);
1143 if (evsel->sample_read) {
1144 evsel__set_sample_bit(evsel, READ);
1150 evsel__set_sample_id(evsel, false);
1166 if ((evsel->is_libpfm_event && !attr->sample_period) ||
1167 (!evsel->is_libpfm_event && (!attr->sample_period ||
1177 evsel__set_sample_bit(evsel, PERIOD);
1183 evsel->core.attr.read_format |=
1191 evsel__set_sample_bit(evsel, ADDR);
1200 if (evsel__is_function_event(evsel))
1201 evsel->core.attr.exclude_callchain_user = 1;
1203 if (callchain && callchain->enabled && !evsel->no_aux_samples)
1204 evsel__config_callchain(evsel, opts, callchain);
1206 if (opts->sample_intr_regs && !evsel->no_aux_samples &&
1207 !evsel__is_dummy_event(evsel)) {
1209 evsel__set_sample_bit(evsel, REGS_INTR);
1212 if (opts->sample_user_regs && !evsel->no_aux_samples &&
1213 !evsel__is_dummy_event(evsel)) {
1215 evsel__set_sample_bit(evsel, REGS_USER);
1219 evsel__set_sample_bit(evsel, CPU);
1228 evsel__set_sample_bit(evsel, TIME);
1230 if (opts->raw_samples && !evsel->no_aux_samples) {
1231 evsel__set_sample_bit(evsel, TIME);
1232 evsel__set_sample_bit(evsel, RAW);
1233 evsel__set_sample_bit(evsel, CPU);
1237 evsel__set_sample_bit(evsel, DATA_SRC);
1240 evsel__set_sample_bit(evsel, PHYS_ADDR);
1246 if (opts->branch_stack && !evsel->no_aux_samples) {
1247 evsel__set_sample_bit(evsel, BRANCH_STACK);
1252 arch_evsel__set_sample_weight(evsel);
1273 evsel__set_sample_bit(evsel, CGROUP);
1277 evsel__set_sample_bit(evsel, DATA_PAGE_SIZE);
1280 evsel__set_sample_bit(evsel, CODE_PAGE_SIZE);
1286 evsel__set_sample_bit(evsel, TRANSACTION);
1289 evsel->core.attr.read_format |=
1300 if (evsel__is_group_leader(evsel))
1307 if (target__none(&opts->target) && evsel__is_group_leader(evsel) &&
1311 if (evsel->immediate) {
1322 if (evsel->precise_max)
1335 if (evsel->core.own_cpus || evsel->unit)
1336 evsel->core.attr.read_format |= PERF_FORMAT_ID;
1342 evsel__apply_config_terms(evsel, opts, track);
1344 evsel->ignore_missing_thread = opts->ignore_missing_thread;
1349 evsel__set_sample_bit(evsel, PERIOD);
1351 evsel__reset_sample_bit(evsel, PERIOD);
1362 if (evsel__is_dummy_event(evsel))
1363 evsel__reset_sample_bit(evsel, BRANCH_STACK);
1365 if (evsel__is_offcpu_event(evsel))
1366 evsel->core.attr.sample_type &= OFFCPU_SAMPLE_TYPES;
1368 arch__post_evsel_config(evsel, attr);
1371 int evsel__set_filter(struct evsel *evsel, const char *filter)
1376 free(evsel->filter);
1377 evsel->filter = new_filter;
1384 static int evsel__append_filter(struct evsel *evsel, const char *fmt, const char *filter)
1388 if (evsel->filter == NULL)
1389 return evsel__set_filter(evsel, filter);
1391 if (asprintf(&new_filter, fmt, evsel->filter, filter) > 0) {
1392 free(evsel->filter);
1393 evsel->filter = new_filter;
1400 int evsel__append_tp_filter(struct evsel *evsel, const char *filter)
1402 return evsel__append_filter(evsel, "(%s) && (%s)", filter);
1405 int evsel__append_addr_filter(struct evsel *evsel, const char *filter)
1407 return evsel__append_filter(evsel, "%s,%s", filter);
1411 int evsel__enable_cpu(struct evsel *evsel, int cpu_map_idx)
1413 return perf_evsel__enable_cpu(&evsel->core, cpu_map_idx);
1416 int evsel__enable(struct evsel *evsel)
1418 int err = perf_evsel__enable(&evsel->core);
1421 evsel->disabled = false;
1426 int evsel__disable_cpu(struct evsel *evsel, int cpu_map_idx)
1428 return perf_evsel__disable_cpu(&evsel->core, cpu_map_idx);
1431 int evsel__disable(struct evsel *evsel)
1433 int err = perf_evsel__disable(&evsel->core);
1441 evsel->disabled = true;
1458 static void evsel__free_config_terms(struct evsel *evsel)
1460 free_config_terms(&evsel->config_terms);
1463 void evsel__exit(struct evsel *evsel)
1465 assert(list_empty(&evsel->core.node));
1466 assert(evsel->evlist == NULL);
1467 bpf_counter__destroy(evsel);
1468 perf_bpf_filter__destroy(evsel);
1469 evsel__free_counts(evsel);
1470 perf_evsel__free_fd(&evsel->core);
1471 perf_evsel__free_id(&evsel->core);
1472 evsel__free_config_terms(evsel);
1473 cgroup__put(evsel->cgrp);
1474 perf_cpu_map__put(evsel->core.cpus);
1475 perf_cpu_map__put(evsel->core.own_cpus);
1476 perf_thread_map__put(evsel->core.threads);
1477 zfree(&evsel->group_name);
1478 zfree(&evsel->name);
1479 zfree(&evsel->filter);
1480 zfree(&evsel->pmu_name);
1481 zfree(&evsel->group_pmu_name);
1482 zfree(&evsel->unit);
1483 zfree(&evsel->metric_id);
1484 evsel__zero_per_pkg(evsel);
1485 hashmap__free(evsel->per_pkg_mask);
1486 evsel->per_pkg_mask = NULL;
1487 zfree(&evsel->metric_events);
1488 perf_evsel__object.fini(evsel);
1491 void evsel__delete(struct evsel *evsel)
1493 if (!evsel)
1496 evsel__exit(evsel);
1497 free(evsel);
1500 void evsel__compute_deltas(struct evsel *evsel, int cpu_map_idx, int thread,
1505 if (!evsel->prev_raw_counts)
1508 tmp = *perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread);
1509 *perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread) = *count;
1516 static int evsel__read_one(struct evsel *evsel, int cpu_map_idx, int thread)
1518 struct perf_counts_values *count = perf_counts(evsel->counts, cpu_map_idx, thread);
1520 return perf_evsel__read(&evsel->core, cpu_map_idx, thread, count);
1523 static void evsel__set_count(struct evsel *counter, int cpu_map_idx, int thread,
1538 static int evsel__process_group_data(struct evsel *leader, int cpu_map_idx, int thread, u64 *data)
1557 struct evsel *counter;
1572 static int evsel__read_group(struct evsel *leader, int cpu_map_idx, int thread)
1602 int evsel__read_counter(struct evsel *evsel, int cpu_map_idx, int thread)
1604 u64 read_format = evsel->core.attr.read_format;
1607 return evsel__read_group(evsel, cpu_map_idx, thread);
1609 return evsel__read_one(evsel, cpu_map_idx, thread);
1612 int __evsel__read_on_cpu(struct evsel *evsel, int cpu_map_idx, int thread, bool scale)
1617 if (FD(evsel, cpu_map_idx, thread) < 0)
1620 if (evsel->counts == NULL && evsel__alloc_counts(evsel) < 0)
1623 if (readn(FD(evsel, cpu_map_idx, thread), &count, nv * sizeof(u64)) <= 0)
1626 evsel__compute_deltas(evsel, cpu_map_idx, thread, &count);
1628 *perf_counts(evsel->counts, cpu_map_idx, thread) = count;
1632 static int evsel__match_other_cpu(struct evsel *evsel, struct evsel *other,
1637 cpu = perf_cpu_map__cpu(evsel->core.cpus, cpu_map_idx);
1641 static int evsel__hybrid_group_cpu_map_idx(struct evsel *evsel, int cpu_map_idx)
1643 struct evsel *leader = evsel__leader(evsel);
1645 if ((evsel__is_hybrid(evsel) && !evsel__is_hybrid(leader)) ||
1646 (!evsel__is_hybrid(evsel) && evsel__is_hybrid(leader))) {
1647 return evsel__match_other_cpu(evsel, leader, cpu_map_idx);
1653 static int get_group_fd(struct evsel *evsel, int cpu_map_idx, int thread)
1655 struct evsel *leader = evsel__leader(evsel);
1658 if (evsel__is_group_leader(evsel))
1667 cpu_map_idx = evsel__hybrid_group_cpu_map_idx(evsel, cpu_map_idx);
1681 static void evsel__remove_fd(struct evsel *pos, int nr_cpus, int nr_threads, int thread_idx)
1688 static int update_fds(struct evsel *evsel,
1692 struct evsel *pos;
1697 evlist__for_each_entry(evsel->evlist, pos) {
1698 nr_cpus = pos != evsel ? nr_cpus : cpu_map_idx;
1703 * Since fds for next evsel has not been created,
1706 if (pos == evsel)
1712 static bool evsel__ignore_missing_thread(struct evsel *evsel,
1719 if (!evsel->ignore_missing_thread)
1723 if (evsel->core.system_wide)
1738 if (update_fds(evsel, nr_cpus, cpu_map_idx, threads->nr, thread))
1765 bool evsel__precise_ip_fallback(struct evsel *evsel)
1768 if (!evsel->precise_max)
1775 if (!evsel->core.attr.precise_ip) {
1776 evsel->core.attr.precise_ip = evsel->precise_ip_original;
1780 if (!evsel->precise_ip_original)
1781 evsel->precise_ip_original = evsel->core.attr.precise_ip;
1783 evsel->core.attr.precise_ip--;
1784 pr_debug2_peo("decreasing precise_ip by one (%d)\n", evsel->core.attr.precise_ip);
1785 display_attr(&evsel->core.attr);
1792 static int __evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus,
1797 if ((perf_missing_features.write_backward && evsel->core.attr.write_backward) ||
1798 (perf_missing_features.aux_output && evsel->core.attr.aux_output))
1821 if (evsel->core.fd == NULL &&
1822 perf_evsel__alloc_fd(&evsel->core, perf_cpu_map__nr(cpus), nthreads) < 0)
1825 evsel->open_flags = PERF_FLAG_FD_CLOEXEC;
1826 if (evsel->cgrp)
1827 evsel->open_flags |= PERF_FLAG_PID_CGROUP;
1832 static void evsel__disable_missing_features(struct evsel *evsel)
1835 evsel->core.attr.read_format &= ~PERF_FORMAT_LOST;
1837 evsel__set_sample_bit(evsel, WEIGHT);
1838 evsel__reset_sample_bit(evsel, WEIGHT_STRUCT);
1841 evsel->core.attr.clockid = CLOCK_MONOTONIC; /* should always work */
1843 evsel->core.attr.use_clockid = 0;
1844 evsel->core.attr.clockid = 0;
1847 evsel->open_flags &= ~(unsigned long)PERF_FLAG_FD_CLOEXEC;
1849 evsel->core.attr.mmap2 = 0;
1850 if (evsel->pmu && evsel->pmu->missing_features.exclude_guest)
1851 evsel->core.attr.exclude_guest = evsel->core.attr.exclude_host = 0;
1853 evsel->core.attr.branch_sample_type &= ~(PERF_SAMPLE_BRANCH_NO_FLAGS |
1855 if (perf_missing_features.group_read && evsel->core.attr.inherit)
1856 evsel->core.attr.read_format &= ~(PERF_FORMAT_GROUP|PERF_FORMAT_ID);
1858 evsel->core.attr.ksymbol = 0;
1860 evsel->core.attr.bpf_event = 0;
1862 evsel->core.attr.branch_sample_type &= ~PERF_SAMPLE_BRANCH_HW_INDEX;
1864 evsel->core.attr.sample_id_all = 0;
1867 int evsel__prepare_open(struct evsel *evsel, struct perf_cpu_map *cpus,
1872 err = __evsel__prepare_open(evsel, cpus, threads);
1876 evsel__disable_missing_features(evsel);
1881 bool evsel__detect_missing_features(struct evsel *evsel)
1888 (evsel->core.attr.read_format & PERF_FORMAT_LOST)) {
1893 (evsel->core.attr.sample_type & PERF_SAMPLE_WEIGHT_STRUCT)) {
1898 (evsel->core.attr.sample_type & PERF_SAMPLE_CODE_PAGE_SIZE)) {
1903 (evsel->core.attr.sample_type & PERF_SAMPLE_DATA_PAGE_SIZE)) {
1907 } else if (!perf_missing_features.cgroup && evsel->core.attr.cgroup) {
1912 (evsel->core.attr.branch_sample_type & PERF_SAMPLE_BRANCH_HW_INDEX)) {
1916 } else if (!perf_missing_features.aux_output && evsel->core.attr.aux_output) {
1920 } else if (!perf_missing_features.bpf && evsel->core.attr.bpf_event) {
1924 } else if (!perf_missing_features.ksymbol && evsel->core.attr.ksymbol) {
1928 } else if (!perf_missing_features.write_backward && evsel->core.attr.write_backward) {
1932 } else if (!perf_missing_features.clockid_wrong && evsel->core.attr.use_clockid) {
1936 } else if (!perf_missing_features.clockid && evsel->core.attr.use_clockid) {
1940 } else if (!perf_missing_features.cloexec && (evsel->open_flags & PERF_FLAG_FD_CLOEXEC)) {
1944 } else if (!perf_missing_features.mmap2 && evsel->core.attr.mmap2) {
1948 } else if (evsel->core.attr.exclude_guest || evsel->core.attr.exclude_host) {
1949 if (evsel->pmu == NULL)
1950 evsel->pmu = evsel__find_pmu(evsel);
1952 if (evsel->pmu)
1953 evsel->pmu->missing_features.exclude_guest = true;
1956 evsel->core.attr.exclude_host = false;
1957 evsel->core.attr.exclude_guest = false;
1960 if (evsel->exclude_GH) {
1974 (evsel->core.attr.branch_sample_type &
1981 evsel->core.attr.inherit &&
1982 (evsel->core.attr.read_format & PERF_FORMAT_GROUP) &&
1983 evsel__is_group_leader(evsel)) {
2019 static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus,
2027 err = __evsel__prepare_open(evsel, cpus, threads);
2039 if (evsel->cgrp)
2040 pid = evsel->cgrp->fd;
2043 evsel__disable_missing_features(evsel);
2045 pr_debug3("Opening: %s\n", evsel__name(evsel));
2046 display_attr(&evsel->core.attr);
2056 if (!evsel->cgrp && !evsel->core.system_wide)
2059 group_fd = get_group_fd(evsel, idx, thread);
2062 pr_debug("broken group leader for %s\n", evsel->name);
2071 pid, perf_cpu_map__cpu(cpus, idx).cpu, group_fd, evsel->open_flags);
2073 fd = sys_perf_event_open(&evsel->core.attr, pid,
2075 group_fd, evsel->open_flags);
2077 FD(evsel, idx, thread) = fd;
2087 bpf_counter__install_pe(evsel, idx, fd);
2090 test_attr__open(&evsel->core.attr, pid,
2092 fd, group_fd, evsel->open_flags);
2098 if (evsel->bpf_fd >= 0) {
2100 int bpf_fd = evsel->bpf_fd;
2130 if (evsel__precise_ip_fallback(evsel))
2133 if (evsel__ignore_missing_thread(evsel, perf_cpu_map__nr(cpus),
2152 if (evsel__detect_missing_features(evsel))
2161 if (FD(evsel, idx, thread) >= 0)
2162 close(FD(evsel, idx, thread));
2163 FD(evsel, idx, thread) = -1;
2171 int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus,
2174 return evsel__open_cpu(evsel, cpus, threads, 0, perf_cpu_map__nr(cpus));
2177 void evsel__close(struct evsel *evsel)
2179 perf_evsel__close(&evsel->core);
2180 perf_evsel__free_id(&evsel->core);
2183 int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, int cpu_map_idx)
2186 return evsel__open_cpu(evsel, cpus, NULL, 0, perf_cpu_map__nr(cpus));
2188 return evsel__open_cpu(evsel, cpus, NULL, cpu_map_idx, cpu_map_idx + 1);
2191 int evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *threads)
2193 return evsel__open(evsel, NULL, threads);
2196 static int perf_evsel__parse_id_sample(const struct evsel *evsel,
2200 u64 type = evsel->core.attr.sample_type;
2202 bool swapped = evsel->needs_swap;
2276 * The evsel's sample_size is based on PERF_SAMPLE_MASK which includes
2347 int evsel__parse_sample(struct evsel *evsel, union perf_event *event,
2350 u64 type = evsel->core.attr.sample_type;
2351 bool swapped = evsel->needs_swap;
2366 data->period = evsel->core.attr.sample_period;
2373 if (!evsel->core.attr.sample_id_all)
2375 return perf_evsel__parse_id_sample(evsel, event, data);
2380 if (perf_event__check_size(event, evsel->sample_size))
2446 u64 read_format = evsel->core.attr.read_format;
2550 if (evsel__has_branch_hw_idx(evsel)) {
2587 u64 mask = evsel->core.attr.sample_regs_user;
2643 u64 mask = evsel->core.attr.sample_regs_intr;
2693 int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *event,
2696 u64 type = evsel->core.attr.sample_type;
2707 if (!evsel->core.attr.sample_id_all)
2709 if (perf_evsel__parse_id_sample(evsel, event, &data))
2718 if (perf_event__check_size(event, evsel->sample_size))
2736 u16 evsel__id_hdr_size(struct evsel *evsel)
2738 u64 sample_type = evsel->core.attr.sample_type;
2763 struct tep_format_field *evsel__field(struct evsel *evsel, const char *name)
2765 return tep_find_field(evsel->tp_format, name);
2768 void *evsel__rawptr(struct evsel *evsel, struct perf_sample *sample, const char *name)
2770 struct tep_format_field *field = evsel__field(evsel, name);
2827 u64 evsel__intval(struct evsel *evsel, struct perf_sample *sample, const char *name)
2829 struct tep_format_field *field = evsel__field(evsel, name);
2831 return field ? format_field__intval(field, sample, evsel->needs_swap) : 0;
2835 bool evsel__fallback(struct evsel *evsel, int err, char *msg, size_t msgsize)
2840 evsel->core.attr.type == PERF_TYPE_HARDWARE &&
2841 evsel->core.attr.config == PERF_COUNT_HW_CPU_CYCLES) {
2853 evsel->core.attr.type = PERF_TYPE_SOFTWARE;
2854 evsel->core.attr.config = PERF_COUNT_SW_CPU_CLOCK;
2856 zfree(&evsel->name);
2858 } else if (err == EACCES && !evsel->core.attr.exclude_kernel &&
2860 const char *name = evsel__name(evsel);
2865 if (evsel->core.attr.exclude_user)
2870 (strchr(name, ':') && !evsel->is_libpfm_event))
2876 free(evsel->name);
2877 evsel->name = new_name;
2881 evsel->core.attr.exclude_kernel = 1;
2882 evsel->core.attr.exclude_hv = 1;
2926 int __weak arch_evsel__open_strerror(struct evsel *evsel __maybe_unused,
2933 int evsel__open_strerror(struct evsel *evsel, struct target *target,
2957 "No permission to enable %s event.\n\n", evsel__name(evsel));
2975 return scnprintf(msg, size, "The %s event is not supported.", evsel__name(evsel));
2983 if (evsel__has_callchain(evsel) &&
2996 if (evsel->core.attr.sample_type & PERF_SAMPLE_BRANCH_STACK)
2999 evsel__name(evsel));
3000 if (evsel->core.attr.aux_output)
3003 evsel__name(evsel));
3004 if (evsel->core.attr.sample_period != 0)
3007 evsel__name(evsel));
3008 if (evsel->core.attr.precise_ip)
3012 if (evsel->core.attr.type == PERF_TYPE_HARDWARE)
3024 if (evsel->core.attr.sample_type & PERF_SAMPLE_CODE_PAGE_SIZE && perf_missing_features.code_page_size)
3026 if (evsel->core.attr.sample_type & PERF_SAMPLE_DATA_PAGE_SIZE && perf_missing_features.data_page_size)
3028 if (evsel->core.attr.write_backward && perf_missing_features.write_backward)
3039 evsel__name(evsel));
3049 ret = arch_evsel__open_strerror(evsel, msg, size);
3056 err, str_error_r(err, sbuf, sizeof(sbuf)), evsel__name(evsel));
3059 struct perf_env *evsel__env(struct evsel *evsel)
3061 if (evsel && evsel->evlist && evsel->evlist->env)
3062 return evsel->evlist->env;
3066 static int store_evsel_ids(struct evsel *evsel, struct evlist *evlist)
3070 for (cpu_map_idx = 0; cpu_map_idx < xyarray__max_x(evsel->core.fd); cpu_map_idx++) {
3071 for (thread = 0; thread < xyarray__max_y(evsel->core.fd);
3073 int fd = FD(evsel, cpu_map_idx, thread);
3075 if (perf_evlist__id_add_fd(&evlist->core, &evsel->core,
3084 int evsel__store_ids(struct evsel *evsel, struct evlist *evlist)
3086 struct perf_cpu_map *cpus = evsel->core.cpus;
3087 struct perf_thread_map *threads = evsel->core.threads;
3089 if (perf_evsel__alloc_id(&evsel->core, perf_cpu_map__nr(cpus), threads->nr))
3092 return store_evsel_ids(evsel, evlist);
3095 void evsel__zero_per_pkg(struct evsel *evsel)
3100 if (evsel->per_pkg_mask) {
3101 hashmap__for_each_entry(evsel->per_pkg_mask, cur, bkt)
3104 hashmap__clear(evsel->per_pkg_mask);
3109 * evsel__is_hybrid - does the evsel have a known PMU that is hybrid. Note, this
3113 bool evsel__is_hybrid(const struct evsel *evsel)
3118 return evsel->core.is_pmu_core;
3121 struct evsel *evsel__leader(const struct evsel *evsel)
3123 return container_of(evsel->core.leader, struct evsel, core);
3126 bool evsel__has_leader(struct evsel *evsel, struct evsel *leader)
3128 return evsel->core.leader == &leader->core;
3131 bool evsel__is_leader(struct evsel *evsel)
3133 return evsel__has_leader(evsel, evsel);
3136 void evsel__set_leader(struct evsel *evsel, struct evsel *leader)
3138 evsel->core.leader = &leader->core;
3141 int evsel__source_count(const struct evsel *evsel)
3143 struct evsel *pos;
3146 evlist__for_each_entry(evsel->evlist, pos) {
3147 if (pos->metric_leader == evsel)
3153 bool __weak arch_evsel__must_be_in_group(const struct evsel *evsel __maybe_unused)
3163 void evsel__remove_from_group(struct evsel *evsel, struct evsel *leader)
3165 if (!arch_evsel__must_be_in_group(evsel) && evsel != leader) {
3166 evsel__set_leader(evsel, evsel);
3167 evsel->core.nr_members = 0;