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

Commit f250c030 authored by Ingo Molnar's avatar Ingo Molnar
Browse files

perf record: Split out counter creation into a helper function



Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <new-submission>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent ee7b31fe
Loading
Loading
Loading
Loading
+53 −47
Original line number Diff line number Diff line
@@ -336,20 +336,13 @@ static void synthesize_events(void)
	closedir(proc);
}

static void open_counters(int cpu, pid_t pid)
static int group_fd;

static void create_counter(int counter, int cpu, pid_t pid)
{
	struct perf_counter_attr attr;
	int counter, group_fd;
	int track = 1;

	if (pid > 0) {
		pid_synthesize_comm_event(pid, 0);
		pid_synthesize_mmap_events(pid);
	}

	group_fd = -1;
	for (counter = 0; counter < nr_counters; counter++) {

	memset(&attr, 0, sizeof(attr));
	attr.config		= event_id[counter];
	attr.sample_period	= event_count[counter];
@@ -358,10 +351,9 @@ static void open_counters(int cpu, pid_t pid)
	attr.comm		= track;
	attr.inherit	= (cpu < 0) && inherit;

		track = 0; // only the first counter needs these
	track = 0; /* only the first counter needs these */

		fd[nr_cpu][counter] =
			sys_perf_counter_open(&attr, pid, cpu, group_fd, 0);
	fd[nr_cpu][counter] = sys_perf_counter_open(&attr, pid, cpu, group_fd, 0);

	if (fd[nr_cpu][counter] < 0) {
		int err = errno;
@@ -395,6 +387,20 @@ static void open_counters(int cpu, pid_t pid)
		exit(-1);
	}
}

static void open_counters(int cpu, pid_t pid)
{
	int counter;

	if (pid > 0) {
		pid_synthesize_comm_event(pid, 0);
		pid_synthesize_mmap_events(pid);
	}

	group_fd = -1;
	for (counter = 0; counter < nr_counters; counter++)
		create_counter(counter, cpu, pid);

	nr_cpu++;
}