Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp313516pxm; Wed, 2 Mar 2022 16:08:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJyNVq3GsxJYw3xPF1B4+ty5IMgmSw3Jhbvvn7Hj/M1M5sEo6R23YxmIBypTkGHWL6RsMvl8 X-Received: by 2002:a05:6a00:1d8b:b0:4f1:bd8:811 with SMTP id z11-20020a056a001d8b00b004f10bd80811mr35737041pfw.25.1646266100836; Wed, 02 Mar 2022 16:08:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646266100; cv=none; d=google.com; s=arc-20160816; b=beYw3WvoGJhJwWycbLsJTybPsP2sEWjkZEWBgl36RY0A0xIQ2OvWezP38nhGbD1bII 2jfX5MUMJ8cMSnEVmZS4aA5Sb8VoBJx0LYqPVagYkY931oLgluZx24y2YRb9FEA3W2dt l/c44bDQa+sazDNJzrw8RyhDmJ5X2HJh2iHkG75ZO8i2WqvPgOwK0zmcS96eyqiSFb47 cm+/Jl4YjyUVV7KvTyFN4t988HfEy7zCdwTHMh7nJmCVjx6d1a9um/Y9ujh1LKaDbly0 L1I2NrQCq28wplLMV/rD8m9MdFDSeVFThVB8KI+9gTMyDfZ+tBuZYGZh1k/9HMh0VyQQ CinQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=CEKWb6R7+cAQ66Uf4XSFXj+lPOyT3hvXT4C+FF7Vd7A=; b=XjimS7QP2BI7UU+dCxeI9auxT429E1D7a0o5MIij+qA+dK0BnSHvQKbhpTnVItQDCs EAhVSHpIZ4bCMqfDwwnzRo220Tx1MdQqZ7J7Qd9kKdxPmLwZa5GqBDPAuZouURABf9P5 pRCq+VLTuEgojHxUj/7+HBsIn3duawVPy3UruKDkG50jQb87BFRpJnvIcj+9LqLmTZRT mM5PfgoCkgZHhgOLh4AXaPjIL7uvC7hQDzVhMCNUyfSQmuKT+mLgO8hAx3UQpgG5Vtwf uvpDRkV5GhU8uP2eXnU4iD89xkl55xpZJVhr81loS+g5TmfaVpjDjyA+DrDwwRZ3FoJz TLPA== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id i76-20020a639d4f000000b003784f4488cdsi529110pgd.180.2022.03.02.16.08.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 16:08:20 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 725761B513B; Wed, 2 Mar 2022 15:24:43 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244868AbiCBTE0 convert rfc822-to-8bit (ORCPT + 99 others); Wed, 2 Mar 2022 14:04:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237677AbiCBTEX (ORCPT ); Wed, 2 Mar 2022 14:04:23 -0500 Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [207.211.30.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C78A252E33 for ; Wed, 2 Mar 2022 11:03:22 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-455-NZhuc65vOBaQ65zdZKFB-g-1; Wed, 02 Mar 2022 14:03:18 -0500 X-MC-Unique: NZhuc65vOBaQ65zdZKFB-g-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 334F8100C618; Wed, 2 Mar 2022 19:03:17 +0000 (UTC) Received: from x1.com (unknown [10.22.32.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D69519C59; Wed, 2 Mar 2022 19:03:13 +0000 (UTC) From: Daniel Bristot de Oliveira To: Steven Rostedt Cc: Daniel Bristot de Oliveira , Jonathan Corbet , Clark Williams , Juri Lelli , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-devel@vger.kernel.org Subject: [PATCH V3 09/15] rtla/trace: Add trace event filter helpers Date: Wed, 2 Mar 2022 20:01:34 +0100 Message-Id: <12623b1684684549d53b90f4bf66fae44584fd14.1646247211.git.bristot@kernel.org> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=bristot@kernel.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset=WINDOWS-1252 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a set of helper functions to allow rtla tools to filter events in the trace instance. Cc: Daniel Bristot de Oliveira Cc: Steven Rostedt Cc: Jonathan Corbet Signed-off-by: Daniel Bristot de Oliveira --- tools/tracing/rtla/src/trace.c | 83 ++++++++++++++++++++++++++++++++++ tools/tracing/rtla/src/trace.h | 3 ++ 2 files changed, 86 insertions(+) diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index 7f8661b2724d..ef44bab0c404 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -204,6 +204,8 @@ static void trace_events_free(struct trace_events *events) tevent = tevent->next; + if (free_event->filter) + free(free_event->filter); if (free_event->trigger) free(free_event->trigger); free(free_event->system); @@ -237,6 +239,21 @@ struct trace_events *trace_event_alloc(const char *event_string) return tevent; } +/* + * trace_event_add_filter - record an event filter + */ +int trace_event_add_filter(struct trace_events *event, char *filter) +{ + if (event->filter) + free(event->filter); + + event->filter = strdup(filter); + if (!event->filter) + return 1; + + return 0; +} + /* * trace_event_add_trigger - record an event trigger action */ @@ -252,6 +269,33 @@ int trace_event_add_trigger(struct trace_events *event, char *trigger) return 0; } +/* + * trace_event_disable_filter - disable an event filter + */ +static void trace_event_disable_filter(struct trace_instance *instance, + struct trace_events *tevent) +{ + char filter[1024]; + int retval; + + if (!tevent->filter) + return; + + if (!tevent->filter_enabled) + return; + + debug_msg("Disabling %s:%s filter %s\n", tevent->system, + tevent->event ? : "*", tevent->filter); + + snprintf(filter, 1024, "!%s\n", tevent->filter); + + retval = tracefs_event_file_write(instance->inst, tevent->system, + tevent->event, "filter", filter); + if (retval < 0) + err_msg("Error disabling %s:%s filter %s\n", tevent->system, + tevent->event ? : "*", tevent->filter); +} + /* * trace_event_disable_trigger - disable an event trigger */ @@ -293,6 +337,7 @@ void trace_events_disable(struct trace_instance *instance, while (tevent) { debug_msg("Disabling event %s:%s\n", tevent->system, tevent->event ? : "*"); if (tevent->enabled) { + trace_event_disable_filter(instance, tevent); trace_event_disable_trigger(instance, tevent); tracefs_event_disable(instance->inst, tevent->system, tevent->event); } @@ -302,6 +347,41 @@ void trace_events_disable(struct trace_instance *instance, } } +/* + * trace_event_enable_filter - enable an event filter associated with an event + */ +static int trace_event_enable_filter(struct trace_instance *instance, + struct trace_events *tevent) +{ + char filter[1024]; + int retval; + + if (!tevent->filter) + return 0; + + if (!tevent->event) { + err_msg("Filter %s applies only for single events, not for all %s:* events\n", + tevent->filter, tevent->system); + return 1; + } + + snprintf(filter, 1024, "%s\n", tevent->filter); + + debug_msg("Enabling %s:%s filter %s\n", tevent->system, + tevent->event ? : "*", tevent->filter); + + retval = tracefs_event_file_write(instance->inst, tevent->system, + tevent->event, "filter", filter); + if (retval < 0) { + err_msg("Error enabling %s:%s filter %s\n", tevent->system, + tevent->event ? : "*", tevent->filter); + return 1; + } + + tevent->filter_enabled = 1; + return 0; +} + /* * trace_event_enable_trigger - enable an event trigger associated with an event */ @@ -356,6 +436,9 @@ int trace_events_enable(struct trace_instance *instance, return 1; } + retval = trace_event_enable_filter(instance, tevent); + if (retval) + return 1; retval = trace_event_enable_trigger(instance, tevent); if (retval) diff --git a/tools/tracing/rtla/src/trace.h b/tools/tracing/rtla/src/trace.h index 856b26d93064..51ad344c600b 100644 --- a/tools/tracing/rtla/src/trace.h +++ b/tools/tracing/rtla/src/trace.h @@ -6,8 +6,10 @@ struct trace_events { struct trace_events *next; char *system; char *event; + char *filter; char *trigger; char enabled; + char filter_enabled; char trigger_enabled; }; @@ -43,4 +45,5 @@ void trace_events_destroy(struct trace_instance *instance, int trace_events_enable(struct trace_instance *instance, struct trace_events *events); +int trace_event_add_filter(struct trace_events *event, char *filter); int trace_event_add_trigger(struct trace_events *event, char *trigger); -- 2.34.1