2012-11-10 00:46:47 +00:00
|
|
|
#include "evlist.h"
|
|
|
|
#include "evsel.h"
|
|
|
|
#include "parse-events.h"
|
|
|
|
#include "tests.h"
|
2014-07-14 21:46:48 +00:00
|
|
|
#include "debug.h"
|
2012-11-10 00:46:47 +00:00
|
|
|
|
|
|
|
static int perf_evsel__roundtrip_cache_name_test(void)
|
|
|
|
{
|
|
|
|
char name[128];
|
|
|
|
int type, op, err = 0, ret = 0, i, idx;
|
|
|
|
struct perf_evsel *evsel;
|
2013-03-11 07:43:12 +00:00
|
|
|
struct perf_evlist *evlist = perf_evlist__new();
|
2012-11-10 00:46:47 +00:00
|
|
|
|
|
|
|
if (evlist == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
|
|
|
|
for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
|
|
|
|
/* skip invalid cache type */
|
|
|
|
if (!perf_evsel__is_cache_op_valid(type, op))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
|
|
|
|
__perf_evsel__hw_cache_type_op_res_name(type, op, i,
|
|
|
|
name, sizeof(name));
|
perf tools: Add parse_events_error interface
Adding support to return error information from parse_events function.
Following struct will be populated by parse_events function on return:
struct parse_events_error {
int idx;
char *str;
char *help;
};
where 'idx' is the position in the string where the parsing failed,
'str' contains dynamically allocated error string describing the error
and 'help' is optional help string.
The change contains reporting function, which currently does not display
anything. The code changes to supply error data for specific event types
are coming in next patches. However this is what the expected output is:
$ sudo perf record -e 'sched:krava' ls
event syntax error: 'sched:krava'
\___ unknown tracepoint
...
$ perf record -e 'cpu/even=0x1/' ls
event syntax error: 'cpu/even=0x1/'
\___ unknown term
valid terms: pc,any,inv,edge,cmask,event,in_tx,ldlat,umask,in_tx_cp,offcore_rsp,config,config1,config2,name,period,branch_type
...
$ perf record -e cycles,cache-mises ls
event syntax error: '..es,cache-mises'
\___ parser error
...
The output functions cut the beginning of the event string so the error
starts up to 10th character and cut the end of the string of it crosses
the terminal width.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1429729824-13932-2-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 <acme@redhat.com>
2015-04-22 19:10:16 +00:00
|
|
|
err = parse_events(evlist, name, NULL);
|
2012-11-10 00:46:47 +00:00
|
|
|
if (err)
|
|
|
|
ret = err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
idx = 0;
|
|
|
|
evsel = perf_evlist__first(evlist);
|
|
|
|
|
|
|
|
for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
|
|
|
|
for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
|
|
|
|
/* skip invalid cache type */
|
|
|
|
if (!perf_evsel__is_cache_op_valid(type, op))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
|
|
|
|
__perf_evsel__hw_cache_type_op_res_name(type, op, i,
|
|
|
|
name, sizeof(name));
|
|
|
|
if (evsel->idx != idx)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
++idx;
|
|
|
|
|
|
|
|
if (strcmp(perf_evsel__name(evsel), name)) {
|
|
|
|
pr_debug("%s != %s\n", perf_evsel__name(evsel), name);
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
evsel = perf_evsel__next(evsel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
perf_evlist__delete(evlist);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __perf_evsel__name_array_test(const char *names[], int nr_names)
|
|
|
|
{
|
|
|
|
int i, err;
|
|
|
|
struct perf_evsel *evsel;
|
2013-03-11 07:43:12 +00:00
|
|
|
struct perf_evlist *evlist = perf_evlist__new();
|
2012-11-10 00:46:47 +00:00
|
|
|
|
|
|
|
if (evlist == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (i = 0; i < nr_names; ++i) {
|
perf tools: Add parse_events_error interface
Adding support to return error information from parse_events function.
Following struct will be populated by parse_events function on return:
struct parse_events_error {
int idx;
char *str;
char *help;
};
where 'idx' is the position in the string where the parsing failed,
'str' contains dynamically allocated error string describing the error
and 'help' is optional help string.
The change contains reporting function, which currently does not display
anything. The code changes to supply error data for specific event types
are coming in next patches. However this is what the expected output is:
$ sudo perf record -e 'sched:krava' ls
event syntax error: 'sched:krava'
\___ unknown tracepoint
...
$ perf record -e 'cpu/even=0x1/' ls
event syntax error: 'cpu/even=0x1/'
\___ unknown term
valid terms: pc,any,inv,edge,cmask,event,in_tx,ldlat,umask,in_tx_cp,offcore_rsp,config,config1,config2,name,period,branch_type
...
$ perf record -e cycles,cache-mises ls
event syntax error: '..es,cache-mises'
\___ parser error
...
The output functions cut the beginning of the event string so the error
starts up to 10th character and cut the end of the string of it crosses
the terminal width.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1429729824-13932-2-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 <acme@redhat.com>
2015-04-22 19:10:16 +00:00
|
|
|
err = parse_events(evlist, names[i], NULL);
|
2012-11-10 00:46:47 +00:00
|
|
|
if (err) {
|
|
|
|
pr_debug("failed to parse event '%s', err %d\n",
|
|
|
|
names[i], err);
|
|
|
|
goto out_delete_evlist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err = 0;
|
2016-06-23 14:26:15 +00:00
|
|
|
evlist__for_each_entry(evlist, evsel) {
|
2012-11-10 00:46:47 +00:00
|
|
|
if (strcmp(perf_evsel__name(evsel), names[evsel->idx])) {
|
|
|
|
--err;
|
|
|
|
pr_debug("%s != %s\n", perf_evsel__name(evsel), names[evsel->idx]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out_delete_evlist:
|
|
|
|
perf_evlist__delete(evlist);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define perf_evsel__name_array_test(names) \
|
|
|
|
__perf_evsel__name_array_test(names, ARRAY_SIZE(names))
|
|
|
|
|
perf tests: Pass the subtest index to each test routine
Some tests have sub-tests we want to run, so allow passing this.
Wang tried to avoid having to touch all tests, but then, having the
test.func in an anonymous union makes the build fail on older compilers,
like the one in RHEL6, where:
test a = {
.func = foo,
};
fails.
To fix it leave the func pointer in the main structure and pass the subtest
index to all tests, end result function is the same, but we have just one
function pointer, not two, with and without the subtest index as an argument.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-5genj0ficwdmelpoqlds0u4y@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2015-11-19 15:01:48 +00:00
|
|
|
int test__perf_evsel__roundtrip_name_test(int subtest __maybe_unused)
|
2012-11-10 00:46:47 +00:00
|
|
|
{
|
|
|
|
int err = 0, ret = 0;
|
|
|
|
|
|
|
|
err = perf_evsel__name_array_test(perf_evsel__hw_names);
|
|
|
|
if (err)
|
|
|
|
ret = err;
|
|
|
|
|
2015-12-03 08:34:16 +00:00
|
|
|
err = __perf_evsel__name_array_test(perf_evsel__sw_names,
|
|
|
|
PERF_COUNT_SW_DUMMY + 1);
|
2012-11-10 00:46:47 +00:00
|
|
|
if (err)
|
|
|
|
ret = err;
|
|
|
|
|
|
|
|
err = perf_evsel__roundtrip_cache_name_test();
|
|
|
|
if (err)
|
|
|
|
ret = err;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|