xref: /linux/tools/perf/util/expr.h (revision 03c11eb3b16dc0058589751dfd91f254be2be613)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
207516736SAndi Kleen #ifndef PARSE_CTX_H
307516736SAndi Kleen #define PARSE_CTX_H 1
407516736SAndi Kleen 
5bd560973SIan Rogers struct hashmap;
6fc393839SJiri Olsa struct metric_ref;
7fc393839SJiri Olsa 
8871f9f59SJiri Olsa struct expr_scanner_ctx {
91725e9cdSIan Rogers 	char *user_requested_cpu_list;
101e1a873dSKajol Jain 	int runtime;
111725e9cdSIan Rogers 	bool system_wide;
123340a083SIan Rogers 	bool is_test;
13871f9f59SJiri Olsa };
14871f9f59SJiri Olsa 
151a6abddeSIan Rogers struct expr_parse_ctx {
161a6abddeSIan Rogers 	struct hashmap	*ids;
171a6abddeSIan Rogers 	struct expr_scanner_ctx sctx;
181a6abddeSIan Rogers };
191a6abddeSIan Rogers 
201a6abddeSIan Rogers struct expr_id_data;
211a6abddeSIan Rogers 
22114a9d6eSIan Rogers struct hashmap *ids__new(void);
23114a9d6eSIan Rogers void ids__free(struct hashmap *ids);
2480be6434SIan Rogers int ids__insert(struct hashmap *ids, const char *id);
25114a9d6eSIan Rogers /*
26114a9d6eSIan Rogers  * Union two sets of ids (hashmaps) and construct a third, freeing ids1 and
27114a9d6eSIan Rogers  * ids2.
28114a9d6eSIan Rogers  */
29114a9d6eSIan Rogers struct hashmap *ids__union(struct hashmap *ids1, struct hashmap *ids2);
30114a9d6eSIan Rogers 
31cb94a02eSIan Rogers struct expr_parse_ctx *expr__ctx_new(void);
32ded80bdaSIan Rogers void expr__ctx_clear(struct expr_parse_ctx *ctx);
33cb94a02eSIan Rogers void expr__ctx_free(struct expr_parse_ctx *ctx);
34114a9d6eSIan Rogers 
353fd29fa6SJiri Olsa void expr__del_id(struct expr_parse_ctx *ctx, const char *id);
36332603c2SJiri Olsa int expr__add_id(struct expr_parse_ctx *ctx, const char *id);
372c46f542SJiri Olsa int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val);
389aba0adaSIan Rogers int expr__add_id_val_source_count(struct expr_parse_ctx *ctx, const char *id,
399aba0adaSIan Rogers 				double val, int source_count);
40fc393839SJiri Olsa int expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref);
415c5f5e83SJiri Olsa int expr__get_id(struct expr_parse_ctx *ctx, const char *id,
425c5f5e83SJiri Olsa 		 struct expr_id_data **data);
43798c3f4aSIan Rogers bool expr__subset_of_ids(struct expr_parse_ctx *haystack,
44798c3f4aSIan Rogers 			 struct expr_parse_ctx *needles);
45acf71b05SJiri Olsa int expr__resolve_id(struct expr_parse_ctx *ctx, const char *id,
46acf71b05SJiri Olsa 		     struct expr_id_data **datap);
47114a9d6eSIan Rogers 
48ded80bdaSIan Rogers int expr__parse(double *final_val, struct expr_parse_ctx *ctx,
49fa831fbbSIan Rogers 		const char *expr);
50114a9d6eSIan Rogers 
517e06a5e3SIan Rogers int expr__find_ids(const char *expr, const char *one,
52fa831fbbSIan Rogers 		   struct expr_parse_ctx *ids);
5307516736SAndi Kleen 
5429396cd5SIan Rogers double expr_id_data__value(const struct expr_id_data *data);
559aba0adaSIan Rogers double expr_id_data__source_count(const struct expr_id_data *data);
561725e9cdSIan Rogers double expr__get_literal(const char *literal, const struct expr_scanner_ctx *ctx);
574a4a9bf9SIan Rogers double expr__has_event(const struct expr_parse_ctx *ctx, bool compute_ids, const char *id);
58*9d5da30eSJames Clark double expr__strcmp_cpuid_str(const struct expr_parse_ctx *ctx, bool compute_ids, const char *id);
5929396cd5SIan Rogers 
6007516736SAndi Kleen #endif
61