From patchwork Thu Sep 29 14:35:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 9356507 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8D29F600C8 for ; Thu, 29 Sep 2016 14:38:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D65429ADD for ; Thu, 29 Sep 2016 14:38:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 722BB29AE2; Thu, 29 Sep 2016 14:38:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0FB1529ADD for ; Thu, 29 Sep 2016 14:38:58 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bpcSl-0008CI-WA; Thu, 29 Sep 2016 14:37:28 +0000 Received: from 179-240-180-13.3g.claro.net.br ([179.240.180.13] helo=jouet.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.85_2 #1 (Red Hat Linux)) id 1bpcS7-0007rA-Vy; Thu, 29 Sep 2016 14:36:48 +0000 Received: by jouet.infradead.org (Postfix, from userid 1000) id B51441415DD; Thu, 29 Sep 2016 11:36:09 -0300 (BRT) From: Arnaldo Carvalho de Melo To: Ingo Molnar Subject: [PATCH 06/27] perf tools: Make perf_evsel__append_filter() generic Date: Thu, 29 Sep 2016 11:35:35 -0300 Message-Id: <1475159756-21326-7-git-send-email-acme@kernel.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1475159756-21326-1-git-send-email-acme@kernel.org> References: <1475159756-21326-1-git-send-email-acme@kernel.org> X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mathieu Poirier , Alexander Shishkin , linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , Peter Zijlstra , Jiri Olsa , Linux Weekly News , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Mathieu Poirier By making function perf_evsel__append_filter() take a format rather than an operator it is possible to reuse the code for other purposes (ex. Intel PT and CoreSight) than tracepoints. Signed-off-by: Mathieu Poirier Acked-by: Adrian Hunter Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Peter Zijlstra Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/1474037045-31730-2-git-send-email-mathieu.poirier@linaro.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-trace.c | 9 +++++++-- tools/perf/util/evsel.c | 4 ++-- tools/perf/util/evsel.h | 2 +- tools/perf/util/parse-events.c | 4 ++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 1a54ce9d101c..e04ba9d852d4 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2143,6 +2143,7 @@ out_delete_sys_enter: static int trace__set_ev_qualifier_filter(struct trace *trace) { int err = -1; + struct perf_evsel *sys_exit; char *filter = asprintf_expr_inout_ints("id", !trace->not_ev_qualifier, trace->ev_qualifier_ids.nr, trace->ev_qualifier_ids.entries); @@ -2150,8 +2151,12 @@ static int trace__set_ev_qualifier_filter(struct trace *trace) if (filter == NULL) goto out_enomem; - if (!perf_evsel__append_filter(trace->syscalls.events.sys_enter, "&&", filter)) - err = perf_evsel__append_filter(trace->syscalls.events.sys_exit, "&&", filter); + if (!perf_evsel__append_filter(trace->syscalls.events.sys_enter, + "(%s) && (%s)", filter)) { + sys_exit = trace->syscalls.events.sys_exit; + err = perf_evsel__append_filter(sys_exit, + "(%s) && (%s)", filter); + } free(filter); out: diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index f3225a2e6eee..4f327b522e5c 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1046,14 +1046,14 @@ int perf_evsel__set_filter(struct perf_evsel *evsel, const char *filter) } int perf_evsel__append_filter(struct perf_evsel *evsel, - const char *op, const char *filter) + const char *fmt, const char *filter) { char *new_filter; if (evsel->filter == NULL) return perf_evsel__set_filter(evsel, filter); - if (asprintf(&new_filter,"(%s) %s (%s)", evsel->filter, op, filter) > 0) { + if (asprintf(&new_filter, fmt, evsel->filter, filter) > 0) { free(evsel->filter); evsel->filter = new_filter; return 0; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 323806082c58..7ef960298b3d 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -236,7 +236,7 @@ void perf_evsel__set_sample_id(struct perf_evsel *evsel, int perf_evsel__set_filter(struct perf_evsel *evsel, const char *filter); int perf_evsel__append_filter(struct perf_evsel *evsel, - const char *op, const char *filter); + const char *fmt, const char *filter); int perf_evsel__apply_filter(struct perf_evsel *evsel, int ncpus, int nthreads, const char *filter); int perf_evsel__enable(struct perf_evsel *evsel); diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 2eb8b1ed4cc8..b14784c765eb 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1767,7 +1767,7 @@ static int set_filter(struct perf_evsel *evsel, const void *arg) return -1; } - if (perf_evsel__append_filter(evsel, "&&", str) < 0) { + if (perf_evsel__append_filter(evsel, "(%s) && (%s)", str) < 0) { fprintf(stderr, "not enough memory to hold filter string\n"); return -1; @@ -1798,7 +1798,7 @@ static int add_exclude_perf_filter(struct perf_evsel *evsel, snprintf(new_filter, sizeof(new_filter), "common_pid != %d", getpid()); - if (perf_evsel__append_filter(evsel, "&&", new_filter) < 0) { + if (perf_evsel__append_filter(evsel, "(%s) && (%s)", new_filter) < 0) { fprintf(stderr, "not enough memory to hold filter string\n"); return -1;