From: He Kuang <hekuang@huawei.com>
To: <a.p.zijlstra@chello.nl>, <mingo@redhat.com>, <acme@kernel.org>,
<jolsa@kernel.org>, <kan.liang@intel.com>,
<adrian.hunter@intel.com>
Cc: <wangnan0@huawei.com>, <pi3orama@163.com>, <hekuang@huawei.com>,
<linux-kernel@vger.kernel.org>
Subject: [PATCH v2 2/4] perf tools: Prompt error message for wrong terms of hw/sw events
Date: Fri, 25 Sep 2015 11:11:49 +0000 [thread overview]
Message-ID: <1443179511-59238-2-git-send-email-hekuang@huawei.com> (raw)
In-Reply-To: <1443179511-59238-1-git-send-email-hekuang@huawei.com>
Prompt proper error message when wrong config terms is specificed for
hw/sw type perf events. This patch makes the original error prompt
function formats_error_string() more generic, which only outputs the
static config terms for hw/sw perf events, and prepends pmu formats
for pmu events.
Before this patch:
$ perf record -e 'cpu-clock/freq=200/' -a sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.028 MB perf.data (202 samples) ]
$ perf record -e 'cpu-clock/freqx=200/' -a sleep 1
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.042 MB perf.data (506 samples) ]
After this patch:
$ perf record -e 'cpu-clock/freqx=200/' -a sleep 1
event syntax error: 'cpu-clock/freqx=200/'
\___ unknown term
valid terms: config,config1,config2,name,period,freq,branch_type,time,call-graph,stack-size
Run 'perf list' for a list of valid events
usage: perf record [<options>] [<command>]
or: perf record [<options>] -- <command> [<options>]
-e, --event <event> event selector. use 'perf list' to list available events
Signed-off-by: He Kuang <hekuang@huawei.com>
---
tools/perf/util/parse-events.c | 26 ++++++++++++++++++++++++++
tools/perf/util/parse-events.h | 1 +
tools/perf/util/pmu.c | 35 ++++++++++++-----------------------
3 files changed, 39 insertions(+), 23 deletions(-)
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index aa64cf3..f624b99 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -656,6 +656,9 @@ do { \
CHECK_TYPE_VAL(STR);
break;
default:
+ err->str = strdup("unknown term");
+ err->idx = term->err_term;
+ err->help = parse_events_formats_error_string(NULL);
return -EINVAL;
}
@@ -1875,3 +1878,26 @@ void parse_events_evlist_error(struct parse_events_evlist *data,
err->str = strdup(str);
WARN_ONCE(!err->str, "WARNING: failed to allocate error string");
}
+
+char *parse_events_formats_error_string(char *additional_terms)
+{
+ char *str;
+ static const char *static_terms = "config,config1,config2,name,"
+ "period,freq,branch_type,time,"
+ "call-graph,stack-size\n";
+
+ /* valid terms */
+ if (additional_terms) {
+ if (!asprintf(&str, "valid terms: %s,%s",
+ additional_terms, static_terms))
+ goto fail;
+ free(additional_terms);
+ } else {
+ if (!asprintf(&str, "valid terms: %s", static_terms))
+ goto fail;
+ }
+ return str;
+
+fail:
+ return NULL;
+}
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index ffee7ec..c7b904a 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -156,5 +156,6 @@ int print_hwcache_events(const char *event_glob, bool name_only);
extern int is_valid_tracepoint(const char *event_string);
int valid_event_mount(const char *eventfs);
+char *parse_events_formats_error_string(char *additional_terms);
#endif /* __PERF_PARSE_EVENTS_H */
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 89c91a1..ea3dd04 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -626,38 +626,26 @@ static int pmu_resolve_param_term(struct parse_events_term *term,
return -1;
}
-static char *formats_error_string(struct list_head *formats)
+static char *pmu_formats_string(struct list_head *formats)
{
struct perf_pmu_format *format;
- char *err, *str;
- static const char *static_terms = "config,config1,config2,name,"
- "period,freq,branch_type,time,"
- "call-graph,stack-size\n";
+ char *str;
+ struct strbuf buf;
unsigned i = 0;
- if (!asprintf(&str, "valid terms:"))
+ if (!formats)
return NULL;
+ strbuf_init(&buf, 0);
/* sysfs exported terms */
- list_for_each_entry(format, formats, list) {
- char c = i++ ? ',' : ' ';
-
- err = str;
- if (!asprintf(&str, "%s%c%s", err, c, format->name))
- goto fail;
- free(err);
- }
+ list_for_each_entry(format, formats, list)
+ strbuf_addf(&buf, i++ ? ",%s" : "%s",
+ format->name);
- /* static terms */
- err = str;
- if (!asprintf(&str, "%s,%s", err, static_terms))
- goto fail;
+ str = strbuf_detach(&buf, NULL);
+ strbuf_release(&buf);
- free(err);
return str;
-fail:
- free(err);
- return NULL;
}
/*
@@ -695,7 +683,8 @@ static int pmu_config_term(struct list_head *formats,
if (err) {
err->idx = term->err_term;
err->str = strdup("unknown term");
- err->help = formats_error_string(formats);
+ err->help = parse_events_formats_error_string(
+ pmu_formats_string(formats));
}
return -EINVAL;
}
--
1.8.5.2
next prev parent reply other threads:[~2015-09-25 11:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-25 11:11 [PATCH v2 1/4] perf tools: Adds the config_term callback for different type events He Kuang
2015-09-25 11:11 ` He Kuang [this message]
2015-09-27 20:27 ` [PATCH v2 2/4] perf tools: Prompt error message for wrong terms of hw/sw events Jiri Olsa
2015-09-27 20:28 ` Jiri Olsa
2015-09-27 20:30 ` Jiri Olsa
2015-09-25 11:11 ` [PATCH v2 3/4] perf tools: Adds the tracepoint name parsing support He Kuang
2015-09-27 20:33 ` Jiri Olsa
2015-09-27 20:34 ` Jiri Olsa
2015-09-25 11:11 ` [PATCH v2 4/4] perf tools: Enable event_config terms to tracepoint events He Kuang
2015-09-27 20:41 ` Jiri Olsa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1443179511-59238-2-git-send-email-hekuang@huawei.com \
--to=hekuang@huawei.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pi3orama@163.com \
--cc=wangnan0@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®