Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 084ab9f8 authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo Committed by Ingo Molnar
Browse files

perf stat: Better report failure to collect system wide stats



Before:

[acme@doppio linux-2.6-tip]$ perf stat -a sleep 1s

 Performance counter stats for 'sleep 1s':

  <not counted>  task-clock-msecs
  <not counted>  context-switches
  <not counted>  CPU-migrations
  <not counted>  page-faults
  <not counted>  cycles
  <not counted>  instructions
  <not counted>  branches
  <not counted>  branch-misses
  <not counted>  cache-references
  <not counted>  cache-misses

    1.016998463  seconds time elapsed

[acme@doppio linux-2.6-tip]$

Now:

[acme@doppio linux-2.6-tip]$ perf stat -a sleep 1s
No permission to collect system-wide stats.
Consider tweaking /proc/sys/kernel/perf_event_paranoid.
[acme@doppio linux-2.6-tip]$

Reported-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1269274229-20442-4-git-send-email-acme@infradead.org>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent ca721e45
Loading
Loading
Loading
Loading
+28 −11
Original line number Original line Diff line number Diff line
@@ -144,10 +144,11 @@ struct stats runtime_branches_stats;
#define ERR_PERF_OPEN \
#define ERR_PERF_OPEN \
"Error: counter %d, sys_perf_event_open() syscall returned with %d (%s)\n"
"Error: counter %d, sys_perf_event_open() syscall returned with %d (%s)\n"


static void create_perf_stat_counter(int counter)
static int create_perf_stat_counter(int counter)
{
{
	struct perf_event_attr *attr = attrs + counter;
	struct perf_event_attr *attr = attrs + counter;
	int thread;
	int thread;
	int ncreated = 0;


	if (scale)
	if (scale)
		attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
		attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
@@ -159,9 +160,11 @@ static void create_perf_stat_counter(int counter)
		for (cpu = 0; cpu < nr_cpus; cpu++) {
		for (cpu = 0; cpu < nr_cpus; cpu++) {
			fd[cpu][counter][0] = sys_perf_event_open(attr,
			fd[cpu][counter][0] = sys_perf_event_open(attr,
					-1, cpumap[cpu], -1, 0);
					-1, cpumap[cpu], -1, 0);
			if (fd[cpu][counter][0] < 0 && verbose)
			if (fd[cpu][counter][0] < 0)
				fprintf(stderr, ERR_PERF_OPEN, counter,
				pr_debug(ERR_PERF_OPEN, counter,
					 fd[cpu][counter][0], strerror(errno));
					 fd[cpu][counter][0], strerror(errno));
			else
				++ncreated;
		}
		}
	} else {
	} else {
		attr->inherit	     = inherit;
		attr->inherit	     = inherit;
@@ -172,12 +175,16 @@ static void create_perf_stat_counter(int counter)
		for (thread = 0; thread < thread_num; thread++) {
		for (thread = 0; thread < thread_num; thread++) {
			fd[0][counter][thread] = sys_perf_event_open(attr,
			fd[0][counter][thread] = sys_perf_event_open(attr,
				all_tids[thread], -1, -1, 0);
				all_tids[thread], -1, -1, 0);
			if (fd[0][counter][thread] < 0 && verbose)
			if (fd[0][counter][thread] < 0)
				fprintf(stderr, ERR_PERF_OPEN, counter,
				pr_debug(ERR_PERF_OPEN, counter,
					 fd[0][counter][thread],
					 fd[0][counter][thread],
					 strerror(errno));
					 strerror(errno));
			else
				++ncreated;
		}
		}
	}
	}

	return ncreated;
}
}


/*
/*
@@ -264,7 +271,7 @@ static int run_perf_stat(int argc __used, const char **argv)
{
{
	unsigned long long t0, t1;
	unsigned long long t0, t1;
	int status = 0;
	int status = 0;
	int counter;
	int counter, ncreated = 0;
	int child_ready_pipe[2], go_pipe[2];
	int child_ready_pipe[2], go_pipe[2];
	const bool forks = (argc > 0);
	const bool forks = (argc > 0);
	char buf;
	char buf;
@@ -324,7 +331,16 @@ static int run_perf_stat(int argc __used, const char **argv)
	}
	}


	for (counter = 0; counter < nr_counters; counter++)
	for (counter = 0; counter < nr_counters; counter++)
		create_perf_stat_counter(counter);
		ncreated += create_perf_stat_counter(counter);

	if (ncreated == 0) {
		pr_err("No permission to collect %sstats.\n"
		       "Consider tweaking /proc/sys/kernel/perf_event_paranoid.\n",
		       system_wide ? "system-wide " : "");
		if (child_pid != -1)
			kill(child_pid, SIGTERM);
		return -1;
	}


	/*
	/*
	 * Enable counters and exec the command:
	 * Enable counters and exec the command:
@@ -587,6 +603,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
		status = run_perf_stat(argc, argv);
		status = run_perf_stat(argc, argv);
	}
	}


	if (status != -1)
		print_stat(argc, argv);
		print_stat(argc, argv);


	return status;
	return status;