trace-cmd filtering
v2 cover trace-cmd filtering
Hi Steve,
This implements my fix to restore single input filtering behavior (bz217038) and adds support for global filters, as you requested.
On another topic, a current behavior that seems weird in my opinion is that the following negates the second filter as well.
"trace-cmd -i trace.dat.1 -v -F tp1 -i trace.dat.2 -F tp2"
I'd prefer that -v would apply only to the following -F. It'd allow me to do:
"trace-cmd -v -F 'mm_page_alloc' -i trace.dat.1 -i trace.dat.2 ... \
-i trace.dat.10 -F 'mm_page_alloc:order==1'"It obviously breaks the interface, so I didn't implement it here. Would like to hear your input, though. We could have a new syntax:
"trace-cmd ! -F tp1 -F tp2 ! -F tp3"
Thanks,
Gabriel Krisman Bertazi (3):
trace-cmd report: Ensure filter is applied to single input file
trace-cmd-report: Support global filters
documentation: trace-cmd-report: Document filter scope
.../trace-cmd/trace-cmd-report.1.txt | 8 +++- tracecmd/trace-read.c | 45 ++++++++++++------- 2 files changed, 34 insertions(+), 19 deletions(-)
Signature · 1 line
2.40.0
PATCH v2 1/3 trace-cmd report: Ensure filter is applied to single input file
Since 955d05fc7aee ("trace-cmd report: Make filter arguments match their files"), the -F filtering is silently ignored when a trace file is provided with -i and the filter comes after -i . The reason is that the filter is now associated with input_files and not saved to the global list only in this case, but process_filters still only checks the global list when handles->input_file is not set.
Avoid this by checking last_input_file first, which always contains a pointer to the correct filter in this case.
This was only lightly tested, using a single trace file.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=217038
---
Since v1:
- use rev. xmas tree for variable declaration (steve)
--- tracecmd/trace-read.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
tracecmd/trace-read.c +4 -3
@@ -564,14 +564,15 @@ static void make_pid_filter(struct tracecmd_input *handle,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 ; -make_pid_filter (handles->handle, handles->input_file); +make_pid_filter (handles->handle, input_file); -if (handles->input_file) - filter = handles->input_file->filter_str; +if (input_file) + filter = input_file->filter_str;else filter = filter_strings;
Signature · 1 line
2.40.0
PATCH v2 2/3 trace-cmd-report: Support global filters
In reply to Gabriel Krisman BertaziWhen 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.
--- tracecmd/trace-read.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-)
tracecmd/trace-read.c +26 -16
@@ -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 ); }
Signature · 1 line
2.40.0
PATCH v2 3/3 documentation: trace-cmd-report: Document filter scope
In reply to Gabriel Krisman BertaziDocument how filters provided before any input files are global while filters coming after a -i only apply to that filter.
--- Documentation/trace-cmd/trace-cmd-report.1.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
Documentation/trace-cmd/trace-cmd-report.1.txt +6 -2
@@ -69,8 +69,12 @@ OPTIONS is only to the microsecond. To see the full timestamp, add the *-t* option. *-F* 'filter':: - Add a filter to limit what events are displayed. The format of the filter - is: + Add a filter to limit what events are displayed. Filters defined + after an input file (specified with *-i*) only apply to that + input file. Filters provided before any input file is given are + considered global and apply to all input files. + + The format of the filter is: [source,bison] ----
Signature · 1 line
2.40.0
Quoted 1 line · Gabriel Krisman Bertazi
Hi Steve,
I wanted to ping you regarding this patchset. Do you intend to take this as-is?
Thanks!
Quoted 30 lines
This implements my fix to restore single input filtering behavior (bz217038) and adds support for global filters, as you requested.
On another topic, a current behavior that seems weird in my opinion is that the following negates the second filter as well.
"trace-cmd -i trace.dat.1 -v -F tp1 -i trace.dat.2 -F tp2"
I'd prefer that -v would apply only to the following -F. It'd allow me to do:
"trace-cmd -v -F 'mm_page_alloc' -i trace.dat.1 -i trace.dat.2 ... \ -i trace.dat.10 -F 'mm_page_alloc:order==1'"It obviously breaks the interface, so I didn't implement it here. Would like to hear your input, though. We could have a new syntax:
"trace-cmd ! -F tp1 -F tp2 ! -F tp3"
Thanks,
Gabriel Krisman Bertazi (3):
trace-cmd report: Ensure filter is applied to single input file
trace-cmd-report: Support global filters
documentation: trace-cmd-report: Document filter scope.../trace-cmd/trace-cmd-report.1.txt | 8 +++- tracecmd/trace-read.c | 45 ++++++++++++------- 2 files changed, 34 insertions(+), 19 deletions(-)
Signature · 1 line
Gabriel Krisman Bertazi
Quoted 7 lines · On Sat, 06 May 2023 18:35:34 -0400 Gabriel Krisman Bertazi <[email protected]>…
Quoted 1 line · Gabriel Krisman Bertazi
Hi Steve,
I wanted to ping you regarding this patchset. Do you intend to take this as-is?
Apologies, I've been mostly focused on the kernel the last few weeks, but as I'm giving a talk on the tracing libraries on Thursday, I'll be focusing on them now ;-)
https://ossna2023.sched.com/event/1K58e
So I'll reply in a few days.
-- Steve
Quoted 1 line · On Thu, 30 Mar 2023 15:52:08 -0300 Gabriel Krisman Bertazi <[email protected]>…
Hi Steve,
Hi Gabriel,
Sorry for taking so long. I finally got time to start looking at the libtrace* trace-cmd code, and I queued this up for the next push.
Thanks Gabriel!
-- Steve
Quoted 31 lines
This implements my fix to restore single input filtering behavior (bz217038) and adds support for global filters, as you requested.
On another topic, a current behavior that seems weird in my opinion is that the following negates the second filter as well.
"trace-cmd -i trace.dat.1 -v -F tp1 -i trace.dat.2 -F tp2"
I'd prefer that -v would apply only to the following -F. It'd allow me to do:
"trace-cmd -v -F 'mm_page_alloc' -i trace.dat.1 -i trace.dat.2 ... \ -i trace.dat.10 -F 'mm_page_alloc:order==1'"It obviously breaks the interface, so I didn't implement it here. Would like to hear your input, though. We could have a new syntax:
"trace-cmd ! -F tp1 -F tp2 ! -F tp3"
Thanks,
Gabriel Krisman Bertazi (3):
trace-cmd report: Ensure filter is applied to single input file
trace-cmd-report: Support global filters
documentation: trace-cmd-report: Document filter scope.../trace-cmd/trace-cmd-report.1.txt | 8 +++- tracecmd/trace-read.c | 45 ++++++++++++------- 2 files changed, 34 insertions(+), 19 deletions(-)