xref: /openbmc/linux/tools/perf/util/expr.h (revision f3531d1a)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef PARSE_CTX_H
3 #define PARSE_CTX_H 1
4 
5 struct hashmap;
6 struct metric_ref;
7 
8 struct expr_scanner_ctx {
9 	char *user_requested_cpu_list;
10 	int runtime;
11 	bool system_wide;
12 };
13 
14 struct expr_parse_ctx {
15 	struct hashmap	*ids;
16 	struct expr_scanner_ctx sctx;
17 };
18 
19 struct expr_id_data;
20 
21 struct hashmap *ids__new(void);
22 void ids__free(struct hashmap *ids);
23 int ids__insert(struct hashmap *ids, const char *id);
24 /*
25  * Union two sets of ids (hashmaps) and construct a third, freeing ids1 and
26  * ids2.
27  */
28 struct hashmap *ids__union(struct hashmap *ids1, struct hashmap *ids2);
29 
30 struct expr_parse_ctx *expr__ctx_new(void);
31 void expr__ctx_clear(struct expr_parse_ctx *ctx);
32 void expr__ctx_free(struct expr_parse_ctx *ctx);
33 
34 void expr__del_id(struct expr_parse_ctx *ctx, const char *id);
35 int expr__add_id(struct expr_parse_ctx *ctx, const char *id);
36 int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val);
37 int expr__add_id_val_source_count(struct expr_parse_ctx *ctx, const char *id,
38 				double val, int source_count);
39 int expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref);
40 int expr__get_id(struct expr_parse_ctx *ctx, const char *id,
41 		 struct expr_id_data **data);
42 bool expr__subset_of_ids(struct expr_parse_ctx *haystack,
43 			 struct expr_parse_ctx *needles);
44 int expr__resolve_id(struct expr_parse_ctx *ctx, const char *id,
45 		     struct expr_id_data **datap);
46 
47 int expr__parse(double *final_val, struct expr_parse_ctx *ctx,
48 		const char *expr);
49 
50 int expr__find_ids(const char *expr, const char *one,
51 		   struct expr_parse_ctx *ids);
52 
53 double expr_id_data__value(const struct expr_id_data *data);
54 double expr_id_data__source_count(const struct expr_id_data *data);
55 double expr__get_literal(const char *literal, const struct expr_scanner_ctx *ctx);
56 
57 #endif
58