@@ -562,30 +562,40 @@ static void make_pid_filter(struct tracecmd_input *handle,
}
}
+static int __process_filters(struct tracecmd_input *handle,
+ struct filter_str *filters)
+{
+ struct tracecmd_filter *trace_filter;
+
+ for (; filters; filters = filters->next) {
+ trace_filter = tracecmd_filter_add(handle,
+ filters->filter,
+ filters->neg);
+ if (!trace_filter)
+ die("Failed to create event filter: %s",
+ filters->filter);
+ }
+
+ return !!filters;
+}
+
static void process_filters(struct handle_list *handles)
{
struct input_files *input_file = handles->input_file ?: last_input_file;
- struct tracecmd_filter *trace_filter;
- struct filter_str *filter;
- int filters = 0;
+ int added = 0;
make_pid_filter(handles->handle, input_file);
+ /*
+ * Order of filter processing matters. Apply the global filters
+ * before file-specific ones.
+ */
+ added += __process_filters(handles->handle, filter_strings);
if (input_file)
- filter = input_file->filter_str;
- else
- filter = filter_strings;
-
- for (; filter; filter = filter->next) {
- trace_filter = tracecmd_filter_add(handles->handle,
- filter->filter,
- filter->neg);
- if (!trace_filter)
- die("Failed to create event filter: %s", filter->filter);
+ added += __process_filters(handles->handle,
+ input_file->filter_str);
- filters++;
- }
- if (filters && test_filters_mode)
+ if (added && test_filters_mode)
exit(0);
}
When a filter is provided before an input file, consider it globally applying to all traces: i.e., the following will trace kernel_stack out of both traces instead of only the first: $ trace-cmd report -v -F kernel_stack -i trace1.dat -i trace2.dat Filter order matters due to the order of processing. Always process global filters first, which are likely more generic. Signed-off-by: Gabriel Krisman Bertazi <krisman@suse.de> --- tracecmd/trace-read.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-)