From patchwork Thu Sep 15 16:37:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 76334 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp47917qgf; Thu, 15 Sep 2016 09:37:43 -0700 (PDT) X-Received: by 10.66.254.102 with SMTP id ah6mr16060540pad.59.1473957463029; Thu, 15 Sep 2016 09:37:43 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a73si1962352pfc.20.2016.09.15.09.37.42; Thu, 15 Sep 2016 09:37:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755656AbcIOQhk (ORCPT + 27 others); Thu, 15 Sep 2016 12:37:40 -0400 Received: from mail-it0-f41.google.com ([209.85.214.41]:37831 "EHLO mail-it0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754991AbcIOQhO (ORCPT ); Thu, 15 Sep 2016 12:37:14 -0400 Received: by mail-it0-f41.google.com with SMTP id 186so83764351itf.0 for ; Thu, 15 Sep 2016 09:37:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hx9kjwucObeKUvRffigLHhFZeWIcsAlpjUpg0e0ZOpw=; b=Z2wXVHGUIRoGKYK/YDOGfaevfpYmI4CIDbhbyJ4b5g1Rs289OEBq2COBBrMNW6StKb AmAH5QHIbRfH2eopDiZlh0wjY8Ri/O4YjTnYszP/fDWF6Ow2FnYi+MSIj+E0qSeUxVl7 65vPB1Wodkmm4sLbl3lWHqGf3ZeUSoOC0bRIQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hx9kjwucObeKUvRffigLHhFZeWIcsAlpjUpg0e0ZOpw=; b=c5HA0AIDIFW4PEL60KJvc5NJkNqzrtnPNVtIxLy97mKjaR+k2TvGvKyS+gJvtyKX4g mfj4K+vrbTbf3H1P+++gI+8n2+/iBoDyWuw/PeDHtuyG82TGLBE3eV4tBHx7NAGJC8qa Cx7rg3A0W8kIlH4YXuZGcsslDYZbraCtPPFaYmsz8rCEsulCg9G9Obgvix89cmgIOKhR O+ylvTey2NmflTTaHW2WHWiRz/2l2C9hPwtwexUNsl/+c6P07TAB40cqEtidqt1aOypb +4F1ks90MOmpK3mAuf9Eh8mpDqEHs+3CIxWULPw3dFykwQ7mDIzAKQYEzfAGT87ZdV5q bFWQ== X-Gm-Message-State: AE9vXwNLpal+ZWkGFqIP5bhXpn0WM6QfHD8KiRKA+hOSTl5Jwj8TAX6fXHQiIPKyttld5iXa X-Received: by 10.36.148.7 with SMTP id j7mr517143ite.81.1473957432964; Thu, 15 Sep 2016 09:37:12 -0700 (PDT) Received: from t430.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id i80sm1253646ita.5.2016.09.15.09.37.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Sep 2016 09:37:12 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org, adrian.hunter@intel.com Cc: mingo@redhat.com, peterz@infradead.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, acme@infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH V6 1/3] perf tools: making perf_evsel__append_filter() generic Date: Thu, 15 Sep 2016 10:37:06 -0600 Message-Id: <1473957428-28311-2-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1473957428-28311-1-git-send-email-mathieu.poirier@linaro.org> References: <1473957428-28311-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. intelPT and CoreSight) than tracepoints. Signed-off-by: Mathieu Poirier --- 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(-) -- 2.7.4 diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index b8c6766301db..4c2704332c14 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2140,6 +2140,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); @@ -2147,8 +2148,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 21fd573106ed..b93369745e08 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 4d44129e050b..7ab59f15892f 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -234,7 +234,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 6c913c3914fb..9692300585f6 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1762,7 +1762,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; @@ -1793,7 +1793,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;