perf tool: Add event name to error message for filters
PATCH 1/1 perf tool: Add event name to error message for filters
Use of a bad filter currently generates the message:
Error: failed to set filter with 22 (Invalid argument)
Add the event name to make it clear to which event the filter failed to apply:
Error: Failed to set filter on event sched:sg_lb_stats: 22: Invalid argument
--- tools/perf/builtin-record.c | 2 -- tools/perf/builtin-stat.c | 5 +---- tools/perf/util/evsel.c | 16 +++++++++++++--- 3 files changed, 14 insertions(+), 9 deletions(-)
tools/perf/builtin-record.c +0 -2
@@ -162,8 +162,6 @@ static int record__open(struct record *rec) }if (perf_evlist__apply_filters (evlist)) { -error ("failed to set filter with %d (%s)\n" , errno, -strerror_r (errno, msg,sizeof (msg))); rc =-1 ; goto out; }
tools/perf/builtin-stat.c +1 -4
@@ -684,11 +684,8 @@ static int __run_perf_stat(int argc, const char **argv) unit_width = l; } -if (perf_evlist__apply_filters (evsel_list)) { -error ("failed to set filter with %d (%s)\n" , errno, -strerror_r (errno, msg,sizeof (msg))); +if (perf_evlist__apply_filters (evsel_list))return -1 ; - }/* * Enable counters and exec the command:
tools/perf/util/evsel.c +13 -3
@@ -807,9 +807,19 @@ static int perf_evsel__run_ioctl(struct perf_evsel *evsel, int ncpus, int nthreaint perf_evsel__set_filter (struct perf_evsel *evsel,int ncpus,int nthreads,const char *filter) { -return perf_evsel__run_ioctl (evsel, ncpus, nthreads, -PERF_EVENT_IOC_SET_FILTER , - (void *)filter); +int err; +char msg[512 ]; + + err =perf_evsel__run_ioctl (evsel, ncpus, nthreads, +PERF_EVENT_IOC_SET_FILTER , + (void *)filter); +if (err) { +error ("Failed to set filter on event %s: %d: %s\n" , +perf_evsel__name (evsel), errno, +strerror_r (errno, msg,sizeof (msg))); + } + +return err; }int perf_evsel__enable (struct perf_evsel *evsel,int ncpus,int nthreads)
Signature · 1 line
2.2.1
Arnaldo Carvalho de Melo
maintainerEm Tue, Mar 24, 2015 at 12:10:17PM -0400, David Ahern escreveu:
Quoted 20 lines
Use of a bad filter currently generates the message:
Error: failed to set filter with 22 (Invalid argument)Add the event name to make it clear to which event the filter failed to apply:
Error: Failed to set filter on event sched:sg_lb_stats: 22: Invalid argumentSigned-off-by David Ahern <[email protected]>Cc Jiri Olsa <[email protected]>Cc Namhyung Kim <[email protected]>+++
b/tools/perf/util/evsel.ctools/perf/util/evsel.c +0
-3@@ -807,9 +807,19 @@ static int perf_evsel__run_ioctl(struct perf_evsel *evsel, int ncpus, int nthreaint perf_evsel__set_filter (struct perf_evsel *evsel,int ncpus,int nthreads,const char *filter) { -return perf_evsel__run_ioctl (evsel, ncpus, nthreads, -PERF_EVENT_IOC_SET_FILTER , - (void *)filter);
tools/perf/util/evsel.c static int perf_evsel__run_ioctl(struct perf_evsel *evsel, int ncpus, int nthrea · line 819
Quoted 10 lines
tools/perf/util/evsel.c +10
-0+int err; +char msg[512 ]; + + err =perf_evsel__run_ioctl (evsel, ncpus, nthreads, +PERF_EVENT_IOC_SET_FILTER , + (void *)filter); +if (err) { +error ("Failed to set filter on event %s: %d: %s\n" , +perf_evsel__name (evsel), errno, +strerror_r (errno, msg,sizeof (msg)));
Humm, probably this will be the only call to error() from evsel.c, making it require the error() routine, which in turn will break the python binding, lemme check...
If that is the case we'll have to somehow propagate to the caller of perf_evlist__apply_filters what was the evsel that had a filter that caused the problem.
- Arnaldo
Quoted 8 lines
tools/perf/util/evsel.c +3
-0+ } + +return err; }int perf_evsel__enable (struct perf_evsel *evsel,int ncpus,int nthreads)Signature · 1 line
2.2.1
Arnaldo Carvalho de Melo
maintainerEm Tue, Mar 24, 2015 at 06:29:56PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 36 lines
Em Tue, Mar 24, 2015 at 12:10:17PM -0400, David Ahern escreveu:
Quoted 20 lines
Use of a bad filter currently generates the message:
Error: failed to set filter with 22 (Invalid argument)Add the event name to make it clear to which event the filter failed to apply:
Error: Failed to set filter on event sched:sg_lb_stats: 22: Invalid argumentSigned-off-by David Ahern <[email protected]>Cc Jiri Olsa <[email protected]>Cc Namhyung Kim <[email protected]>+++
b/tools/perf/util/evsel.c(quoted diff) +0
-3@@ -807,9 +807,19 @@ static int perf_evsel__run_ioctl(struct perf_evsel *evsel, int ncpus, int nthrea int perf_evsel__set_filter(struct perf_evsel *evsel, int ncpus, int nthreads, const char *filter) { - return perf_evsel__run_ioctl(evsel, ncpus, nthreads, - PERF_EVENT_IOC_SET_FILTER, - (void *)filter);Review static int perf_evsel__run_ioctl(struct perf_evsel *evsel, int ncpus, int nthrea · line 819
Quoted 10 lines
(quoted diff) +10
-0+ int err; + char msg[512]; + + err = perf_evsel__run_ioctl(evsel, ncpus, nthreads, + PERF_EVENT_IOC_SET_FILTER, + (void *)filter); + if (err) { + error("Failed to set filter on event %s: %d: %s\n", + perf_evsel__name(evsel), errno, + strerror_r(errno, msg, sizeof(msg)));Humm, probably this will be the only call to
error()fromevsel.c, making it require theerror()routine, which in turn will break the python binding, lemme check...
Quoted 3 lines
If that is the case we'll have to somehow propagate to the caller of
perf_evlist__apply_filterswhat was the evsel that had a filter that caused the problem.
With the patch below, that leaves printing something, using whatever UI, to the tool, acceptable?
[root@ssdandy linux]# perf record -e sched:sched_switch -e sched:*fork --filter parent_pid==1 -e sched:*wait* --filter bla usleep 1
Error: failed to set filter "bla" on event sched:sched_stat_iowait with 22 (Invalid argument)
[root@ssdandy linux]#
tools/perf/builtin-record.c +3 -2
@@ -161,8 +161,9 @@ try_again: } } -if (perf_evlist__apply_filters (evlist)) { -error ("failed to set filter with %d (%s)\n" , errno, +if (perf_evlist__apply_filters (evlist, &pos)) { +error ("failed to set filter \"%s\" on event %s with %d (%s)\n" , + pos->filter,perf_evsel__name (pos), errno,strerror_r (errno, msg,sizeof (msg))); rc =-1 ; goto out;
tools/perf/builtin-stat.c +3 -2
@@ -684,8 +684,9 @@ static int __run_perf_stat(int argc, const char **argv) unit_width = l; } -if (perf_evlist__apply_filters (evsel_list)) { -error ("failed to set filter with %d (%s)\n" , errno, +if (perf_evlist__apply_filters (evsel_list, &counter)) { +error ("failed to set filter \"%s\" on event %s with %d (%s)\n" , + counter->filter,perf_evsel__name (counter), errno,strerror_r (errno, msg,sizeof (msg)));return -1 ; }
tools/perf/util/evlist.c +4 -2
@@ -1050,7 +1050,7 @@ out_delete_threads:return -1 ; } -int perf_evlist__apply_filters (struct perf_evlist *evlist) +int perf_evlist__apply_filters (struct perf_evlist *evlist,struct perf_evsel **err_evsel) {struct perf_evsel *evsel;int err =0 ;
@@ -1062,8 +1062,10 @@ int perf_evlist__apply_filters(struct perf_evlist *evlist)continue ; err =perf_evsel__set_filter (evsel, ncpus, nthreads, evsel->filter); -if (err) +if (err) { + *err_evsel = evsel;break ; + } }return err;
tools/perf/util/evlist.h +1 -1
@@ -152,7 +152,7 @@ static inline void perf_evlist__set_maps(struct perf_evlist *evlist, }int perf_evlist__create_maps (struct perf_evlist *evlist,struct target *target); -int perf_evlist__apply_filters (struct perf_evlist *evlist); +int perf_evlist__apply_filters (struct perf_evlist *evlist,struct perf_evsel **err_evsel);void __perf_evlist__set_leader (struct list_head *list);void perf_evlist__set_leader (struct perf_evlist *evlist);
Quoted 2 lines · Arnaldo Carvalho de Melo
With the patch below, that leaves printing something, using whatever UI, to the tool, acceptable?
I keep forgetting about the python bindings.
Your patch serves the purpose. Thanks, Arnaldo.
Arnaldo Carvalho de Melo
maintainerEm Tue, Mar 24, 2015 at 04:00:36PM -0600, David Ahern escreveu:
Quoted 5 lines · Arnaldo Carvalho de Melo
Quoted 2 lines
With the patch below, that leaves printing something, using whatever UI, to the tool, acceptable?
I keep forgetting about the python bindings.
Oh, its not just about the python bindings, but kinda layering violation, i.e. we should leave the error reporting to the actual tool, that may be using GTK, Qt, some custom made TUI, whatever UI.
The python bindings, were not a problem somehow, at least 'perf test python' hasn't failed when I tried.
Quoted 1 line
Your patch serves the purpose. Thanks, Arnaldo.
Thanks,
Applying with your Acked-by and Based-on-a-patch-by.
- Arnaldo
Quoted 5 lines · David Ahern
Quoted 2 lines · Arnaldo Carvalho de Melo
With the patch below, that leaves printing something, using whatever UI, to the tool, acceptable?
I keep forgetting about the python bindings.
# perf test
for each change ;-)
jirka