From patchwork Fri Nov 13 12:29:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 56508 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp1007700lbb; Fri, 13 Nov 2015 04:32:15 -0800 (PST) X-Received: by 10.67.22.99 with SMTP id hr3mr31602459pad.10.1447417931997; Fri, 13 Nov 2015 04:32:11 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l11si27183755pbq.245.2015.11.13.04.32.11; Fri, 13 Nov 2015 04:32:11 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932729AbbKMMcH (ORCPT + 28 others); Fri, 13 Nov 2015 07:32:07 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:24564 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932657AbbKMMcC (ORCPT ); Fri, 13 Nov 2015 07:32:02 -0500 Received: from 172.24.1.47 (EHLO SZXEML423-HUB.china.huawei.com) ([172.24.1.47]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BQY85712; Fri, 13 Nov 2015 20:29:48 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by SZXEML423-HUB.china.huawei.com (10.82.67.154) with Microsoft SMTP Server id 14.3.235.1; Fri, 13 Nov 2015 20:29:37 +0800 From: Wang Nan To: , , CC: , , , Wang Nan , Arnaldo Carvalho de Melo Subject: [PATCH 05/12] perf tools: Allow BPF program config probing options Date: Fri, 13 Nov 2015 12:29:14 +0000 Message-ID: <1447417761-156094-6-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1447417761-156094-1-git-send-email-wangnan0@huawei.com> References: <1447417761-156094-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A090205.5645D838.018F, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 73b7238ddd59ab28af575d8bfd954911 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org By extending the syntax of BPF object section names, this patch allows user to config probing options like what they can do in 'perf probe'. Test result: For following BPF file bpf.c: SEC("inlines=no\n" "func=SyS_dup?") int func(void *ctx) { return 1; } Cmdline: # ./perf record -e ./test_probe_glob.c ls / ... [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.013 MB perf.data ] # ./perf evlist perf_bpf_probe:func_1 perf_bpf_probe:func Change "inlines=no" to "inlines=yes": Cmdline: # ./perf record -e ./test_probe_glob.c ls / ... [ perf record: Woken up 2 times to write data ] [ perf record: Captured and wrote 0.013 MB perf.data ] # ./perf evlist perf_bpf_probe:func_3 perf_bpf_probe:func_2 perf_bpf_probe:func_1 perf_bpf_probe:func Signed-off-by: Wang Nan Cc: Alexei Starovoitov Cc: Arnaldo Carvalho de Melo Cc: Masami Hiramatsu Cc: Zefan Li Cc: pi3orama@163.com --- tools/perf/util/bpf-loader.c | 50 +++++++++++++++++++++++++++++++++++++++++++- tools/perf/util/config.c | 9 ++++---- tools/perf/util/util.c | 18 ++++++++++++++++ tools/perf/util/util.h | 2 ++ 4 files changed, 74 insertions(+), 5 deletions(-) -- 1.8.3.4 -- 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/ diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 8d78785..a368ead 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -125,6 +125,38 @@ config__module(const char *value, struct perf_probe_event *pev) return 0; } +static int +config__bool(const char *value, + bool *pbool, bool invert) +{ + int err; + bool bool_value; + + if (!pbool) + return -EINVAL; + + err = convert_str_to_bool(value, &bool_value); + if (err) + return err; + + *pbool = invert ? !bool_value : bool_value; + return 0; +} + +static int +config__inlines(const char *value, + struct perf_probe_event *pev __maybe_unused) +{ + return config__bool(value, &probe_conf.no_inlines, true); +} + +static int +config__force(const char *value, + struct perf_probe_event *pev __maybe_unused) +{ + return config__bool(value, &probe_conf.force_add, false); +} + static struct { const char *key; const char *usage; @@ -142,7 +174,19 @@ static struct { "module= ", "Set kprobe module", config__module, - } + }, + { + "inlines", + "inlines=[yes|no] ", + "Probe at inline symbol", + config__inlines, + }, + { + "force", + "force=[yes|no] ", + "Forcibly add events with existing name", + config__force, + }, }; static int @@ -240,6 +284,10 @@ config_bpf_program(struct bpf_program *prog) const char *config_str; int err; + /* Initialize per-program probing setting */ + probe_conf.no_inlines = false; + probe_conf.force_add = false; + config_str = bpf_program__title(prog, false); if (IS_ERR(config_str)) { pr_debug("bpf: unable to get title for program\n"); diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c index 2e452ac..8219798 100644 --- a/tools/perf/util/config.c +++ b/tools/perf/util/config.c @@ -351,15 +351,16 @@ int perf_config_int(const char *name, const char *value) static int perf_config_bool_or_int(const char *name, const char *value, int *is_bool) { + bool str_bool; + *is_bool = 1; if (!value) return 1; if (!*value) return 0; - if (!strcasecmp(value, "true") || !strcasecmp(value, "yes") || !strcasecmp(value, "on")) - return 1; - if (!strcasecmp(value, "false") || !strcasecmp(value, "no") || !strcasecmp(value, "off")) - return 0; + + if (convert_str_to_bool(value, &str_bool) == 0) + return str_bool ? 1 : 0; *is_bool = 0; return perf_config_int(name, value); } diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 47b1e36..55785d5 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -695,3 +695,21 @@ fetch_kernel_version(unsigned int *puint, char *str, *puint = (version << 16) + (patchlevel << 8) + sublevel; return 0; } + +int convert_str_to_bool(const char *str, bool *result) +{ + if (!result || !str) + return -EINVAL; + + if (!strcasecmp(str, "true") || !strcasecmp(str, "yes") || !strcasecmp(str, "on")) { + *result = true; + return 0; + } + + if (!strcasecmp(str, "false") || !strcasecmp(str, "no") || !strcasecmp(str, "off")) { + *result = false; + return 0; + } + + return -EINVAL; +} diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index dcc6590..be90932 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -358,4 +358,6 @@ int fetch_kernel_version(unsigned int *puint, #define KVER_FMT "%d.%d.%d" #define KVER_PARAM(x) KVER_VERSION(x), KVER_PATCHLEVEL(x), KVER_SUBLEVEL(x) +int convert_str_to_bool(const char *str, bool *result); + #endif /* GIT_COMPAT_UTIL_H */