Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b39b8393 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo
Browse files

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: default avatarJiri 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 70d73de4
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -1541,7 +1541,7 @@ static int setup_events(const char * const *attrs, unsigned len)
	unsigned i;
	unsigned i;


	for (i = 0; i < len; i++) {
	for (i = 0; i < len; i++) {
		if (parse_events(evsel_list, attrs[i]))
		if (parse_events(evsel_list, attrs[i], NULL))
			return -1;
			return -1;
	}
	}
	return 0;
	return 0;
+1 −1
Original line number Original line Diff line number Diff line
@@ -482,7 +482,7 @@ static int do_test_code_reading(bool try_kcore)
		else
		else
			str = "cycles";
			str = "cycles";
		pr_debug("Parsing event '%s'\n", str);
		pr_debug("Parsing event '%s'\n", str);
		ret = parse_events(evlist, str);
		ret = parse_events(evlist, str, NULL);
		if (ret < 0) {
		if (ret < 0) {
			pr_debug("parse_events failed\n");
			pr_debug("parse_events failed\n");
			goto out_err;
			goto out_err;
+2 −2
Original line number Original line Diff line number Diff line
@@ -23,7 +23,7 @@ static int perf_evsel__roundtrip_cache_name_test(void)
			for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
			for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
				__perf_evsel__hw_cache_type_op_res_name(type, op, i,
				__perf_evsel__hw_cache_type_op_res_name(type, op, i,
									name, sizeof(name));
									name, sizeof(name));
				err = parse_events(evlist, name);
				err = parse_events(evlist, name, NULL);
				if (err)
				if (err)
					ret = err;
					ret = err;
			}
			}
@@ -71,7 +71,7 @@ static int __perf_evsel__name_array_test(const char *names[], int nr_names)
                return -ENOMEM;
                return -ENOMEM;


	for (i = 0; i < nr_names; ++i) {
	for (i = 0; i < nr_names; ++i) {
		err = parse_events(evlist, names[i]);
		err = parse_events(evlist, names[i], NULL);
		if (err) {
		if (err) {
			pr_debug("failed to parse event '%s', err %d\n",
			pr_debug("failed to parse event '%s', err %d\n",
				 names[i], err);
				 names[i], err);
+1 −1
Original line number Original line Diff line number Diff line
@@ -695,7 +695,7 @@ int test__hists_cumulate(void)


	TEST_ASSERT_VAL("No memory", evlist);
	TEST_ASSERT_VAL("No memory", evlist);


	err = parse_events(evlist, "cpu-clock");
	err = parse_events(evlist, "cpu-clock", NULL);
	if (err)
	if (err)
		goto out;
		goto out;


+2 −2
Original line number Original line Diff line number Diff line
@@ -108,10 +108,10 @@ int test__hists_filter(void)


	TEST_ASSERT_VAL("No memory", evlist);
	TEST_ASSERT_VAL("No memory", evlist);


	err = parse_events(evlist, "cpu-clock");
	err = parse_events(evlist, "cpu-clock", NULL);
	if (err)
	if (err)
		goto out;
		goto out;
	err = parse_events(evlist, "task-clock");
	err = parse_events(evlist, "task-clock", NULL);
	if (err)
	if (err)
		goto out;
		goto out;


Loading