Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp300422pxm; Wed, 2 Mar 2022 15:50:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJyt56hx90wyFQjqA6RT8GZHhIM3Eyc2uMgZ9wpP2mexGsCqNfyYgaF+u11R4uLcIMKJgsF5 X-Received: by 2002:a63:481b:0:b0:378:9b24:5163 with SMTP id v27-20020a63481b000000b003789b245163mr15462319pga.224.1646265015544; Wed, 02 Mar 2022 15:50:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646265015; cv=none; d=google.com; s=arc-20160816; b=LTkCo0axQ7rGIaa4dC+1U6DfNo87qGehrAz74UVV2gnIT4qhJ+Z6txOMk5N+C8a99y 38QD7b575O7F2foTummV0VKqk7077N1F5InXi070vqmIwHU5W1ls/LOUxbonfZpQ18rP VoWPtT6VdF+cx7hqWHLKuXnJjEX//GeJU0E3awq02tlWdrBOuSf9zaleF982xNB2r9B6 LQn80uCtRhKyIPAOJWjNWcDTO48dVlbmAZWSDvyKcAIxx2XuXNF8duliqI3AwmORt/bn vXSTTAjJpjXY+Nf5/tDQ4okY40H0ukBTMPxq142zfwnvBc96foDx39BlhuvAt8jcwvV4 L+5A== 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=Q5pwUuvvQkMWIqmv+VCXp1HBpfOIZNnIO/B1RGW8kmU=; b=SqXUR+pZJqxOFSa8ZZoqWlNXlttBny6wSt0idHCWEeILp3cRz6GVW0dNNnr2thgvPu N08VuL5ywQ37kxKuEg7rD/WJNPLXVZcZ3WkhWIPxCZ/pu5u/nTIEoqO6ecXXfNfyUcGP fjrk3R43t+jJFwZ+FV4onvOK8wz3TLmHO1RSbWdS/8wI/9VhylQsx7xHh3r48Uf6GaBI FbCyjoqH27k7hsWh45/PPXuLNYbrRBdmSGDQ39Cae8ZuWsHde1H63qiXmYIKJdIWfaZp Ulq0AcImlAkzJIFgQ6HNXTYiJPjlajpWeyxW1UlJr3WizdFcPj5l8d6wyJUYJJOsHIVc 8pcw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d128-20020a636886000000b00372adc47322si448517pgc.186.2022.03.02.15.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 15:50:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (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 1ACF049275; Wed, 2 Mar 2022 15:12:33 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244859AbiCBTER convert rfc822-to-8bit (ORCPT + 99 others); Wed, 2 Mar 2022 14:04:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244849AbiCBTEK (ORCPT ); Wed, 2 Mar 2022 14:04:10 -0500 Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2C1F949681 for ; Wed, 2 Mar 2022 11:03:14 -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-330-j5JV5jAJPzKw3pQm9IliKQ-1; Wed, 02 Mar 2022 14:03:10 -0500 X-MC-Unique: j5JV5jAJPzKw3pQm9IliKQ-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 725BD1800D50; Wed, 2 Mar 2022 19:03:09 +0000 (UTC) Received: from x1.com (unknown [10.22.32.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id 41B5919C59; Wed, 2 Mar 2022 19:02:45 +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 07/15] rtla/trace: Add trace event trigger helpers Date: Wed, 2 Mar 2022 20:01:32 +0100 Message-Id: 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 trigger event actions 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 | 88 +++++++++++++++++++++++++++++++++- tools/tracing/rtla/src/trace.h | 4 ++ 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index 9ad3d8890ec5..7f8661b2724d 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->trigger) + free(free_event->trigger); free(free_event->system); free(free_event); } @@ -235,6 +237,48 @@ struct trace_events *trace_event_alloc(const char *event_string) return tevent; } +/* + * trace_event_add_trigger - record an event trigger action + */ +int trace_event_add_trigger(struct trace_events *event, char *trigger) +{ + if (event->trigger) + free(event->trigger); + + event->trigger = strdup(trigger); + if (!event->trigger) + return 1; + + return 0; +} + +/* + * trace_event_disable_trigger - disable an event trigger + */ +static void trace_event_disable_trigger(struct trace_instance *instance, + struct trace_events *tevent) +{ + char trigger[1024]; + int retval; + + if (!tevent->trigger) + return; + + if (!tevent->trigger_enabled) + return; + + debug_msg("Disabling %s:%s trigger %s\n", tevent->system, + tevent->event ? : "*", tevent->trigger); + + snprintf(trigger, 1024, "!%s\n", tevent->trigger); + + retval = tracefs_event_file_write(instance->inst, tevent->system, + tevent->event, "trigger", trigger); + if (retval < 0) + err_msg("Error disabling %s:%s trigger %s\n", tevent->system, + tevent->event ? : "*", tevent->trigger); +} + /* * trace_events_disable - disable all trace events */ @@ -248,14 +292,52 @@ void trace_events_disable(struct trace_instance *instance, while (tevent) { debug_msg("Disabling event %s:%s\n", tevent->system, tevent->event ? : "*"); - if (tevent->enabled) + if (tevent->enabled) { + trace_event_disable_trigger(instance, tevent); tracefs_event_disable(instance->inst, tevent->system, tevent->event); + } tevent->enabled = 0; tevent = tevent->next; } } +/* + * trace_event_enable_trigger - enable an event trigger associated with an event + */ +static int trace_event_enable_trigger(struct trace_instance *instance, + struct trace_events *tevent) +{ + char trigger[1024]; + int retval; + + if (!tevent->trigger) + return 0; + + if (!tevent->event) { + err_msg("Trigger %s applies only for single events, not for all %s:* events\n", + tevent->trigger, tevent->system); + return 1; + } + + snprintf(trigger, 1024, "%s\n", tevent->trigger); + + debug_msg("Enabling %s:%s trigger %s\n", tevent->system, + tevent->event ? : "*", tevent->trigger); + + retval = tracefs_event_file_write(instance->inst, tevent->system, + tevent->event, "trigger", trigger); + if (retval < 0) { + err_msg("Error enabling %s:%s trigger %s\n", tevent->system, + tevent->event ? : "*", tevent->trigger); + return 1; + } + + tevent->trigger_enabled = 1; + + return 0; +} + /* * trace_events_enable - enable all events */ @@ -275,6 +357,10 @@ int trace_events_enable(struct trace_instance *instance, } + retval = trace_event_enable_trigger(instance, tevent); + if (retval) + return 1; + tevent->enabled = 1; tevent = tevent->next; } diff --git a/tools/tracing/rtla/src/trace.h b/tools/tracing/rtla/src/trace.h index 9f9751f7ee36..856b26d93064 100644 --- a/tools/tracing/rtla/src/trace.h +++ b/tools/tracing/rtla/src/trace.h @@ -6,7 +6,9 @@ struct trace_events { struct trace_events *next; char *system; char *event; + char *trigger; char enabled; + char trigger_enabled; }; struct trace_instance { @@ -40,3 +42,5 @@ void trace_events_destroy(struct trace_instance *instance, struct trace_events *events); int trace_events_enable(struct trace_instance *instance, struct trace_events *events); + +int trace_event_add_trigger(struct trace_events *event, char *trigger); -- 2.34.1