From patchwork Fri Apr 8 15:07:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 65411 Delivered-To: patch@linaro.org Received: by 10.112.43.237 with SMTP id z13csp123708lbl; Fri, 8 Apr 2016 08:08:25 -0700 (PDT) X-Received: by 10.66.160.201 with SMTP id xm9mr13344785pab.68.1460128104241; Fri, 08 Apr 2016 08:08:24 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qm9si1325800pac.165.2016.04.08.08.08.23; Fri, 08 Apr 2016 08:08:24 -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; 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 S1758558AbcDHPIH (ORCPT + 29 others); Fri, 8 Apr 2016 11:08:07 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:46519 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758378AbcDHPIE (ORCPT ); Fri, 8 Apr 2016 11:08:04 -0400 Received: from 172.24.1.48 (EHLO szxeml431-hub.china.huawei.com) ([172.24.1.48]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DEV72771; Fri, 08 Apr 2016 23:07:38 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml431-hub.china.huawei.com (10.82.67.208) with Microsoft SMTP Server id 14.3.235.1; Fri, 8 Apr 2016 23:07:30 +0800 From: Wang Nan To: CC: , , , , Arnaldo Carvalho de Melo , Jiri Olsa Subject: [PATCH 1/4] perf trace: Improve error message when receive non-tracepoint events Date: Fri, 8 Apr 2016 15:07:22 +0000 Message-ID: <1460128045-97310-2-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1460128045-97310-1-git-send-email-wangnan0@huawei.com> References: <1460128045-97310-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.0A020205.5707C93B.0141, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 2fdf13f4fe77750a5c3296a89a1d18f3 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Before this patch, strange error message is provided if passed a non-tracepoint event to 'perf trace': # perf trace -a --ev cycles sleep 1 Failed to set filter "common_pid != 27500" on event cycles with 22 (Invalid argument) This is because 'perf trace' accepts all valid events during cmdline parsing, but in fact user can only provide tracepoints, because it needs filter. This patch validate evlist, report error earlier: # ./perf trace -a --ev cycles sleep 1 Only support tracepoint events! Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Li Zefan Cc: pi3orama@163.com --- tools/perf/builtin-trace.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) -- 1.8.3.4 diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 11290b5..6fbed86 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2680,6 +2680,17 @@ out_enomem: goto out; } +static int validate_evlist(struct perf_evlist *evlist) +{ + struct perf_evsel *evsel; + + evlist__for_each(evlist, evsel) { + if (evsel->attr.type != PERF_TYPE_TRACEPOINT) + return -EINVAL; + } + return 0; +} + static int trace__run(struct trace *trace, int argc, const char **argv) { struct perf_evlist *evlist = trace->evlist; @@ -3273,6 +3284,11 @@ int cmd_trace(int argc, const char **argv, const char *prefix __maybe_unused) argc = parse_options_subcommand(argc, argv, trace_options, trace_subcommands, trace_usage, PARSE_OPT_STOP_AT_NON_OPTION); + if (validate_evlist(trace.evlist)) { + pr_err("Only support tracepoint events!\n"); + return -EINVAL; + } + if (trace.trace_pgfaults) { trace.opts.sample_address = true; trace.opts.sample_time = true;