xref: /linux/tools/perf/util/config.h (revision c34e9ab9a612ee8b18273398ef75c207b01f516d)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __PERF_CONFIG_H
3 #define __PERF_CONFIG_H
4 
5 #include <stdbool.h>
6 #include <linux/list.h>
7 
8 struct perf_config_item {
9 	char *name;
10 	char *value;
11 	bool from_system_config;
12 	struct list_head node;
13 };
14 
15 struct perf_config_section {
16 	char *name;
17 	struct list_head items;
18 	bool from_system_config;
19 	struct list_head node;
20 };
21 
22 struct perf_config_set {
23 	struct list_head sections;
24 };
25 
26 extern const char *config_exclusive_filename;
27 
28 typedef int (*config_fn_t)(const char *, const char *, void *);
29 
30 int perf_default_config(const char *, const char *, void *);
31 int perf_config(config_fn_t fn, void *);
32 int perf_config_scan(const char *name, const char *fmt, ...) __scanf(2, 3);
33 const char *perf_config_get(const char *name);
34 int perf_config_set(struct perf_config_set *set,
35 		    config_fn_t fn, void *data);
36 int perf_config_int(int *dest, const char *, const char *);
37 int perf_config_u8(u8 *dest, const char *name, const char *value);
38 int perf_config_u64(u64 *dest, const char *, const char *);
39 int perf_config_bool(const char *, const char *);
40 int config_error_nonbool(const char *);
41 const char *perf_etc_perfconfig(void);
42 const char *perf_home_perfconfig(void);
43 int perf_config_system(void);
44 int perf_config_global(void);
45 
46 struct perf_config_set *perf_config_set__new(void);
47 struct perf_config_set *perf_config_set__load_file(const char *file);
48 void perf_config_set__delete(struct perf_config_set *set);
49 int perf_config_set__collect(struct perf_config_set *set, const char *file_name,
50 			     const char *var, const char *value);
51 void perf_config__exit(void);
52 void perf_config__refresh(void);
53 
54 /**
55  * perf_config_sections__for_each - iterate thru all the sections
56  * @list: list_head instance to iterate
57  * @section: struct perf_config_section iterator
58  */
59 #define perf_config_sections__for_each_entry(list, section)	\
60         list_for_each_entry(section, list, node)
61 
62 /**
63  * perf_config_items__for_each - iterate thru all the items
64  * @list: list_head instance to iterate
65  * @item: struct perf_config_item iterator
66  */
67 #define perf_config_items__for_each_entry(list, item)	\
68         list_for_each_entry(item, list, node)
69 
70 /**
71  * perf_config_set__for_each - iterate thru all the config section-item pairs
72  * @set: evlist instance to iterate
73  * @section: struct perf_config_section iterator
74  * @item: struct perf_config_item iterator
75  */
76 #define perf_config_set__for_each_entry(set, section, item)			\
77 	perf_config_sections__for_each_entry(&set->sections, section)		\
78 	perf_config_items__for_each_entry(&section->items, item)
79 
80 #endif /* __PERF_CONFIG_H */
81