xref: /linux/tools/perf/util/expr.h (revision f6fb0960f920e3040088992f32bbceded7a74322)
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,
6ded80bdaSIan Rogers // for now use our copy uncoditionally, 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 
16*f6fb0960SJiri Olsa struct expr_id {
17*f6fb0960SJiri Olsa 	char		*id;
18*f6fb0960SJiri Olsa 	struct expr_id	*parent;
19*f6fb0960SJiri Olsa };
20*f6fb0960SJiri Olsa 
21aecce63eSJiri Olsa struct expr_parse_ctx {
22ded80bdaSIan Rogers 	struct hashmap	 ids;
23*f6fb0960SJiri Olsa 	struct expr_id	*parent;
2407516736SAndi Kleen };
2507516736SAndi Kleen 
26070b3b5aSJiri Olsa struct expr_id_data {
27fc393839SJiri Olsa 	union {
28070b3b5aSJiri Olsa 		double val;
29fc393839SJiri Olsa 		struct {
30fc393839SJiri Olsa 			const char *metric_name;
31fc393839SJiri Olsa 			const char *metric_expr;
32acf71b05SJiri Olsa 			bool counted;
33fc393839SJiri Olsa 		} ref;
34*f6fb0960SJiri Olsa 		struct expr_id	*parent;
35fc393839SJiri Olsa 	};
36fc393839SJiri Olsa 
37fc393839SJiri Olsa 	bool is_ref;
38070b3b5aSJiri Olsa };
39070b3b5aSJiri Olsa 
40871f9f59SJiri Olsa struct expr_scanner_ctx {
41871f9f59SJiri Olsa 	int start_token;
421e1a873dSKajol Jain 	int runtime;
43871f9f59SJiri Olsa };
44871f9f59SJiri Olsa 
45aecce63eSJiri Olsa void expr__ctx_init(struct expr_parse_ctx *ctx);
46ded80bdaSIan Rogers void expr__ctx_clear(struct expr_parse_ctx *ctx);
473fd29fa6SJiri Olsa void expr__del_id(struct expr_parse_ctx *ctx, const char *id);
48332603c2SJiri Olsa int expr__add_id(struct expr_parse_ctx *ctx, const char *id);
492c46f542SJiri Olsa int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val);
50fc393839SJiri Olsa int expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref);
515c5f5e83SJiri Olsa int expr__get_id(struct expr_parse_ctx *ctx, const char *id,
525c5f5e83SJiri Olsa 		 struct expr_id_data **data);
53acf71b05SJiri Olsa int expr__resolve_id(struct expr_parse_ctx *ctx, const char *id,
54acf71b05SJiri Olsa 		     struct expr_id_data **datap);
55ded80bdaSIan Rogers int expr__parse(double *final_val, struct expr_parse_ctx *ctx,
56ded80bdaSIan Rogers 		const char *expr, int runtime);
57ded80bdaSIan Rogers int expr__find_other(const char *expr, const char *one,
58ded80bdaSIan Rogers 		struct expr_parse_ctx *ids, int runtime);
5907516736SAndi Kleen 
6007516736SAndi Kleen #endif
61