Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp4402578pxb; Mon, 21 Feb 2022 20:25:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJwkeazBykXIc+UlOAGHEsuwDQyoXVvZvHDKJ4nfUMl+o03Ox6HZb1+C6cAYVmqOzcQXKJNj X-Received: by 2002:aa7:918f:0:b0:4cc:3c00:b2dd with SMTP id x15-20020aa7918f000000b004cc3c00b2ddmr23142119pfa.77.1645503929777; Mon, 21 Feb 2022 20:25:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645503929; cv=none; d=google.com; s=arc-20160816; b=SCWzGiSkyGrgU5uZemE+lyIddaxI/9AQbhyoI2+qRDP8f3pzdOaqjpjdZYrlwufcD3 rsy7J9qroSmdM6jRFalKuUUTUC6Kyudy2jIUpPodiCuH3xUzi2IjFhxRwiqfWrXDWBhm rKMx4D+Ki5AZZRsR1B5ZPTQ/545sSoOvv1lMJsjIaErM1KQ+3TYKugNMOfu1qOnsKGdN 9RVgH0RIHSzi1aGdXrC3OG99AYDgiK5QlywWAyjv4ii6Oxl6Ll3GQv4VbgwfeuVCM9qz RgvsiycrWQhtTm0cU7VFL0URM9mSr8bzoKuRbjJd9ZStbw8egxsSEPQx9PQRD8K19eBs OoHA== 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=DgiQ8QiaDQ4wLJTIFXLl0mN2KcAL74TU+YZJC9+89KQ=; b=wLTgIUTuLdWtJycW4tLLaEbPbnJ3lC7nQYyMFtEqWF0MMb23GJR6ZHBNCJNlZ/1DiE WARZ9vXyiIwRr3rKLVGhC0nB+evGzrNzVvEZuqm0rNNuDJ+Pu1jEegspa6C0CB2VenWP vOqN/A58wgtlMEKQefiSJOqSqS83i1Te9qwlOVAsSiqohlaSh65s5F0whbuJZLeWmDKY ATBmcxtjT63JS6mxdWjihiUdJJi6ab9sO/4ZVqXhK5tOnsyh3Lp5Yau7y+Dt0aiHeCFF f+D1N2Jd6AAJsT+B0YvmBYfRCqrzOmIDJUXiIRr+o7dWXElaPgaYM5Zse+TC9UsgR4YP dY+Q== 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 x186si3387760pgb.787.2022.02.21.20.25.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 20:25:29 -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 B042095A3A; Mon, 21 Feb 2022 20:20:17 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235439AbiBUWSC convert rfc822-to-8bit (ORCPT + 99 others); Mon, 21 Feb 2022 17:18:02 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:39654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235409AbiBUWR7 (ORCPT ); Mon, 21 Feb 2022 17:17:59 -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 B97D023BC3 for ; Mon, 21 Feb 2022 14:17:26 -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-85-sIQqazEuP1qrPjthYbe9ag-1; Mon, 21 Feb 2022 17:17:22 -0500 X-MC-Unique: sIQqazEuP1qrPjthYbe9ag-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3FA581006AA8; Mon, 21 Feb 2022 22:17:21 +0000 (UTC) Received: from x1.com (unknown [10.22.16.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA59C5DB8F; Mon, 21 Feb 2022 22:17:18 +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 V2 05/11] rtla/trace: Add trace events helpers Date: Mon, 21 Feb 2022 23:16:50 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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 the rtla tools to enable additional tracepoints 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 | 104 +++++++++++++++++++++++++++++++++ tools/tracing/rtla/src/trace.h | 15 +++++ 2 files changed, 119 insertions(+) diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index 83de259abcc1..9ad3d8890ec5 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -190,3 +190,107 @@ int trace_instance_start(struct trace_instance *trace) { return tracefs_trace_on(trace->inst); } + +/* + * trace_events_free - free a list of trace events + */ +static void trace_events_free(struct trace_events *events) +{ + struct trace_events *tevent = events; + struct trace_events *free_event; + + while (tevent) { + free_event = tevent; + + tevent = tevent->next; + + free(free_event->system); + free(free_event); + } +} + +/* + * trace_event_alloc - alloc and parse a single trace event + */ +struct trace_events *trace_event_alloc(const char *event_string) +{ + struct trace_events *tevent; + + tevent = calloc(1, sizeof(*tevent)); + if (!tevent) + return NULL; + + tevent->system = strdup(event_string); + if (!tevent->system) { + free(tevent); + return NULL; + } + + tevent->event = strstr(tevent->system, ":"); + if (tevent->event) { + *tevent->event = '\0'; + tevent->event = &tevent->event[1]; + } + + return tevent; +} + +/* + * trace_events_disable - disable all trace events + */ +void trace_events_disable(struct trace_instance *instance, + struct trace_events *events) +{ + struct trace_events *tevent = events; + + if (!events) + return; + + while (tevent) { + debug_msg("Disabling event %s:%s\n", tevent->system, tevent->event ? : "*"); + if (tevent->enabled) + tracefs_event_disable(instance->inst, tevent->system, tevent->event); + + tevent->enabled = 0; + tevent = tevent->next; + } +} + +/* + * trace_events_enable - enable all events + */ +int trace_events_enable(struct trace_instance *instance, + struct trace_events *events) +{ + struct trace_events *tevent = events; + int retval; + + while (tevent) { + debug_msg("Enabling event %s:%s\n", tevent->system, tevent->event ? : "*"); + retval = tracefs_event_enable(instance->inst, tevent->system, tevent->event); + if (retval < 0) { + err_msg("Error enabling event %s:%s\n", tevent->system, + tevent->event ? : "*"); + return 1; + } + + + tevent->enabled = 1; + tevent = tevent->next; + } + + return 0; +} + +/* + * trace_events_destroy - disable and free all trace events + */ +void trace_events_destroy(struct trace_instance *instance, + struct trace_events *events) +{ + if (!events) + return; + + trace_events_disable(instance, events); + trace_events_free(events); +} diff --git a/tools/tracing/rtla/src/trace.h b/tools/tracing/rtla/src/trace.h index 0ea1df0ad9a7..9f9751f7ee36 100644 --- a/tools/tracing/rtla/src/trace.h +++ b/tools/tracing/rtla/src/trace.h @@ -2,6 +2,13 @@ #include #include +struct trace_events { + struct trace_events *next; + char *system; + char *event; + char enabled; +}; + struct trace_instance { struct tracefs_instance *inst; struct tep_handle *tep; @@ -25,3 +32,11 @@ void destroy_instance(struct tracefs_instance *inst); int save_trace_to_file(struct tracefs_instance *inst, const char *filename); int collect_registered_events(struct tep_event *tep, struct tep_record *record, int cpu, void *context); + +struct trace_events *trace_event_alloc(const char *event_string); +void trace_events_disable(struct trace_instance *instance, + struct trace_events *events); +void trace_events_destroy(struct trace_instance *instance, + struct trace_events *events); +int trace_events_enable(struct trace_instance *instance, + struct trace_events *events); -- 2.34.1