Skip to content

Commit 1965817

Browse files
olsajiriacmel
authored andcommitted
perf tools: Enhance parsing events tracepoint error output
Enhancing parsing events tracepoint error output. Adding more verbose output when the tracepoint is not found or the tracing event path cannot be access. $ sudo perf record -e sched:sched_krava ls event syntax error: 'sched:sched_krava' \___ unknown tracepoint Error: File /sys/kernel/debug/tracing//tracing/events/sched/sched_krava not found. Hint: Perhaps this kernel misses some CONFIG_ setting to enable this feature?. Run 'perf list' for a list of valid events ... $ perf record -e sched:sched_krava ls event syntax error: 'sched:sched_krava' \___ can't access trace events Error: No permissions to read /sys/kernel/debug/tracing//tracing/events/sched/sched_krava Hint: Try 'sudo mount -o remount,mode=755 /sys/kernel/debug' Run 'perf list' for a list of valid events ... Signed-off-by: Jiri Olsa <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Raphael Beamonte <[email protected]> Cc: David Ahern <[email protected]> Cc: Matt Fleming <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 8dd2a13 commit 1965817

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

tools/perf/util/parse-events.c

+32-3
Original file line numberDiff line numberDiff line change
@@ -387,15 +387,44 @@ int parse_events_add_cache(struct list_head *list, int *idx,
387387
return add_event(list, idx, &attr, name, NULL);
388388
}
389389

390+
static void tracepoint_error(struct parse_events_error *error, int err,
391+
char *sys, char *name)
392+
{
393+
char help[BUFSIZ];
394+
395+
/*
396+
* We get error directly from syscall errno ( > 0),
397+
* or from encoded pointer's error ( < 0).
398+
*/
399+
err = abs(err);
400+
401+
switch (err) {
402+
case EACCES:
403+
error->str = strdup("can't access trace events");
404+
break;
405+
case ENOENT:
406+
error->str = strdup("unknown tracepoint");
407+
break;
408+
default:
409+
error->str = strdup("failed to add tracepoint");
410+
break;
411+
}
412+
413+
tracing_path__strerror_open_tp(err, help, sizeof(help), sys, name);
414+
error->help = strdup(help);
415+
}
416+
390417
static int add_tracepoint(struct list_head *list, int *idx,
391418
char *sys_name, char *evt_name,
392419
struct parse_events_error *error __maybe_unused)
393420
{
394421
struct perf_evsel *evsel;
395422

396423
evsel = perf_evsel__newtp_idx(sys_name, evt_name, (*idx)++);
397-
if (IS_ERR(evsel))
424+
if (IS_ERR(evsel)) {
425+
tracepoint_error(error, PTR_ERR(evsel), sys_name, evt_name);
398426
return PTR_ERR(evsel);
427+
}
399428

400429
list_add_tail(&evsel->node, list);
401430
return 0;
@@ -413,7 +442,7 @@ static int add_tracepoint_multi_event(struct list_head *list, int *idx,
413442
snprintf(evt_path, MAXPATHLEN, "%s/%s", tracing_events_path, sys_name);
414443
evt_dir = opendir(evt_path);
415444
if (!evt_dir) {
416-
perror("Can't open event dir");
445+
tracepoint_error(error, errno, sys_name, evt_name);
417446
return -1;
418447
}
419448

@@ -453,7 +482,7 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
453482

454483
events_dir = opendir(tracing_events_path);
455484
if (!events_dir) {
456-
perror("Can't open event dir");
485+
tracepoint_error(error, errno, sys_name, evt_name);
457486
return -1;
458487
}
459488

tools/perf/util/parse-events.y

+9-7
Original file line numberDiff line numberDiff line change
@@ -371,28 +371,30 @@ event_legacy_tracepoint:
371371
PE_NAME '-' PE_NAME ':' PE_NAME
372372
{
373373
struct parse_events_evlist *data = _data;
374+
struct parse_events_error *error = data->error;
374375
struct list_head *list;
375376
char sys_name[128];
376377
snprintf(&sys_name, 128, "%s-%s", $1, $3);
377378

378379
ALLOC_LIST(list);
379-
ABORT_ON(parse_events_add_tracepoint(list, &data->idx, &sys_name, $5, data->error));
380+
if (parse_events_add_tracepoint(list, &data->idx, &sys_name, $5, error)) {
381+
if (error)
382+
error->idx = @1.first_column;
383+
return -1;
384+
}
380385
$$ = list;
381386
}
382387
|
383388
PE_NAME ':' PE_NAME
384389
{
385390
struct parse_events_evlist *data = _data;
391+
struct parse_events_error *error = data->error;
386392
struct list_head *list;
387393

388394
ALLOC_LIST(list);
389-
if (parse_events_add_tracepoint(list, &data->idx, $1, $3, data->error)) {
390-
struct parse_events_error *error = data->error;
391-
392-
if (error) {
395+
if (parse_events_add_tracepoint(list, &data->idx, $1, $3, error)) {
396+
if (error)
393397
error->idx = @1.first_column;
394-
error->str = strdup("unknown tracepoint");
395-
}
396398
return -1;
397399
}
398400
$$ = list;

0 commit comments

Comments
 (0)