Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Andi Kleen | 0751673 | 2017-03-20 13:17:05 -0700 | [diff] [blame] | 2 | #ifndef PARSE_CTX_H |
| 3 | #define PARSE_CTX_H 1 |
| 4 | |
Ian Rogers | ded80bd | 2020-05-15 15:17:32 -0700 | [diff] [blame] | 5 | // There are fixes that need to land upstream before we can use libbpf's headers, |
| 6 | // for now use our copy uncoditionally, 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 |
Andi Kleen | 0751673 | 2017-03-20 13:17:05 -0700 | [diff] [blame] | 13 | |
Jiri Olsa | fc39383 | 2020-07-19 20:13:11 +0200 | [diff] [blame] | 14 | struct metric_ref; |
| 15 | |
Jiri Olsa | f6fb096 | 2020-07-19 20:13:16 +0200 | [diff] [blame] | 16 | struct expr_id { |
| 17 | char *id; |
| 18 | struct expr_id *parent; |
| 19 | }; |
| 20 | |
Jiri Olsa | aecce63 | 2020-04-02 02:03:34 +0530 | [diff] [blame] | 21 | struct expr_parse_ctx { |
Jiri Olsa | f6fb096 | 2020-07-19 20:13:16 +0200 | [diff] [blame] | 22 | struct hashmap ids; |
| 23 | struct expr_id *parent; |
Andi Kleen | 0751673 | 2017-03-20 13:17:05 -0700 | [diff] [blame] | 24 | }; |
| 25 | |
Jiri Olsa | 070b3b5 | 2020-07-12 15:26:18 +0200 | [diff] [blame] | 26 | struct expr_id_data { |
Jiri Olsa | fc39383 | 2020-07-19 20:13:11 +0200 | [diff] [blame] | 27 | union { |
| 28 | double val; |
| 29 | struct { |
| 30 | const char *metric_name; |
| 31 | const char *metric_expr; |
Jiri Olsa | acf71b0 | 2020-07-19 20:13:12 +0200 | [diff] [blame] | 32 | bool counted; |
Jiri Olsa | fc39383 | 2020-07-19 20:13:11 +0200 | [diff] [blame] | 33 | } ref; |
Jiri Olsa | f6fb096 | 2020-07-19 20:13:16 +0200 | [diff] [blame] | 34 | struct expr_id *parent; |
Jiri Olsa | fc39383 | 2020-07-19 20:13:11 +0200 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | bool is_ref; |
Jiri Olsa | 070b3b5 | 2020-07-12 15:26:18 +0200 | [diff] [blame] | 38 | }; |
| 39 | |
Jiri Olsa | 871f9f5 | 2020-04-02 02:03:35 +0530 | [diff] [blame] | 40 | struct expr_scanner_ctx { |
| 41 | int start_token; |
Kajol Jain | 1e1a873 | 2020-04-02 02:03:37 +0530 | [diff] [blame] | 42 | int runtime; |
Jiri Olsa | 871f9f5 | 2020-04-02 02:03:35 +0530 | [diff] [blame] | 43 | }; |
| 44 | |
Jiri Olsa | aecce63 | 2020-04-02 02:03:34 +0530 | [diff] [blame] | 45 | void expr__ctx_init(struct expr_parse_ctx *ctx); |
Ian Rogers | ded80bd | 2020-05-15 15:17:32 -0700 | [diff] [blame] | 46 | void expr__ctx_clear(struct expr_parse_ctx *ctx); |
Jiri Olsa | 3fd29fa | 2020-07-19 20:13:05 +0200 | [diff] [blame] | 47 | void expr__del_id(struct expr_parse_ctx *ctx, const char *id); |
Jiri Olsa | 332603c | 2020-07-19 20:13:03 +0200 | [diff] [blame] | 48 | int expr__add_id(struct expr_parse_ctx *ctx, const char *id); |
Jiri Olsa | 2c46f54 | 2020-07-12 15:26:17 +0200 | [diff] [blame] | 49 | int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val); |
Jiri Olsa | fc39383 | 2020-07-19 20:13:11 +0200 | [diff] [blame] | 50 | int expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref); |
Jiri Olsa | 5c5f5e8 | 2020-07-19 20:13:04 +0200 | [diff] [blame] | 51 | int expr__get_id(struct expr_parse_ctx *ctx, const char *id, |
| 52 | struct expr_id_data **data); |
Jiri Olsa | acf71b0 | 2020-07-19 20:13:12 +0200 | [diff] [blame] | 53 | int expr__resolve_id(struct expr_parse_ctx *ctx, const char *id, |
| 54 | struct expr_id_data **datap); |
Ian Rogers | ded80bd | 2020-05-15 15:17:32 -0700 | [diff] [blame] | 55 | int expr__parse(double *final_val, struct expr_parse_ctx *ctx, |
| 56 | const char *expr, int runtime); |
| 57 | int expr__find_other(const char *expr, const char *one, |
| 58 | struct expr_parse_ctx *ids, int runtime); |
Andi Kleen | 0751673 | 2017-03-20 13:17:05 -0700 | [diff] [blame] | 59 | |
| 60 | #endif |