]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - tools/perf/util/parse-events.c
perf ui/gtk: Fix segmentation fault on perf_hpp__for_each_format loop
[mirror_ubuntu-bionic-kernel.git] / tools / perf / util / parse-events.c
CommitLineData
d2709c7c 1#include <linux/hw_breakpoint.h>
8ad8db37 2#include "util.h"
6b58e7f1 3#include "../perf.h"
361c99a6 4#include "evlist.h"
69aad6f1 5#include "evsel.h"
8ad8db37
IM
6#include "parse-options.h"
7#include "parse-events.h"
8#include "exec_cmd.h"
50e200f0 9#include "linux/string.h"
5aab621b 10#include "symbol.h"
5beeded1 11#include "cache.h"
8755a8f2 12#include "header.h"
85c66be1 13#include <lk/debugfs.h>
ac20de6f 14#include "parse-events-bison.h"
90e2b22d 15#define YY_EXTRA_TYPE int
89812fc8 16#include "parse-events-flex.h"
5f537a26 17#include "pmu.h"
89812fc8
JO
18
19#define MAX_NAME_LEN 100
8ad8db37 20
8ad8db37 21struct event_symbol {
83a0944f
IM
22 const char *symbol;
23 const char *alias;
8ad8db37
IM
24};
25
82ba1f2f
JO
26#ifdef PARSER_DEBUG
27extern int parse_events_debug;
28#endif
ac20de6f 29int parse_events_parse(void *data, void *scanner);
bcd3279f 30
1dc12760
JO
31static struct event_symbol event_symbols_hw[PERF_COUNT_HW_MAX] = {
32 [PERF_COUNT_HW_CPU_CYCLES] = {
33 .symbol = "cpu-cycles",
34 .alias = "cycles",
35 },
36 [PERF_COUNT_HW_INSTRUCTIONS] = {
37 .symbol = "instructions",
38 .alias = "",
39 },
40 [PERF_COUNT_HW_CACHE_REFERENCES] = {
41 .symbol = "cache-references",
42 .alias = "",
43 },
44 [PERF_COUNT_HW_CACHE_MISSES] = {
45 .symbol = "cache-misses",
46 .alias = "",
47 },
48 [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = {
49 .symbol = "branch-instructions",
50 .alias = "branches",
51 },
52 [PERF_COUNT_HW_BRANCH_MISSES] = {
53 .symbol = "branch-misses",
54 .alias = "",
55 },
56 [PERF_COUNT_HW_BUS_CYCLES] = {
57 .symbol = "bus-cycles",
58 .alias = "",
59 },
60 [PERF_COUNT_HW_STALLED_CYCLES_FRONTEND] = {
61 .symbol = "stalled-cycles-frontend",
62 .alias = "idle-cycles-frontend",
63 },
64 [PERF_COUNT_HW_STALLED_CYCLES_BACKEND] = {
65 .symbol = "stalled-cycles-backend",
66 .alias = "idle-cycles-backend",
67 },
68 [PERF_COUNT_HW_REF_CPU_CYCLES] = {
69 .symbol = "ref-cycles",
70 .alias = "",
71 },
72};
73
74static struct event_symbol event_symbols_sw[PERF_COUNT_SW_MAX] = {
75 [PERF_COUNT_SW_CPU_CLOCK] = {
76 .symbol = "cpu-clock",
77 .alias = "",
78 },
79 [PERF_COUNT_SW_TASK_CLOCK] = {
80 .symbol = "task-clock",
81 .alias = "",
82 },
83 [PERF_COUNT_SW_PAGE_FAULTS] = {
84 .symbol = "page-faults",
85 .alias = "faults",
86 },
87 [PERF_COUNT_SW_CONTEXT_SWITCHES] = {
88 .symbol = "context-switches",
89 .alias = "cs",
90 },
91 [PERF_COUNT_SW_CPU_MIGRATIONS] = {
92 .symbol = "cpu-migrations",
93 .alias = "migrations",
94 },
95 [PERF_COUNT_SW_PAGE_FAULTS_MIN] = {
96 .symbol = "minor-faults",
97 .alias = "",
98 },
99 [PERF_COUNT_SW_PAGE_FAULTS_MAJ] = {
100 .symbol = "major-faults",
101 .alias = "",
102 },
103 [PERF_COUNT_SW_ALIGNMENT_FAULTS] = {
104 .symbol = "alignment-faults",
105 .alias = "",
106 },
107 [PERF_COUNT_SW_EMULATION_FAULTS] = {
108 .symbol = "emulation-faults",
109 .alias = "",
110 },
8ad8db37
IM
111};
112
cdd6c482
IM
113#define __PERF_EVENT_FIELD(config, name) \
114 ((config & PERF_EVENT_##name##_MASK) >> PERF_EVENT_##name##_SHIFT)
5242519b 115
1fc570ad 116#define PERF_EVENT_RAW(config) __PERF_EVENT_FIELD(config, RAW)
cdd6c482 117#define PERF_EVENT_CONFIG(config) __PERF_EVENT_FIELD(config, CONFIG)
1fc570ad 118#define PERF_EVENT_TYPE(config) __PERF_EVENT_FIELD(config, TYPE)
cdd6c482 119#define PERF_EVENT_ID(config) __PERF_EVENT_FIELD(config, EVENT)
5242519b 120
6b58e7f1 121#define for_each_subsystem(sys_dir, sys_dirent, sys_next) \
f6bdafef 122 while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \
6b58e7f1 123 if (sys_dirent.d_type == DT_DIR && \
f6bdafef
JB
124 (strcmp(sys_dirent.d_name, ".")) && \
125 (strcmp(sys_dirent.d_name, "..")))
126
ae07b63f
PZ
127static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir)
128{
129 char evt_path[MAXPATHLEN];
130 int fd;
131
ebf294bf 132 snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", tracing_events_path,
ae07b63f
PZ
133 sys_dir->d_name, evt_dir->d_name);
134 fd = open(evt_path, O_RDONLY);
135 if (fd < 0)
136 return -EINVAL;
137 close(fd);
138
139 return 0;
140}
141
6b58e7f1 142#define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) \
f6bdafef 143 while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next) \
6b58e7f1 144 if (evt_dirent.d_type == DT_DIR && \
f6bdafef 145 (strcmp(evt_dirent.d_name, ".")) && \
ae07b63f
PZ
146 (strcmp(evt_dirent.d_name, "..")) && \
147 (!tp_event_has_id(&sys_dirent, &evt_dirent)))
f6bdafef 148
270bbbe8 149#define MAX_EVENT_LENGTH 512
f6bdafef 150
f6bdafef 151
1ef2ed10 152struct tracepoint_path *tracepoint_id_to_path(u64 config)
f6bdafef 153{
1ef2ed10 154 struct tracepoint_path *path = NULL;
f6bdafef
JB
155 DIR *sys_dir, *evt_dir;
156 struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
8aa8a7c8 157 char id_buf[24];
725b1368 158 int fd;
f6bdafef
JB
159 u64 id;
160 char evt_path[MAXPATHLEN];
725b1368 161 char dir_path[MAXPATHLEN];
f6bdafef 162
ebf294bf 163 if (debugfs_valid_mountpoint(tracing_events_path))
1ef2ed10 164 return NULL;
f6bdafef 165
ebf294bf 166 sys_dir = opendir(tracing_events_path);
f6bdafef 167 if (!sys_dir)
725b1368 168 return NULL;
6b58e7f1
UD
169
170 for_each_subsystem(sys_dir, sys_dirent, sys_next) {
725b1368 171
ebf294bf 172 snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path,
725b1368
ED
173 sys_dirent.d_name);
174 evt_dir = opendir(dir_path);
175 if (!evt_dir)
6b58e7f1 176 continue;
725b1368 177
6b58e7f1 178 for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
725b1368
ED
179
180 snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path,
f6bdafef 181 evt_dirent.d_name);
725b1368 182 fd = open(evt_path, O_RDONLY);
f6bdafef
JB
183 if (fd < 0)
184 continue;
185 if (read(fd, id_buf, sizeof(id_buf)) < 0) {
186 close(fd);
187 continue;
188 }
189 close(fd);
190 id = atoll(id_buf);
191 if (id == config) {
192 closedir(evt_dir);
193 closedir(sys_dir);
59b4caeb 194 path = zalloc(sizeof(*path));
1ef2ed10
FW
195 path->system = malloc(MAX_EVENT_LENGTH);
196 if (!path->system) {
197 free(path);
198 return NULL;
199 }
200 path->name = malloc(MAX_EVENT_LENGTH);
201 if (!path->name) {
202 free(path->system);
203 free(path);
204 return NULL;
205 }
206 strncpy(path->system, sys_dirent.d_name,
207 MAX_EVENT_LENGTH);
208 strncpy(path->name, evt_dirent.d_name,
209 MAX_EVENT_LENGTH);
210 return path;
f6bdafef
JB
211 }
212 }
213 closedir(evt_dir);
214 }
215
f6bdafef 216 closedir(sys_dir);
1ef2ed10
FW
217 return NULL;
218}
219
e7c93f09
NK
220struct tracepoint_path *tracepoint_name_to_path(const char *name)
221{
222 struct tracepoint_path *path = zalloc(sizeof(*path));
223 char *str = strchr(name, ':');
224
225 if (path == NULL || str == NULL) {
226 free(path);
227 return NULL;
228 }
229
230 path->system = strndup(name, str - name);
231 path->name = strdup(str+1);
232
233 if (path->system == NULL || path->name == NULL) {
234 free(path->system);
235 free(path->name);
236 free(path);
237 path = NULL;
238 }
239
240 return path;
241}
242
1424dc96
DA
243const char *event_type(int type)
244{
245 switch (type) {
246 case PERF_TYPE_HARDWARE:
247 return "hardware";
248
249 case PERF_TYPE_SOFTWARE:
250 return "software";
251
252 case PERF_TYPE_TRACEPOINT:
253 return "tracepoint";
254
255 case PERF_TYPE_HW_CACHE:
256 return "hardware-cache";
257
258 default:
259 break;
260 }
261
262 return "unknown";
263}
264
7ae92e74
YZ
265
266
c5cd8ac0 267static int __add_event(struct list_head *list, int *idx,
7ae92e74
YZ
268 struct perf_event_attr *attr,
269 char *name, struct cpu_map *cpus)
89812fc8
JO
270{
271 struct perf_evsel *evsel;
272
273 event_attr_init(attr);
274
275 evsel = perf_evsel__new(attr, (*idx)++);
c5cd8ac0 276 if (!evsel)
89812fc8 277 return -ENOMEM;
89812fc8 278
7ae92e74 279 evsel->cpus = cpus;
9db1763c
ACM
280 if (name)
281 evsel->name = strdup(name);
b847cbdc 282 list_add_tail(&evsel->node, list);
89812fc8
JO
283 return 0;
284}
285
c5cd8ac0 286static int add_event(struct list_head *list, int *idx,
7ae92e74
YZ
287 struct perf_event_attr *attr, char *name)
288{
c5cd8ac0 289 return __add_event(list, idx, attr, name, NULL);
7ae92e74
YZ
290}
291
0b668bc9 292static int parse_aliases(char *str, const char *names[][PERF_EVSEL__MAX_ALIASES], int size)
8326f44d
IM
293{
294 int i, j;
61c45981 295 int n, longest = -1;
8326f44d
IM
296
297 for (i = 0; i < size; i++) {
0b668bc9 298 for (j = 0; j < PERF_EVSEL__MAX_ALIASES && names[i][j]; j++) {
61c45981 299 n = strlen(names[i][j]);
89812fc8 300 if (n > longest && !strncasecmp(str, names[i][j], n))
61c45981
PM
301 longest = n;
302 }
89812fc8 303 if (longest > 0)
61c45981 304 return i;
8326f44d
IM
305 }
306
8953645f 307 return -1;
8326f44d
IM
308}
309
c5cd8ac0 310int parse_events_add_cache(struct list_head *list, int *idx,
89812fc8 311 char *type, char *op_result1, char *op_result2)
8326f44d 312{
89812fc8
JO
313 struct perf_event_attr attr;
314 char name[MAX_NAME_LEN];
61c45981 315 int cache_type = -1, cache_op = -1, cache_result = -1;
89812fc8
JO
316 char *op_result[2] = { op_result1, op_result2 };
317 int i, n;
8326f44d 318
8326f44d
IM
319 /*
320 * No fallback - if we cannot get a clear cache type
321 * then bail out:
322 */
0b668bc9 323 cache_type = parse_aliases(type, perf_evsel__hw_cache,
89812fc8 324 PERF_COUNT_HW_CACHE_MAX);
8326f44d 325 if (cache_type == -1)
89812fc8
JO
326 return -EINVAL;
327
328 n = snprintf(name, MAX_NAME_LEN, "%s", type);
61c45981 329
89812fc8
JO
330 for (i = 0; (i < 2) && (op_result[i]); i++) {
331 char *str = op_result[i];
332
275ef387 333 n += snprintf(name + n, MAX_NAME_LEN - n, "-%s", str);
61c45981
PM
334
335 if (cache_op == -1) {
0b668bc9 336 cache_op = parse_aliases(str, perf_evsel__hw_cache_op,
89812fc8 337 PERF_COUNT_HW_CACHE_OP_MAX);
61c45981 338 if (cache_op >= 0) {
0b668bc9 339 if (!perf_evsel__is_cache_op_valid(cache_type, cache_op))
89812fc8 340 return -EINVAL;
61c45981
PM
341 continue;
342 }
343 }
344
345 if (cache_result == -1) {
0b668bc9
ACM
346 cache_result = parse_aliases(str, perf_evsel__hw_cache_result,
347 PERF_COUNT_HW_CACHE_RESULT_MAX);
61c45981
PM
348 if (cache_result >= 0)
349 continue;
350 }
61c45981 351 }
8326f44d 352
8326f44d
IM
353 /*
354 * Fall back to reads:
355 */
8953645f
IM
356 if (cache_op == -1)
357 cache_op = PERF_COUNT_HW_CACHE_OP_READ;
8326f44d 358
8326f44d
IM
359 /*
360 * Fall back to accesses:
361 */
362 if (cache_result == -1)
363 cache_result = PERF_COUNT_HW_CACHE_RESULT_ACCESS;
364
89812fc8
JO
365 memset(&attr, 0, sizeof(attr));
366 attr.config = cache_type | (cache_op << 8) | (cache_result << 16);
367 attr.type = PERF_TYPE_HW_CACHE;
368 return add_event(list, idx, &attr, name);
bcd3279f
FW
369}
370
c5cd8ac0 371static int add_tracepoint(struct list_head *list, int *idx,
89812fc8 372 char *sys_name, char *evt_name)
bcd3279f 373{
82fe1c29 374 struct perf_evsel *evsel;
bcd3279f 375
82fe1c29 376 evsel = perf_evsel__newtp(sys_name, evt_name, (*idx)++);
c5cd8ac0 377 if (!evsel)
82fe1c29 378 return -ENOMEM;
bcd3279f 379
82fe1c29 380 list_add_tail(&evsel->node, list);
c5cd8ac0 381
82fe1c29 382 return 0;
8326f44d
IM
383}
384
c5cd8ac0 385static int add_tracepoint_multi_event(struct list_head *list, int *idx,
f35488f9 386 char *sys_name, char *evt_name)
bcd3279f
FW
387{
388 char evt_path[MAXPATHLEN];
389 struct dirent *evt_ent;
390 DIR *evt_dir;
89812fc8 391 int ret = 0;
bcd3279f 392
ebf294bf 393 snprintf(evt_path, MAXPATHLEN, "%s/%s", tracing_events_path, sys_name);
bcd3279f 394 evt_dir = opendir(evt_path);
bcd3279f
FW
395 if (!evt_dir) {
396 perror("Can't open event dir");
89812fc8 397 return -1;
bcd3279f
FW
398 }
399
89812fc8 400 while (!ret && (evt_ent = readdir(evt_dir))) {
bcd3279f
FW
401 if (!strcmp(evt_ent->d_name, ".")
402 || !strcmp(evt_ent->d_name, "..")
403 || !strcmp(evt_ent->d_name, "enable")
404 || !strcmp(evt_ent->d_name, "filter"))
405 continue;
406
89812fc8 407 if (!strglobmatch(evt_ent->d_name, evt_name))
fb1d2edf
MH
408 continue;
409
89812fc8 410 ret = add_tracepoint(list, idx, sys_name, evt_ent->d_name);
bcd3279f
FW
411 }
412
0bd3f084 413 closedir(evt_dir);
89812fc8 414 return ret;
bcd3279f
FW
415}
416
c5cd8ac0 417static int add_tracepoint_event(struct list_head *list, int *idx,
f35488f9
JO
418 char *sys_name, char *evt_name)
419{
420 return strpbrk(evt_name, "*?") ?
421 add_tracepoint_multi_event(list, idx, sys_name, evt_name) :
422 add_tracepoint(list, idx, sys_name, evt_name);
423}
424
c5cd8ac0 425static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
f35488f9
JO
426 char *sys_name, char *evt_name)
427{
428 struct dirent *events_ent;
429 DIR *events_dir;
430 int ret = 0;
431
432 events_dir = opendir(tracing_events_path);
433 if (!events_dir) {
434 perror("Can't open event dir");
435 return -1;
436 }
437
438 while (!ret && (events_ent = readdir(events_dir))) {
439 if (!strcmp(events_ent->d_name, ".")
440 || !strcmp(events_ent->d_name, "..")
441 || !strcmp(events_ent->d_name, "enable")
442 || !strcmp(events_ent->d_name, "header_event")
443 || !strcmp(events_ent->d_name, "header_page"))
444 continue;
445
446 if (!strglobmatch(events_ent->d_name, sys_name))
447 continue;
448
449 ret = add_tracepoint_event(list, idx, events_ent->d_name,
450 evt_name);
451 }
452
453 closedir(events_dir);
454 return ret;
455}
456
c5cd8ac0 457int parse_events_add_tracepoint(struct list_head *list, int *idx,
89812fc8 458 char *sys, char *event)
f6bdafef 459{
89812fc8 460 int ret;
f6bdafef 461
89812fc8
JO
462 ret = debugfs_valid_mountpoint(tracing_events_path);
463 if (ret)
464 return ret;
f6bdafef 465
f35488f9
JO
466 if (strpbrk(sys, "*?"))
467 return add_tracepoint_multi_sys(list, idx, sys, event);
468 else
469 return add_tracepoint_event(list, idx, sys, event);
f6bdafef
JB
470}
471
89812fc8
JO
472static int
473parse_breakpoint_type(const char *type, struct perf_event_attr *attr)
1b290d67
FW
474{
475 int i;
476
477 for (i = 0; i < 3; i++) {
89812fc8 478 if (!type || !type[i])
1b290d67
FW
479 break;
480
7582732f
JO
481#define CHECK_SET_TYPE(bit) \
482do { \
483 if (attr->bp_type & bit) \
484 return -EINVAL; \
485 else \
486 attr->bp_type |= bit; \
487} while (0)
488
1b290d67
FW
489 switch (type[i]) {
490 case 'r':
7582732f 491 CHECK_SET_TYPE(HW_BREAKPOINT_R);
1b290d67
FW
492 break;
493 case 'w':
7582732f 494 CHECK_SET_TYPE(HW_BREAKPOINT_W);
1b290d67
FW
495 break;
496 case 'x':
7582732f 497 CHECK_SET_TYPE(HW_BREAKPOINT_X);
1b290d67
FW
498 break;
499 default:
89812fc8 500 return -EINVAL;
1b290d67
FW
501 }
502 }
89812fc8 503
7582732f
JO
504#undef CHECK_SET_TYPE
505
1b290d67
FW
506 if (!attr->bp_type) /* Default */
507 attr->bp_type = HW_BREAKPOINT_R | HW_BREAKPOINT_W;
508
89812fc8 509 return 0;
1b290d67
FW
510}
511
c5cd8ac0 512int parse_events_add_breakpoint(struct list_head *list, int *idx,
89812fc8 513 void *ptr, char *type)
1b290d67 514{
89812fc8 515 struct perf_event_attr attr;
1b290d67 516
89812fc8 517 memset(&attr, 0, sizeof(attr));
9fafd98f 518 attr.bp_addr = (unsigned long) ptr;
1b290d67 519
89812fc8
JO
520 if (parse_breakpoint_type(type, &attr))
521 return -EINVAL;
1b290d67 522
aa59a485
FW
523 /*
524 * We should find a nice way to override the access length
525 * Provide some defaults for now
526 */
89812fc8
JO
527 if (attr.bp_type == HW_BREAKPOINT_X)
528 attr.bp_len = sizeof(long);
aa59a485 529 else
89812fc8 530 attr.bp_len = HW_BREAKPOINT_LEN_4;
61c45981 531
89812fc8 532 attr.type = PERF_TYPE_BREAKPOINT;
4a841d65 533 attr.sample_period = 1;
b908debd 534
287e74aa 535 return add_event(list, idx, &attr, NULL);
74d5b588
JSR
536}
537
8f707d84 538static int config_term(struct perf_event_attr *attr,
6cee6cd3 539 struct parse_events_term *term)
8f707d84 540{
16fa7e82
JO
541#define CHECK_TYPE_VAL(type) \
542do { \
543 if (PARSE_EVENTS__TERM_TYPE_ ## type != term->type_val) \
544 return -EINVAL; \
545} while (0)
546
547 switch (term->type_term) {
8f707d84 548 case PARSE_EVENTS__TERM_TYPE_CONFIG:
16fa7e82 549 CHECK_TYPE_VAL(NUM);
8f707d84
JO
550 attr->config = term->val.num;
551 break;
552 case PARSE_EVENTS__TERM_TYPE_CONFIG1:
16fa7e82 553 CHECK_TYPE_VAL(NUM);
8f707d84
JO
554 attr->config1 = term->val.num;
555 break;
556 case PARSE_EVENTS__TERM_TYPE_CONFIG2:
16fa7e82 557 CHECK_TYPE_VAL(NUM);
8f707d84
JO
558 attr->config2 = term->val.num;
559 break;
560 case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD:
16fa7e82 561 CHECK_TYPE_VAL(NUM);
8f707d84
JO
562 attr->sample_period = term->val.num;
563 break;
564 case PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE:
565 /*
566 * TODO uncomment when the field is available
567 * attr->branch_sample_type = term->val.num;
568 */
569 break;
6b5fc39b
JO
570 case PARSE_EVENTS__TERM_TYPE_NAME:
571 CHECK_TYPE_VAL(STR);
572 break;
8f707d84
JO
573 default:
574 return -EINVAL;
575 }
16fa7e82 576
8f707d84 577 return 0;
16fa7e82 578#undef CHECK_TYPE_VAL
8f707d84
JO
579}
580
581static int config_attr(struct perf_event_attr *attr,
582 struct list_head *head, int fail)
583{
6cee6cd3 584 struct parse_events_term *term;
8f707d84
JO
585
586 list_for_each_entry(term, head, list)
587 if (config_term(attr, term) && fail)
588 return -EINVAL;
589
590 return 0;
591}
592
c5cd8ac0 593int parse_events_add_numeric(struct list_head *list, int *idx,
b527bab5 594 u32 type, u64 config,
8f707d84 595 struct list_head *head_config)
8ad8db37 596{
89812fc8 597 struct perf_event_attr attr;
61c45981 598
89812fc8
JO
599 memset(&attr, 0, sizeof(attr));
600 attr.type = type;
601 attr.config = config;
8f707d84
JO
602
603 if (head_config &&
604 config_attr(&attr, head_config, 1))
605 return -EINVAL;
606
9db1763c 607 return add_event(list, idx, &attr, NULL);
61c45981 608}
8ad8db37 609
6cee6cd3 610static int parse_events__is_name_term(struct parse_events_term *term)
6b5fc39b
JO
611{
612 return term->type_term == PARSE_EVENTS__TERM_TYPE_NAME;
613}
614
9db1763c 615static char *pmu_event_name(struct list_head *head_terms)
6b5fc39b 616{
6cee6cd3 617 struct parse_events_term *term;
6b5fc39b
JO
618
619 list_for_each_entry(term, head_terms, list)
620 if (parse_events__is_name_term(term))
621 return term->val.str;
622
9db1763c 623 return NULL;
6b5fc39b
JO
624}
625
c5cd8ac0 626int parse_events_add_pmu(struct list_head *list, int *idx,
5f537a26
JO
627 char *name, struct list_head *head_config)
628{
629 struct perf_event_attr attr;
630 struct perf_pmu *pmu;
631
632 pmu = perf_pmu__find(name);
633 if (!pmu)
634 return -EINVAL;
635
636 memset(&attr, 0, sizeof(attr));
637
a6146d50
ZY
638 if (perf_pmu__check_alias(pmu, head_config))
639 return -EINVAL;
640
5f537a26
JO
641 /*
642 * Configure hardcoded terms first, no need to check
643 * return value when called with fail == 0 ;)
644 */
645 config_attr(&attr, head_config, 0);
646
647 if (perf_pmu__config(pmu, &attr, head_config))
648 return -EINVAL;
649
7ae92e74
YZ
650 return __add_event(list, idx, &attr, pmu_event_name(head_config),
651 pmu->cpus);
5f537a26
JO
652}
653
6a4bb04c
JO
654int parse_events__modifier_group(struct list_head *list,
655 char *event_mod)
89efb029 656{
6a4bb04c
JO
657 return parse_events__modifier_event(list, event_mod, true);
658}
659
63dab225 660void parse_events__set_leader(char *name, struct list_head *list)
6a4bb04c
JO
661{
662 struct perf_evsel *leader;
663
63dab225
ACM
664 __perf_evlist__set_leader(list);
665 leader = list_entry(list->next, struct perf_evsel, node);
6a4bb04c 666 leader->group_name = name ? strdup(name) : NULL;
89efb029
JO
667}
668
c5cd8ac0 669/* list_event is assumed to point to malloc'ed memory */
5d7be90e
JO
670void parse_events_update_lists(struct list_head *list_event,
671 struct list_head *list_all)
672{
673 /*
674 * Called for single event definition. Update the
89efb029 675 * 'all event' list, and reinit the 'single event'
5d7be90e
JO
676 * list, for next event definition.
677 */
678 list_splice_tail(list_event, list_all);
b847cbdc 679 free(list_event);
5d7be90e
JO
680}
681
f5b1135b
JO
682struct event_modifier {
683 int eu;
684 int ek;
685 int eh;
686 int eH;
687 int eG;
688 int precise;
689 int exclude_GH;
3c176311 690 int sample_read;
f5b1135b
JO
691};
692
693static int get_event_modifier(struct event_modifier *mod, char *str,
694 struct perf_evsel *evsel)
61c45981 695{
f5b1135b
JO
696 int eu = evsel ? evsel->attr.exclude_user : 0;
697 int ek = evsel ? evsel->attr.exclude_kernel : 0;
698 int eh = evsel ? evsel->attr.exclude_hv : 0;
699 int eH = evsel ? evsel->attr.exclude_host : 0;
700 int eG = evsel ? evsel->attr.exclude_guest : 0;
701 int precise = evsel ? evsel->attr.precise_ip : 0;
3c176311 702 int sample_read = 0;
a21ca2ca 703
f5b1135b
JO
704 int exclude = eu | ek | eh;
705 int exclude_GH = evsel ? evsel->exclude_GH : 0;
706
f5b1135b 707 memset(mod, 0, sizeof(*mod));
ceb53fbf 708
61c45981 709 while (*str) {
ab608344
PZ
710 if (*str == 'u') {
711 if (!exclude)
712 exclude = eu = ek = eh = 1;
61c45981 713 eu = 0;
ab608344
PZ
714 } else if (*str == 'k') {
715 if (!exclude)
716 exclude = eu = ek = eh = 1;
61c45981 717 ek = 0;
ab608344
PZ
718 } else if (*str == 'h') {
719 if (!exclude)
720 exclude = eu = ek = eh = 1;
61c45981 721 eh = 0;
99320cc8
JR
722 } else if (*str == 'G') {
723 if (!exclude_GH)
724 exclude_GH = eG = eH = 1;
725 eG = 0;
726 } else if (*str == 'H') {
727 if (!exclude_GH)
728 exclude_GH = eG = eH = 1;
729 eH = 0;
ab608344
PZ
730 } else if (*str == 'p') {
731 precise++;
1342798c
DA
732 /* use of precise requires exclude_guest */
733 if (!exclude_GH)
734 eG = 1;
3c176311
JO
735 } else if (*str == 'S') {
736 sample_read = 1;
ab608344 737 } else
61c45981 738 break;
ab608344 739
61c45981 740 ++str;
5242519b 741 }
ceb53fbf 742
89812fc8
JO
743 /*
744 * precise ip:
745 *
746 * 0 - SAMPLE_IP can have arbitrary skid
747 * 1 - SAMPLE_IP must have constant skid
748 * 2 - SAMPLE_IP requested to have 0 skid
749 * 3 - SAMPLE_IP must have 0 skid
750 *
751 * See also PERF_RECORD_MISC_EXACT_IP
752 */
753 if (precise > 3)
754 return -EINVAL;
ceb53fbf 755
f5b1135b
JO
756 mod->eu = eu;
757 mod->ek = ek;
758 mod->eh = eh;
759 mod->eH = eH;
760 mod->eG = eG;
761 mod->precise = precise;
762 mod->exclude_GH = exclude_GH;
3c176311 763 mod->sample_read = sample_read;
f5b1135b
JO
764 return 0;
765}
766
534123f4
JO
767/*
768 * Basic modifier sanity check to validate it contains only one
769 * instance of any modifier (apart from 'p') present.
770 */
771static int check_modifier(char *str)
772{
773 char *p = str;
774
775 /* The sizeof includes 0 byte as well. */
3c176311 776 if (strlen(str) > (sizeof("ukhGHpppS") - 1))
534123f4
JO
777 return -1;
778
779 while (*p) {
780 if (*p != 'p' && strchr(p + 1, *p))
781 return -1;
782 p++;
783 }
784
785 return 0;
786}
787
f5b1135b
JO
788int parse_events__modifier_event(struct list_head *list, char *str, bool add)
789{
790 struct perf_evsel *evsel;
791 struct event_modifier mod;
792
793 if (str == NULL)
794 return 0;
795
534123f4
JO
796 if (check_modifier(str))
797 return -EINVAL;
798
f5b1135b
JO
799 if (!add && get_event_modifier(&mod, str, NULL))
800 return -EINVAL;
801
89812fc8 802 list_for_each_entry(evsel, list, node) {
f5b1135b
JO
803
804 if (add && get_event_modifier(&mod, str, evsel))
805 return -EINVAL;
806
807 evsel->attr.exclude_user = mod.eu;
808 evsel->attr.exclude_kernel = mod.ek;
809 evsel->attr.exclude_hv = mod.eh;
810 evsel->attr.precise_ip = mod.precise;
811 evsel->attr.exclude_host = mod.eH;
812 evsel->attr.exclude_guest = mod.eG;
813 evsel->exclude_GH = mod.exclude_GH;
3c176311 814 evsel->sample_read = mod.sample_read;
89812fc8 815 }
ceb53fbf 816
61c45981
PM
817 return 0;
818}
8ad8db37 819
ac2ba9f3
RR
820int parse_events_name(struct list_head *list, char *name)
821{
822 struct perf_evsel *evsel;
823
824 list_for_each_entry(evsel, list, node) {
825 if (!evsel->name)
826 evsel->name = strdup(name);
827 }
828
829 return 0;
830}
831
50e200f0
AK
832static int parse_events__scanner(const char *str, void *data, int start_token);
833
834static int parse_events_fixup(int ret, const char *str, void *data,
835 int start_token)
836{
837 char *o = strdup(str);
838 char *s = NULL;
839 char *t = o;
840 char *p;
841 int len = 0;
842
843 if (!o)
844 return ret;
845 while ((p = strsep(&t, ",")) != NULL) {
846 if (s)
847 str_append(&s, &len, ",");
848 str_append(&s, &len, "cpu/");
849 str_append(&s, &len, p);
850 str_append(&s, &len, "/");
851 }
852 free(o);
853 if (!s)
854 return -ENOMEM;
855 return parse_events__scanner(s, data, start_token);
856}
857
90e2b22d 858static int parse_events__scanner(const char *str, void *data, int start_token)
61c45981 859{
89812fc8 860 YY_BUFFER_STATE buffer;
ac20de6f 861 void *scanner;
46010ab2 862 int ret;
bcd3279f 863
90e2b22d 864 ret = parse_events_lex_init_extra(start_token, &scanner);
ac20de6f
ZY
865 if (ret)
866 return ret;
867
868 buffer = parse_events__scan_string(str, scanner);
a21ca2ca 869
82ba1f2f
JO
870#ifdef PARSER_DEBUG
871 parse_events_debug = 1;
872#endif
ac20de6f
ZY
873 ret = parse_events_parse(data, scanner);
874
875 parse_events__flush_buffer(buffer, scanner);
876 parse_events__delete_buffer(buffer, scanner);
877 parse_events_lex_destroy(scanner);
50e200f0
AK
878 if (ret && !strchr(str, '/'))
879 ret = parse_events_fixup(ret, str, data, start_token);
ac20de6f
ZY
880 return ret;
881}
bcd3279f 882
90e2b22d
JO
883/*
884 * parse event config string, return a list of event terms.
885 */
886int parse_events_terms(struct list_head *terms, const char *str)
887{
23b6339b 888 struct parse_events_terms data = {
90e2b22d
JO
889 .terms = NULL,
890 };
891 int ret;
892
893 ret = parse_events__scanner(str, &data, PE_START_TERMS);
894 if (!ret) {
895 list_splice(data.terms, terms);
896 free(data.terms);
897 return 0;
898 }
899
b2c34fde
AH
900 if (data.terms)
901 parse_events__free_terms(data.terms);
90e2b22d
JO
902 return ret;
903}
904
d8f7bbc9 905int parse_events(struct perf_evlist *evlist, const char *str)
ac20de6f 906{
23b6339b 907 struct parse_events_evlist data = {
ac20de6f
ZY
908 .list = LIST_HEAD_INIT(data.list),
909 .idx = evlist->nr_entries,
910 };
911 int ret;
bcd3279f 912
90e2b22d 913 ret = parse_events__scanner(str, &data, PE_START_EVENTS);
89812fc8 914 if (!ret) {
46010ab2
JO
915 int entries = data.idx - evlist->nr_entries;
916 perf_evlist__splice_list_tail(evlist, &data.list, entries);
97f63e4a 917 evlist->nr_groups += data.nr_groups;
89812fc8
JO
918 return 0;
919 }
bcd3279f 920
5d7be90e
JO
921 /*
922 * There are 2 users - builtin-record and builtin-test objects.
923 * Both call perf_evlist__delete in case of error, so we dont
924 * need to bother.
925 */
bcd3279f 926 return ret;
8ad8db37
IM
927}
928
f120f9d5 929int parse_events_option(const struct option *opt, const char *str,
1d037ca1 930 int unset __maybe_unused)
f120f9d5
JO
931{
932 struct perf_evlist *evlist = *(struct perf_evlist **)opt->value;
d8f7bbc9 933 int ret = parse_events(evlist, str);
9175ce1f
AK
934
935 if (ret) {
936 fprintf(stderr, "invalid or unsupported event: '%s'\n", str);
937 fprintf(stderr, "Run 'perf list' for a list of valid events\n");
938 }
939 return ret;
f120f9d5
JO
940}
941
361c99a6 942int parse_filter(const struct option *opt, const char *str,
1d037ca1 943 int unset __maybe_unused)
c171b552 944{
361c99a6 945 struct perf_evlist *evlist = *(struct perf_evlist **)opt->value;
69aad6f1 946 struct perf_evsel *last = NULL;
c171b552 947
361c99a6 948 if (evlist->nr_entries > 0)
0c21f736 949 last = perf_evlist__last(evlist);
69aad6f1
ACM
950
951 if (last == NULL || last->attr.type != PERF_TYPE_TRACEPOINT) {
c171b552
LZ
952 fprintf(stderr,
953 "-F option should follow a -e tracepoint option\n");
954 return -1;
955 }
956
69aad6f1
ACM
957 last->filter = strdup(str);
958 if (last->filter == NULL) {
c171b552
LZ
959 fprintf(stderr, "not enough memory to hold filter string\n");
960 return -1;
961 }
c171b552
LZ
962
963 return 0;
964}
965
86847b62 966static const char * const event_type_descriptors[] = {
86847b62
TG
967 "Hardware event",
968 "Software event",
969 "Tracepoint event",
970 "Hardware cache event",
41bdcb23
LW
971 "Raw hardware event descriptor",
972 "Hardware breakpoint",
86847b62
TG
973};
974
f6bdafef
JB
975/*
976 * Print the events from <debugfs_mount_point>/tracing/events
977 */
978
a3277d2d
FW
979void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
980 bool name_only)
f6bdafef
JB
981{
982 DIR *sys_dir, *evt_dir;
983 struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
f6bdafef 984 char evt_path[MAXPATHLEN];
725b1368 985 char dir_path[MAXPATHLEN];
f6bdafef 986
ebf294bf 987 if (debugfs_valid_mountpoint(tracing_events_path))
f6bdafef
JB
988 return;
989
ebf294bf 990 sys_dir = opendir(tracing_events_path);
f6bdafef 991 if (!sys_dir)
725b1368 992 return;
6b58e7f1
UD
993
994 for_each_subsystem(sys_dir, sys_dirent, sys_next) {
668b8788
ACM
995 if (subsys_glob != NULL &&
996 !strglobmatch(sys_dirent.d_name, subsys_glob))
997 continue;
725b1368 998
ebf294bf 999 snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path,
725b1368
ED
1000 sys_dirent.d_name);
1001 evt_dir = opendir(dir_path);
1002 if (!evt_dir)
6b58e7f1 1003 continue;
725b1368 1004
6b58e7f1 1005 for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
668b8788
ACM
1006 if (event_glob != NULL &&
1007 !strglobmatch(evt_dirent.d_name, event_glob))
1008 continue;
1009
a3277d2d
FW
1010 if (name_only) {
1011 printf("%s:%s ", sys_dirent.d_name, evt_dirent.d_name);
1012 continue;
1013 }
1014
f6bdafef
JB
1015 snprintf(evt_path, MAXPATHLEN, "%s:%s",
1016 sys_dirent.d_name, evt_dirent.d_name);
947b4ad1 1017 printf(" %-50s [%s]\n", evt_path,
41bdcb23 1018 event_type_descriptors[PERF_TYPE_TRACEPOINT]);
f6bdafef
JB
1019 }
1020 closedir(evt_dir);
1021 }
f6bdafef
JB
1022 closedir(sys_dir);
1023}
1024
20c457b8
TR
1025/*
1026 * Check whether event is in <debugfs_mount_point>/tracing/events
1027 */
1028
1029int is_valid_tracepoint(const char *event_string)
1030{
1031 DIR *sys_dir, *evt_dir;
1032 struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
1033 char evt_path[MAXPATHLEN];
1034 char dir_path[MAXPATHLEN];
1035
ebf294bf 1036 if (debugfs_valid_mountpoint(tracing_events_path))
20c457b8
TR
1037 return 0;
1038
ebf294bf 1039 sys_dir = opendir(tracing_events_path);
20c457b8
TR
1040 if (!sys_dir)
1041 return 0;
1042
1043 for_each_subsystem(sys_dir, sys_dirent, sys_next) {
1044
ebf294bf 1045 snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path,
20c457b8
TR
1046 sys_dirent.d_name);
1047 evt_dir = opendir(dir_path);
1048 if (!evt_dir)
1049 continue;
1050
1051 for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
1052 snprintf(evt_path, MAXPATHLEN, "%s:%s",
1053 sys_dirent.d_name, evt_dirent.d_name);
1054 if (!strcmp(evt_path, event_string)) {
1055 closedir(evt_dir);
1056 closedir(sys_dir);
1057 return 1;
1058 }
1059 }
1060 closedir(evt_dir);
1061 }
1062 closedir(sys_dir);
1063 return 0;
1064}
1065
1dc12760
JO
1066static void __print_events_type(u8 type, struct event_symbol *syms,
1067 unsigned max)
668b8788 1068{
668b8788 1069 char name[64];
1dc12760 1070 unsigned i;
668b8788 1071
1dc12760 1072 for (i = 0; i < max ; i++, syms++) {
668b8788
ACM
1073 if (strlen(syms->alias))
1074 snprintf(name, sizeof(name), "%s OR %s",
1075 syms->symbol, syms->alias);
1076 else
1077 snprintf(name, sizeof(name), "%s", syms->symbol);
1078
947b4ad1 1079 printf(" %-50s [%s]\n", name,
668b8788
ACM
1080 event_type_descriptors[type]);
1081 }
1082}
1083
1dc12760
JO
1084void print_events_type(u8 type)
1085{
1086 if (type == PERF_TYPE_SOFTWARE)
1087 __print_events_type(type, event_symbols_sw, PERF_COUNT_SW_MAX);
1088 else
1089 __print_events_type(type, event_symbols_hw, PERF_COUNT_HW_MAX);
1090}
1091
a3277d2d 1092int print_hwcache_events(const char *event_glob, bool name_only)
668b8788
ACM
1093{
1094 unsigned int type, op, i, printed = 0;
0b668bc9 1095 char name[64];
668b8788
ACM
1096
1097 for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
1098 for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
1099 /* skip invalid cache type */
0b668bc9 1100 if (!perf_evsel__is_cache_op_valid(type, op))
668b8788
ACM
1101 continue;
1102
1103 for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
0b668bc9
ACM
1104 __perf_evsel__hw_cache_type_op_res_name(type, op, i,
1105 name, sizeof(name));
947b4ad1 1106 if (event_glob != NULL && !strglobmatch(name, event_glob))
668b8788
ACM
1107 continue;
1108
a3277d2d
FW
1109 if (name_only)
1110 printf("%s ", name);
1111 else
1112 printf(" %-50s [%s]\n", name,
1113 event_type_descriptors[PERF_TYPE_HW_CACHE]);
668b8788
ACM
1114 ++printed;
1115 }
1116 }
1117 }
1118
dc098b35
AK
1119 if (printed)
1120 printf("\n");
668b8788
ACM
1121 return printed;
1122}
1123
1dc12760 1124static void print_symbol_events(const char *event_glob, unsigned type,
a3277d2d
FW
1125 struct event_symbol *syms, unsigned max,
1126 bool name_only)
8ad8db37 1127{
1dc12760 1128 unsigned i, printed = 0;
947b4ad1 1129 char name[MAX_NAME_LEN];
8ad8db37 1130
1dc12760 1131 for (i = 0; i < max; i++, syms++) {
668b8788
ACM
1132
1133 if (event_glob != NULL &&
1134 !(strglobmatch(syms->symbol, event_glob) ||
1135 (syms->alias && strglobmatch(syms->alias, event_glob))))
1136 continue;
8ad8db37 1137
a3277d2d
FW
1138 if (name_only) {
1139 printf("%s ", syms->symbol);
1140 continue;
1141 }
1142
74d5b588 1143 if (strlen(syms->alias))
947b4ad1 1144 snprintf(name, MAX_NAME_LEN, "%s OR %s", syms->symbol, syms->alias);
74d5b588 1145 else
947b4ad1 1146 strncpy(name, syms->symbol, MAX_NAME_LEN);
8ad8db37 1147
1dc12760
JO
1148 printf(" %-50s [%s]\n", name, event_type_descriptors[type]);
1149
1150 printed++;
8ad8db37
IM
1151 }
1152
1dc12760 1153 if (printed)
668b8788 1154 printf("\n");
1dc12760
JO
1155}
1156
1157/*
1158 * Print the help text for the event symbols:
1159 */
a3277d2d 1160void print_events(const char *event_glob, bool name_only)
1dc12760 1161{
a3277d2d
FW
1162 if (!name_only) {
1163 printf("\n");
1164 printf("List of pre-defined events (to be used in -e):\n");
1165 }
1dc12760
JO
1166
1167 print_symbol_events(event_glob, PERF_TYPE_HARDWARE,
a3277d2d 1168 event_symbols_hw, PERF_COUNT_HW_MAX, name_only);
1dc12760
JO
1169
1170 print_symbol_events(event_glob, PERF_TYPE_SOFTWARE,
a3277d2d 1171 event_symbols_sw, PERF_COUNT_SW_MAX, name_only);
1dc12760 1172
a3277d2d 1173 print_hwcache_events(event_glob, name_only);
668b8788 1174
dc098b35
AK
1175 print_pmu_events(event_glob, name_only);
1176
668b8788
ACM
1177 if (event_glob != NULL)
1178 return;
73c24cb8 1179
a3277d2d 1180 if (!name_only) {
a3277d2d
FW
1181 printf(" %-50s [%s]\n",
1182 "rNNN",
1183 event_type_descriptors[PERF_TYPE_RAW]);
1184 printf(" %-50s [%s]\n",
1185 "cpu/t1=v1[,t2=v2,t3 ...]/modifier",
1186 event_type_descriptors[PERF_TYPE_RAW]);
af3df2cf 1187 printf(" (see 'man perf-list' on how to encode it)\n");
a3277d2d
FW
1188 printf("\n");
1189
1190 printf(" %-50s [%s]\n",
1191 "mem:<addr>[:access]",
41bdcb23 1192 event_type_descriptors[PERF_TYPE_BREAKPOINT]);
a3277d2d
FW
1193 printf("\n");
1194 }
1b290d67 1195
a3277d2d 1196 print_tracepoint_events(NULL, NULL, name_only);
8ad8db37 1197}
8f707d84 1198
6cee6cd3 1199int parse_events__is_hardcoded_term(struct parse_events_term *term)
8f707d84 1200{
16fa7e82 1201 return term->type_term != PARSE_EVENTS__TERM_TYPE_USER;
8f707d84
JO
1202}
1203
6cee6cd3 1204static int new_term(struct parse_events_term **_term, int type_val,
16fa7e82 1205 int type_term, char *config,
b527bab5 1206 char *str, u64 num)
8f707d84 1207{
6cee6cd3 1208 struct parse_events_term *term;
8f707d84
JO
1209
1210 term = zalloc(sizeof(*term));
1211 if (!term)
1212 return -ENOMEM;
1213
1214 INIT_LIST_HEAD(&term->list);
16fa7e82
JO
1215 term->type_val = type_val;
1216 term->type_term = type_term;
8f707d84
JO
1217 term->config = config;
1218
16fa7e82 1219 switch (type_val) {
8f707d84
JO
1220 case PARSE_EVENTS__TERM_TYPE_NUM:
1221 term->val.num = num;
1222 break;
1223 case PARSE_EVENTS__TERM_TYPE_STR:
1224 term->val.str = str;
1225 break;
1226 default:
4be8be6b 1227 free(term);
8f707d84
JO
1228 return -EINVAL;
1229 }
1230
1231 *_term = term;
1232 return 0;
1233}
1234
6cee6cd3 1235int parse_events_term__num(struct parse_events_term **term,
b527bab5 1236 int type_term, char *config, u64 num)
16fa7e82
JO
1237{
1238 return new_term(term, PARSE_EVENTS__TERM_TYPE_NUM, type_term,
1239 config, NULL, num);
1240}
1241
6cee6cd3 1242int parse_events_term__str(struct parse_events_term **term,
16fa7e82
JO
1243 int type_term, char *config, char *str)
1244{
1245 return new_term(term, PARSE_EVENTS__TERM_TYPE_STR, type_term,
1246 config, str, 0);
1247}
1248
6cee6cd3 1249int parse_events_term__sym_hw(struct parse_events_term **term,
1d33d6dc
JO
1250 char *config, unsigned idx)
1251{
1252 struct event_symbol *sym;
1253
1254 BUG_ON(idx >= PERF_COUNT_HW_MAX);
1255 sym = &event_symbols_hw[idx];
1256
1257 if (config)
1258 return new_term(term, PARSE_EVENTS__TERM_TYPE_STR,
1259 PARSE_EVENTS__TERM_TYPE_USER, config,
1260 (char *) sym->symbol, 0);
1261 else
1262 return new_term(term, PARSE_EVENTS__TERM_TYPE_STR,
1263 PARSE_EVENTS__TERM_TYPE_USER,
1264 (char *) "event", (char *) sym->symbol, 0);
1265}
1266
6cee6cd3
ACM
1267int parse_events_term__clone(struct parse_events_term **new,
1268 struct parse_events_term *term)
a6146d50
ZY
1269{
1270 return new_term(new, term->type_val, term->type_term, term->config,
1271 term->val.str, term->val.num);
1272}
1273
8f707d84
JO
1274void parse_events__free_terms(struct list_head *terms)
1275{
6cee6cd3 1276 struct parse_events_term *term, *h;
8f707d84
JO
1277
1278 list_for_each_entry_safe(term, h, terms, list)
1279 free(term);
8f707d84 1280}