Lines Matching +full:long +full:- +full:term

1 // SPDX-License-Identifier: GPL-2.0
10 #include "term.h"
14 #include <subcmd/parse-options.h>
15 #include "parse-events.h"
21 #include <util/parse-events-bison.h>
22 #include <util/parse-events-flex.h>
26 #include "util/parse-branch-options.h"
29 #include "util/bpf-filter.h"
42 .symbol = "cpu-cycles",
50 .symbol = "cache-references",
54 .symbol = "cache-misses",
58 .symbol = "branch-instructions",
62 .symbol = "branch-misses",
66 .symbol = "bus-cycles",
70 .symbol = "stalled-cycles-frontend",
71 .alias = "idle-cycles-frontend",
74 .symbol = "stalled-cycles-backend",
75 .alias = "idle-cycles-backend",
78 .symbol = "ref-cycles",
85 .symbol = "cpu-clock",
89 .symbol = "task-clock",
93 .symbol = "page-faults",
97 .symbol = "context-switches",
101 .symbol = "cpu-migrations",
105 .symbol = "minor-faults",
109 .symbol = "major-faults",
113 .symbol = "alignment-faults",
117 .symbol = "emulation-faults",
125 .symbol = "bpf-output",
129 .symbol = "cgroup-switches",
147 return "hardware-cache"; in event_type()
159 struct parse_events_term *term; in get_config_str() local
164 list_for_each_entry(term, &head_terms->terms, list) in get_config_str()
165 if (term->type_term == type_term) in get_config_str()
166 return term->val.str; in get_config_str()
182 * fix_raw - For each raw term see if there is an event (aka alias) in pmu that
184 * event then change the term to be an event, if not then change it to
185 * be a config term. For example, "read" may be an event of the PMU or
186 * a raw hex encoding of 0xead. The fix-up is done late so the PMU of
188 * ahead-of-time.
189 * @config_terms: the list of terms that may contain a raw term.
194 struct parse_events_term *term; in fix_raw() local
196 list_for_each_entry(term, &config_terms->terms, list) { in fix_raw()
199 if (term->type_term != PARSE_EVENTS__TERM_TYPE_RAW) in fix_raw()
202 if (perf_pmu__have_event(pmu, term->val.str)) { in fix_raw()
203 zfree(&term->config); in fix_raw()
204 term->config = term->val.str; in fix_raw()
205 term->type_val = PARSE_EVENTS__TERM_TYPE_NUM; in fix_raw()
206 term->type_term = PARSE_EVENTS__TERM_TYPE_USER; in fix_raw()
207 term->val.num = 1; in fix_raw()
208 term->no_value = true; in fix_raw()
212 zfree(&term->config); in fix_raw()
213 term->config = strdup("config"); in fix_raw()
215 num = strtoull(term->val.str + 1, NULL, 16); in fix_raw()
217 free(term->val.str); in fix_raw()
218 term->type_val = PARSE_EVENTS__TERM_TYPE_NUM; in fix_raw()
219 term->type_term = PARSE_EVENTS__TERM_TYPE_CONFIG; in fix_raw()
220 term->val.num = num; in fix_raw()
221 term->no_value = false; in fix_raw()
234 struct perf_cpu_map *cpus = perf_cpu_map__is_empty(cpu_list) && pmu ? pmu->cpus : cpu_list; in __add_event()
240 if (pmu && (attr->type == PERF_TYPE_RAW || attr->type >= PERF_TYPE_MAX)) { in __add_event()
241 perf_pmu__warn_invalid_config(pmu, attr->config, name, in __add_event()
243 perf_pmu__warn_invalid_config(pmu, attr->config1, name, in __add_event()
245 perf_pmu__warn_invalid_config(pmu, attr->config2, name, in __add_event()
247 perf_pmu__warn_invalid_config(pmu, attr->config3, name, in __add_event()
260 evsel->core.cpus = cpus; in __add_event()
261 evsel->core.own_cpus = perf_cpu_map__get(cpus); in __add_event()
262 evsel->core.requires_cpu = pmu ? pmu->is_uncore : false; in __add_event()
263 evsel->core.is_pmu_core = pmu ? pmu->is_core : false; in __add_event()
264 evsel->auto_merge_stats = auto_merge_stats; in __add_event()
265 evsel->pmu = pmu; in __add_event()
266 evsel->pmu_name = pmu ? strdup(pmu->name) : NULL; in __add_event()
269 evsel->name = strdup(name); in __add_event()
272 evsel->metric_id = strdup(metric_id); in __add_event()
275 list_splice_init(config_terms, &evsel->config_terms); in __add_event()
278 list_add_tail(&evsel->core.node, list); in __add_event()
298 /*auto_merge_stats=*/false, /*cpu_list=*/NULL) ? 0 : -ENOMEM; in add_event()
321 return -ENOMEM; in add_event_tool()
322 evsel->tool_event = tool_event; in add_event_tool()
326 free((char *)evsel->unit); in add_event_tool()
327 evsel->unit = strdup("ns"); in add_event_tool()
333 * parse_aliases - search names for entries beginning or equalling str ignoring
344 *longest = -1; in parse_aliases()
356 return -1; in parse_aliases()
360 struct parse_events_term *term,
363 struct parse_events_term *term,
371 * parse_events__decode_legacy_cache - Search name for the legacy cache event
382 int len, cache_type = -1, cache_op = -1, cache_result = -1; in parse_events__decode_legacy_cache()
387 if (cache_type == -1) in parse_events__decode_legacy_cache()
388 return -EINVAL; in parse_events__decode_legacy_cache()
396 return -EINVAL; in parse_events__decode_legacy_cache()
411 return -EINVAL; in parse_events__decode_legacy_cache()
422 if (cache_op == -1) in parse_events__decode_legacy_cache()
428 if (cache_result == -1) in parse_events__decode_legacy_cache()
438 * parse_events__filter_pmu - returns false if a wildcard PMU should be
444 if (parse_state->pmu_filter == NULL) in parse_events__filter_pmu()
447 return strcmp(parse_state->pmu_filter, pmu->name) != 0; in parse_events__filter_pmu()
485 if (!pmu->is_core) { in parse_events_add_cache()
493 ret = parse_events__decode_legacy_cache(name, pmu->type, &attr.config); in parse_events_add_cache()
500 if (config_attr(&attr, parsed_terms, parse_state->error, in parse_events_add_cache()
502 return -EINVAL; in parse_events_add_cache()
505 return -ENOMEM; in parse_events_add_cache()
511 return -ENOMEM; in parse_events_add_cache()
515 return found_supported ? 0 : -EINVAL; in parse_events_add_cache()
557 struct evsel *evsel = evsel__newtp_idx(sys_name, evt_name, parse_state->idx++, in add_tracepoint()
558 !parse_state->fake_tp); in add_tracepoint()
561 tracepoint_error(err, PTR_ERR(evsel), sys_name, evt_name, loc->first_column); in add_tracepoint()
569 return -ENOMEM; in add_tracepoint()
570 list_splice(&config_terms, &evsel->config_terms); in add_tracepoint()
573 list_add_tail(&evsel->core.node, list); in add_tracepoint()
590 tracepoint_error(err, errno, sys_name, evt_name, loc->first_column); in add_tracepoint_multi_event()
591 return -1; in add_tracepoint_multi_event()
596 tracepoint_error(err, errno, sys_name, evt_name, loc->first_column); in add_tracepoint_multi_event()
597 return -1; in add_tracepoint_multi_event()
601 if (!strcmp(evt_ent->d_name, ".") in add_tracepoint_multi_event()
602 || !strcmp(evt_ent->d_name, "..") in add_tracepoint_multi_event()
603 || !strcmp(evt_ent->d_name, "enable") in add_tracepoint_multi_event()
604 || !strcmp(evt_ent->d_name, "filter")) in add_tracepoint_multi_event()
607 if (!strglobmatch(evt_ent->d_name, evt_name)) in add_tracepoint_multi_event()
612 ret = add_tracepoint(parse_state, list, sys_name, evt_ent->d_name, in add_tracepoint_multi_event()
617 tracepoint_error(err, ENOENT, sys_name, evt_name, loc->first_column); in add_tracepoint_multi_event()
618 ret = -1; in add_tracepoint_multi_event()
651 tracepoint_error(err, errno, sys_name, evt_name, loc->first_column); in add_tracepoint_multi_sys()
652 return -1; in add_tracepoint_multi_sys()
656 if (!strcmp(events_ent->d_name, ".") in add_tracepoint_multi_sys()
657 || !strcmp(events_ent->d_name, "..") in add_tracepoint_multi_sys()
658 || !strcmp(events_ent->d_name, "enable") in add_tracepoint_multi_sys()
659 || !strcmp(events_ent->d_name, "header_event") in add_tracepoint_multi_sys()
660 || !strcmp(events_ent->d_name, "header_page")) in add_tracepoint_multi_sys()
663 if (!strglobmatch(events_ent->d_name, sys_name)) in add_tracepoint_multi_sys()
666 ret = add_tracepoint_event(parse_state, list, events_ent->d_name, in add_tracepoint_multi_sys()
684 len = perf_env__kernel_is_64_bit(&env) ? sizeof(u64) : sizeof(long); in default_breakpoint_len()
691 return sizeof(long); in default_breakpoint_len()
706 if (attr->bp_type & bit) \ in parse_breakpoint_type()
707 return -EINVAL; \ in parse_breakpoint_type()
709 attr->bp_type |= bit; \ in parse_breakpoint_type()
723 return -EINVAL; in parse_breakpoint_type()
729 if (!attr->bp_type) /* Default */ in parse_breakpoint_type()
730 attr->bp_type = HW_BREAKPOINT_R | HW_BREAKPOINT_W; in parse_breakpoint_type()
748 return -EINVAL; in parse_events_add_breakpoint()
764 if (config_attr(&attr, head_config, parse_state->error, in parse_events_add_breakpoint()
766 return -EINVAL; in parse_events_add_breakpoint()
769 return -ENOMEM; in parse_events_add_breakpoint()
774 return add_event(list, &parse_state->idx, &attr, name, /*mertic_id=*/NULL, in parse_events_add_breakpoint()
778 static int check_type_val(struct parse_events_term *term, in check_type_val() argument
782 if (type == term->type_val) in check_type_val()
786 parse_events_error__handle(err, term->err_val, in check_type_val()
792 return -EINVAL; in check_type_val()
800 * Update according to parse-events.l in config_term_name()
803 [PARSE_EVENTS__TERM_TYPE_USER] = "<sysfs term>", in config_term_name()
813 [PARSE_EVENTS__TERM_TYPE_CALLGRAPH] = "call-graph", in config_term_name()
814 [PARSE_EVENTS__TERM_TYPE_STACKSIZE] = "stack-size", in config_term_name()
815 [PARSE_EVENTS__TERM_TYPE_NOINHERIT] = "no-inherit", in config_term_name()
817 [PARSE_EVENTS__TERM_TYPE_MAX_STACK] = "max-stack", in config_term_name()
820 [PARSE_EVENTS__TERM_TYPE_NOOVERWRITE] = "no-overwrite", in config_term_name()
821 [PARSE_EVENTS__TERM_TYPE_DRV_CFG] = "driver-config", in config_term_name()
823 [PARSE_EVENTS__TERM_TYPE_AUX_OUTPUT] = "aux-output", in config_term_name()
824 [PARSE_EVENTS__TERM_TYPE_AUX_SAMPLE_SIZE] = "aux-sample-size", in config_term_name()
825 [PARSE_EVENTS__TERM_TYPE_METRIC_ID] = "metric-id", in config_term_name()
827 [PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE] = "legacy-cache", in config_term_name()
831 return "unknown term"; in config_term_name()
842 parse_events_error__handle(err, -1, in config_term_avail()
884 parse_events_error__handle(err, -1, err_str, NULL); in config_term_avail()
895 struct parse_events_term *term, in config_term_common() argument
900 if (check_type_val(term, err, PARSE_EVENTS__TERM_TYPE_ ## type)) \ in config_term_common()
901 return -EINVAL; \ in config_term_common()
904 switch (term->type_term) { in config_term_common()
907 attr->config = term->val.num; in config_term_common()
911 attr->config1 = term->val.num; in config_term_common()
915 attr->config2 = term->val.num; in config_term_common()
919 attr->config3 = term->val.num; in config_term_common()
929 if (strcmp(term->val.str, "no") && in config_term_common()
930 parse_branch_str(term->val.str, in config_term_common()
931 &attr->branch_sample_type)) { in config_term_common()
932 parse_events_error__handle(err, term->err_val, in config_term_common()
935 return -EINVAL; in config_term_common()
940 if (term->val.num > 1) { in config_term_common()
941 parse_events_error__handle(err, term->err_val, in config_term_common()
944 return -EINVAL; in config_term_common()
982 if ((unsigned int)term->val.num > 1) { in config_term_common()
983 parse_events_error__handle(err, term->err_val, in config_term_common()
986 return -EINVAL; in config_term_common()
994 if (term->val.num > UINT_MAX) { in config_term_common()
995 parse_events_error__handle(err, term->err_val, in config_term_common()
998 return -EINVAL; in config_term_common()
1006 parse_events_error__handle(err, term->err_term, in config_term_common()
1007 strdup(config_term_name(term->type_term)), in config_term_common()
1009 return -EINVAL; in config_term_common()
1013 * Check term availability after basic checking so in config_term_common()
1017 * user will see "'<sysfs term>' is not usable in 'perf stat'" in config_term_common()
1018 * if an invalid config term is provided for legacy events in config_term_common()
1021 if (!config_term_avail(term->type_term, err)) in config_term_common()
1022 return -EINVAL; in config_term_common()
1028 struct parse_events_term *term, in config_term_pmu() argument
1031 if (term->type_term == PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE) { in config_term_pmu()
1032 struct perf_pmu *pmu = perf_pmus__find_by_type(attr->type); in config_term_pmu()
1037 if (asprintf(&err_str, "Failed to find PMU for type %d", attr->type) >= 0) in config_term_pmu()
1038 parse_events_error__handle(err, term->err_term, in config_term_pmu()
1040 return -EINVAL; in config_term_pmu()
1048 !perf_pmu__have_event(pmu, term->config)) { in config_term_pmu()
1049 attr->type = PERF_TYPE_HW_CACHE; in config_term_pmu()
1050 return parse_events__decode_legacy_cache(term->config, pmu->type, in config_term_pmu()
1051 &attr->config); in config_term_pmu()
1053 term->type_term = PARSE_EVENTS__TERM_TYPE_USER; in config_term_pmu()
1054 term->no_value = true; in config_term_pmu()
1057 if (term->type_term == PARSE_EVENTS__TERM_TYPE_HARDWARE) { in config_term_pmu()
1058 struct perf_pmu *pmu = perf_pmus__find_by_type(attr->type); in config_term_pmu()
1063 if (asprintf(&err_str, "Failed to find PMU for type %d", attr->type) >= 0) in config_term_pmu()
1064 parse_events_error__handle(err, term->err_term, in config_term_pmu()
1066 return -EINVAL; in config_term_pmu()
1072 if (perf_pmu__have_event(pmu, term->config)) { in config_term_pmu()
1073 term->type_term = PARSE_EVENTS__TERM_TYPE_USER; in config_term_pmu()
1074 term->no_value = true; in config_term_pmu()
1076 attr->type = PERF_TYPE_HARDWARE; in config_term_pmu()
1077 attr->config = term->val.num; in config_term_pmu()
1079 attr->config |= (__u64)pmu->type << PERF_PMU_TYPE_SHIFT; in config_term_pmu()
1083 if (term->type_term == PARSE_EVENTS__TERM_TYPE_USER || in config_term_pmu()
1084 term->type_term == PARSE_EVENTS__TERM_TYPE_DRV_CFG) { in config_term_pmu()
1091 return config_term_common(attr, term, err); in config_term_pmu()
1096 struct parse_events_term *term, in config_term_tracepoint() argument
1099 switch (term->type_term) { in config_term_tracepoint()
1110 return config_term_common(attr, term, err); in config_term_tracepoint()
1129 parse_events_error__handle(err, term->err_term, in config_term_tracepoint()
1130 strdup(config_term_name(term->type_term)), in config_term_tracepoint()
1131 strdup("valid terms: call-graph,stack-size\n")); in config_term_tracepoint()
1133 return -EINVAL; in config_term_tracepoint()
1145 struct parse_events_term *term; in config_attr() local
1147 list_for_each_entry(term, &head->terms, list) in config_attr()
1148 if (config_term(attr, term, err)) in config_attr()
1149 return -EINVAL; in config_attr()
1162 return -ENOMEM; \ in get_config_terms()
1164 INIT_LIST_HEAD(&__t->list); \ in get_config_terms()
1165 __t->type = EVSEL__CONFIG_TERM_ ## __type; \ in get_config_terms()
1166 __t->weak = __weak; \ in get_config_terms()
1167 list_add_tail(&__t->list, head_terms) in get_config_terms()
1172 __t->val.__name = __val; \ in get_config_terms()
1178 __t->val.str = strdup(__val); \ in get_config_terms()
1179 if (!__t->val.str) { \ in get_config_terms()
1181 return -ENOMEM; \ in get_config_terms()
1183 __t->free_str = true; \ in get_config_terms()
1186 struct parse_events_term *term; in get_config_terms() local
1188 list_for_each_entry(term, &head_config->terms, list) { in get_config_terms()
1189 switch (term->type_term) { in get_config_terms()
1191 ADD_CONFIG_TERM_VAL(PERIOD, period, term->val.num, term->weak); in get_config_terms()
1194 ADD_CONFIG_TERM_VAL(FREQ, freq, term->val.num, term->weak); in get_config_terms()
1197 ADD_CONFIG_TERM_VAL(TIME, time, term->val.num, term->weak); in get_config_terms()
1200 ADD_CONFIG_TERM_STR(CALLGRAPH, term->val.str, term->weak); in get_config_terms()
1203 ADD_CONFIG_TERM_STR(BRANCH, term->val.str, term->weak); in get_config_terms()
1207 term->val.num, term->weak); in get_config_terms()
1211 term->val.num ? 1 : 0, term->weak); in get_config_terms()
1215 term->val.num ? 0 : 1, term->weak); in get_config_terms()
1219 term->val.num, term->weak); in get_config_terms()
1223 term->val.num, term->weak); in get_config_terms()
1227 term->val.num ? 1 : 0, term->weak); in get_config_terms()
1231 term->val.num ? 0 : 1, term->weak); in get_config_terms()
1234 ADD_CONFIG_TERM_STR(DRV_CFG, term->val.str, term->weak); in get_config_terms()
1238 term->val.num ? true : false, term->weak); in get_config_terms()
1242 term->val.num ? 1 : 0, term->weak); in get_config_terms()
1246 term->val.num, term->weak); in get_config_terms()
1267 * each bit of attr->config that the user has changed.
1272 struct parse_events_term *term; in get_config_chgs() local
1276 list_for_each_entry(term, &head_config->terms, list) { in get_config_chgs()
1277 switch (term->type_term) { in get_config_chgs()
1279 type = perf_pmu__format_type(pmu, term->config); in get_config_chgs()
1282 bits |= perf_pmu__format_bits(pmu, term->config); in get_config_chgs()
1336 return -EINVAL; in parse_events_add_tracepoint()
1351 parse_events_error__handle(err, loc->first_column, strdup("unsupported tracepoint"), in parse_events_add_tracepoint()
1353 return -1; in parse_events_add_tracepoint()
1376 if (config_attr(&attr, head_config, parse_state->error, in __parse_events_add_numeric()
1378 return -EINVAL; in __parse_events_add_numeric()
1381 return -ENOMEM; in __parse_events_add_numeric()
1386 ret = __add_event(list, &parse_state->idx, &attr, /*init_attr*/true, name, in __parse_events_add_numeric()
1388 /*cpu_list=*/NULL) ? 0 : -ENOMEM; in __parse_events_add_numeric()
1412 type, pmu->type, in parse_events_add_numeric()
1428 return add_event_tool(list, &parse_state->idx, tool_event); in parse_events_add_tool()
1433 struct evsel_config_term *term; in config_term_percore() local
1435 list_for_each_entry(term, config_terms, list) { in config_term_percore()
1436 if (term->type == EVSEL__CONFIG_TERM_PERCORE) in config_term_percore()
1437 return term->val.percore; in config_term_percore()
1451 struct parse_events_error *err = parse_state->error; in parse_events_add_pmu()
1460 if (pmu->selectable && const_parsed_terms && in parse_events_add_pmu()
1461 list_empty(&const_parsed_terms->terms)) { in parse_events_add_pmu()
1462 strbuf_addf(&sb, "%s//", pmu->name); in parse_events_add_pmu()
1464 strbuf_addf(&sb, "%s/", pmu->name); in parse_events_add_pmu()
1473 if (pmu->perf_event_attr_init_default) in parse_events_add_pmu()
1474 pmu->perf_event_attr_init_default(pmu, &attr); in parse_events_add_pmu()
1476 attr.type = pmu->type; in parse_events_add_pmu()
1478 if (!const_parsed_terms || list_empty(&const_parsed_terms->terms)) { in parse_events_add_pmu()
1479 evsel = __add_event(list, &parse_state->idx, &attr, in parse_events_add_pmu()
1484 return evsel ? 0 : -ENOMEM; in parse_events_add_pmu()
1497 if (config_attr(&attr, &parsed_terms, parse_state->error, config_term_pmu)) { in parse_events_add_pmu()
1499 return -EINVAL; in parse_events_add_pmu()
1506 return -EINVAL; in parse_events_add_pmu()
1514 fprintf(stderr, "..after resolving event: %s/%s/\n", pmu->name, sb.buf); in parse_events_add_pmu()
1520 config_attr(&attr, &parsed_terms, parse_state->error, config_term_pmu)) { in parse_events_add_pmu()
1522 return -EINVAL; in parse_events_add_pmu()
1527 return -ENOMEM; in parse_events_add_pmu()
1531 * When using default config, record which bits of attr->config were in parse_events_add_pmu()
1534 if (pmu->perf_event_attr_init_default && in parse_events_add_pmu()
1537 return -ENOMEM; in parse_events_add_pmu()
1540 if (perf_pmu__config(pmu, &attr, &parsed_terms, parse_state->error)) { in parse_events_add_pmu()
1543 return -EINVAL; in parse_events_add_pmu()
1546 evsel = __add_event(list, &parse_state->idx, &attr, /*init_attr=*/true, in parse_events_add_pmu()
1552 return -ENOMEM; in parse_events_add_pmu()
1555 if (evsel->name) in parse_events_add_pmu()
1556 evsel->use_config_name = true; in parse_events_add_pmu()
1558 evsel->percore = config_term_percore(&evsel->config_terms); in parse_events_add_pmu()
1561 free((char *)evsel->unit); in parse_events_add_pmu()
1562 evsel->unit = strdup(info.unit); in parse_events_add_pmu()
1563 evsel->scale = info.scale; in parse_events_add_pmu()
1564 evsel->per_pkg = info.per_pkg; in parse_events_add_pmu()
1565 evsel->snapshot = info.snapshot; in parse_events_add_pmu()
1574 struct parse_events_term *term; in parse_events_multi_pmu_add() local
1596 if (parse_events_term__num(&term, in parse_events_multi_pmu_add()
1603 list_add_tail(&term->list, &parsed_terms.terms); in parse_events_multi_pmu_add()
1628 pr_debug("%s -> %s/%s/\n", event_name, pmu->name, sb.buf); in parse_events_multi_pmu_add()
1634 if (parse_state->fake_pmu) { in parse_events_multi_pmu_add()
1641 pr_debug("%s -> fake/%s/\n", event_name, sb.buf); in parse_events_multi_pmu_add()
1654 return ok ? 0 : -1; in parse_events_multi_pmu_add()
1670 return -ENOMEM; in parse_events_multi_pmu_add_or_add_pmu()
1680 if (parse_state->fake_pmu) { in parse_events_multi_pmu_add_or_add_pmu()
1698 parse_state->wild_card_pmus = true; in parse_events_multi_pmu_add_or_add_pmu()
1712 parse_events_error__handle(parse_state->error, loc->first_column, in parse_events_multi_pmu_add_or_add_pmu()
1716 return -EINVAL; in parse_events_multi_pmu_add_or_add_pmu()
1729 __perf_evlist__set_leader(list, &leader->core); in parse_events__set_leader()
1730 zfree(&leader->group_name); in parse_events__set_leader()
1731 leader->group_name = name; in parse_events__set_leader()
1743 parse_events_error__handle(parse_state->error, loc->first_column, in parse_events__modifier_list()
1745 return -EINVAL; in parse_events__modifier_list()
1750 int eu = group ? evsel->core.attr.exclude_user : 0; in parse_events__modifier_list()
1751 int ek = group ? evsel->core.attr.exclude_kernel : 0; in parse_events__modifier_list()
1752 int eh = group ? evsel->core.attr.exclude_hv : 0; in parse_events__modifier_list()
1753 int eH = group ? evsel->core.attr.exclude_host : 0; in parse_events__modifier_list()
1754 int eG = group ? evsel->core.attr.exclude_guest : 0; in parse_events__modifier_list()
1756 int exclude_GH = group ? evsel->exclude_GH : 0; in parse_events__modifier_list()
1789 evsel->core.attr.exclude_user = eu; in parse_events__modifier_list()
1790 evsel->core.attr.exclude_kernel = ek; in parse_events__modifier_list()
1791 evsel->core.attr.exclude_hv = eh; in parse_events__modifier_list()
1792 evsel->core.attr.exclude_host = eH; in parse_events__modifier_list()
1793 evsel->core.attr.exclude_guest = eG; in parse_events__modifier_list()
1794 evsel->exclude_GH = exclude_GH; in parse_events__modifier_list()
1798 u8 precise = evsel->core.attr.precise_ip + mod.precise; in parse_events__modifier_list()
1802 * 0 - SAMPLE_IP can have arbitrary skid in parse_events__modifier_list()
1803 * 1 - SAMPLE_IP must have constant skid in parse_events__modifier_list()
1804 * 2 - SAMPLE_IP requested to have 0 skid in parse_events__modifier_list()
1805 * 3 - SAMPLE_IP must have 0 skid in parse_events__modifier_list()
1815 parse_events_error__handle(parse_state->error, in parse_events__modifier_list()
1816 loc->first_column, in parse_events__modifier_list()
1819 return -EINVAL; in parse_events__modifier_list()
1821 evsel->core.attr.precise_ip = precise; in parse_events__modifier_list()
1824 evsel->precise_max = 1; in parse_events__modifier_list()
1826 evsel->core.attr.exclude_idle = 1; in parse_events__modifier_list()
1828 evsel->sample_read = 1; in parse_events__modifier_list()
1830 evsel->core.attr.pinned = 1; in parse_events__modifier_list()
1832 evsel->core.attr.exclusive = 1; in parse_events__modifier_list()
1834 evsel->weak_group = true; in parse_events__modifier_list()
1836 evsel->bpf_counter = true; in parse_events__modifier_list()
1838 evsel->retire_lat = true; in parse_events__modifier_list()
1863 if (!evsel->name) { in parse_events__set_default_name()
1864 evsel->name = used_name ? strdup(name) : name; in parse_events__set_default_name()
1866 if (!evsel->name) in parse_events__set_default_name()
1867 return -ENOMEM; in parse_events__set_default_name()
1919 list_splice(&parse_state.terms->terms, &terms->terms); in parse_events_terms()
1943 return -EINVAL; in evsel__compute_group_pmu_name()
1945 group_pmu_name = pmu->name; in evsel__compute_group_pmu_name()
1948 * the pmu_name of the first non-software event to avoid breaking the in evsel__compute_group_pmu_name()
1963 * non-software PMU. for_each_group_(member|evsel) isn't used as in evsel__compute_group_pmu_name()
1968 group_pmu_name = leader_pmu->name; in evsel__compute_group_pmu_name()
1969 } else if (leader->core.nr_members > 1) { in evsel__compute_group_pmu_name()
1981 group_pmu_name = pos_pmu->name; in evsel__compute_group_pmu_name()
1988 evsel->group_pmu_name = strdup(group_pmu_name); in evsel__compute_group_pmu_name()
1989 return evsel->group_pmu_name ? 0 : -ENOMEM; in evsel__compute_group_pmu_name()
1995 return lhs->core.idx - rhs->core.idx; in arch_evlist__cmp()
2013 * occurs. If both events don't have a group we want to fall-through to in evlist__cmp()
2017 if (lhs_core->leader != lhs_core || lhs_core->nr_members > 1) { in evlist__cmp()
2019 lhs_sort_idx = lhs_core->leader->idx; in evlist__cmp()
2022 lhs_sort_idx = *force_grouped_idx != -1 && arch_evsel__must_be_in_group(lhs) in evlist__cmp()
2024 : lhs_core->idx; in evlist__cmp()
2026 if (rhs_core->leader != rhs_core || rhs_core->nr_members > 1) { in evlist__cmp()
2028 rhs_sort_idx = rhs_core->leader->idx; in evlist__cmp()
2031 rhs_sort_idx = *force_grouped_idx != -1 && arch_evsel__must_be_in_group(rhs) in evlist__cmp()
2033 : rhs_core->idx; in evlist__cmp()
2037 return lhs_sort_idx - rhs_sort_idx; in evlist__cmp()
2041 lhs_pmu_name = lhs->group_pmu_name; in evlist__cmp()
2042 rhs_pmu_name = rhs->group_pmu_name; in evlist__cmp()
2054 int idx = 0, force_grouped_idx = -1; in parse_events__sort_events_and_fix_groups()
2080 pos->core.idx = idx++; in parse_events__sort_events_and_fix_groups()
2083 if (force_grouped_idx == -1 && pos == pos_leader && pos->core.nr_members < 2 && in parse_events__sort_events_and_fix_groups()
2085 force_grouped_idx = pos->core.idx; in parse_events__sort_events_and_fix_groups()
2098 const char *pos_pmu_name = pos->group_pmu_name; in parse_events__sort_events_and_fix_groups()
2100 bool pos_force_grouped = force_grouped_idx != -1 && in parse_events__sort_events_and_fix_groups()
2104 if (pos->core.idx != idx) in parse_events__sort_events_and_fix_groups()
2106 pos->core.idx = idx++; in parse_events__sort_events_and_fix_groups()
2107 pos->core.nr_members = 0; in parse_events__sort_events_and_fix_groups()
2116 cur_leader_pmu_name = cur_leader->group_pmu_name; in parse_events__sort_events_and_fix_groups()
2117 if ((cur_leaders_grp != pos->core.leader && in parse_events__sort_events_and_fix_groups()
2127 cur_leaders_grp = pos->core.leader; in parse_events__sort_events_and_fix_groups()
2144 pos_leader->core.nr_members++; in parse_events__sort_events_and_fix_groups()
2155 .idx = evlist->core.nr_entries, in __parse_events()
2169 return -1; in __parse_events()
2188 last->cmdline_group_boundary = true; in __parse_events()
2194 * There are 2 users - builtin-record and builtin-test objects. in __parse_events()
2225 INIT_LIST_HEAD(&err->list); in parse_events_error__init()
2232 list_for_each_entry_safe(pos, tmp, &err->list, list) { in parse_events_error__exit()
2233 zfree(&pos->str); in parse_events_error__exit()
2234 zfree(&pos->help); in parse_events_error__exit()
2235 list_del_init(&pos->list); in parse_events_error__exit()
2254 entry->idx = idx; in parse_events_error__handle()
2255 entry->str = str; in parse_events_error__handle()
2256 entry->help = help; in parse_events_error__handle()
2257 list_add(&entry->list, &err->list); in parse_events_error__handle()
2281 /* -2 for extra '' in the final fprintf */ in __parse_events_error__print()
2282 int width = get_term_width() - 2; in __parse_events_error__print()
2298 max_len = width - len_str; in __parse_events_error__print()
2304 cut = err_idx - max_err_idx; in __parse_events_error__print()
2312 if ((len_event - cut) > max_len) { in __parse_events_error__print()
2313 buf[max_len - 1] = buf[max_len - 2] = '.'; in __parse_events_error__print()
2317 idx = len_str + err_idx - cut; in __parse_events_error__print()
2334 list_for_each_entry(pos, &err->list, list) { in parse_events_error__print()
2337 __parse_events_error__print(pos->idx, pos->str, pos->help, event); in parse_events_error__print()
2351 list_for_each_entry(pos, &err->list, list) { in parse_events_error__contains()
2352 if (strstr(pos->str, needle) != NULL) in parse_events_error__contains()
2363 struct parse_events_option_args *args = opt->value; in parse_events_option()
2368 ret = __parse_events(*args->evlistp, str, args->pmu_filter, &err, in parse_events_option()
2383 struct parse_events_option_args *args = opt->value; in parse_events_option_new_evlist()
2386 if (*args->evlistp == NULL) { in parse_events_option_new_evlist()
2387 *args->evlistp = evlist__new(); in parse_events_option_new_evlist()
2389 if (*args->evlistp == NULL) { in parse_events_option_new_evlist()
2391 return -1; in parse_events_option_new_evlist()
2396 evlist__delete(*args->evlistp); in parse_events_option_new_evlist()
2397 *args->evlistp = NULL; in parse_events_option_new_evlist()
2418 if (evlist->core.nr_entries > 0) in foreach_evsel_in_last_glob()
2424 return -1; in foreach_evsel_in_last_glob()
2428 if (last->core.node.prev == &evlist->core.entries) in foreach_evsel_in_last_glob()
2430 last = list_entry(last->core.node.prev, struct evsel, core.node); in foreach_evsel_in_last_glob()
2431 } while (!last->cmdline_group_boundary); in foreach_evsel_in_last_glob()
2445 "--filter option should follow a -e tracepoint or HW tracer option\n"); in set_filter()
2446 return -1; in set_filter()
2449 if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT) { in set_filter()
2453 return -1; in set_filter()
2460 if (pmu->type == evsel->core.attr.type) { in set_filter()
2470 return perf_bpf_filter__parse(&evsel->bpf_filters, str); in set_filter()
2475 return -1; in set_filter()
2484 struct evlist *evlist = *(struct evlist **)opt->value; in parse_filter()
2495 if (evsel == NULL || evsel->core.attr.type != PERF_TYPE_TRACEPOINT) { in add_exclude_perf_filter()
2497 "--exclude-perf option should follow a -e tracepoint option\n"); in add_exclude_perf_filter()
2498 return -1; in add_exclude_perf_filter()
2506 return -1; in add_exclude_perf_filter()
2516 struct evlist *evlist = *(struct evlist **)opt->value; in exclude_perf()
2522 int parse_events__is_hardcoded_term(struct parse_events_term *term) in parse_events__is_hardcoded_term() argument
2524 return term->type_term != PARSE_EVENTS__TERM_TYPE_USER; in parse_events__is_hardcoded_term()
2531 struct parse_events_term *term; in new_term() local
2533 term = malloc(sizeof(*term)); in new_term()
2534 if (!term) in new_term()
2535 return -ENOMEM; in new_term()
2537 *term = *temp; in new_term()
2538 INIT_LIST_HEAD(&term->list); in new_term()
2539 term->weak = false; in new_term()
2541 switch (term->type_val) { in new_term()
2543 term->val.num = num; in new_term()
2546 term->val.str = str; in new_term()
2549 free(term); in new_term()
2550 return -EINVAL; in new_term()
2553 *_term = term; in new_term()
2557 int parse_events_term__num(struct parse_events_term **term, in parse_events_term__num() argument
2571 .err_term = loc_term ? loc_term->first_column : 0, in parse_events_term__num()
2572 .err_val = loc_val ? loc_val->first_column : 0, in parse_events_term__num()
2575 return new_term(term, &temp, /*str=*/NULL, num); in parse_events_term__num()
2578 int parse_events_term__str(struct parse_events_term **term, in parse_events_term__str() argument
2590 .err_term = loc_term ? loc_term->first_column : 0, in parse_events_term__str()
2591 .err_val = loc_val ? loc_val->first_column : 0, in parse_events_term__str()
2594 return new_term(term, &temp, str, /*num=*/0); in parse_events_term__str()
2597 int parse_events_term__term(struct parse_events_term **term, in parse_events_term__term() argument
2602 return parse_events_term__str(term, term_lhs, NULL, in parse_events_term__term()
2608 const struct parse_events_term *term) in parse_events_term__clone() argument
2611 struct parse_events_term temp = *term; in parse_events_term__clone()
2614 if (term->config) { in parse_events_term__clone()
2615 temp.config = strdup(term->config); in parse_events_term__clone()
2617 return -ENOMEM; in parse_events_term__clone()
2619 if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) in parse_events_term__clone()
2620 return new_term(new, &temp, /*str=*/NULL, term->val.num); in parse_events_term__clone()
2622 str = strdup(term->val.str); in parse_events_term__clone()
2625 return -ENOMEM; in parse_events_term__clone()
2630 void parse_events_term__delete(struct parse_events_term *term) in parse_events_term__delete() argument
2632 if (term->type_val != PARSE_EVENTS__TERM_TYPE_NUM) in parse_events_term__delete()
2633 zfree(&term->val.str); in parse_events_term__delete()
2635 zfree(&term->config); in parse_events_term__delete()
2636 free(term); in parse_events_term__delete()
2642 struct parse_events_term *term; in parse_events_terms__copy() local
2644 list_for_each_entry (term, &src->terms, list) { in parse_events_terms__copy()
2648 ret = parse_events_term__clone(&n, term); in parse_events_terms__copy()
2652 list_add_tail(&n->list, &dest->terms); in parse_events_terms__copy()
2659 INIT_LIST_HEAD(&terms->terms); in parse_events_terms__init()
2664 struct parse_events_term *term, *h; in parse_events_terms__exit() local
2666 list_for_each_entry_safe(term, h, &terms->terms, list) { in parse_events_terms__exit()
2667 list_del_init(&term->list); in parse_events_terms__exit()
2668 parse_events_term__delete(term); in parse_events_terms__exit()
2682 struct parse_events_term *term; in parse_events_terms__to_strbuf() local
2688 list_for_each_entry(term, &terms->terms, list) { in parse_events_terms__to_strbuf()
2698 if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) in parse_events_terms__to_strbuf()
2699 if (term->no_value) { in parse_events_terms__to_strbuf()
2700 assert(term->val.num == 1); in parse_events_terms__to_strbuf()
2701 ret = strbuf_addf(sb, "%s", term->config); in parse_events_terms__to_strbuf()
2703 ret = strbuf_addf(sb, "%s=%#"PRIx64, term->config, term->val.num); in parse_events_terms__to_strbuf()
2704 else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) { in parse_events_terms__to_strbuf()
2705 if (term->config) { in parse_events_terms__to_strbuf()
2706 ret = strbuf_addf(sb, "%s=", term->config); in parse_events_terms__to_strbuf()
2709 } else if ((unsigned int)term->type_term < __PARSE_EVENTS__TERM_TYPE_NR) { in parse_events_terms__to_strbuf()
2710 ret = strbuf_addf(sb, "%s=", config_term_name(term->type_term)); in parse_events_terms__to_strbuf()
2714 assert(!term->no_value); in parse_events_terms__to_strbuf()
2715 ret = strbuf_addf(sb, "%s", term->val.str); in parse_events_terms__to_strbuf()
2757 /* "no-overwrite" is the longest name */ in parse_events_formats_error_string()
2759 (sizeof("no-overwrite") - 1)]; in parse_events_formats_error_string()