blob: fc2b5e824a66306665a979b5608006841d8794c1 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Andi Kleen07516732017-03-20 13:17:05 -07002#ifndef PARSE_CTX_H
3#define PARSE_CTX_H 1
4
Ian Rogersded80bd2020-05-15 15:17:32 -07005// 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 Kleen07516732017-03-20 13:17:05 -070013
Jiri Olsafc393832020-07-19 20:13:11 +020014struct metric_ref;
15
Jiri Olsaf6fb0962020-07-19 20:13:16 +020016struct expr_id {
17 char *id;
18 struct expr_id *parent;
19};
20
Jiri Olsaaecce632020-04-02 02:03:34 +053021struct expr_parse_ctx {
Jiri Olsaf6fb0962020-07-19 20:13:16 +020022 struct hashmap ids;
23 struct expr_id *parent;
Andi Kleen07516732017-03-20 13:17:05 -070024};
25
Jiri Olsa070b3b52020-07-12 15:26:18 +020026struct expr_id_data {
Jiri Olsafc393832020-07-19 20:13:11 +020027 union {
28 double val;
29 struct {
30 const char *metric_name;
31 const char *metric_expr;
Jiri Olsaacf71b02020-07-19 20:13:12 +020032 bool counted;
Jiri Olsafc393832020-07-19 20:13:11 +020033 } ref;
Jiri Olsaf6fb0962020-07-19 20:13:16 +020034 struct expr_id *parent;
Jiri Olsafc393832020-07-19 20:13:11 +020035 };
36
37 bool is_ref;
Jiri Olsa070b3b52020-07-12 15:26:18 +020038};
39
Jiri Olsa871f9f52020-04-02 02:03:35 +053040struct expr_scanner_ctx {
41 int start_token;
Kajol Jain1e1a8732020-04-02 02:03:37 +053042 int runtime;
Jiri Olsa871f9f52020-04-02 02:03:35 +053043};
44
Jiri Olsaaecce632020-04-02 02:03:34 +053045void expr__ctx_init(struct expr_parse_ctx *ctx);
Ian Rogersded80bd2020-05-15 15:17:32 -070046void expr__ctx_clear(struct expr_parse_ctx *ctx);
Jiri Olsa3fd29fa2020-07-19 20:13:05 +020047void expr__del_id(struct expr_parse_ctx *ctx, const char *id);
Jiri Olsa332603c2020-07-19 20:13:03 +020048int expr__add_id(struct expr_parse_ctx *ctx, const char *id);
Jiri Olsa2c46f542020-07-12 15:26:17 +020049int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val);
Jiri Olsafc393832020-07-19 20:13:11 +020050int expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref);
Jiri Olsa5c5f5e82020-07-19 20:13:04 +020051int expr__get_id(struct expr_parse_ctx *ctx, const char *id,
52 struct expr_id_data **data);
Jiri Olsaacf71b02020-07-19 20:13:12 +020053int expr__resolve_id(struct expr_parse_ctx *ctx, const char *id,
54 struct expr_id_data **datap);
Ian Rogersded80bd2020-05-15 15:17:32 -070055int expr__parse(double *final_val, struct expr_parse_ctx *ctx,
56 const char *expr, int runtime);
57int expr__find_other(const char *expr, const char *one,
58 struct expr_parse_ctx *ids, int runtime);
Andi Kleen07516732017-03-20 13:17:05 -070059
60#endif