Re: [PATCH 02/19] perf ftrace: detect workload failure

From: Arnaldo Carvalho de Melo
Date: Wed May 20 2020 - 16:51:08 EST


Em Sun, May 10, 2020 at 11:06:11PM +0800, Changbin Du escreveu:
> Currently there's no error message prompted if we failed to start workload.
> And we still get some trace which is confusing. Let's tell users what
> happened.

Applied, but please in the future add Before and After output of the
commands for these to be clear even to my 4yo kid:

commit 2a5193e460eaf8792a87f678e3c5f78c88db2123
Author: Changbin Du <changbin.du@xxxxxxxxx>
Date: Sun May 10 23:06:11 2020 +0800

perf ftrace: Detect workload failure

Currently there's no error message prompted if we failed to start
workload. And we still get some trace which is confusing. Let's tell
users what happened.

Committer testing:

Before:

# perf ftrace nonsense |& head
5) | switch_mm_irqs_off() {
5) 0.400 us | load_new_mm_cr3();
5) 3.261 us | }
------------------------------------------
5) <idle>-0 => <...>-3494
------------------------------------------

5) | finish_task_switch() {
5) ==========> |
5) | smp_irq_work_interrupt() {
# type nonsense
-bash: type: nonsense: not found
#

After:

# perf ftrace nonsense |& head
workload failed: No such file or directory
# type nonsense
-bash: type: nonsense: not found
#

Signed-off-by: Changbin Du <changbin.du@xxxxxxxxx>
Tested-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
Cc: Steven Rostedt (VMware) <rostedt@xxxxxxxxxxx>
Link: http://lore.kernel.org/lkml/20200510150628.16610-3-changbin.du@xxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>

diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index b7d3fb5fa8b1..2bfc1b0db536 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -45,6 +45,7 @@ struct filter_entry {
char name[];
};

+static volatile int workload_exec_errno;
static bool done;

static void sig_handler(int sig __maybe_unused)
@@ -63,7 +64,7 @@ static void ftrace__workload_exec_failed_signal(int signo __maybe_unused,
siginfo_t *info __maybe_unused,
void *ucontext __maybe_unused)
{
- /* workload_exec_errno = info->si_value.sival_int; */
+ workload_exec_errno = info->si_value.sival_int;
done = true;
}

@@ -383,6 +384,14 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)

write_tracing_file("tracing_on", "0");

+ if (workload_exec_errno) {
+ const char *emsg = str_error_r(workload_exec_errno, buf, sizeof(buf));
+ /* flush stdout first so below error msg appears at the end. */
+ fflush(stdout);
+ pr_err("workload failed: %s\n", emsg);
+ goto out_close_fd;
+ }
+
/* read remaining buffer contents */
while (true) {
int n = read(trace_fd, buf, sizeof(buf));
@@ -397,7 +406,7 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv)
out_reset:
reset_tracing_files(ftrace);
out:
- return done ? 0 : -1;
+ return (done && !workload_exec_errno) ? 0 : -1;
}

static int perf_ftrace_config(const char *var, const char *value, void *cb)