expr.c (fc393839c11bbe2c7f1a44ab34e5f2a219d8366e) expr.c (acf71b05d1a19726594a8436ba9d8af871941e6c)
1// SPDX-License-Identifier: GPL-2.0
2#include <stdbool.h>
3#include <assert.h>
4#include <errno.h>
5#include <stdlib.h>
6#include <string.h>
7#include "metricgroup.h"
8#include "debug.h"

--- 98 unchanged lines hidden (view full) ---

107 /*
108 * Intentionally passing just const char pointers,
109 * originally from 'struct pmu_event' object.
110 * We don't need to change them, so there's no
111 * need to create our own copy.
112 */
113 data_ptr->ref.metric_name = ref->metric_name;
114 data_ptr->ref.metric_expr = ref->metric_expr;
1// SPDX-License-Identifier: GPL-2.0
2#include <stdbool.h>
3#include <assert.h>
4#include <errno.h>
5#include <stdlib.h>
6#include <string.h>
7#include "metricgroup.h"
8#include "debug.h"

--- 98 unchanged lines hidden (view full) ---

107 /*
108 * Intentionally passing just const char pointers,
109 * originally from 'struct pmu_event' object.
110 * We don't need to change them, so there's no
111 * need to create our own copy.
112 */
113 data_ptr->ref.metric_name = ref->metric_name;
114 data_ptr->ref.metric_expr = ref->metric_expr;
115 data_ptr->ref.counted = false;
115 data_ptr->is_ref = true;
116
117 ret = hashmap__set(&ctx->ids, name, data_ptr,
118 (const void **)&old_key, (void **)&old_data);
119 if (ret)
120 free(data_ptr);
121
122 pr_debug2("adding ref metric %s: %s\n",

--- 5 unchanged lines hidden (view full) ---

128}
129
130int expr__get_id(struct expr_parse_ctx *ctx, const char *id,
131 struct expr_id_data **data)
132{
133 return hashmap__find(&ctx->ids, id, (void **)data) ? 0 : -1;
134}
135
116 data_ptr->is_ref = true;
117
118 ret = hashmap__set(&ctx->ids, name, data_ptr,
119 (const void **)&old_key, (void **)&old_data);
120 if (ret)
121 free(data_ptr);
122
123 pr_debug2("adding ref metric %s: %s\n",

--- 5 unchanged lines hidden (view full) ---

129}
130
131int expr__get_id(struct expr_parse_ctx *ctx, const char *id,
132 struct expr_id_data **data)
133{
134 return hashmap__find(&ctx->ids, id, (void **)data) ? 0 : -1;
135}
136
137int expr__resolve_id(struct expr_parse_ctx *ctx, const char *id,
138 struct expr_id_data **datap)
139{
140 struct expr_id_data *data;
141
142 if (expr__get_id(ctx, id, datap) || !*datap) {
143 pr_debug("%s not found\n", id);
144 return -1;
145 }
146
147 data = *datap;
148
149 pr_debug2("lookup: is_ref %d, counted %d, val %f: %s\n",
150 data->is_ref, data->ref.counted, data->val, id);
151
152 if (data->is_ref && !data->ref.counted) {
153 data->ref.counted = true;
154 pr_debug("processing metric: %s ENTRY\n", id);
155 if (expr__parse(&data->val, ctx, data->ref.metric_expr, 1)) {
156 pr_debug("%s failed to count\n", id);
157 return -1;
158 }
159 pr_debug("processing metric: %s EXIT: %f\n", id, data->val);
160 }
161
162 return 0;
163}
164
136void expr__del_id(struct expr_parse_ctx *ctx, const char *id)
137{
138 struct expr_id_data *old_val = NULL;
139 char *old_key = NULL;
140
141 hashmap__delete(&ctx->ids, id,
142 (const void **)&old_key, (void **)&old_val);
143 free(old_key);

--- 24 unchanged lines hidden (view full) ---

168 struct expr_scanner_ctx scanner_ctx = {
169 .start_token = start,
170 .runtime = runtime,
171 };
172 YY_BUFFER_STATE buffer;
173 void *scanner;
174 int ret;
175
165void expr__del_id(struct expr_parse_ctx *ctx, const char *id)
166{
167 struct expr_id_data *old_val = NULL;
168 char *old_key = NULL;
169
170 hashmap__delete(&ctx->ids, id,
171 (const void **)&old_key, (void **)&old_val);
172 free(old_key);

--- 24 unchanged lines hidden (view full) ---

197 struct expr_scanner_ctx scanner_ctx = {
198 .start_token = start,
199 .runtime = runtime,
200 };
201 YY_BUFFER_STATE buffer;
202 void *scanner;
203 int ret;
204
205 pr_debug2("parsing metric: %s\n", expr);
206
176 ret = expr_lex_init_extra(&scanner_ctx, &scanner);
177 if (ret)
178 return ret;
179
180 buffer = expr__scan_string(expr, scanner);
181
182#ifdef PARSER_DEBUG
183 expr_debug = 1;

--- 27 unchanged lines hidden ---
207 ret = expr_lex_init_extra(&scanner_ctx, &scanner);
208 if (ret)
209 return ret;
210
211 buffer = expr__scan_string(expr, scanner);
212
213#ifdef PARSER_DEBUG
214 expr_debug = 1;

--- 27 unchanged lines hidden ---