summaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-script.c
diff options
context:
space:
mode:
authorAndi Kleen <ak@linux.intel.com>2019-03-11 10:44:52 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-03-11 15:13:05 -0400
commite87e548126cdc66fd4f194b38b59f351b6e5d3e8 (patch)
tree7704e4781f9d4e003260a9d79f69f68d4a587f4f /tools/perf/builtin-script.c
parent2fb71043e8894ca78258f7458a2db2eb3a142a22 (diff)
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: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Andi Kleen <ak@linux.intel.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Link: http://lkml.kernel.org/r/20190311144502.15423-2-andi@firstfloor.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-script.c')
-rw-r--r--tools/perf/builtin-script.c71
1 files changed, 47 insertions, 24 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 111787e83784..b695b20ffc8a 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1933,6 +1933,13 @@ static int cleanup_scripting(void)
1933 return scripting_ops ? scripting_ops->stop_script() : 0; 1933 return scripting_ops ? scripting_ops->stop_script() : 0;
1934} 1934}
1935 1935
1936static bool filter_cpu(struct perf_sample *sample)
1937{
1938 if (cpu_list)
1939 return !test_bit(sample->cpu, cpu_bitmap);
1940 return false;
1941}
1942
1936static int process_sample_event(struct perf_tool *tool, 1943static int process_sample_event(struct perf_tool *tool,
1937 union perf_event *event, 1944 union perf_event *event,
1938 struct perf_sample *sample, 1945 struct perf_sample *sample,
@@ -1967,7 +1974,7 @@ static int process_sample_event(struct perf_tool *tool,
1967 if (al.filtered) 1974 if (al.filtered)
1968 goto out_put; 1975 goto out_put;
1969 1976
1970 if (cpu_list && !test_bit(sample->cpu, cpu_bitmap)) 1977 if (filter_cpu(sample))
1971 goto out_put; 1978 goto out_put;
1972 1979
1973 if (scripting_ops) 1980 if (scripting_ops)
@@ -2052,9 +2059,11 @@ static int process_comm_event(struct perf_tool *tool,
2052 sample->tid = event->comm.tid; 2059 sample->tid = event->comm.tid;
2053 sample->pid = event->comm.pid; 2060 sample->pid = event->comm.pid;
2054 } 2061 }
2055 perf_sample__fprintf_start(sample, thread, evsel, 2062 if (!filter_cpu(sample)) {
2063 perf_sample__fprintf_start(sample, thread, evsel,
2056 PERF_RECORD_COMM, stdout); 2064 PERF_RECORD_COMM, stdout);
2057 perf_event__fprintf(event, stdout); 2065 perf_event__fprintf(event, stdout);
2066 }
2058 ret = 0; 2067 ret = 0;
2059out: 2068out:
2060 thread__put(thread); 2069 thread__put(thread);
@@ -2088,9 +2097,11 @@ static int process_namespaces_event(struct perf_tool *tool,
2088 sample->tid = event->namespaces.tid; 2097 sample->tid = event->namespaces.tid;
2089 sample->pid = event->namespaces.pid; 2098 sample->pid = event->namespaces.pid;
2090 } 2099 }
2091 perf_sample__fprintf_start(sample, thread, evsel, 2100 if (!filter_cpu(sample)) {
2092 PERF_RECORD_NAMESPACES, stdout); 2101 perf_sample__fprintf_start(sample, thread, evsel,
2093 perf_event__fprintf(event, stdout); 2102 PERF_RECORD_NAMESPACES, stdout);
2103 perf_event__fprintf(event, stdout);
2104 }
2094 ret = 0; 2105 ret = 0;
2095out: 2106out:
2096 thread__put(thread); 2107 thread__put(thread);
@@ -2122,9 +2133,11 @@ static int process_fork_event(struct perf_tool *tool,
2122 sample->tid = event->fork.tid; 2133 sample->tid = event->fork.tid;
2123 sample->pid = event->fork.pid; 2134 sample->pid = event->fork.pid;
2124 } 2135 }
2125 perf_sample__fprintf_start(sample, thread, evsel, 2136 if (!filter_cpu(sample)) {
2126 PERF_RECORD_FORK, stdout); 2137 perf_sample__fprintf_start(sample, thread, evsel,
2127 perf_event__fprintf(event, stdout); 2138 PERF_RECORD_FORK, stdout);
2139 perf_event__fprintf(event, stdout);
2140 }
2128 thread__put(thread); 2141 thread__put(thread);
2129 2142
2130 return 0; 2143 return 0;
@@ -2152,9 +2165,11 @@ static int process_exit_event(struct perf_tool *tool,
2152 sample->tid = event->fork.tid; 2165 sample->tid = event->fork.tid;
2153 sample->pid = event->fork.pid; 2166 sample->pid = event->fork.pid;
2154 } 2167 }
2155 perf_sample__fprintf_start(sample, thread, evsel, 2168 if (!filter_cpu(sample)) {
2156 PERF_RECORD_EXIT, stdout); 2169 perf_sample__fprintf_start(sample, thread, evsel,
2157 perf_event__fprintf(event, stdout); 2170 PERF_RECORD_EXIT, stdout);
2171 perf_event__fprintf(event, stdout);
2172 }
2158 2173
2159 if (perf_event__process_exit(tool, event, sample, machine) < 0) 2174 if (perf_event__process_exit(tool, event, sample, machine) < 0)
2160 err = -1; 2175 err = -1;
@@ -2188,9 +2203,11 @@ static int process_mmap_event(struct perf_tool *tool,
2188 sample->tid = event->mmap.tid; 2203 sample->tid = event->mmap.tid;
2189 sample->pid = event->mmap.pid; 2204 sample->pid = event->mmap.pid;
2190 } 2205 }
2191 perf_sample__fprintf_start(sample, thread, evsel, 2206 if (!filter_cpu(sample)) {
2192 PERF_RECORD_MMAP, stdout); 2207 perf_sample__fprintf_start(sample, thread, evsel,
2193 perf_event__fprintf(event, stdout); 2208 PERF_RECORD_MMAP, stdout);
2209 perf_event__fprintf(event, stdout);
2210 }
2194 thread__put(thread); 2211 thread__put(thread);
2195 return 0; 2212 return 0;
2196} 2213}
@@ -2220,9 +2237,11 @@ static int process_mmap2_event(struct perf_tool *tool,
2220 sample->tid = event->mmap2.tid; 2237 sample->tid = event->mmap2.tid;
2221 sample->pid = event->mmap2.pid; 2238 sample->pid = event->mmap2.pid;
2222 } 2239 }
2223 perf_sample__fprintf_start(sample, thread, evsel, 2240 if (!filter_cpu(sample)) {
2224 PERF_RECORD_MMAP2, stdout); 2241 perf_sample__fprintf_start(sample, thread, evsel,
2225 perf_event__fprintf(event, stdout); 2242 PERF_RECORD_MMAP2, stdout);
2243 perf_event__fprintf(event, stdout);
2244 }
2226 thread__put(thread); 2245 thread__put(thread);
2227 return 0; 2246 return 0;
2228} 2247}
@@ -2247,9 +2266,11 @@ static int process_switch_event(struct perf_tool *tool,
2247 return -1; 2266 return -1;
2248 } 2267 }
2249 2268
2250 perf_sample__fprintf_start(sample, thread, evsel, 2269 if (!filter_cpu(sample)) {
2251 PERF_RECORD_SWITCH, stdout); 2270 perf_sample__fprintf_start(sample, thread, evsel,
2252 perf_event__fprintf(event, stdout); 2271 PERF_RECORD_SWITCH, stdout);
2272 perf_event__fprintf(event, stdout);
2273 }
2253 thread__put(thread); 2274 thread__put(thread);
2254 return 0; 2275 return 0;
2255} 2276}
@@ -2270,9 +2291,11 @@ process_lost_event(struct perf_tool *tool,
2270 if (thread == NULL) 2291 if (thread == NULL)
2271 return -1; 2292 return -1;
2272 2293
2273 perf_sample__fprintf_start(sample, thread, evsel, 2294 if (!filter_cpu(sample)) {
2274 PERF_RECORD_LOST, stdout); 2295 perf_sample__fprintf_start(sample, thread, evsel,
2275 perf_event__fprintf(event, stdout); 2296 PERF_RECORD_LOST, stdout);
2297 perf_event__fprintf(event, stdout);
2298 }
2276 thread__put(thread); 2299 thread__put(thread);
2277 return 0; 2300 return 0;
2278} 2301}