Commit f250c030 authored by Ingo Molnar's avatar Ingo Molnar

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
......@@ -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;
......@@ -394,7 +386,21 @@ static void open_counters(int cpu, pid_t pid)
error("failed to mmap with %d (%s)\n", errno, strerror(errno));
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++;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment