Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756837AbbHZNrY (ORCPT ); Wed, 26 Aug 2015 09:47:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52574 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756778AbbHZNrU (ORCPT ); Wed, 26 Aug 2015 09:47:20 -0400 From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , David Ahern , Ingo Molnar , Namhyung Kim , Peter Zijlstra , Matt Fleming , =?UTF-8?q?Rapha=C3=ABl=20Beamonte?= Subject: [PATCH 11/11] perf tools: Enhance parsing events tracepoint error output Date: Wed, 26 Aug 2015 15:46:53 +0200 Message-Id: <1440596813-12844-12-git-send-email-jolsa@kernel.org> In-Reply-To: <1440596813-12844-1-git-send-email-jolsa@kernel.org> References: <1440596813-12844-1-git-send-email-jolsa@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4577 Lines: 144 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 ... Link: http://lkml.kernel.org/n/tip-l0lu26995rir1h6v0e7kqyzz@git.kernel.org Signed-off-by: Jiri Olsa --- tools/perf/util/parse-events.c | 30 +++++++++++++++++++++++++++--- tools/perf/util/parse-events.y | 16 +++++++++------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index ff8a28ac31b7..1a6d8c80388d 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -387,6 +387,28 @@ int parse_events_add_cache(struct list_head *list, int *idx, return add_event(list, idx, &attr, name, NULL); } +static void tracepoint_error(struct parse_events_error *error, int err, + char *sys, char *name) +{ + char help[BUFSIZ]; + err = abs(err); + + switch (err) { + case EACCES: + error->str = strdup("can't access trace events"); + break; + case ENOENT: + error->str = strdup("unknown tracepoint"); + break; + default: + error->str = strdup("failed to add tracepoint"); + break; + } + + tracing_path_strerror_open_tp(err, help, sizeof(help), sys, name); + error->help = strdup(help); +} + static int add_tracepoint(struct list_head *list, int *idx, char *sys_name, char *evt_name, struct parse_events_error *error __maybe_unused) @@ -394,8 +416,10 @@ static int add_tracepoint(struct list_head *list, int *idx, struct perf_evsel *evsel; evsel = perf_evsel__newtp_idx(sys_name, evt_name, (*idx)++); - if (IS_ERR(evsel)) + if (IS_ERR(evsel)) { + tracepoint_error(error, PTR_ERR(evsel), sys_name, evt_name); return -ENOMEM; + } list_add_tail(&evsel->node, list); @@ -414,7 +438,7 @@ static int add_tracepoint_multi_event(struct list_head *list, int *idx, snprintf(evt_path, MAXPATHLEN, "%s/%s", tracing_events_path, sys_name); evt_dir = opendir(evt_path); if (!evt_dir) { - perror("Can't open event dir"); + tracepoint_error(error, errno, sys_name, evt_name); return -1; } @@ -454,7 +478,7 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx, events_dir = opendir(tracing_events_path); if (!events_dir) { - perror("Can't open event dir"); + tracepoint_error(error, errno, sys_name, evt_name); return -1; } diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index 742914746794..2ccc6911dc5e 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -371,28 +371,30 @@ event_legacy_tracepoint: PE_NAME '-' PE_NAME ':' PE_NAME { struct parse_events_evlist *data = _data; + struct parse_events_error *error = data->error; struct list_head *list; char sys_name[128]; snprintf(&sys_name, 128, "%s-%s", $1, $3); ALLOC_LIST(list); - ABORT_ON(parse_events_add_tracepoint(list, &data->idx, &sys_name, $5, data->error)); + if (parse_events_add_tracepoint(list, &data->idx, &sys_name, $5, error)) { + if (error) + error->idx = @1.first_column; + return -1; + } $$ = list; } | PE_NAME ':' PE_NAME { struct parse_events_evlist *data = _data; + struct parse_events_error *error = data->error; struct list_head *list; ALLOC_LIST(list); - if (parse_events_add_tracepoint(list, &data->idx, $1, $3, data->error)) { - struct parse_events_error *error = data->error; - - if (error) { + if (parse_events_add_tracepoint(list, &data->idx, $1, $3, error)) { + if (error) error->idx = @1.first_column; - error->str = strdup("unknown tracepoint"); - } return -1; } $$ = list; -- 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/