Commit e87e5481 authored by Andi Kleen's avatar Andi Kleen Committed by Arnaldo Carvalho de Melo

perf script: Filter COMM/FORK/.. events by CPU

The --cpu option only filtered samples. Filter other perf events, such
as COMM, FORK, SWITCH by the CPU too.
Reported-by: default avatarJiri Olsa <jolsa@kernel.org>
Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/20190311144502.15423-2-andi@firstfloor.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 2fb71043
...@@ -1933,6 +1933,13 @@ static int cleanup_scripting(void) ...@@ -1933,6 +1933,13 @@ static int cleanup_scripting(void)
return scripting_ops ? scripting_ops->stop_script() : 0; return scripting_ops ? scripting_ops->stop_script() : 0;
} }
static bool filter_cpu(struct perf_sample *sample)
{
if (cpu_list)
return !test_bit(sample->cpu, cpu_bitmap);
return false;
}
static int process_sample_event(struct perf_tool *tool, static int process_sample_event(struct perf_tool *tool,
union perf_event *event, union perf_event *event,
struct perf_sample *sample, struct perf_sample *sample,
...@@ -1967,7 +1974,7 @@ static int process_sample_event(struct perf_tool *tool, ...@@ -1967,7 +1974,7 @@ static int process_sample_event(struct perf_tool *tool,
if (al.filtered) if (al.filtered)
goto out_put; goto out_put;
if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) if (filter_cpu(sample))
goto out_put; goto out_put;
if (scripting_ops) if (scripting_ops)
...@@ -2052,9 +2059,11 @@ static int process_comm_event(struct perf_tool *tool, ...@@ -2052,9 +2059,11 @@ static int process_comm_event(struct perf_tool *tool,
sample->tid = event->comm.tid; sample->tid = event->comm.tid;
sample->pid = event->comm.pid; sample->pid = event->comm.pid;
} }
perf_sample__fprintf_start(sample, thread, evsel, if (!filter_cpu(sample)) {
perf_sample__fprintf_start(sample, thread, evsel,
PERF_RECORD_COMM, stdout); PERF_RECORD_COMM, stdout);
perf_event__fprintf(event, stdout); perf_event__fprintf(event, stdout);
}
ret = 0; ret = 0;
out: out:
thread__put(thread); thread__put(thread);
...@@ -2088,9 +2097,11 @@ static int process_namespaces_event(struct perf_tool *tool, ...@@ -2088,9 +2097,11 @@ static int process_namespaces_event(struct perf_tool *tool,
sample->tid = event->namespaces.tid; sample->tid = event->namespaces.tid;
sample->pid = event->namespaces.pid; sample->pid = event->namespaces.pid;
} }
perf_sample__fprintf_start(sample, thread, evsel, if (!filter_cpu(sample)) {
PERF_RECORD_NAMESPACES, stdout); perf_sample__fprintf_start(sample, thread, evsel,
perf_event__fprintf(event, stdout); PERF_RECORD_NAMESPACES, stdout);
perf_event__fprintf(event, stdout);
}
ret = 0; ret = 0;
out: out:
thread__put(thread); thread__put(thread);
...@@ -2122,9 +2133,11 @@ static int process_fork_event(struct perf_tool *tool, ...@@ -2122,9 +2133,11 @@ static int process_fork_event(struct perf_tool *tool,
sample->tid = event->fork.tid; sample->tid = event->fork.tid;
sample->pid = event->fork.pid; sample->pid = event->fork.pid;
} }
perf_sample__fprintf_start(sample, thread, evsel, if (!filter_cpu(sample)) {
PERF_RECORD_FORK, stdout); perf_sample__fprintf_start(sample, thread, evsel,
perf_event__fprintf(event, stdout); PERF_RECORD_FORK, stdout);
perf_event__fprintf(event, stdout);
}
thread__put(thread); thread__put(thread);
return 0; return 0;
...@@ -2152,9 +2165,11 @@ static int process_exit_event(struct perf_tool *tool, ...@@ -2152,9 +2165,11 @@ static int process_exit_event(struct perf_tool *tool,
sample->tid = event->fork.tid; sample->tid = event->fork.tid;
sample->pid = event->fork.pid; sample->pid = event->fork.pid;
} }
perf_sample__fprintf_start(sample, thread, evsel, if (!filter_cpu(sample)) {
PERF_RECORD_EXIT, stdout); perf_sample__fprintf_start(sample, thread, evsel,
perf_event__fprintf(event, stdout); PERF_RECORD_EXIT, stdout);
perf_event__fprintf(event, stdout);
}
if (perf_event__process_exit(tool, event, sample, machine) < 0) if (perf_event__process_exit(tool, event, sample, machine) < 0)
err = -1; err = -1;
...@@ -2188,9 +2203,11 @@ static int process_mmap_event(struct perf_tool *tool, ...@@ -2188,9 +2203,11 @@ static int process_mmap_event(struct perf_tool *tool,
sample->tid = event->mmap.tid; sample->tid = event->mmap.tid;
sample->pid = event->mmap.pid; sample->pid = event->mmap.pid;
} }
perf_sample__fprintf_start(sample, thread, evsel, if (!filter_cpu(sample)) {
PERF_RECORD_MMAP, stdout); perf_sample__fprintf_start(sample, thread, evsel,
perf_event__fprintf(event, stdout); PERF_RECORD_MMAP, stdout);
perf_event__fprintf(event, stdout);
}
thread__put(thread); thread__put(thread);
return 0; return 0;
} }
...@@ -2220,9 +2237,11 @@ static int process_mmap2_event(struct perf_tool *tool, ...@@ -2220,9 +2237,11 @@ static int process_mmap2_event(struct perf_tool *tool,
sample->tid = event->mmap2.tid; sample->tid = event->mmap2.tid;
sample->pid = event->mmap2.pid; sample->pid = event->mmap2.pid;
} }
perf_sample__fprintf_start(sample, thread, evsel, if (!filter_cpu(sample)) {
PERF_RECORD_MMAP2, stdout); perf_sample__fprintf_start(sample, thread, evsel,
perf_event__fprintf(event, stdout); PERF_RECORD_MMAP2, stdout);
perf_event__fprintf(event, stdout);
}
thread__put(thread); thread__put(thread);
return 0; return 0;
} }
...@@ -2247,9 +2266,11 @@ static int process_switch_event(struct perf_tool *tool, ...@@ -2247,9 +2266,11 @@ static int process_switch_event(struct perf_tool *tool,
return -1; return -1;
} }
perf_sample__fprintf_start(sample, thread, evsel, if (!filter_cpu(sample)) {
PERF_RECORD_SWITCH, stdout); perf_sample__fprintf_start(sample, thread, evsel,
perf_event__fprintf(event, stdout); PERF_RECORD_SWITCH, stdout);
perf_event__fprintf(event, stdout);
}
thread__put(thread); thread__put(thread);
return 0; return 0;
} }
...@@ -2270,9 +2291,11 @@ process_lost_event(struct perf_tool *tool, ...@@ -2270,9 +2291,11 @@ process_lost_event(struct perf_tool *tool,
if (thread == NULL) if (thread == NULL)
return -1; return -1;
perf_sample__fprintf_start(sample, thread, evsel, if (!filter_cpu(sample)) {
PERF_RECORD_LOST, stdout); perf_sample__fprintf_start(sample, thread, evsel,
perf_event__fprintf(event, stdout); PERF_RECORD_LOST, stdout);
perf_event__fprintf(event, stdout);
}
thread__put(thread); thread__put(thread);
return 0; return 0;
} }
......
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