libtracefs: Add "precedence" to tracefs_synth_add_start/end_filter()
PATCH v2 1/1 libtracefs: Add "precedence" to tracefs_synth_add_start/end_filter()
From: "Steven Rostedt (VMware)" <[email protected]>
While implementing the sqlhist, I found that the tracefs_synth_add_start/end_filter() was not sufficient in adding the possible filters that the kernel accepts. That is, we could not implement:
A && (B || C) && D
as it only allowed appending operators, and the kernel sets && as a higher precedence than ||. That is, if we try to do the above with just:
A && B || C && D
The kernel will interpret it as:
(A && B) || (C && D)
To fix this, add a "precedence" that will allow the user to add "parenthesis" to the logic:
#define AND 0 #define OR 1
1. tracefs_synth_add_start( A, 0, AND);
2. tracefs_synth_add_start( B, 1, AND);
3. tracefs_synth_add_start( C, 1, OR);
4. tracefs_synth_add_start( D, 0, AND);
Will produce the A && (B || C) && D
Because 1, will add A (AND is ignored) and save precedence '0'
2, will add B, but precedence is 1, so 1 '(' is added 3, will add C, with same precedence as step 2. 4, will add D, but since the precedence dropped, it adds
a ')' before the "&&"
The "neg" is given a precedence too, to state where to add the "!"
(note, the original code had "-" for negative, which was wrong)
To produce: (A || !(B && !C)) && D
This time with (compare, neg, precedence, do_or)
1. tracefs_synth_add_start( A, 0, 1, AND);
2. tracefs_synth_add_start( B, 2, 2, OR);
3. tracefs_synth_add_start( C, 1, 2, AND);
4. tracefs_synth_add_start( D, 0, 0, AND);
Also, rename the parameter in tracefs from "or" to "or_conj" as "or" is a keyword in C++ as reported by Yordan Karadzhov:
---
Changes since v1:
- Fixed the return of add_synth_filter()
include/tracefs.h | 8 +- src/tracefs-hist.c | 206 +++++++++++++++++++++++++-------------------- 2 files changed, 117 insertions(+), 97 deletions(-)
include/tracefs.h +4 -4
@@ -354,13 +354,13 @@ int tracefs_synth_add_end_field(struct tracefs_synth *synth,int tracefs_synth_add_start_filter (struct tracefs_synth *synth,const char *field,enum tracefs_synth_compare compare, -const char *val, -bool neg,bool or); +const char *val,unsigned int neg, +unsigned int precedence,bool or_conj);int tracefs_synth_add_end_filter (struct tracefs_synth *synth,const char *field,enum tracefs_synth_compare compare, -const char *val, -bool neg,bool or); +const char *val,unsigned int neg, +unsigned int precedence,bool or_conj);int tracefs_synth_create (struct tracefs_instance *instance,struct tracefs_synth *synth); int tracefs_synth_destroy(struct tracefs_instance *instance,
src/tracefs-hist.c +113 -93
313 lines not on this page · raw message
Signature · 1 line
2.31.1