xref: /linux/tools/perf/util/expr.h (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef PARSE_CTX_H
3 #define PARSE_CTX_H 1
4 
5 // There are fixes that need to land upstream before we can use libbpf's headers,
6 // for now use our copy unconditionally, since the data structures at this point
7 // are exactly the same, no problem.
8 //#ifdef HAVE_LIBBPF_SUPPORT
9 //#include <bpf/hashmap.h>
10 //#else
11 #include "util/hashmap.h"
12 //#endif
13 
14 struct metric_ref;
15 
16 struct expr_parse_ctx {
17 	struct hashmap	*ids;
18 	int runtime;
19 };
20 
21 struct expr_id_data;
22 
23 struct expr_scanner_ctx {
24 	int runtime;
25 };
26 
27 struct hashmap *ids__new(void);
28 void ids__free(struct hashmap *ids);
29 int ids__insert(struct hashmap *ids, const char *id);
30 /*
31  * Union two sets of ids (hashmaps) and construct a third, freeing ids1 and
32  * ids2.
33  */
34 struct hashmap *ids__union(struct hashmap *ids1, struct hashmap *ids2);
35 
36 struct expr_parse_ctx *expr__ctx_new(void);
37 void expr__ctx_clear(struct expr_parse_ctx *ctx);
38 void expr__ctx_free(struct expr_parse_ctx *ctx);
39 
40 void expr__del_id(struct expr_parse_ctx *ctx, const char *id);
41 int expr__add_id(struct expr_parse_ctx *ctx, const char *id);
42 int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val);
43 int expr__add_id_val_source_count(struct expr_parse_ctx *ctx, const char *id,
44 				double val, int source_count);
45 int expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref);
46 int expr__get_id(struct expr_parse_ctx *ctx, const char *id,
47 		 struct expr_id_data **data);
48 bool expr__subset_of_ids(struct expr_parse_ctx *haystack,
49 			 struct expr_parse_ctx *needles);
50 int expr__resolve_id(struct expr_parse_ctx *ctx, const char *id,
51 		     struct expr_id_data **datap);
52 
53 int expr__parse(double *final_val, struct expr_parse_ctx *ctx,
54 		const char *expr);
55 
56 int expr__find_ids(const char *expr, const char *one,
57 		   struct expr_parse_ctx *ids);
58 
59 double expr_id_data__value(const struct expr_id_data *data);
60 double expr_id_data__source_count(const struct expr_id_data *data);
61 double expr__get_literal(const char *literal);
62 
63 #endif
64