From patchwork Fri Sep 16 14:44:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 76390 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp534800qgf; Fri, 16 Sep 2016 07:44:54 -0700 (PDT) X-Received: by 10.67.3.38 with SMTP id bt6mr23807277pad.86.1474037093933; Fri, 16 Sep 2016 07:44:53 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b77si10075819pfb.196.2016.09.16.07.44.53; Fri, 16 Sep 2016 07:44:53 -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 S935206AbcIPOoZ (ORCPT + 27 others); Fri, 16 Sep 2016 10:44:25 -0400 Received: from mail-it0-f52.google.com ([209.85.214.52]:33871 "EHLO mail-it0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757874AbcIPOoL (ORCPT ); Fri, 16 Sep 2016 10:44:11 -0400 Received: by mail-it0-f52.google.com with SMTP id 15so10561856ita.1 for ; Fri, 16 Sep 2016 07:44:11 -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=ESeyTFWUJe6jktmoV3GoVi15/7wNpMucp3HFHOEnzuA=; b=HTQyHEv4JcT5JVTy/of30pQPQVWHa93NT6K35h02KkG8xvfn3GAh9vosebCLI1fkS6 Xq8/AFRbNfcV6oFXyfHtb/kBh3aOFxiOOUaUfpI4gJ1tFMLXmJ1efcvLmA5VjSmlRLTC ZOuWhD/RU+inAE56oRRcMXI7A9tVGka6AhjJg= 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=ESeyTFWUJe6jktmoV3GoVi15/7wNpMucp3HFHOEnzuA=; b=cGulO1uZe+qHg4axEgwzNr0Os9waj20hTRnvTKUWNeRdRaRpLsXpDNdNycYf0saI/3 wX64KuCpZnwbEbtkYLExDNiH0K0UWq0Vay6007Ui/3deigjQqHJiONBu2Dw9CElE0Ia0 BO2YB+e0PwUBBburfBiaCi6QJ0DvH8OXCcHfCs4ipsrnc/x0mKOwqZzarVmUOes7ikO/ rE6+mUE3wP4Bn4kL5iErqWgzNIGsdTCuiRrPkt2DpAky/w7MyZFBupotNscTj3CiCwEM XX/bpV7QJ/ArauuDj5sQEE4f9gX9I63s/8wTJ3TzPd/OMmc3Q9zky270gFpIEwA7Cl/q Lo8w== X-Gm-Message-State: AE9vXwOvyDWca9WH14AlmKis4HuAHiH66fhNJ0MVwDL16rUgWmq3Ripu7w2RRX3ZZNWWGS5v X-Received: by 10.36.125.137 with SMTP id b131mr6276105itc.55.1474037049864; Fri, 16 Sep 2016 07:44:09 -0700 (PDT) Received: from t430.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id 88sm3811653iol.30.2016.09.16.07.44.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 16 Sep 2016 07:44:09 -0700 (PDT) From: Mathieu Poirier To: acme@kernel.org Cc: adrian.hunter@intel.com, acme@infradead.org, mingo@redhat.com, peterz@infradead.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH V7 1/3] perf tools: making perf_evsel__append_filter() generic Date: Fri, 16 Sep 2016 08:44:03 -0600 Message-Id: <1474037045-31730-2-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1474037045-31730-1-git-send-email-mathieu.poirier@linaro.org> References: <1474037045-31730-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. Intel PT and CoreSight) than tracepoints. Signed-off-by: Mathieu Poirier Acked-by: Adrian Hunter --- 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;