Skip to content

Commit 1e7ab82

Browse files
captain5050acmel
authored andcommitted
perf expr: Move ID handling to its own function
This will facilitate sharing in a follow-on change. Signed-off-by: Ian Rogers <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: John Garry <[email protected]> Cc: Kajol Jain <[email protected]> Cc: Kan Liang <[email protected]> Cc: Madhavan Srinivasan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Paul A . Clarke <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Riccardo Mancini <[email protected]> Cc: Song Liu <[email protected]> Cc: Wan Jiabing <[email protected]> Cc: Yury Norov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent fdf1e29 commit 1e7ab82

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

tools/perf/util/expr.y

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define YYDEBUG 1
44
#include <assert.h>
55
#include <math.h>
6+
#include <stdlib.h>
67
#include "util/debug.h"
78
#define IN_EXPR_Y 1
89
#include "expr.h"
@@ -82,6 +83,39 @@ static struct ids union_expr(struct ids ids1, struct ids ids2)
8283
return result;
8384
}
8485

86+
static struct ids handle_id(struct expr_parse_ctx *ctx, char *id,
87+
bool compute_ids)
88+
{
89+
struct ids result;
90+
91+
if (!compute_ids) {
92+
/*
93+
* Compute the event's value from ID. If the ID isn't known then
94+
* it isn't used to compute the formula so set to NAN.
95+
*/
96+
struct expr_id_data *data;
97+
98+
result.val = NAN;
99+
if (expr__resolve_id(ctx, id, &data) == 0)
100+
result.val = expr_id_data__value(data);
101+
102+
result.ids = NULL;
103+
free(id);
104+
} else {
105+
/*
106+
* Set the value to BOTTOM to show that any value is possible
107+
* when the event is computed. Create a set of just the ID.
108+
*/
109+
result.val = BOTTOM;
110+
result.ids = ids__new();
111+
if (!result.ids || ids__insert(result.ids, id)) {
112+
pr_err("Error creating IDs for '%s'", id);
113+
free(id);
114+
}
115+
}
116+
return result;
117+
}
118+
85119
/*
86120
* If we're not computing ids or $1 and $3 are constants, compute the new
87121
* constant value using OP. Its invariant that there are no ids. If computing
@@ -167,32 +201,7 @@ expr: NUMBER
167201
$$.val = $1;
168202
$$.ids = NULL;
169203
}
170-
| ID
171-
{
172-
if (!compute_ids) {
173-
/*
174-
* Compute the event's value from ID. If the ID isn't known then
175-
* it isn't used to compute the formula so set to NAN.
176-
*/
177-
struct expr_id_data *data;
178-
179-
$$.val = NAN;
180-
if (expr__resolve_id(ctx, $1, &data) == 0)
181-
$$.val = expr_id_data__value(data);
182-
183-
$$.ids = NULL;
184-
free($1);
185-
} else {
186-
/*
187-
* Set the value to BOTTOM to show that any value is possible
188-
* when the event is computed. Create a set of just the ID.
189-
*/
190-
$$.val = BOTTOM;
191-
$$.ids = ids__new();
192-
if (!$$.ids || ids__insert($$.ids, $1))
193-
YYABORT;
194-
}
195-
}
204+
| ID { $$ = handle_id(ctx, $1, compute_ids); }
196205
| expr '|' expr { BINARY_LONG_OP($$, |, $1, $3); }
197206
| expr '&' expr { BINARY_LONG_OP($$, &, $1, $3); }
198207
| expr '^' expr { BINARY_LONG_OP($$, ^, $1, $3); }

0 commit comments

Comments
 (0)