Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
07516736 AK |
2 | #ifndef PARSE_CTX_H |
3 | #define PARSE_CTX_H 1 | |
4 | ||
bdf45725 IR |
5 | #ifdef HAVE_LIBBPF_SUPPORT |
6 | #include <bpf/hashmap.h> | |
7 | #else | |
ded80bda | 8 | #include "util/hashmap.h" |
bdf45725 | 9 | #endif |
07516736 | 10 | |
fc393839 JO |
11 | struct metric_ref; |
12 | ||
1a6abdde | 13 | struct expr_scanner_ctx { |
1725e9cd | 14 | char *user_requested_cpu_list; |
1a6abdde | 15 | int runtime; |
1725e9cd | 16 | bool system_wide; |
1a6abdde IR |
17 | }; |
18 | ||
aecce63e | 19 | struct expr_parse_ctx { |
cb94a02e | 20 | struct hashmap *ids; |
1a6abdde | 21 | struct expr_scanner_ctx sctx; |
07516736 AK |
22 | }; |
23 | ||
29396cd5 | 24 | struct expr_id_data; |
070b3b5a | 25 | |
114a9d6e IR |
26 | struct hashmap *ids__new(void); |
27 | void ids__free(struct hashmap *ids); | |
80be6434 | 28 | int ids__insert(struct hashmap *ids, const char *id); |
114a9d6e IR |
29 | /* |
30 | * Union two sets of ids (hashmaps) and construct a third, freeing ids1 and | |
31 | * ids2. | |
32 | */ | |
33 | struct hashmap *ids__union(struct hashmap *ids1, struct hashmap *ids2); | |
34 | ||
cb94a02e | 35 | struct expr_parse_ctx *expr__ctx_new(void); |
ded80bda | 36 | void expr__ctx_clear(struct expr_parse_ctx *ctx); |
cb94a02e | 37 | void expr__ctx_free(struct expr_parse_ctx *ctx); |
114a9d6e | 38 | |
3fd29fa6 | 39 | void expr__del_id(struct expr_parse_ctx *ctx, const char *id); |
332603c2 | 40 | int expr__add_id(struct expr_parse_ctx *ctx, const char *id); |
2c46f542 | 41 | int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val); |
9aba0ada IR |
42 | int expr__add_id_val_source_count(struct expr_parse_ctx *ctx, const char *id, |
43 | double val, int source_count); | |
fc393839 | 44 | int expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref); |
5c5f5e83 JO |
45 | int expr__get_id(struct expr_parse_ctx *ctx, const char *id, |
46 | struct expr_id_data **data); | |
798c3f4a IR |
47 | bool expr__subset_of_ids(struct expr_parse_ctx *haystack, |
48 | struct expr_parse_ctx *needles); | |
acf71b05 JO |
49 | int expr__resolve_id(struct expr_parse_ctx *ctx, const char *id, |
50 | struct expr_id_data **datap); | |
114a9d6e | 51 | |
ded80bda | 52 | int expr__parse(double *final_val, struct expr_parse_ctx *ctx, |
fa831fbb | 53 | const char *expr); |
114a9d6e | 54 | |
7e06a5e3 | 55 | int expr__find_ids(const char *expr, const char *one, |
fa831fbb | 56 | struct expr_parse_ctx *ids); |
07516736 | 57 | |
29396cd5 | 58 | double expr_id_data__value(const struct expr_id_data *data); |
9aba0ada | 59 | double expr_id_data__source_count(const struct expr_id_data *data); |
1725e9cd | 60 | double expr__get_literal(const char *literal, const struct expr_scanner_ctx *ctx); |
29396cd5 | 61 | |
07516736 | 62 | #endif |