xref: /linux/tools/perf/util/expr.h (revision 9aba0adae8c773ba0c0adc7c4d97768e044166cb)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
207516736SAndi Kleen #ifndef PARSE_CTX_H
307516736SAndi Kleen #define PARSE_CTX_H 1
407516736SAndi Kleen 
5ded80bdaSIan Rogers // There are fixes that need to land upstream before we can use libbpf's headers,
64d39c89fSIngo Molnar // for now use our copy unconditionally, since the data structures at this point
7ded80bdaSIan Rogers // are exactly the same, no problem.
8ded80bdaSIan Rogers //#ifdef HAVE_LIBBPF_SUPPORT
9ded80bdaSIan Rogers //#include <bpf/hashmap.h>
10ded80bdaSIan Rogers //#else
11ded80bdaSIan Rogers #include "util/hashmap.h"
12ded80bdaSIan Rogers //#endif
1307516736SAndi Kleen 
14fc393839SJiri Olsa struct metric_ref;
15fc393839SJiri Olsa 
16aecce63eSJiri Olsa struct expr_parse_ctx {
17cb94a02eSIan Rogers 	struct hashmap	*ids;
18fa831fbbSIan Rogers 	int runtime;
1907516736SAndi Kleen };
2007516736SAndi Kleen 
2129396cd5SIan Rogers struct expr_id_data;
22070b3b5aSJiri Olsa 
23871f9f59SJiri Olsa struct expr_scanner_ctx {
241e1a873dSKajol Jain 	int runtime;
25871f9f59SJiri Olsa };
26871f9f59SJiri Olsa 
27114a9d6eSIan Rogers struct hashmap *ids__new(void);
28114a9d6eSIan Rogers void ids__free(struct hashmap *ids);
2980be6434SIan Rogers int ids__insert(struct hashmap *ids, const char *id);
30114a9d6eSIan Rogers /*
31114a9d6eSIan Rogers  * Union two sets of ids (hashmaps) and construct a third, freeing ids1 and
32114a9d6eSIan Rogers  * ids2.
33114a9d6eSIan Rogers  */
34114a9d6eSIan Rogers struct hashmap *ids__union(struct hashmap *ids1, struct hashmap *ids2);
35114a9d6eSIan Rogers 
36cb94a02eSIan Rogers struct expr_parse_ctx *expr__ctx_new(void);
37ded80bdaSIan Rogers void expr__ctx_clear(struct expr_parse_ctx *ctx);
38cb94a02eSIan Rogers void expr__ctx_free(struct expr_parse_ctx *ctx);
39114a9d6eSIan Rogers 
403fd29fa6SJiri Olsa void expr__del_id(struct expr_parse_ctx *ctx, const char *id);
41332603c2SJiri Olsa int expr__add_id(struct expr_parse_ctx *ctx, const char *id);
422c46f542SJiri Olsa int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val);
43*9aba0adaSIan Rogers int expr__add_id_val_source_count(struct expr_parse_ctx *ctx, const char *id,
44*9aba0adaSIan Rogers 				double val, int source_count);
45fc393839SJiri Olsa int expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref);
465c5f5e83SJiri Olsa int expr__get_id(struct expr_parse_ctx *ctx, const char *id,
475c5f5e83SJiri Olsa 		 struct expr_id_data **data);
48798c3f4aSIan Rogers bool expr__subset_of_ids(struct expr_parse_ctx *haystack,
49798c3f4aSIan Rogers 			 struct expr_parse_ctx *needles);
50acf71b05SJiri Olsa int expr__resolve_id(struct expr_parse_ctx *ctx, const char *id,
51acf71b05SJiri Olsa 		     struct expr_id_data **datap);
52114a9d6eSIan Rogers 
53ded80bdaSIan Rogers int expr__parse(double *final_val, struct expr_parse_ctx *ctx,
54fa831fbbSIan Rogers 		const char *expr);
55114a9d6eSIan Rogers 
567e06a5e3SIan Rogers int expr__find_ids(const char *expr, const char *one,
57fa831fbbSIan Rogers 		   struct expr_parse_ctx *ids);
5807516736SAndi Kleen 
5929396cd5SIan Rogers double expr_id_data__value(const struct expr_id_data *data);
60*9aba0adaSIan Rogers double expr_id_data__source_count(const struct expr_id_data *data);
613613f6c1SIan Rogers double expr__get_literal(const char *literal);
6229396cd5SIan Rogers 
6307516736SAndi Kleen #endif
64