xref: /linux/tools/perf/util/expr.h (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
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 	bool is_test;
13 };
14 
15 struct expr_parse_ctx {
16 	struct hashmap	*ids;
17 	struct expr_scanner_ctx sctx;
18 };
19 
20 struct expr_id_data;
21 
22 struct hashmap *ids__new(void);
23 void ids__free(struct hashmap *ids);
24 int ids__insert(struct hashmap *ids, const char *id);
25 /*
26  * Union two sets of ids (hashmaps) and construct a third, freeing ids1 and
27  * ids2.
28  */
29 struct hashmap *ids__union(struct hashmap *ids1, struct hashmap *ids2);
30 
31 struct expr_parse_ctx *expr__ctx_new(void);
32 void expr__ctx_clear(struct expr_parse_ctx *ctx);
33 void expr__ctx_free(struct expr_parse_ctx *ctx);
34 
35 void expr__del_id(struct expr_parse_ctx *ctx, const char *id);
36 int expr__add_id(struct expr_parse_ctx *ctx, const char *id);
37 int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val);
38 int expr__add_id_val_source_count(struct expr_parse_ctx *ctx, const char *id,
39 				double val, int source_count);
40 int expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref);
41 int expr__get_id(struct expr_parse_ctx *ctx, const char *id,
42 		 struct expr_id_data **data);
43 bool expr__subset_of_ids(struct expr_parse_ctx *haystack,
44 			 struct expr_parse_ctx *needles);
45 int expr__resolve_id(struct expr_parse_ctx *ctx, const char *id,
46 		     struct expr_id_data **datap);
47 
48 int expr__parse(double *final_val, struct expr_parse_ctx *ctx,
49 		const char *expr);
50 
51 int expr__find_ids(const char *expr, const char *one,
52 		   struct expr_parse_ctx *ids);
53 
54 double expr_id_data__value(const struct expr_id_data *data);
55 double expr_id_data__source_count(const struct expr_id_data *data);
56 double expr__get_literal(const char *literal, const struct expr_scanner_ctx *ctx);
57 double expr__has_event(const struct expr_parse_ctx *ctx, bool compute_ids, const char *id);
58 double expr__strcmp_cpuid_str(const struct expr_parse_ctx *ctx, bool compute_ids, const char *id);
59 
60 #endif
61