Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
11struct metric_ref;
12
13struct expr_scanner_ctx {
14 char *user_requested_cpu_list;
15 int runtime;
16 bool system_wide;
17};
18
19struct expr_parse_ctx {
20 struct hashmap *ids;
21 struct expr_scanner_ctx sctx;
22};
23
24struct expr_id_data;
25
26struct hashmap *ids__new(void);
27void ids__free(struct hashmap *ids);
28int 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 */
33struct hashmap *ids__union(struct hashmap *ids1, struct hashmap *ids2);
34
35struct expr_parse_ctx *expr__ctx_new(void);
36void expr__ctx_clear(struct expr_parse_ctx *ctx);
37void expr__ctx_free(struct expr_parse_ctx *ctx);
38
39void expr__del_id(struct expr_parse_ctx *ctx, const char *id);
40int expr__add_id(struct expr_parse_ctx *ctx, const char *id);
41int expr__add_id_val(struct expr_parse_ctx *ctx, const char *id, double val);
42int expr__add_id_val_source_count(struct expr_parse_ctx *ctx, const char *id,
43 double val, int source_count);
44int expr__add_ref(struct expr_parse_ctx *ctx, struct metric_ref *ref);
45int expr__get_id(struct expr_parse_ctx *ctx, const char *id,
46 struct expr_id_data **data);
47bool expr__subset_of_ids(struct expr_parse_ctx *haystack,
48 struct expr_parse_ctx *needles);
49int expr__resolve_id(struct expr_parse_ctx *ctx, const char *id,
50 struct expr_id_data **datap);
51
52int expr__parse(double *final_val, struct expr_parse_ctx *ctx,
53 const char *expr);
54
55int expr__find_ids(const char *expr, const char *one,
56 struct expr_parse_ctx *ids);
57
58double expr_id_data__value(const struct expr_id_data *data);
59double expr_id_data__source_count(const struct expr_id_data *data);
60double expr__get_literal(const char *literal, const struct expr_scanner_ctx *ctx);
61
62#endif