Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp1243151pxb; Fri, 18 Feb 2022 03:51:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxseXDxFMfakVkcWR2pxaFOl1c+Dd4wu/lgLY4Bs5ERT/oooOLidaTHuoJDO22KPfO7Stgb X-Received: by 2002:a17:906:6158:b0:6ce:61d6:f243 with SMTP id p24-20020a170906615800b006ce61d6f243mr6068097ejl.268.1645185082320; Fri, 18 Feb 2022 03:51:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645185082; cv=none; d=google.com; s=arc-20160816; b=XkzFr9QbTMsk3Ynemu39s68w7DI2acz/c0QEU2qGs+PyUa8VDpuJOtsrixBTXcG74u LAL5//XvXiYzdJi7swwYdZgC1glSD0WuY/k4jcuRUpfQo9Fepqf94+6UlY4o3c8GqUkj QCm93LqXTKB5Uazr/PyyChBqTAEhccqn7QE8/VNai7i5ahUyTkXc0M6YHUKuVAF3ZegS 6/bCLvVA0mxm/XSfvdE8inVp1hhQLlM3VVXeGKTRSOu4ZinzSY47Qmrfxh/ry/Yz7XUS e2Ut+ym4B6OKZ2MRK+xi1IoL4Pf9WIeffI2VeEVH+1Apb1vklan6TI57+lFEAlsYPnMC Yxtg== 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=L4lm3eirJcK+l/0/Ma7slGMKft9+r/Ap8uJoA4vpTMM=; b=tkomvvGYFJZsJfcuhH9agslVHQ8/0ne/QpwGIMei+Winvzjb62vPwWaTwx6DSYFrHQ 9r5T1DDZKJBn4Ow+duOtpIbk4Lu+0vlQt10U2+ArIxhpnJn1kUmOgOwwGWAqRe+1nfYP h0KGbUF7zMD6cg8gsKVz+ApsL3kFuqsXaxN955WBsQkr2oXljzNwtgAsp59WWdWbv9J2 ze9AzKNzP+pnnxmJidGW0j9wgJjXoQc3kMFHmSLExIXsliWqmSIha1TrhtTeh923hwyJ V0b87mDkWDFn0jxEOBpX4/8znzXEzZb7E2+lbEqbL+qWfX96F8h2GuonC+kAwLwbHgvW 8fkw== 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:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k4si5688791edx.338.2022.02.18.03.50.57; Fri, 18 Feb 2022 03:51:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233190AbiBRLKH convert rfc822-to-8bit (ORCPT + 99 others); Fri, 18 Feb 2022 06:10:07 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:34982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234449AbiBRLKA (ORCPT ); Fri, 18 Feb 2022 06:10:00 -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 C67C62AEDA2 for ; Fri, 18 Feb 2022 03:09:44 -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-319-YTY_sJGoMAilkI0SQEnw7g-1; Fri, 18 Feb 2022 06:09:40 -0500 X-MC-Unique: YTY_sJGoMAilkI0SQEnw7g-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 2F7F71006AA3; Fri, 18 Feb 2022 11:09:39 +0000 (UTC) Received: from x1.com (unknown [10.22.32.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B92F2B4B5; Fri, 18 Feb 2022 11:09:37 +0000 (UTC) From: Daniel Bristot de Oliveira To: Steven Rostedt Cc: Daniel Bristot de Oliveira , Jonathan Corbet , linux-trace-devel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/7] rtla/trace: Add trace events helpers Date: Fri, 18 Feb 2022 12:09:17 +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=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL,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 Cc: linux-trace-devel@vger.kernel.org Cc: linux-doc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Daniel Bristot de Oliveira --- tools/tracing/rtla/src/trace.c | 105 +++++++++++++++++++++++++++++++++ tools/tracing/rtla/src/trace.h | 15 +++++ 2 files changed, 120 insertions(+) diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index 83de259abcc1..1a3e346c6b17 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -190,3 +190,108 @@ int trace_instance_start(struct trace_instance *trace) { return tracefs_trace_on(trace->inst); } + +/* + * free_trace_events - free a list of trace events + */ +static void free_trace_events(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); + } +} + +/* + * alloc_trace_event - alloc and parse a single trace event + */ +struct trace_events *alloc_trace_event(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; +} + +/* + * disable_trace_events - disable all trace events + */ +void disable_trace_events(struct trace_instance *instance, + struct trace_events *events) +{ + struct trace_events *tevent = events; + + if (!events) + return; + + while (tevent) { + if (tevent->enabled) + tracefs_event_disable(instance->inst, tevent->system, tevent->event); + + tevent->enabled = 0; + tevent = tevent->next; + } +} + +/* + * enable_trace_events - enable all events + */ +int enable_trace_events(struct trace_instance *instance, + struct trace_events *events) +{ + struct trace_events *tevent = events; + int retval; + + while (tevent) { + retval = tracefs_event_enable(instance->inst, tevent->system, tevent->event); + if (retval < 0) { + if (tevent->event) + err_msg("Error enabling event %s:%s\n", + tevent->system, tevent->event); + else + err_msg("Error enabling events %s:*\n", + tevent->system); + return 1; + } + + tevent->enabled = 1; + tevent = tevent->next; + } + + return 0; +} + +/* + * destroy_trace_events - disable and free all trace events + */ +void destroy_trace_events(struct trace_instance *instance, + struct trace_events *events) +{ + if (!events) + return; + + disable_trace_events(instance, events); + free_trace_events(events); +} diff --git a/tools/tracing/rtla/src/trace.h b/tools/tracing/rtla/src/trace.h index 0ea1df0ad9a7..762a04667c51 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; + int 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 *alloc_trace_event(const char *event_string); +void disable_trace_events(struct trace_instance *instance, + struct trace_events *events); +void destroy_trace_events(struct trace_instance *instance, + struct trace_events *events); +int enable_trace_events(struct trace_instance *instance, + struct trace_events *events); -- 2.34.1