From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757027AbbEFDGM (ORCPT ); Tue, 5 May 2015 23:06:12 -0400 Received: from terminus.zytor.com ([198.137.202.10]:35942 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755363AbbEFDGH (ORCPT ); Tue, 5 May 2015 23:06:07 -0400 Date: Tue, 5 May 2015 20:05:51 -0700 From: tip-bot for Jiri Olsa Message-ID: Cc: hpa@zytor.com, linux-kernel@vger.kernel.org, mingo@kernel.org, acme@redhat.com, dsahern@gmail.com, tglx@linutronix.de, a.p.zijlstra@chello.nl, namhyung@kernel.org, jolsa@kernel.org, paulus@samba.org Reply-To: linux-kernel@vger.kernel.org, hpa@zytor.com, acme@redhat.com, mingo@kernel.org, tglx@linutronix.de, dsahern@gmail.com, jolsa@kernel.org, paulus@samba.org, namhyung@kernel.org, a.p.zijlstra@chello.nl In-Reply-To: <1429729824-13932-8-git-send-email-jolsa@kernel.org> References: <1429729824-13932-8-git-send-email-jolsa@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf tools: Add static terms support for parse_events_error Git-Commit-ID: 3b0e371cc05dfb624f990ea5e1da2bff615adaef X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 3b0e371cc05dfb624f990ea5e1da2bff615adaef Gitweb: http://git.kernel.org/tip/3b0e371cc05dfb624f990ea5e1da2bff615adaef Author: Jiri Olsa AuthorDate: Wed, 22 Apr 2015 21:10:22 +0200 Committer: Arnaldo Carvalho de Melo CommitDate: Wed, 29 Apr 2015 10:38:01 -0300 perf tools: Add static terms support for parse_events_error Allowing static terms like 'name,period,config,config1..' processing to report back error. $ perf record -e 'cpu/event=1,name=1/' ls event syntax error: '..=1,name=1/' \___ expected string value $ perf record -e 'cpu/event=1,period=krava/' ls event syntax error: '..,period=krava/' \___ expected numeric value $ perf record -e 'cpu/config=krava1/' ls event syntax error: '../config=krava1/' \___ expected numeric value Signed-off-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Cc: David Ahern Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1429729824-13932-8-git-send-email-jolsa@kernel.org [ Renamed 'error' variables to 'err', not to clash with util.h error() ] Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/parse-events.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 1d810d1..278aebe 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -545,13 +545,31 @@ int parse_events_add_breakpoint(struct list_head *list, int *idx, return add_event(list, idx, &attr, NULL); } +static int check_type_val(struct parse_events_term *term, + struct parse_events_error *err, + int type) +{ + if (type == term->type_val) + return 0; + + if (err) { + err->idx = term->err_val; + if (type == PARSE_EVENTS__TERM_TYPE_NUM) + err->str = strdup("expected numeric value"); + else + err->str = strdup("expected string value"); + } + return -EINVAL; +} + static int config_term(struct perf_event_attr *attr, - struct parse_events_term *term) + struct parse_events_term *term, + struct parse_events_error *err) { -#define CHECK_TYPE_VAL(type) \ -do { \ - if (PARSE_EVENTS__TERM_TYPE_ ## type != term->type_val) \ - return -EINVAL; \ +#define CHECK_TYPE_VAL(type) \ +do { \ + if (check_type_val(term, err, PARSE_EVENTS__TERM_TYPE_ ## type)) \ + return -EINVAL; \ } while (0) switch (term->type_term) { @@ -595,12 +613,13 @@ do { \ } static int config_attr(struct perf_event_attr *attr, - struct list_head *head) + struct list_head *head, + struct parse_events_error *err) { struct parse_events_term *term; list_for_each_entry(term, head, list) - if (config_term(attr, term)) + if (config_term(attr, term, err)) return -EINVAL; return 0; @@ -617,7 +636,7 @@ int parse_events_add_numeric(struct list_head *list, int *idx, attr.config = config; if (head_config && - config_attr(&attr, head_config)) + config_attr(&attr, head_config, NULL)) return -EINVAL; return add_event(list, idx, &attr, NULL); @@ -672,7 +691,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data, * Configure hardcoded terms first, no need to check * return value when called with fail == 0 ;) */ - if (config_attr(&attr, head_config)) + if (config_attr(&attr, head_config, data->error)) return -EINVAL; if (perf_pmu__config(pmu, &attr, head_config, data->error))