Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965518AbbEFDOa (ORCPT ); Tue, 5 May 2015 23:14:30 -0400 Received: from terminus.zytor.com ([198.137.202.10]:36362 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757954AbbEFDOS (ORCPT ); Tue, 5 May 2015 23:14:18 -0400 Date: Tue, 5 May 2015 20:13:45 -0700 From: tip-bot for Masami Hiramatsu Message-ID: Cc: namhyung@kernel.org, hpa@zytor.com, dsahern@gmail.com, acme@redhat.com, jolsa@redhat.com, mingo@kernel.org, peterz@infradead.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, masami.hiramatsu.pt@hitachi.com Reply-To: tglx@linutronix.de, masami.hiramatsu.pt@hitachi.com, acme@redhat.com, mingo@kernel.org, jolsa@redhat.com, namhyung@kernel.org, hpa@zytor.com, dsahern@gmail.com, linux-kernel@vger.kernel.org, peterz@infradead.org In-Reply-To: <20150424094746.23967.52434.stgit@localhost.localdomain> References: <20150424094746.23967.52434.stgit@localhost.localdomain> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf tools: Add strfilter__string to recover rules string Git-Commit-ID: 3f51972c599cf95702819bd06a7a5412c523ebfe X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3526 Lines: 122 Commit-ID: 3f51972c599cf95702819bd06a7a5412c523ebfe Gitweb: http://git.kernel.org/tip/3f51972c599cf95702819bd06a7a5412c523ebfe Author: Masami Hiramatsu AuthorDate: Fri, 24 Apr 2015 18:47:46 +0900 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 4 May 2015 12:43:54 -0300 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: Masami Hiramatsu Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20150424094746.23967.52434.stgit@localhost.localdomain Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/strfilter.c | 67 +++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/strfilter.h | 9 ++++++ 2 files changed, 76 insertions(+) diff --git a/tools/perf/util/strfilter.c b/tools/perf/util/strfilter.c index f3429cd..bcae659 100644 --- a/tools/perf/util/strfilter.c +++ b/tools/perf/util/strfilter.c @@ -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; +} diff --git a/tools/perf/util/strfilter.h b/tools/perf/util/strfilter.h index d007cdc..cff5eda 100644 --- a/tools/perf/util/strfilter.h +++ b/tools/perf/util/strfilter.h @@ -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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/