From patchwork Thu Mar 30 18:52:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13194734 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9C6DC761A6 for ; Thu, 30 Mar 2023 18:52:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231148AbjC3Swo (ORCPT ); Thu, 30 Mar 2023 14:52:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229862AbjC3Swn (ORCPT ); Thu, 30 Mar 2023 14:52:43 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCE7DFF3A for ; Thu, 30 Mar 2023 11:52:24 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 01C5E219E6; Thu, 30 Mar 2023 18:52:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1680202343; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Az2cNVIvgxzkStMlDWPi3f911ZMX3ggcRYCfYG8Fr34=; b=T0FRTpK3nND4223+lpPdRzQf17ea+1wFIYWl1pkdS6VGugIhAxoSl1Gyq0iZBdn+B/EeBd wA9eKCxIJJ9s9uCOv0Yu1OUkuyxp9VuOANUnfnfTM0KErJM3hv7QaognOEwkrvze+QZO96 HMdUJfJ8XdLXBjLq+cIkuRLwFQ8glmE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1680202343; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Az2cNVIvgxzkStMlDWPi3f911ZMX3ggcRYCfYG8Fr34=; b=gcOdQ9i0uemCLsSOUKW0VnQA8C0qKhykCHBCfz34IhoOoXTJXKYnOZnHGOREgfchJIdJFg VjD/AYR+0qdvcKBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 698AB133E0; Thu, 30 Mar 2023 18:52:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 3oRQDGbaJWSvMgAAMHmgww (envelope-from ); Thu, 30 Mar 2023 18:52:22 +0000 From: Gabriel Krisman Bertazi To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH trace-cmd v2 1/3] trace-cmd report: Ensure filter is applied to single input file Date: Thu, 30 Mar 2023 15:52:09 -0300 Message-Id: <20230330185211.5604-2-krisman@suse.de> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230330185211.5604-1-krisman@suse.de> References: <20230330185211.5604-1-krisman@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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 Fixes: 955d05fc7aee ("trace-cmd report: Make filter arguments match their files") Signed-off-by: Gabriel krisman Bertazi --- Since v1: - use rev. xmas tree for variable declaration (steve) --- tracecmd/trace-read.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tracecmd/trace-read.c b/tracecmd/trace-read.c index 52ba818..6a872d7 100644 --- a/tracecmd/trace-read.c +++ b/tracecmd/trace-read.c @@ -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; From patchwork Thu Mar 30 18:52:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13194735 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10556C761A6 for ; Thu, 30 Mar 2023 18:52:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230049AbjC3Swv (ORCPT ); Thu, 30 Mar 2023 14:52:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229862AbjC3Swu (ORCPT ); Thu, 30 Mar 2023 14:52:50 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23224EC7C for ; Thu, 30 Mar 2023 11:52:27 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 91BBC1F85D; Thu, 30 Mar 2023 18:52:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1680202346; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jZutCq9+0TxYs9yO+EsXc7MsuG/N5ce7rR6afByPjx4=; b=srZk09M3x2nL0IFoodN8dPiSAYTVNiMCH5jcUtab7GluCrGDRKb+8dN1xRrz84c67i2j40 zvqv62GBqAkhbzwZEPIAPTDQz7/5jXx5Un4QazRccvVjEeHb0eA/J8bCnE7Y4jsCCHFQtn xIXkpIW0q9nFACW2FtIp6ml+LJB6nCU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1680202346; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jZutCq9+0TxYs9yO+EsXc7MsuG/N5ce7rR6afByPjx4=; b=I+a5IXfuIthsz3ChlYaQ1gkJc3VlE/j4mvY7qSvd1GjaIcyk+WYUWjC/s0e0Gwklm3Ab23 gadejatgREZ+XODg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 0E321133E0; Thu, 30 Mar 2023 18:52:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ChJwL2naJWS9MgAAMHmgww (envelope-from ); Thu, 30 Mar 2023 18:52:25 +0000 From: Gabriel Krisman Bertazi To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH trace-cmd v2 2/3] trace-cmd-report: Support global filters Date: Thu, 30 Mar 2023 15:52:10 -0300 Message-Id: <20230330185211.5604-3-krisman@suse.de> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230330185211.5604-1-krisman@suse.de> References: <20230330185211.5604-1-krisman@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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 --- tracecmd/trace-read.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/tracecmd/trace-read.c b/tracecmd/trace-read.c index 6a872d7..f645c05 100644 --- a/tracecmd/trace-read.c +++ b/tracecmd/trace-read.c @@ -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); } From patchwork Thu Mar 30 18:52:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 13194736 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1F9CC761A6 for ; Thu, 30 Mar 2023 18:52:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229521AbjC3Sw5 (ORCPT ); Thu, 30 Mar 2023 14:52:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229862AbjC3Sw4 (ORCPT ); Thu, 30 Mar 2023 14:52:56 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82A35E38D for ; Thu, 30 Mar 2023 11:52:31 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2EF5B219E1; Thu, 30 Mar 2023 18:52:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1680202350; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9/LX+/x0zQKBc/HM3MPlOiF5a3jsDjP4p7tApoRAXuQ=; b=HvgHFhfnfr8qdvI8J//nm0F8YKj5uKBH2IpmwHr2cP7E7UqYEvRy8PaYZMAoEr5kuQutVO 5WIHVhAHNkCEtkLgPZD+X+zJThB+HtuaeIp2IYOvzIBkTDOuNeJvLTaFAhs/qW2W01hvyh ezWA5Kp2Fmb7i9h2VVKvIPnrvRtH1iE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1680202350; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9/LX+/x0zQKBc/HM3MPlOiF5a3jsDjP4p7tApoRAXuQ=; b=0fVzk5go5qZEPI3mKDQrxnB6YeZ25UIHHYL9bb3dXKkpO362biFZCfHV+PqLK5jv1isycE xsPhIVYgv21+mjAA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9BC68133E0; Thu, 30 Mar 2023 18:52:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id nHpzFm3aJWTFMgAAMHmgww (envelope-from ); Thu, 30 Mar 2023 18:52:29 +0000 From: Gabriel Krisman Bertazi To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH trace-cmd v2 3/3] documentation: trace-cmd-report: Document filter scope Date: Thu, 30 Mar 2023 15:52:11 -0300 Message-Id: <20230330185211.5604-4-krisman@suse.de> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230330185211.5604-1-krisman@suse.de> References: <20230330185211.5604-1-krisman@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Document how filters provided before any input files are global while filters coming after a -i only apply to that filter. Signed-off-by: Gabriel Krisman Bertazi --- Documentation/trace-cmd/trace-cmd-report.1.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Documentation/trace-cmd/trace-cmd-report.1.txt b/Documentation/trace-cmd/trace-cmd-report.1.txt index 71df9a8..ddbde81 100644 --- a/Documentation/trace-cmd/trace-cmd-report.1.txt +++ b/Documentation/trace-cmd/trace-cmd-report.1.txt @@ -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] ----