Skip to contentSkip to conversation

perf tool: report user-friendly errors from trace

PATCH New Ramkumar Ramachandra 2 participants 2 messages Oct 4, 2013 – Oct 15, 2013 perf events

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 perf tool: report user-friendly errors from trace

Currently, execution of 'perf trace' reports the following cryptic message to the user:

$ perf trace
Couldn't read the raw_syscalls tracepoints information!

Typically this happens because the user does not have permissions to read the debugfs filesystem. Also handle the case when the kernel was not compiled with debugfs support or when it isn't mounted.

Now, the tool prints detailed error messages:

$ perf trace
Error:  Unable to find debugfs
Hint:   Was your kernel was compiled with debugfs support?
Hint:   Is the debugfs filesystem mounted?
$ perf trace
Error:  No permissions to read $debugfs/tracing/events/raw_syscalls
Hint:   Change the permissions of the debugfs filesystem
Cc Ingo Molnar <[email protected]>
Cc David Ahern <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

---
We don't want to spoonfeed the user with an exact command-line to execute. She is competent enough to Google and find out what debugfs is, and how to use it.

 tools/perf/builtin-trace.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)
tools/perf/builtin-trace.c +21 -9
index 71aa3e3..ee32453 100644
@@ -915,17 +915,13 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
 	}
 
 	if (perf_evlist__add_newtp(evlist, "raw_syscalls", "sys_enter", trace__sys_enter) ||
-	    perf_evlist__add_newtp(evlist, "raw_syscalls", "sys_exit", trace__sys_exit)) {
-		fprintf(trace->output, "Couldn't read the raw_syscalls tracepoints information!\n");
-		goto out_delete_evlist;
-	}
+		perf_evlist__add_newtp(evlist, "raw_syscalls", "sys_exit", trace__sys_exit))
+		goto out_error_tp;
 
 	if (trace->sched &&
-	    perf_evlist__add_newtp(evlist, "sched", "sched_stat_runtime",
-				   trace__sched_stat_runtime)) {
-		fprintf(trace->output, "Couldn't read the sched_stat_runtime tracepoint information!\n");
-		goto out_delete_evlist;
-	}
+		perf_evlist__add_newtp(evlist, "sched", "sched_stat_runtime",
+				trace__sched_stat_runtime))
+		goto out_error_tp;
 
 	err = perf_evlist__create_maps(evlist, &trace->opts.target);
 	if (err < 0) {
@@ -1041,6 +1037,22 @@ out_delete_evlist:
 	perf_evlist__delete(evlist);
 out:
 	return err;
+out_error_tp:
+	switch(errno) {
+	case ENOENT:
+		fprintf(trace->output, "Error:\tUnable to find debugfs\n");
+		fprintf(trace->output, "Hint:\tWas your kernel was compiled with debugfs support?\n");
+		fprintf(trace->output, "Hint:\tIs the debugfs filesystem mounted?\n");
+		break;
+	case EACCES:
+		fprintf(trace->output, "Error:\tNo permissions to read $debugfs/tracing/events/raw_syscalls\n");
+		fprintf(trace->output, "Hint:\tChange the permissions of the debugfs filesystem\n");
+		break;
+	default:
+		fprintf(trace->output, "Can't trace: %s\n", sys_errlist[errno]);
+		break;
+	}
+	goto out_delete_evlist;
 }
 
 static int trace__replay(struct trace *trace)
Signature · 1 line
1.8.4.477.g5d89aa9
#1 lore raw

[tip:perf/core] perf trace: Improve the error messages

perf trace: Improve the error messages
Commit-ID:  87f918685a452be514d060a09eeb4e0c91422e86
Gitweb:     http://git.kernel.org/tip/87f918685a452be514d060a09eeb4e0c91422e86
Author:     Ramkumar Ramachandra <[email protected]>
AuthorDate: Fri, 4 Oct 2013 10:47:31 +0530
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 14 Oct 2013 10:24:04 -0300

perf trace: Improve the error messages

Currently, execution of 'perf trace' reports the following cryptic message to the user:

$ perf trace
Couldn't read the raw_syscalls tracepoints information!

Typically this happens because the user does not have permissions to read the debugfs filesystem. Also handle the case when the kernel was not compiled with debugfs support or when it isn't mounted.

Now, the tool prints detailed error messages:

$ perf trace
Error:	Unable to find debugfs
Hint:	Was your kernel was compiled with debugfs support?
Hint:	Is the debugfs filesystem mounted?
Hint:	Try 'sudo mount -t debugfs nodev /sys/kernel/debug'
$ perf trace
Error:	No permissions to read /sys/kernel/debug//tracing/events/raw_syscalls
Hint:	Try 'sudo mount -o remount,mode=755 /sys/kernel/debug/'

[ Added ready to use commands to fix the issues as extra hints, use the
current debugfs mount point when reporting permission error, use strerror_r instead of the deprecated sys_errlist, as reported by David Ahern ]

---
 tools/perf/builtin-trace.c | 37 ++++++++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 9 deletions(-)
tools/perf/builtin-trace.c +28 -9
index 19ddcab..5496546 100644
@@ -1590,17 +1590,13 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
 	}
 
 	if (perf_evlist__add_newtp(evlist, "raw_syscalls", "sys_enter", trace__sys_enter) ||
-	    perf_evlist__add_newtp(evlist, "raw_syscalls", "sys_exit", trace__sys_exit)) {
-		fprintf(trace->output, "Couldn't read the raw_syscalls tracepoints information!\n");
-		goto out_delete_evlist;
-	}
+		perf_evlist__add_newtp(evlist, "raw_syscalls", "sys_exit", trace__sys_exit))
+		goto out_error_tp;
 
 	if (trace->sched &&
-	    perf_evlist__add_newtp(evlist, "sched", "sched_stat_runtime",
-				   trace__sched_stat_runtime)) {
-		fprintf(trace->output, "Couldn't read the sched_stat_runtime tracepoint information!\n");
-		goto out_delete_evlist;
-	}
+		perf_evlist__add_newtp(evlist, "sched", "sched_stat_runtime",
+				trace__sched_stat_runtime))
+		goto out_error_tp;
 
 	err = perf_evlist__create_maps(evlist, &trace->opts.target);
 	if (err < 0) {
@@ -1717,6 +1713,29 @@ out_delete_evlist:
 out:
 	trace->live = false;
 	return err;
+out_error_tp:
+	switch(errno) {
+	case ENOENT:
+		fputs("Error:\tUnable to find debugfs\n"
+		      "Hint:\tWas your kernel was compiled with debugfs support?\n"
+		      "Hint:\tIs the debugfs filesystem mounted?\n"
+		      "Hint:\tTry 'sudo mount -t debugfs nodev /sys/kernel/debug'\n",
+		      trace->output);
+		break;
+	case EACCES:
+		fprintf(trace->output,
+			"Error:\tNo permissions to read %s/tracing/events/raw_syscalls\n"
+			"Hint:\tTry 'sudo mount -o remount,mode=755 %s'\n",
+			debugfs_mountpoint, debugfs_mountpoint);
+		break;
+	default: {
+		char bf[256];
+		fprintf(trace->output, "Can't trace: %s\n",
+			strerror_r(errno, bf, sizeof(bf)));
+	}
+		break;
+	}
+	goto out_delete_evlist;
 }
 
 static int trace__replay(struct trace *trace)