Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 191115
b: refs/heads/master
c: 46be604
h: refs/heads/master
i:
  191113: 75394fc
  191111: a73d98a
v: v3
  • Loading branch information
Zhang, Yanmin authored and Ingo Molnar committed Mar 18, 2010
1 parent 521ba3e commit ccdf481
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 6be2850effd6a8bae11d623c8c52e88d2fbc0e96
refs/heads/master: 46be604b5ba738d53e5f5314813a4e7092864baf
33 changes: 15 additions & 18 deletions trunk/tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ static struct perf_header_attr *get_header_attr(struct perf_event_attr *a, int n
return h_attr;
}

static void create_counter(int counter, int cpu, pid_t pid, bool forks)
static void create_counter(int counter, int cpu, pid_t pid)
{
char *filter = filters[counter];
struct perf_event_attr *attr = attrs + counter;
Expand Down Expand Up @@ -275,10 +275,10 @@ static void create_counter(int counter, int cpu, pid_t pid, bool forks)
attr->mmap = track;
attr->comm = track;
attr->inherit = inherit;
attr->disabled = 1;

if (forks)
if (target_pid == -1 && !system_wide) {
attr->disabled = 1;
attr->enable_on_exec = 1;
}

try_again:
fd[nr_cpu][counter] = sys_perf_event_open(attr, pid, cpu, group_fd, 0);
Expand Down Expand Up @@ -380,17 +380,15 @@ static void create_counter(int counter, int cpu, pid_t pid, bool forks)
exit(-1);
}
}

ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_ENABLE);
}

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

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

nr_cpu++;
}
Expand Down Expand Up @@ -425,7 +423,7 @@ static int __cmd_record(int argc, const char **argv)
int err;
unsigned long waking = 0;
int child_ready_pipe[2], go_pipe[2];
const bool forks = target_pid == -1 && argc > 0;
const bool forks = argc > 0;
char buf;

page_size = sysconf(_SC_PAGE_SIZE);
Expand Down Expand Up @@ -496,13 +494,13 @@ static int __cmd_record(int argc, const char **argv)
atexit(atexit_header);

if (forks) {
pid = fork();
child_pid = fork();
if (pid < 0) {
perror("failed to fork");
exit(-1);
}

if (!pid) {
if (!child_pid) {
close(child_ready_pipe[0]);
close(go_pipe[1]);
fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC);
Expand Down Expand Up @@ -531,11 +529,6 @@ static int __cmd_record(int argc, const char **argv)
exit(-1);
}

child_pid = pid;

if (!system_wide)
target_pid = pid;

close(child_ready_pipe[1]);
close(go_pipe[0]);
/*
Expand All @@ -548,13 +541,17 @@ static int __cmd_record(int argc, const char **argv)
close(child_ready_pipe[0]);
}

if (forks && target_pid == -1 && !system_wide)
pid = child_pid;
else
pid = target_pid;

if ((!system_wide && !inherit) || profile_cpu != -1) {
open_counters(profile_cpu, target_pid, forks);
open_counters(profile_cpu, pid);
} else {
nr_cpus = read_cpu_map();
for (i = 0; i < nr_cpus; i++)
open_counters(cpumap[i], target_pid, forks);
open_counters(cpumap[i], pid);
}

if (file_new) {
Expand Down

0 comments on commit ccdf481

Please sign in to comment.