提交 3f51972c 编写于 作者: M Masami Hiramatsu 提交者: Arnaldo Carvalho de Melo

perf tools: Add strfilter__string to recover rules string

Add strfilter__string to recover rules string from strfilter.  This will
be good for debugging.
Signed-off-by: NMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20150424094746.23967.52434.stgit@localhost.localdomainSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 4e60a2ca
......@@ -237,3 +237,70 @@ bool strfilter__compare(struct strfilter *filter, const char *str)
return false;
return strfilter_node__compare(filter->root, str);
}
static int strfilter_node__sprint(struct strfilter_node *node, char *buf);
/* sprint node in parenthesis if needed */
static int strfilter_node__sprint_pt(struct strfilter_node *node, char *buf)
{
int len;
int pt = node->r ? 2 : 0; /* don't need to check node->l */
if (buf && pt)
*buf++ = '(';
len = strfilter_node__sprint(node, buf);
if (len < 0)
return len;
if (buf && pt)
*(buf + len) = ')';
return len + pt;
}
static int strfilter_node__sprint(struct strfilter_node *node, char *buf)
{
int len = 0, rlen;
if (!node || !node->p)
return -EINVAL;
switch (*node->p) {
case '|':
case '&':
len = strfilter_node__sprint_pt(node->l, buf);
if (len < 0)
return len;
case '!':
if (buf) {
*(buf + len++) = *node->p;
buf += len;
} else
len++;
rlen = strfilter_node__sprint_pt(node->r, buf);
if (rlen < 0)
return rlen;
len += rlen;
break;
default:
len = strlen(node->p);
if (buf)
strcpy(buf, node->p);
}
return len;
}
char *strfilter__string(struct strfilter *filter)
{
int len;
char *ret = NULL;
len = strfilter_node__sprint(filter->root, NULL);
if (len < 0)
return NULL;
ret = malloc(len + 1);
if (ret)
strfilter_node__sprint(filter->root, ret);
return ret;
}
......@@ -71,4 +71,13 @@ bool strfilter__compare(struct strfilter *filter, const char *str);
*/
void strfilter__delete(struct strfilter *filter);
/**
* strfilter__string - Reconstruct a rule string from filter
* @filter: String filter to reconstruct
*
* Reconstruct a rule string from @filter. This will be good for
* debug messages. Note that returning string must be freed afterward.
*/
char *strfilter__string(struct strfilter *filter);
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册