Commit 6af206fd authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo
Browse files

perf stat: Don't show counter information when workload fails



When starting a workload 'stat' wasn't using prepare_workload evlist
method's signal based exec() error reporting mechanism.

Use it so that the we don't report 'not counted' counters.

Before:

  [acme@zoo linux]$ perf stat dfadsfa
  dfadsfa: No such file or directory

   Performance counter stats for 'dfadsfa':

       <not counted>      task-clock
       <not counted>      context-switches
       <not counted>      cpu-migrations
       <not counted>      page-faults
       <not counted>      cycles
       <not counted>      stalled-cycles-frontend
     <not supported>      stalled-cycles-backend
       <not counted>      instructions
       <not counted>      branches
       <not counted>      branch-misses

         0.001831462 seconds time elapsed

  [acme@zoo linux]$

After:

  [acme@zoo linux]$ perf stat dfadsfa
  dfadsfa: No such file or directory
  [acme@zoo linux]$

Reported-by: default avatarDavid Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-5yui3bv7e3hitxucnjsn6z8q@git.kernel.org


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 1341f3e4
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -509,6 +509,18 @@ static void handle_initial_delay(void)
	}
}

static volatile bool workload_exec_failed;

/*
 * perf_evlist__prepare_workload will send a SIGUSR1
 * if the fork fails, since we asked by setting its
 * want_signal to true.
 */
static void workload_exec_failed_signal(int signo __maybe_unused)
{
	workload_exec_failed = true;
}

static int __run_perf_stat(int argc, const char **argv)
{
	char msg[512];
@@ -529,7 +541,7 @@ static int __run_perf_stat(int argc, const char **argv)

	if (forks) {
		if (perf_evlist__prepare_workload(evsel_list, &target, argv,
						  false, false) < 0) {
						  false, true) < 0) {
			perror("failed to prepare workload");
			return -1;
		}
@@ -584,6 +596,14 @@ static int __run_perf_stat(int argc, const char **argv)
	clock_gettime(CLOCK_MONOTONIC, &ref_time);

	if (forks) {
		/*
		 * perf_evlist__prepare_workload will, after we call
		 * perf_evlist__start_Workload, send a SIGUSR1 if the exec call
		 * fails, that we will catch in workload_signal to flip
		 * workload_exec_failed.
 		 */
		signal(SIGUSR1, workload_exec_failed_signal);

		perf_evlist__start_workload(evsel_list);
		handle_initial_delay();

@@ -594,6 +614,10 @@ static int __run_perf_stat(int argc, const char **argv)
			}
		}
		wait(&status);

		if (workload_exec_failed)
			return -1;

		if (WIFSIGNALED(status))
			psignal(WTERMSIG(status), argv[0]);
	} else {