![Masami Hiramatsu](/assets/img/avatar_default.png)
Add strfilter for general purpose string filter. Every filter rules are descrived by glob matching pattern and '!' prefix which means Logical NOT. A strfilter consists of those filter rules connected with '&' and '|'. A set of rules can be folded by using '(' and ')'. It also accepts spaces around rules and those operators. Format: <rule> ::= <glob-exp> | "!" <rule> | <rule> <op> <rule> | "(" <rule> ")" <op> ::= "&" | "|" e.g.: "(add* | del*) & *timer" filter rules pass strings which start with add or del and end with timer. This will be used by perf probe --filter. Changes in V2: - Fix to check result of strdup() and strfilter__alloc(). - Encapsulate and simplify interfaces as like regex(3). Cc: 2nddept-manager@sdl.hitachi.co.jp Cc: Franck Bui-Huu <fbuihuu@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com> Cc: Steven Rostedt <rostedt@goodmis.org> LKML-Reference: <20110120141530.25915.12673.stgit@ltc236.sdl.hitachi.co.jp> Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
49 lines
1.3 KiB
C
49 lines
1.3 KiB
C
#ifndef __PERF_STRFILTER_H
|
|
#define __PERF_STRFILTER_H
|
|
/* General purpose glob matching filter */
|
|
|
|
#include <linux/list.h>
|
|
#include <stdbool.h>
|
|
|
|
/* A node of string filter */
|
|
struct strfilter_node {
|
|
struct strfilter_node *l; /* Tree left branche (for &,|) */
|
|
struct strfilter_node *r; /* Tree right branche (for !,&,|) */
|
|
const char *p; /* Operator or rule */
|
|
};
|
|
|
|
/* String filter */
|
|
struct strfilter {
|
|
struct strfilter_node *root;
|
|
};
|
|
|
|
/**
|
|
* strfilter__new - Create a new string filter
|
|
* @rules: Filter rule, which is a combination of glob expressions.
|
|
* @err: Pointer which points an error detected on @rules
|
|
*
|
|
* Parse @rules and return new strfilter. Return NULL if an error detected.
|
|
* In that case, *@err will indicate where it is detected, and *@err is NULL
|
|
* if a memory allocation is failed.
|
|
*/
|
|
struct strfilter *strfilter__new(const char *rules, const char **err);
|
|
|
|
/**
|
|
* strfilter__compare - compare given string and a string filter
|
|
* @self: String filter
|
|
* @str: target string
|
|
*
|
|
* Compare @str and @self. Return true if the str match the rule
|
|
*/
|
|
bool strfilter__compare(struct strfilter *self, const char *str);
|
|
|
|
/**
|
|
* strfilter__delete - delete a string filter
|
|
* @self: String filter to delete
|
|
*
|
|
* Delete @self.
|
|
*/
|
|
void strfilter__delete(struct strfilter *self);
|
|
|
|
#endif
|