From patchwork Sun Sep 6 05:55:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 53162 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by patches.linaro.org (Postfix) with ESMTPS id 6EB8E212FE for ; Sun, 6 Sep 2015 05:56:58 +0000 (UTC) Received: by lanb10 with SMTP id b10sf18066812lan.3 for ; Sat, 05 Sep 2015 22:56:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe; bh=mWhw6pZlzgxbqZAK/SGg8LzENdI6dW/Z935qDwNFpV8=; b=e4CM/zvkzYA3cb/U97l3keYi9NhVUd68GZa14lJQ4HHqsey5DydbaCNdz6mIrwf58E /EOCl295he32iMIembWNBrqEFV1QmzFCEas/WRIvzfK37oso8W9UTpLyBiKflhBMUkxo JkNC5+0OfqJzzvX1xhh+U6fPeaXDz2QNous4EZsCmQzoRsOqJ4c2okIdrixx3F/20Adq O8RVYkSbXpCnhkShJEWjSmPasZCDgjGBDI9nQzAZ7Dr2D9HgAAV1ybV3h+Qmrt4eWXyo qc2VLk9+4H/jd1Nip5SX2eOVx1aB6wMgP7DOvLwD/XcyWQ2MyOz51c6JXaK5JgExlIXp qSbw== X-Gm-Message-State: ALoCoQkBjmm/+8+vl6lgXKRowk/fXdITe+J2ZrOlZK6lPShBFu/egC3rC57DtKANYPGgygfjGr/E X-Received: by 10.180.188.211 with SMTP id gc19mr253813wic.6.1441519017015; Sat, 05 Sep 2015 22:56:57 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.1.73 with SMTP id 9ls417972lak.17.gmail; Sat, 05 Sep 2015 22:56:56 -0700 (PDT) X-Received: by 10.152.228.135 with SMTP id si7mr11561374lac.77.1441519016810; Sat, 05 Sep 2015 22:56:56 -0700 (PDT) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id l10si7064057lah.173.2015.09.05.22.56.56 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 05 Sep 2015 22:56:56 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by lamp12 with SMTP id p12so34157687lam.0 for ; Sat, 05 Sep 2015 22:56:56 -0700 (PDT) X-Received: by 10.112.168.66 with SMTP id zu2mr991912lbb.29.1441519016648; Sat, 05 Sep 2015 22:56:56 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.164.42 with SMTP id yn10csp819753lbb; Sat, 5 Sep 2015 22:56:55 -0700 (PDT) X-Received: by 10.68.196.233 with SMTP id ip9mr29765390pbc.139.1441519015228; Sat, 05 Sep 2015 22:56:55 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v3si13446046pbs.195.2015.09.05.22.56.54; Sat, 05 Sep 2015 22:56:55 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751287AbbIFF4u (ORCPT + 28 others); Sun, 6 Sep 2015 01:56:50 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:41544 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750987AbbIFF4k (ORCPT ); Sun, 6 Sep 2015 01:56:40 -0400 Received: from 172.24.1.51 (EHLO szxeml428-hub.china.huawei.com) ([172.24.1.51]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CRV76257; Sun, 06 Sep 2015 13:55:38 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml428-hub.china.huawei.com (10.82.67.183) with Microsoft SMTP Server id 14.3.235.1; Sun, 6 Sep 2015 13:55:25 +0800 From: Wang Nan To: CC: , Wang Nan , "Alexei Starovoitov" , Brendan Gregg , Daniel Borkmann , David Ahern , "He Kuang" , Jiri Olsa , Kaixu Xia , Masami Hiramatsu , Namhyung Kim , Paul Mackerras , Peter Zijlstra , Zefan Li , Subject: [PATCH] perf tools: Allow BPF placeholder dummy events to collect --filter options Date: Sun, 6 Sep 2015 05:55:18 +0000 Message-ID: <1441518918-149316-1-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1440822125-52691-4-git-send-email-wangnan0@huawei.com> References: <1440822125-52691-4-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: wangnan0@huawei.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch improves collection and setting of filters, allows --filter be set to BPF placeholder events (which is a software dummy event). perf_evsel__is_dummy(), perf_evsel__is_bpf_placeholder() and perf_evsel__can_filter() are introduced for this. Test result: # perf record --event dummy --exclude-perf --exclude-perf option should follow a -e tracepoint option # perf record --event dummy:u --exclude-perf ls --exclude-perf option should follow a -e tracepoint option # perf record --event test.o --exclude-perf ls Added new event: perf_bpf_probe:func_vfs_write (on vfs_write) ... # perf record --event dummy.o --exclude-perf ls Added new event: perf_bpf_probe:func_write (on sys_write) ... Signed-off-by: Wang Nan Cc: Alexei Starovoitov Cc: Brendan Gregg Cc: Daniel Borkmann Cc: David Ahern Cc: He Kuang Cc: Jiri Olsa Cc: Kaixu Xia Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Zefan Li Cc: pi3orama@163.com Cc: Arnaldo Carvalho de Melo --- tools/perf/util/evlist.c | 7 +++++++ tools/perf/util/evsel.c | 32 ++++++++++++++++++++++++++++++++ tools/perf/util/evsel.h | 23 +++++++++++++++++++++++ tools/perf/util/parse-events.c | 4 ++-- 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 93db4c1..29212dc 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1223,6 +1223,13 @@ int perf_evlist__apply_filters(struct perf_evlist *evlist, struct perf_evsel **e continue; /* + * Filters are allowed to be set to dummy event for BPF object + * placeholder. Don't really apply them. + */ + if (perf_evsel__is_dummy(evsel)) + continue; + + /* * filters only work for tracepoint event, which doesn't have cpu limit. * So evlist and evsel should always be same. */ diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 73cf9fc..e307ea2 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2344,3 +2344,35 @@ int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target, err, strerror_r(err, sbuf, sizeof(sbuf)), perf_evsel__name(evsel)); } + +bool perf_evsel__is_bpf_placeholder(struct perf_evsel *evsel) +{ + if (!perf_evsel__is_dummy(evsel)) + return false; + if (!evsel->name) + return false; + /* + * If evsel->name doesn't starts with 'dummy', it must be a BPF + * place holder. + */ + if (strncmp(evsel->name, perf_evsel__sw_names[PERF_COUNT_SW_DUMMY], + strlen(perf_evsel__sw_names[PERF_COUNT_SW_DUMMY]))) + return true; + /* + * Very rare case: evsel->name is 'dummy_crazy.bpf'. + * + * Let's check name suffix. A bpf file should ends with one of: + * '.o', '.c' or '.bpf'. + */ +#define SUFFIX_CMP(s)\ + strcmp(evsel->name + strlen(evsel->name) - (sizeof(s) - 1), s) + + if (SUFFIX_CMP(".o") == 0) + return true; + if (SUFFIX_CMP(".c") == 0) + return true; + if (SUFFIX_CMP(".bpf") == 0) + return true; + return false; +#undef SUFFIX_CMP +} diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index fd22f83..864fd3f 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -372,11 +372,34 @@ bool perf_evsel__fallback(struct perf_evsel *evsel, int err, int perf_evsel__open_strerror(struct perf_evsel *evsel, struct target *target, int err, char *msg, size_t size); +bool perf_evsel__is_bpf_placeholder(struct perf_evsel *evsel); + static inline int perf_evsel__group_idx(struct perf_evsel *evsel) { return evsel->idx - evsel->leader->idx; } +static inline bool perf_evsel__is_dummy(struct perf_evsel *evsel) +{ + if (!evsel) + return false; + if (evsel->attr.type != PERF_TYPE_SOFTWARE) + return false; + if (evsel->attr.config != PERF_COUNT_SW_DUMMY) + return false; + return true; +} + +static inline int perf_evsel__can_filter(struct perf_evsel *evsel) +{ + if (!evsel) + return false; + if (evsel->attr.type == PERF_TYPE_TRACEPOINT) + return true; + + return perf_evsel__is_bpf_placeholder(evsel); +} + #define for_each_group_member(_evsel, _leader) \ for ((_evsel) = list_entry((_leader)->node.next, struct perf_evsel, node); \ (_evsel) && (_evsel)->leader == (_leader); \ diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index b560f5f..d961e90 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -1346,7 +1346,7 @@ static int set_filter(struct perf_evsel *evsel, const void *arg) { const char *str = arg; - if (evsel == NULL || evsel->attr.type != PERF_TYPE_TRACEPOINT) { + if (!perf_evsel__can_filter(evsel)) { fprintf(stderr, "--filter option should follow a -e tracepoint option\n"); return -1; @@ -1375,7 +1375,7 @@ static int add_exclude_perf_filter(struct perf_evsel *evsel, { char new_filter[64]; - if (evsel == NULL || evsel->attr.type != PERF_TYPE_TRACEPOINT) { + if (!perf_evsel__can_filter(evsel)) { fprintf(stderr, "--exclude-perf option should follow a -e tracepoint option\n"); return -1;