Merge branches 'acpi-scan', 'acpi-resource', 'acpi-apei', 'acpi-extlog' and 'acpi...
[sfrench/cifs-2.6.git] / tools / perf / util / expr.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef PARSE_CTX_H
3 #define PARSE_CTX_H 1
4
5 #ifdef HAVE_LIBBPF_SUPPORT
6 #include <bpf/hashmap.h>
7 #else
8 #include "util/hashmap.h"
9 #endif
10
11 struct metric_ref;
12
13 struct expr_scanner_ctx {
14         char *user_requested_cpu_list;
15         int runtime;
16         bool system_wide;
17 };
18
19 struct expr_parse_ctx {
20         struct hashmap  *ids;
21         struct expr_scanner_ctx sctx;
22 };
23
24 struct expr_id_data;
25
26 struct hashmap *ids__new(void);
27 void ids__free(struct hashmap *ids);
28 int ids__insert(struct hashmap *ids, const char *id);
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
35 struct expr_parse_ctx *expr__ctx_new(void);
36 void expr__ctx_clear(struct expr_parse_ctx *ctx);
37 void expr__ctx_free(struct expr_parse_ctx *ctx);
38
39 void expr__del_id(struct expr_parse_ctx *ctx, const char *id);
40 int expr__add_id(struct expr_parse_ctx *ctx, const char *id);
41 int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val);
42 int expr__add_id_val_source_count(struct expr_parse_ctx *ctx, const char *id,
43                                 double val, int source_count);
44 int expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref);
45 int expr__get_id(struct expr_parse_ctx *ctx, const char *id,
46                  struct expr_id_data **data);
47 bool expr__subset_of_ids(struct expr_parse_ctx *haystack,
48                          struct expr_parse_ctx *needles);
49 int expr__resolve_id(struct expr_parse_ctx *ctx, const char *id,
50                      struct expr_id_data **datap);
51
52 int expr__parse(double *final_val, struct expr_parse_ctx *ctx,
53                 const char *expr);
54
55 int expr__find_ids(const char *expr, const char *one,
56                    struct expr_parse_ctx *ids);
57
58 double expr_id_data__value(const struct expr_id_data *data);
59 double expr_id_data__source_count(const struct expr_id_data *data);
60 double expr__get_literal(const char *literal, const struct expr_scanner_ctx *ctx);
61
62 #endif