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"
22 #include <util/parse-events-bison.h>
23 #include <util/parse-events-flex.h>
27 #include "util/parse-branch-options.h"
30 #include "util/bpf-filter.h"
43 .symbol = "cpu-cycles",
51 .symbol = "cache-references",
55 .symbol = "cache-misses",
59 .symbol = "branch-instructions",
63 .symbol = "branch-misses",
67 .symbol = "bus-cycles",
71 .symbol = "stalled-cycles-frontend",
72 .alias = "idle-cycles-frontend",
75 .symbol = "stalled-cycles-backend",
76 .alias = "idle-cycles-backend",
79 .symbol = "ref-cycles",
86 .symbol = "cpu-clock",
90 .symbol = "task-clock",
94 .symbol = "page-faults",
98 .symbol = "context-switches",
102 .symbol = "cpu-migrations",
106 .symbol = "minor-faults",
110 .symbol = "major-faults",
114 .symbol = "alignment-faults",
118 .symbol = "emulation-faults",
126 .symbol = "bpf-output",
130 .symbol = "cgroup-switches",
148 return "hardware-cache";
160 struct parse_events_term *term;
165 list_for_each_entry(term, &head_terms->terms, list)
166 if (term->type_term == type_term)
167 return term->val.str;
183 * fix_raw - For each raw term see if there is an event (aka alias) in pmu that
185 * event then change the term to be an event, if not then change it to
186 * be a config term. For example, "read" may be an event of the PMU or
187 * a raw hex encoding of 0xead. The fix-up is done late so the PMU of
189 * ahead-of-time.
190 * @config_terms: the list of terms that may contain a raw term.
195 struct parse_events_term *term;
197 list_for_each_entry(term, &config_terms->terms, list) {
200 if (term->type_term != PARSE_EVENTS__TERM_TYPE_RAW)
203 if (perf_pmu__have_event(pmu, term->val.str)) {
204 zfree(&term->config);
205 term->config = term->val.str;
206 term->type_val = PARSE_EVENTS__TERM_TYPE_NUM;
207 term->type_term = PARSE_EVENTS__TERM_TYPE_USER;
208 term->val.num = 1;
209 term->no_value = true;
213 zfree(&term->config);
214 term->config = strdup("config");
216 num = strtoull(term->val.str + 1, NULL, 16);
218 free(term->val.str);
219 term->type_val = PARSE_EVENTS__TERM_TYPE_NUM;
220 term->type_term = PARSE_EVENTS__TERM_TYPE_CONFIG;
221 term->val.num = num;
222 term->no_value = false;
235 struct perf_cpu_map *cpus = perf_cpu_map__is_empty(cpu_list) && pmu ? pmu->cpus : cpu_list;
241 if (pmu && (attr->type == PERF_TYPE_RAW || attr->type >= PERF_TYPE_MAX)) {
242 perf_pmu__warn_invalid_config(pmu, attr->config, name,
244 perf_pmu__warn_invalid_config(pmu, attr->config1, name,
246 perf_pmu__warn_invalid_config(pmu, attr->config2, name,
248 perf_pmu__warn_invalid_config(pmu, attr->config3, name,
261 evsel->core.cpus = cpus;
262 evsel->core.own_cpus = perf_cpu_map__get(cpus);
263 evsel->core.requires_cpu = pmu ? pmu->is_uncore : false;
264 evsel->core.is_pmu_core = pmu ? pmu->is_core : false;
265 evsel->auto_merge_stats = auto_merge_stats;
266 evsel->pmu = pmu;
267 evsel->alternate_hw_config = alternate_hw_config;
270 evsel->name = strdup(name);
273 evsel->metric_id = strdup(metric_id);
276 list_splice_init(config_terms, &evsel->config_terms);
279 list_add_tail(&evsel->core.node, list);
302 alternate_hw_config) ? 0 : -ENOMEM;
306 * parse_aliases - search names for entries beginning or equalling str ignoring
317 *longest = -1;
329 return -1;
333 struct parse_events_term *term,
336 struct parse_events_term *term,
344 * parse_events__decode_legacy_cache - Search name for the legacy cache event
355 int len, cache_type = -1, cache_op = -1, cache_result = -1;
360 if (cache_type == -1)
361 return -EINVAL;
369 return -EINVAL;
384 return -EINVAL;
395 if (cache_op == -1)
401 if (cache_result == -1)
411 * parse_events__filter_pmu - returns false if a wildcard PMU should be
417 if (parse_state->pmu_filter == NULL)
420 return strcmp(parse_state->pmu_filter, pmu->name) != 0;
459 if (!pmu->is_core) {
467 ret = parse_events__decode_legacy_cache(name, pmu->type, &attr.config);
474 if (config_attr(&attr, parsed_terms, parse_state->error,
476 return -EINVAL;
479 return -ENOMEM;
486 return -ENOMEM;
490 return found_supported ? 0 : -EINVAL;
531 struct evsel *evsel = evsel__newtp_idx(sys_name, evt_name, parse_state->idx++,
532 !parse_state->fake_tp);
535 tracepoint_error(err, PTR_ERR(evsel), sys_name, evt_name, loc->first_column);
543 return -ENOMEM;
544 list_splice(&config_terms, &evsel->config_terms);
547 list_add_tail(&evsel->core.node, list);
564 tracepoint_error(err, errno, sys_name, evt_name, loc->first_column);
565 return -1;
570 tracepoint_error(err, errno, sys_name, evt_name, loc->first_column);
571 return -1;
575 if (!strcmp(evt_ent->d_name, ".")
576 || !strcmp(evt_ent->d_name, "..")
577 || !strcmp(evt_ent->d_name, "enable")
578 || !strcmp(evt_ent->d_name, "filter"))
581 if (!strglobmatch(evt_ent->d_name, evt_name))
586 ret = add_tracepoint(parse_state, list, sys_name, evt_ent->d_name,
591 tracepoint_error(err, ENOENT, sys_name, evt_name, loc->first_column);
592 ret = -1;
625 tracepoint_error(err, errno, sys_name, evt_name, loc->first_column);
626 return -1;
631 tracepoint_error(err, errno, sys_name, evt_name, loc->first_column);
632 return -1;
636 if (!strcmp(events_ent->d_name, ".")
637 || !strcmp(events_ent->d_name, "..")
638 || !strcmp(events_ent->d_name, "enable")
639 || !strcmp(events_ent->d_name, "header_event")
640 || !strcmp(events_ent->d_name, "header_page"))
643 if (!strglobmatch(events_ent->d_name, sys_name))
646 ret = add_tracepoint_event(parse_state, list, events_ent->d_name,
662 len = perf_env__kernel_is_64_bit(&env) ? sizeof(u64) : sizeof(long);
669 return sizeof(long);
684 if (attr->bp_type & bit) \
685 return -EINVAL; \
687 attr->bp_type |= bit; \
701 return -EINVAL;
707 if (!attr->bp_type) /* Default */
708 attr->bp_type = HW_BREAKPOINT_R | HW_BREAKPOINT_W;
726 return -EINVAL;
742 if (config_attr(&attr, head_config, parse_state->error,
744 return -EINVAL;
747 return -ENOMEM;
752 return add_event(list, &parse_state->idx, &attr, name, /*mertic_id=*/NULL,
756 static int check_type_val(struct parse_events_term *term,
760 if (type == term->type_val)
764 parse_events_error__handle(err, term->err_val,
770 return -EINVAL;
778 * Update according to parse-events.l
781 [PARSE_EVENTS__TERM_TYPE_USER] = "<sysfs term>",
791 [PARSE_EVENTS__TERM_TYPE_CALLGRAPH] = "call-graph",
792 [PARSE_EVENTS__TERM_TYPE_STACKSIZE] = "stack-size",
793 [PARSE_EVENTS__TERM_TYPE_NOINHERIT] = "no-inherit",
795 [PARSE_EVENTS__TERM_TYPE_MAX_STACK] = "max-stack",
798 [PARSE_EVENTS__TERM_TYPE_NOOVERWRITE] = "no-overwrite",
799 [PARSE_EVENTS__TERM_TYPE_DRV_CFG] = "driver-config",
801 [PARSE_EVENTS__TERM_TYPE_AUX_OUTPUT] = "aux-output",
802 [PARSE_EVENTS__TERM_TYPE_AUX_ACTION] = "aux-action",
803 [PARSE_EVENTS__TERM_TYPE_AUX_SAMPLE_SIZE] = "aux-sample-size",
804 [PARSE_EVENTS__TERM_TYPE_METRIC_ID] = "metric-id",
806 [PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE] = "legacy-cache",
810 return "unknown term";
821 parse_events_error__handle(err, -1,
864 parse_events_error__handle(err, -1, err_str, NULL);
875 struct parse_events_term *term,
880 if (check_type_val(term, err, PARSE_EVENTS__TERM_TYPE_ ## type)) \
881 return -EINVAL; \
884 switch (term->type_term) {
887 attr->config = term->val.num;
891 attr->config1 = term->val.num;
895 attr->config2 = term->val.num;
899 attr->config3 = term->val.num;
909 if (strcmp(term->val.str, "no") &&
910 parse_branch_str(term->val.str,
911 &attr->branch_sample_type)) {
912 parse_events_error__handle(err, term->err_val,
915 return -EINVAL;
920 if (term->val.num > 1) {
921 parse_events_error__handle(err, term->err_val,
924 return -EINVAL;
962 if ((unsigned int)term->val.num > 1) {
963 parse_events_error__handle(err, term->err_val,
966 return -EINVAL;
977 if (term->val.num > UINT_MAX) {
978 parse_events_error__handle(err, term->err_val,
981 return -EINVAL;
989 parse_events_error__handle(err, term->err_term,
990 strdup(parse_events__term_type_str(term->type_term)),
992 return -EINVAL;
996 * Check term availability after basic checking so
1000 * user will see "'<sysfs term>' is not usable in 'perf stat'"
1001 * if an invalid config term is provided for legacy events
1004 if (!config_term_avail(term->type_term, err))
1005 return -EINVAL;
1011 struct parse_events_term *term,
1014 if (term->type_term == PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE) {
1015 struct perf_pmu *pmu = perf_pmus__find_by_type(attr->type);
1020 if (asprintf(&err_str, "Failed to find PMU for type %d", attr->type) >= 0)
1021 parse_events_error__handle(err, term->err_term,
1023 return -EINVAL;
1031 !perf_pmu__have_event(pmu, term->config)) {
1032 attr->type = PERF_TYPE_HW_CACHE;
1033 return parse_events__decode_legacy_cache(term->config, pmu->type,
1034 &attr->config);
1036 term->type_term = PARSE_EVENTS__TERM_TYPE_USER;
1037 term->no_value = true;
1040 if (term->type_term == PARSE_EVENTS__TERM_TYPE_HARDWARE) {
1041 struct perf_pmu *pmu = perf_pmus__find_by_type(attr->type);
1046 if (asprintf(&err_str, "Failed to find PMU for type %d", attr->type) >= 0)
1047 parse_events_error__handle(err, term->err_term,
1049 return -EINVAL;
1055 if (perf_pmu__have_event(pmu, term->config)) {
1056 term->type_term = PARSE_EVENTS__TERM_TYPE_USER;
1057 term->no_value = true;
1058 term->alternate_hw_config = true;
1060 attr->type = PERF_TYPE_HARDWARE;
1061 attr->config = term->val.num;
1063 attr->config |= (__u64)pmu->type << PERF_PMU_TYPE_SHIFT;
1067 if (term->type_term == PARSE_EVENTS__TERM_TYPE_USER ||
1068 term->type_term == PARSE_EVENTS__TERM_TYPE_DRV_CFG) {
1075 return config_term_common(attr, term, err);
1079 struct parse_events_term *term,
1082 switch (term->type_term) {
1094 return config_term_common(attr, term, err);
1113 parse_events_error__handle(err, term->err_term,
1114 strdup(parse_events__term_type_str(term->type_term)),
1115 strdup("valid terms: call-graph,stack-size\n")
1118 return -EINVAL;
1129 struct parse_events_term *term;
1131 list_for_each_entry(term, &head->terms, list)
1132 if (config_term(attr, term, err))
1133 return -EINVAL;
1146 return -ENOMEM; \
1148 INIT_LIST_HEAD(&__t->list); \
1149 __t->type = EVSEL__CONFIG_TERM_ ## __type; \
1150 __t->weak = __weak; \
1151 list_add_tail(&__t->list, head_terms)
1156 __t->val.__name = __val; \
1162 __t->val.str = strdup(__val); \
1163 if (!__t->val.str) { \
1165 return -ENOMEM; \
1167 __t->free_str = true; \
1170 struct parse_events_term *term;
1172 list_for_each_entry(term, &head_config->terms, list) {
1173 switch (term->type_term) {
1175 ADD_CONFIG_TERM_VAL(PERIOD, period, term->val.num, term->weak);
1178 ADD_CONFIG_TERM_VAL(FREQ, freq, term->val.num, term->weak);
1181 ADD_CONFIG_TERM_VAL(TIME, time, term->val.num, term->weak);
1184 ADD_CONFIG_TERM_STR(CALLGRAPH, term->val.str, term->weak);
1187 ADD_CONFIG_TERM_STR(BRANCH, term->val.str, term->weak);
1191 term->val.num, term->weak);
1195 term->val.num ? 1 : 0, term->weak);
1199 term->val.num ? 0 : 1, term->weak);
1203 term->val.num, term->weak);
1207 term->val.num, term->weak);
1211 term->val.num ? 1 : 0, term->weak);
1215 term->val.num ? 0 : 1, term->weak);
1218 ADD_CONFIG_TERM_STR(DRV_CFG, term->val.str, term->weak);
1222 term->val.num ? true : false, term->weak);
1226 term->val.num ? 1 : 0, term->weak);
1229 ADD_CONFIG_TERM_STR(AUX_ACTION, term->val.str, term->weak);
1233 term->val.num, term->weak);
1254 * each bit of attr->config that the user has changed.
1259 struct parse_events_term *term;
1263 list_for_each_entry(term, &head_config->terms, list) {
1264 switch (term->type_term) {
1266 type = perf_pmu__format_type(pmu, term->config);
1269 bits |= perf_pmu__format_bits(pmu, term->config);
1324 return -EINVAL;
1354 if (config_attr(&attr, head_config, parse_state->error,
1356 return -EINVAL;
1359 return -ENOMEM;
1364 ret = __add_event(list, &parse_state->idx, &attr, /*init_attr*/true, name,
1367 ) == NULL ? -ENOMEM : 0;
1391 type, pmu->type,
1405 struct evsel_config_term *term;
1407 list_for_each_entry(term, config_terms, list) {
1408 if (term->type == EVSEL__CONFIG_TERM_PERCORE)
1409 return term->val.percore;
1423 struct parse_events_error *err = parse_state->error;
1432 if (pmu->selectable && const_parsed_terms &&
1433 list_empty(&const_parsed_terms->terms)) {
1434 strbuf_addf(&sb, "%s//", pmu->name);
1436 strbuf_addf(&sb, "%s/", pmu->name);
1445 if (pmu->perf_event_attr_init_default)
1446 pmu->perf_event_attr_init_default(pmu, &attr);
1448 attr.type = pmu->type;
1450 if (!const_parsed_terms || list_empty(&const_parsed_terms->terms)) {
1451 evsel = __add_event(list, &parse_state->idx, &attr,
1456 return evsel ? 0 : -ENOMEM;
1469 if (config_attr(&attr, &parsed_terms, parse_state->error, config_term_pmu)) {
1471 return -EINVAL;
1479 return -EINVAL;
1487 fprintf(stderr, "..after resolving event: %s/%s/\n", pmu->name, sb.buf);
1493 config_attr(&attr, &parsed_terms, parse_state->error, config_term_pmu)) {
1495 return -EINVAL;
1500 return -ENOMEM;
1504 * When using default config, record which bits of attr->config were
1507 if (pmu->perf_event_attr_init_default &&
1510 return -ENOMEM;
1515 parse_state->error)) {
1518 return -EINVAL;
1521 evsel = __add_event(list, &parse_state->idx, &attr, /*init_attr=*/true,
1528 return -ENOMEM;
1531 if (evsel->name)
1532 evsel->use_config_name = true;
1534 evsel->percore = config_term_percore(&evsel->config_terms);
1537 free((char *)evsel->unit);
1538 evsel->unit = strdup(info.unit);
1539 evsel->scale = info.scale;
1540 evsel->per_pkg = info.per_pkg;
1541 evsel->snapshot = info.snapshot;
1550 struct parse_events_term *term;
1572 if (parse_events_term__num(&term,
1579 list_add_tail(&term->list, &parsed_terms.terms);
1604 pr_debug("%s -> %s/%s/\n", event_name, pmu->name, sb.buf);
1610 if (parse_state->fake_pmu) {
1617 pr_debug("%s -> fake/%s/\n", event_name, sb.buf);
1630 return ok ? 0 : -1;
1646 return -ENOMEM;
1657 if (parse_state->fake_pmu) {
1677 parse_state->wild_card_pmus = true;
1692 parse_events_error__handle(parse_state->error, loc->first_column,
1696 return -EINVAL;
1709 __perf_evlist__set_leader(list, &leader->core);
1710 zfree(&leader->group_name);
1711 leader->group_name = name;
1723 parse_events_error__handle(parse_state->error, loc->first_column,
1725 return -EINVAL;
1730 int eu = group ? evsel->core.attr.exclude_user : 0;
1731 int ek = group ? evsel->core.attr.exclude_kernel : 0;
1732 int eh = group ? evsel->core.attr.exclude_hv : 0;
1733 int eH = group ? evsel->core.attr.exclude_host : 0;
1734 int eG = group ? evsel->core.attr.exclude_guest : 0;
1736 int exclude_GH = group ? evsel->exclude_GH : 0;
1765 evsel->core.attr.exclude_user = eu;
1766 evsel->core.attr.exclude_kernel = ek;
1767 evsel->core.attr.exclude_hv = eh;
1768 evsel->core.attr.exclude_host = eH;
1769 evsel->core.attr.exclude_guest = eG;
1770 evsel->exclude_GH = exclude_GH;
1774 u8 precise = evsel->core.attr.precise_ip + mod.precise;
1778 * 0 - SAMPLE_IP can have arbitrary skid
1779 * 1 - SAMPLE_IP must have constant skid
1780 * 2 - SAMPLE_IP requested to have 0 skid
1781 * 3 - SAMPLE_IP must have 0 skid
1791 parse_events_error__handle(parse_state->error,
1792 loc->first_column,
1795 return -EINVAL;
1797 evsel->core.attr.precise_ip = precise;
1800 evsel->precise_max = 1;
1802 evsel->core.attr.exclude_idle = 1;
1804 evsel->sample_read = 1;
1806 evsel->core.attr.pinned = 1;
1808 evsel->core.attr.exclusive = 1;
1810 evsel->weak_group = true;
1812 evsel->bpf_counter = true;
1814 evsel->retire_lat = true;
1839 if (!evsel->name) {
1840 evsel->name = used_name ? strdup(name) : name;
1842 if (!evsel->name)
1843 return -ENOMEM;
1895 list_splice(&parse_state.terms->terms, &terms->terms);
1919 return -EINVAL;
1921 group_pmu_name = pmu->name;
1924 * the pmu_name of the first non-software event to avoid breaking the
1939 * non-software PMU. for_each_group_(member|evsel) isn't used as
1944 group_pmu_name = leader_pmu->name;
1945 } else if (leader->core.nr_members > 1) {
1957 group_pmu_name = pos_pmu->name;
1964 evsel->group_pmu_name = strdup(group_pmu_name);
1965 return evsel->group_pmu_name ? 0 : -ENOMEM;
1971 return lhs->core.idx - rhs->core.idx;
1990 if (*force_grouped_idx != -1 && arch_evsel__must_be_in_group(lhs)) {
1993 bool lhs_has_group = lhs_core->leader != lhs_core || lhs_core->nr_members > 1;
1995 lhs_sort_idx = lhs_has_group ? lhs_core->leader->idx : lhs_core->idx;
1997 if (*force_grouped_idx != -1 && arch_evsel__must_be_in_group(rhs)) {
2000 bool rhs_has_group = rhs_core->leader != rhs_core || rhs_core->nr_members > 1;
2002 rhs_sort_idx = rhs_has_group ? rhs_core->leader->idx : rhs_core->idx;
2007 return lhs_sort_idx - rhs_sort_idx;
2021 lhs_pmu_name = lhs->group_pmu_name;
2022 rhs_pmu_name = rhs->group_pmu_name;
2030 * constraints must be adhered to - slots first, etc.
2037 int idx = 0, force_grouped_idx = -1;
2065 pos->core.idx = idx++;
2072 if (force_grouped_idx == -1 && arch_evsel__must_be_in_group(pos))
2073 force_grouped_idx = pos_leader->core.idx;
2086 const char *pos_pmu_name = pos->group_pmu_name;
2088 bool pos_force_grouped = force_grouped_idx != -1 &&
2092 if (pos->core.idx != idx)
2094 pos->core.idx = idx++;
2095 pos->core.nr_members = 0;
2103 cur_leaders_grp = &pos->core;
2108 cur_leader_pmu_name = cur_leader->group_pmu_name;
2112 cur_leaders_grp = pos->core.leader;
2115 } else if (cur_leaders_grp != pos->core.leader) {
2127 if (force_grouped_idx != -1 && last_event_was_forced_leader) {
2134 if (pos->core.leader == pos2->core.leader &&
2145 cur_leaders_grp = force_grouped_leader->core.leader;
2148 cur_leaders_grp = &pos->core;
2152 cur_leaders_grp = pos->core.leader;
2167 pos_leader->core.nr_members++;
2178 .idx = evlist->core.nr_entries,
2192 return -1;
2211 last->cmdline_group_boundary = true;
2217 * There are 2 users - builtin-record and builtin-test objects.
2248 INIT_LIST_HEAD(&err->list);
2255 list_for_each_entry_safe(pos, tmp, &err->list, list) {
2256 zfree(&pos->str);
2257 zfree(&pos->help);
2258 list_del_init(&pos->list);
2277 entry->idx = idx;
2278 entry->str = str;
2279 entry->help = help;
2280 list_add(&entry->list, &err->list);
2304 /* -2 for extra '' in the final fprintf */
2305 int width = get_term_width() - 2;
2321 max_len = width - len_str;
2327 cut = err_idx - max_err_idx;
2335 if ((len_event - cut) > max_len) {
2336 buf[max_len - 1] = buf[max_len - 2] = '.';
2340 idx = len_str + err_idx - cut;
2357 list_for_each_entry(pos, &err->list, list) {
2360 __parse_events_error__print(pos->idx, pos->str, pos->help, event);
2374 list_for_each_entry(pos, &err->list, list) {
2375 if (strstr(pos->str, needle) != NULL)
2386 struct parse_events_option_args *args = opt->value;
2391 ret = __parse_events(*args->evlistp, str, args->pmu_filter, &err,
2406 struct parse_events_option_args *args = opt->value;
2409 if (*args->evlistp == NULL) {
2410 *args->evlistp = evlist__new();
2412 if (*args->evlistp == NULL) {
2414 return -1;
2419 evlist__delete(*args->evlistp);
2420 *args->evlistp = NULL;
2441 if (evlist->core.nr_entries > 0)
2447 return -1;
2451 if (last->core.node.prev == &evlist->core.entries)
2453 last = list_entry(last->core.node.prev, struct evsel, core.node);
2454 } while (!last->cmdline_group_boundary);
2468 "--filter option should follow a -e tracepoint or HW tracer option\n");
2469 return -1;
2472 if (evsel->core.attr.type == PERF_TYPE_TRACEPOINT) {
2476 return -1;
2483 if (pmu->type == evsel->core.attr.type) {
2493 return perf_bpf_filter__parse(&evsel->bpf_filters, str);
2498 return -1;
2507 struct evlist *evlist = *(struct evlist **)opt->value;
2518 if (evsel == NULL || evsel->core.attr.type != PERF_TYPE_TRACEPOINT) {
2520 "--exclude-perf option should follow a -e tracepoint option\n");
2521 return -1;
2529 return -1;
2539 struct evlist *evlist = *(struct evlist **)opt->value;
2545 int parse_events__is_hardcoded_term(struct parse_events_term *term)
2547 return term->type_term != PARSE_EVENTS__TERM_TYPE_USER;
2554 struct parse_events_term *term;
2556 term = malloc(sizeof(*term));
2557 if (!term)
2558 return -ENOMEM;
2560 *term = *temp;
2561 INIT_LIST_HEAD(&term->list);
2562 term->weak = false;
2564 switch (term->type_val) {
2566 term->val.num = num;
2569 term->val.str = str;
2572 free(term);
2573 return -EINVAL;
2576 *_term = term;
2580 int parse_events_term__num(struct parse_events_term **term,
2594 .err_term = loc_term ? loc_term->first_column : 0,
2595 .err_val = loc_val ? loc_val->first_column : 0,
2598 return new_term(term, &temp, /*str=*/NULL, num);
2601 int parse_events_term__str(struct parse_events_term **term,
2613 .err_term = loc_term ? loc_term->first_column : 0,
2614 .err_val = loc_val ? loc_val->first_column : 0,
2617 return new_term(term, &temp, str, /*num=*/0);
2620 int parse_events_term__term(struct parse_events_term **term,
2625 return parse_events_term__str(term, term_lhs, NULL,
2631 const struct parse_events_term *term)
2634 struct parse_events_term temp = *term;
2637 if (term->config) {
2638 temp.config = strdup(term->config);
2640 return -ENOMEM;
2642 if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM)
2643 return new_term(new, &temp, /*str=*/NULL, term->val.num);
2645 str = strdup(term->val.str);
2648 return -ENOMEM;
2653 void parse_events_term__delete(struct parse_events_term *term)
2655 if (term->type_val != PARSE_EVENTS__TERM_TYPE_NUM)
2656 zfree(&term->val.str);
2658 zfree(&term->config);
2659 free(term);
2665 struct parse_events_term *term;
2667 list_for_each_entry (term, &src->terms, list) {
2671 ret = parse_events_term__clone(&n, term);
2675 list_add_tail(&n->list, &dest->terms);
2682 INIT_LIST_HEAD(&terms->terms);
2687 struct parse_events_term *term, *h;
2689 list_for_each_entry_safe(term, h, &terms->terms, list) {
2690 list_del_init(&term->list);
2691 parse_events_term__delete(term);
2705 struct parse_events_term *term;
2711 list_for_each_entry(term, &terms->terms, list) {
2721 if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM)
2722 if (term->no_value) {
2723 assert(term->val.num == 1);
2724 ret = strbuf_addf(sb, "%s", term->config);
2726 ret = strbuf_addf(sb, "%s=%#"PRIx64, term->config, term->val.num);
2727 else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) {
2728 if (term->config) {
2729 ret = strbuf_addf(sb, "%s=", term->config);
2732 } else if ((unsigned int)term->type_term < __PARSE_EVENTS__TERM_TYPE_NR) {
2734 parse_events__term_type_str(term->type_term));
2738 assert(!term->no_value);
2739 ret = strbuf_addf(sb, "%s", term->val.str);
2781 /* "no-overwrite" is the longest name */
2783 (sizeof("no-overwrite") - 1)];