From patchwork Tue Nov 30 05:00:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12646353 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 3F475C433EF for ; Tue, 30 Nov 2021 05:01:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230439AbhK3FEV (ORCPT ); Tue, 30 Nov 2021 00:04:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230259AbhK3FEV (ORCPT ); Tue, 30 Nov 2021 00:04:21 -0500 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C278C061574 for ; Mon, 29 Nov 2021 21:01:03 -0800 (PST) Received: by mail-ed1-x533.google.com with SMTP id y13so81404156edd.13 for ; Mon, 29 Nov 2021 21:01:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bx4tcflhExfL16WHTEn4OHU9RTeMCZlVkV76CM5i5g4=; b=CSzT3FLw6zbkbzFt9kD7HiA3Lcuv8XUS3YtyZ4Ehs5hOfgSQHqbxqZVKqW0orN3Wy2 9SceEkGoVDuiSL4qfCD17rJFRtfjTHKsSA2MOdBPURNTZyyq0AaVJnFWsZ/aZVp/4l/B Y2ikj48hfQXtszO4RpAFwGXeNNCA9gqMTASNyx7rKfSpjpJaUJQnVREY1/52rCXhpOWE /AS7OX33dslZC2OWpqhiG3cUz9BlGdgzTzOr/plniwEVwAbqvOF2vCpmIeXrzFc72xpT wOYbFKn4lRToz1EGYTAgRPo9mrr9AS5wMOWyFP1BB9pKXRMcXZYqOAOVC6TiKY6olusP zD/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bx4tcflhExfL16WHTEn4OHU9RTeMCZlVkV76CM5i5g4=; b=ZbBlk6zuvVfUKR5gLhROWcxX2516NF52y6YHD4TkGv7jL/hjHZTwqXN/5sm5Lhi5xp utR+7qtorN5hoVvV9o/W05LziGaJHvvKnO1OdaHZhxMUCRQBoAUQ93UlSIAPC7zStyTO geGzRd7wZAWM/USrNJE+OMZSzL7WRWTvy4sb7WpKkvsTQ/PqaEF7m0wLGPJVIuu/TxR2 pOGIwguIeDB0i/mTOU2cCrkCEqoRZMBMIp1UIKXuriE31Wo7zm9huORpdY68h12ryygo iguArhci36Fxz/B6ysspQgOY+WRf6/bGNS3bCgKuoSGFeGFVBcSWpb/clg/8YGis+s3C Dg8g== X-Gm-Message-State: AOAM530ERxmwk+60wA5eIzIT47UWmAcvzpsrHuoyiF13o05A5sH0hqHI xRiO+yCAywo+19eXoACJ3FVel098gJmrsg== X-Google-Smtp-Source: ABdhPJxWn6F/s2lTkFvWxKxmYg1R+zZsEulK1ySGNBeVpwR6ePPnQ9iyfCD8V3dDOT9TjSjHocappQ== X-Received: by 2002:a17:906:229b:: with SMTP id p27mr65211778eja.264.1638248461656; Mon, 29 Nov 2021 21:01:01 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w18sm10385849edx.55.2021.11.29.21.01.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 21:01:00 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org, y.karadz@gmail.com Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 1/4] libtracefs: Reuse logic for loading events inside the library Date: Tue, 30 Nov 2021 07:00:54 +0200 Message-Id: <20211130050057.336228-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211130050057.336228-1-tz.stoyanov@gmail.com> References: <20211130050057.336228-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The logic for parsing and loading new tep events could be reused in tracefs library. The function load_events() is exposed as internal API. Signed-off-by: Tzvetomir Stoyanov (VMware) --- include/tracefs-local.h | 3 +++ src/tracefs-events.c | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/tracefs-local.h b/include/tracefs-local.h index a59e806..0540956 100644 --- a/include/tracefs-local.h +++ b/include/tracefs-local.h @@ -112,4 +112,7 @@ dynevent_alloc(enum tracefs_dynevent_type type, const char *system, const char *event, const char *address, const char *format); int dynevent_get_count(unsigned int types, const char *system); +int trace_load_events(struct tep_handle *tep, + const char *tracing_dir, const char *system); + #endif /* _TRACE_FS_LOCAL_H */ diff --git a/src/tracefs-events.c b/src/tracefs-events.c index 4679926..e3962e5 100644 --- a/src/tracefs-events.c +++ b/src/tracefs-events.c @@ -688,8 +688,8 @@ char **tracefs_tracers(const char *tracing_dir) return plugins; } -static int load_events(struct tep_handle *tep, - const char *tracing_dir, const char *system) +__hidden int trace_load_events(struct tep_handle *tep, + const char *tracing_dir, const char *system) { int ret = 0, failure = 0; char **events = NULL; @@ -697,6 +697,9 @@ static int load_events(struct tep_handle *tep, int len = 0; int i; + if (!tracing_dir) + tracing_dir = tracefs_tracing_dir(); + events = tracefs_system_events(tracing_dir, system); if (!events) return -ENOENT; @@ -886,14 +889,14 @@ static int fill_local_events_system(const char *tracing_dir, for (i = 0; systems[i]; i++) { if (sys_names && !contains(systems[i], sys_names)) continue; - ret = load_events(tep, tracing_dir, systems[i]); + ret = trace_load_events(tep, tracing_dir, systems[i]); if (ret && parsing_failures) (*parsing_failures)++; } /* Include ftrace, as it is excluded for not having "enable" file */ if (!sys_names || contains("ftrace", sys_names)) - load_events(tep, tracing_dir, "ftrace"); + trace_load_events(tep, tracing_dir, "ftrace"); load_mappings(tracing_dir, tep); From patchwork Tue Nov 30 05:00:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12646355 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 869FCC433FE for ; Tue, 30 Nov 2021 05:01:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230464AbhK3FEX (ORCPT ); Tue, 30 Nov 2021 00:04:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230259AbhK3FEX (ORCPT ); Tue, 30 Nov 2021 00:04:23 -0500 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FD9DC061574 for ; Mon, 29 Nov 2021 21:01:04 -0800 (PST) Received: by mail-ed1-x534.google.com with SMTP id x6so81161588edr.5 for ; Mon, 29 Nov 2021 21:01:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=I5fU3KcBB31QmYdggxkrqadsi/nXpa0Ejrq+FL5Sz7U=; b=WqsWKo8FFwvKrGbzyZ9yZ59asISpkngx0wBTh2HYQpPPP8NvAxfSbXf68VdR3SCRye lJ4DELgGsraxJU0eMPid2uU5+Hrn7Hwal2HM2/sx/swSzPjYXzWcHHPNqNJzU1dL2WKO hM1EhYBASacMl2HfIK7uCJHvYWrkW+xZ1F9pQCULvYlZVY4kmvUl3Stz+nQkTKxQICEe d/JYm/WkU/ZZXuOPYJiygFLNUOiNkPrAWbV5XVHV71sUexgCnikfv4lFDGxt0GiCfoSk Q6GaE6r6vq2jyEVz9hRuOXGxnYXhXunlnzGPRrVt17PyDx9qJ565Va92rW1adBWqbhkO iV1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I5fU3KcBB31QmYdggxkrqadsi/nXpa0Ejrq+FL5Sz7U=; b=tssU2hmJ8CwBeLHVrZwIopB/UMni/U7640JyyyWJ0r8EdLglXPY72/hxmt9TuLQ/HZ /jmfmuIkKr3LIM7Mv61oruG9cL02A65uhVDXebPpajACSJS7tU9fBx2jYipBwrbvNvZT bPZC+AM66enGPi0SoCFj9W7Rp4QEmuy1MbFCyWR8oqSzfTHQQJeTtY7zEHXsYd2buLqy qhmrF8U7id0Xl3Cdhnn10jROTll6joYvXoqkT0YQgcINeBt5R51dQ8bYUVETGCAmZrzJ aUo8ComGFxRY5iWBmsVvCGS3Unl/rENi+3YAMDI1CIGLqjrHlk1B8W4jUKDoH4tgvELk 8c6g== X-Gm-Message-State: AOAM533CKvRcGGPNwZ6S4IOvUwTjhT1mKXGe+Hi7Dyav9w9SPTuy47y3 eum8ExMB6CQVuPd8SzheNFk= X-Google-Smtp-Source: ABdhPJzIj2qBIoZRbbGyUDjhBNh8Td+xVPUpQu9aibrdNLrj9O5dhKxftOQSg4A4eeM8ocDiDjcwgg== X-Received: by 2002:a05:6402:14f:: with SMTP id s15mr36787617edu.118.1638248463099; Mon, 29 Nov 2021 21:01:03 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w18sm10385849edx.55.2021.11.29.21.01.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 21:01:02 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org, y.karadz@gmail.com Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 2/4] libtracefs: New API for getting dynamic event Date: Tue, 30 Nov 2021 07:00:55 +0200 Message-Id: <20211130050057.336228-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211130050057.336228-1-tz.stoyanov@gmail.com> References: <20211130050057.336228-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org A new API is proposed, to get tep event describing given dynamic event: tracefs_dynevent_get_event() The API detects any newly created dynamic events, but does not detect the deletion. Signed-off-by: Tzvetomir Stoyanov (VMware) --- Documentation/libtracefs-dynevents.txt | 14 +++++++++++-- include/tracefs.h | 2 ++ src/tracefs-dynevents.c | 29 ++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Documentation/libtracefs-dynevents.txt b/Documentation/libtracefs-dynevents.txt index a374651..7de06be 100644 --- a/Documentation/libtracefs-dynevents.txt +++ b/Documentation/libtracefs-dynevents.txt @@ -4,8 +4,8 @@ libtracefs(3) NAME ---- tracefs_dynevent_create, tracefs_dynevent_destroy, tracefs_dynevent_destroy_all, -tracefs_dynevent_free, tracefs_dynevent_list_free, tracefs_dynevent_get_all, tracefs_dynevent_info - -Create, destroy, free and get dynamic events. +tracefs_dynevent_free, tracefs_dynevent_list_free, tracefs_dynevent_get_all, tracefs_dynevent_info, +tracefs_dynevent_get_event - Create, destroy, free and get dynamic events. SYNOPSIS -------- @@ -23,6 +23,7 @@ void *tracefs_dynevent_list_free*(struct tracefs_dynevent pass:[*]pass:[*]_event struct tracefs_dynevent pass:[*]*tracefs_dynevent_get*(enum tracefs_dynevent_type _type_, const char pass:[*]_system_, const char pass:[*]_event_); struct tracefs_dynevent pass:[*]pass:[*]*tracefs_dynevent_get_all*(unsigned int _types_, const char pass:[*]_system_); enum tracefs_dynevent_type *tracefs_dynevent_info*(struct tracefs_dynevent pass:[*]_dynevent_, char pass:[*]pass:[*]_system_, char pass:[*]pass:[*]_event_, char pass:[*]pass:[*]_prefix_, char pass:[*]pass:[*]_addr_, char pass:[*]pass:[*]_format_); +struct tep_event pass:[*]*tracefs_dynevent_get_event*(struct tep_handle pass:[*]_tep_, struct tracefs_dynevent pass:[*]_dynevent_); -- DESCRIPTION @@ -68,6 +69,11 @@ if relevant for this event type. If _format_ is non NULL, it will hold the forma dynamic event. Note, that the content in _group_, _event_, _prefix_, _addr_, and _format_ must be freed with free(3) if they are set. +The *tracefs_dynevent_get_event*() function returns tep event, describing the given dynamic event. +If the dynamic event is newly created and not yet loaded in the @tep, the dynamic event system is +rescanned for any new events. The returned pointer to tep event is controlled by @tep and must not +be freed. + RETURN VALUE ------------ @@ -88,6 +94,10 @@ in case of an error or in case there are no events in the system. That array mus on error. If _system_, _event_, _prefix_, _addr_, or _format_ are non NULL, they will contain allocated strings that must be freed by free(3). +The *tracefs_dynevent_get_event*() function returns pointer to tep event or NULL in case of an error +or if the requested dynamic event is missing. The returned pointer to tep event is controlled by +@tep and must not be freed. + ERRORS ------ The following errors are for all the above calls: diff --git a/include/tracefs.h b/include/tracefs.h index 9662603..fbd7d31 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -262,6 +262,8 @@ tracefs_dynevent_get(enum tracefs_dynevent_type type, const char *system, const enum tracefs_dynevent_type tracefs_dynevent_info(struct tracefs_dynevent *dynevent, char **system, char **event, char **prefix, char **addr, char **format); +struct tep_event * +tracefs_dynevent_get_event(struct tep_handle *tep, struct tracefs_dynevent *dynevent); struct tracefs_dynevent * tracefs_eprobe_alloc(const char *system, const char *event, diff --git a/src/tracefs-dynevents.c b/src/tracefs-dynevents.c index ea07d13..2ff3c87 100644 --- a/src/tracefs-dynevents.c +++ b/src/tracefs-dynevents.c @@ -752,3 +752,32 @@ error: return TRACEFS_DYNEVENT_UNKNOWN; } + +/** + * tracefs_dynevent_get_event - return tep event, representing the given dynamic event + * @tep: a handle to the trace event parser context, that holds the events + * @dynevent: a dynamic event context, describing given dynamic event. + * + * Returns pointer to tep event, describing the given dynamic event. The pointer + * is managed by @tep handle and must not be freed. In case of an error, or in case + * the requested dynamic event is missing in the @tep handler - NULL is returned. + */ +struct tep_event * +tracefs_dynevent_get_event(struct tep_handle *tep, struct tracefs_dynevent *dynevent) +{ + struct tep_event *event; + + if (!tep || !dynevent || !dynevent->event) + return NULL; + + /* If the dynamic event is already loaded in the tep, return it */ + event = tep_find_event_by_name(tep, dynevent->system, dynevent->event); + if (event) + return event; + + /* Try to load any new events from the given system */ + if (trace_load_events(tep, NULL, dynevent->system)) + return NULL; + + return tep_find_event_by_name(tep, dynevent->system, dynevent->event); +} From patchwork Tue Nov 30 05:00:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12646357 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 F1260C433F5 for ; Tue, 30 Nov 2021 05:01:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230465AbhK3FEZ (ORCPT ); Tue, 30 Nov 2021 00:04:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230259AbhK3FEY (ORCPT ); Tue, 30 Nov 2021 00:04:24 -0500 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB1DAC061574 for ; Mon, 29 Nov 2021 21:01:05 -0800 (PST) Received: by mail-ed1-x52b.google.com with SMTP id v1so81421371edx.2 for ; Mon, 29 Nov 2021 21:01:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QkU2CUQvXYadtzeoRi/ympe8R5++k8f7Z+495DLdM0g=; b=CY2VhAdmdV2TBsAphzBFREN4i76Brim3TfmzKJ3EnJktYW04YpwNBOpcoFl16g1cpp 1ic6by/ldkVXw8304jaA+9moyWfRZW50x8EQ02+l4MuAjuqLcioGAw+7bZByuW4ROBm+ FVciPk0YvH8B6s4SHq7IgSdiEHNKxzS69u16/dPBXnNlVXhH6Aafjsvo3Wmq5UO2t3mq g/L3soDcvIcIn6HPDHtmaomCvb6lOobzyFXk6+bwlFt66cWbr/7xlvYjeCbdqUo/Uo8z s+g2Led3YCdEv37Gmuu8rb6xVhHztoigwH1IQVZXbDCM8aC7WydG3N9qV0r5iDt+ncU9 gTTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QkU2CUQvXYadtzeoRi/ympe8R5++k8f7Z+495DLdM0g=; b=BFJkjHNGjDAobMZx1Mhe8EZMTQyB9SH7vTkCtpttxAxjIr3SI/BwGkX97PdlwZoKtF C9nwcDhnWPcrDgs7QDWYHOH80DVWi2d09hkTJbe50J1RwTbQeBEMqk3LorhyCv5GlmGo nic61TKsaFv6MsrSCFJJPWxCHWThydPhM0uaZmrMxK8G6qI+WaRVhOt/YiFqQHogYH3V rJeukoZZc+LgQ2PO7oc8yF8TnJNnjMENtp/R7P3p8Uqtj09nCEIK/5gvR/OwwPgroKD6 lFEFQ1wThFDqVyRQydKyQkqyTGbrdqFURDz2w+wygtN43yHw2OEs7J1cJiJbIFb6ZanS 6bvw== X-Gm-Message-State: AOAM531GUE2bKxNuaDDus+FaZMmpvFt77DoxRdujB2tQRsGzxP4gBTJc JsY4ejFpd42stynywIV/Qkm2aCovmlHMQg== X-Google-Smtp-Source: ABdhPJwLxRCR/wUaTWJEE7ULyiw34B+ZHoGz0swVjP5eFeneBAGU10u1CIkfnwdlV2HmSLSRh3RCCg== X-Received: by 2002:a17:907:2d12:: with SMTP id gs18mr63289531ejc.126.1638248464571; Mon, 29 Nov 2021 21:01:04 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w18sm10385849edx.55.2021.11.29.21.01.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 21:01:03 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org, y.karadz@gmail.com Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 3/4] libtracefs: Unit test for tracefs_dynevent_get_event() Date: Tue, 30 Nov 2021 07:00:56 +0200 Message-Id: <20211130050057.336228-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211130050057.336228-1-tz.stoyanov@gmail.com> References: <20211130050057.336228-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Unit tests for dynamic events are extended to test the newly introduced tracefs_dynevent_get_event() API. Signed-off-by: Tzvetomir Stoyanov (VMware) --- Documentation/libtracefs-dynevents.txt | 5 ++- utest/tracefs-utest.c | 58 +++++++++++++++++--------- 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/Documentation/libtracefs-dynevents.txt b/Documentation/libtracefs-dynevents.txt index 7de06be..bd18f5b 100644 --- a/Documentation/libtracefs-dynevents.txt +++ b/Documentation/libtracefs-dynevents.txt @@ -71,8 +71,9 @@ freed with free(3) if they are set. The *tracefs_dynevent_get_event*() function returns tep event, describing the given dynamic event. If the dynamic event is newly created and not yet loaded in the @tep, the dynamic event system is -rescanned for any new events. The returned pointer to tep event is controlled by @tep and must not -be freed. +rescanned for any new events. If the dynamic event is deleted from the system, any subsequent calls +to *tracefs_dynevent_get_event*() may return a tep event, as the deletion is not detected by the API. +The returned pointer to tep event is controlled by @tep and must not be freed. RETURN VALUE ------------ diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c index 3a01f38..c555b06 100644 --- a/utest/tracefs-utest.c +++ b/utest/tracefs-utest.c @@ -567,9 +567,10 @@ struct probe_test { static bool check_probes(struct probe_test *probes, int count, struct tracefs_dynevent **devents, bool in_system, - struct tracefs_instance *instance) + struct tracefs_instance *instance, struct tep_handle *tep) { enum tracefs_dynevent_type type; + struct tep_event *tevent; char *ename; char *address; char *event; @@ -615,6 +616,15 @@ static bool check_probes(struct probe_test *probes, int count, CU_TEST(ret != 0); } + if (in_system) { + tevent = tracefs_dynevent_get_event(tep, devents[i]); + CU_TEST(tevent != NULL); + if (tevent) { + CU_TEST(strcmp(tevent->name, event) == 0); + CU_TEST(strcmp(tevent->system, system) == 0); + } + } + found++; break; } @@ -649,10 +659,14 @@ static void test_kprobes_instance(struct tracefs_instance *instance) struct tracefs_dynevent **dkretprobe; struct tracefs_dynevent **dkprobe; struct tracefs_dynevent **devents; + struct tep_handle *tep; char *tmp; int ret; int i; + tep = tep_alloc(); + CU_TEST(tep != NULL); + dkprobe = calloc(kprobe_count + 1, sizeof(*dkprobe)); dkretprobe = calloc(kretprobe_count + 1, sizeof(*dkretprobe)); @@ -676,7 +690,7 @@ static void test_kprobes_instance(struct tracefs_instance *instance) } dkprobe[i] = NULL; get_dynevents_check(TRACEFS_DYNEVENT_KPROBE | TRACEFS_DYNEVENT_KRETPROBE, 0); - CU_TEST(check_probes(ktests, kprobe_count, dkprobe, false, instance)); + CU_TEST(check_probes(ktests, kprobe_count, dkprobe, false, instance, tep)); for (i = 0; i < kretprobe_count; i++) { dkretprobe[i] = tracefs_kretprobe_alloc(kretests[i].system, kretests[i].event, @@ -685,15 +699,15 @@ static void test_kprobes_instance(struct tracefs_instance *instance) } dkretprobe[i] = NULL; get_dynevents_check(TRACEFS_DYNEVENT_KPROBE | TRACEFS_DYNEVENT_KRETPROBE, 0); - CU_TEST(check_probes(kretests, kretprobe_count, dkretprobe, false, instance)); + CU_TEST(check_probes(kretests, kretprobe_count, dkretprobe, false, instance, tep)); for (i = 0; i < kprobe_count; i++) { CU_TEST(tracefs_dynevent_create(dkprobe[i]) == 0); } devents = get_dynevents_check(TRACEFS_DYNEVENT_KPROBE | TRACEFS_DYNEVENT_KRETPROBE, kprobe_count); - CU_TEST(check_probes(ktests, kprobe_count, devents, true, instance)); - CU_TEST(check_probes(kretests, kretprobe_count, dkretprobe, false, instance)); + CU_TEST(check_probes(ktests, kprobe_count, devents, true, instance, tep)); + CU_TEST(check_probes(kretests, kretprobe_count, dkretprobe, false, instance, tep)); tracefs_dynevent_list_free(devents); devents = NULL; @@ -702,8 +716,8 @@ static void test_kprobes_instance(struct tracefs_instance *instance) } devents = get_dynevents_check(TRACEFS_DYNEVENT_KPROBE | TRACEFS_DYNEVENT_KRETPROBE, kprobe_count + kretprobe_count); - CU_TEST(check_probes(ktests, kprobe_count, devents, true, instance)); - CU_TEST(check_probes(kretests, kretprobe_count, devents, true, instance)); + CU_TEST(check_probes(ktests, kprobe_count, devents, true, instance, tep)); + CU_TEST(check_probes(kretests, kretprobe_count, devents, true, instance, tep)); tracefs_dynevent_list_free(devents); devents = NULL; @@ -712,8 +726,8 @@ static void test_kprobes_instance(struct tracefs_instance *instance) } devents = get_dynevents_check(TRACEFS_DYNEVENT_KPROBE | TRACEFS_DYNEVENT_KRETPROBE, kprobe_count); - CU_TEST(check_probes(ktests, kprobe_count, devents, true, instance)); - CU_TEST(check_probes(kretests, kretprobe_count, dkretprobe, false, instance)); + CU_TEST(check_probes(ktests, kprobe_count, devents, true, instance, tep)); + CU_TEST(check_probes(kretests, kretprobe_count, dkretprobe, false, instance, tep)); tracefs_dynevent_list_free(devents); devents = NULL; @@ -721,8 +735,8 @@ static void test_kprobes_instance(struct tracefs_instance *instance) CU_TEST(tracefs_dynevent_destroy(dkprobe[i], false) == 0); } get_dynevents_check(TRACEFS_DYNEVENT_KPROBE | TRACEFS_DYNEVENT_KRETPROBE, 0); - CU_TEST(check_probes(ktests, kprobe_count, dkprobe, false, instance)); - CU_TEST(check_probes(kretests, kretprobe_count, dkretprobe, false, instance)); + CU_TEST(check_probes(ktests, kprobe_count, dkprobe, false, instance, tep)); + CU_TEST(check_probes(kretests, kretprobe_count, dkretprobe, false, instance, tep)); tracefs_dynevent_list_free(devents); devents = NULL; @@ -743,7 +757,7 @@ static void test_kprobes_instance(struct tracefs_instance *instance) } devents = get_dynevents_check(TRACEFS_DYNEVENT_KPROBE | TRACEFS_DYNEVENT_KRETPROBE, kprobe_count); - CU_TEST(check_probes(ktests, kprobe_count, devents, true, instance)); + CU_TEST(check_probes(ktests, kprobe_count, devents, true, instance, tep)); tracefs_dynevent_list_free(devents); devents = NULL; @@ -754,19 +768,19 @@ static void test_kprobes_instance(struct tracefs_instance *instance) } devents = get_dynevents_check(TRACEFS_DYNEVENT_KPROBE, kprobe_count); - CU_TEST(check_probes(ktests, kprobe_count, devents, true, instance)); + CU_TEST(check_probes(ktests, kprobe_count, devents, true, instance, tep)); tracefs_dynevent_list_free(devents); devents = NULL; devents = get_dynevents_check(TRACEFS_DYNEVENT_KRETPROBE, kretprobe_count); - CU_TEST(check_probes(kretests, kretprobe_count, devents, true, instance)); + CU_TEST(check_probes(kretests, kretprobe_count, devents, true, instance, tep)); tracefs_dynevent_list_free(devents); devents = NULL; devents = get_dynevents_check(TRACEFS_DYNEVENT_KPROBE | TRACEFS_DYNEVENT_KRETPROBE, kprobe_count + kretprobe_count); - CU_TEST(check_probes(ktests, kprobe_count, devents, true, instance)); - CU_TEST(check_probes(kretests, kretprobe_count, devents, true, instance)); + CU_TEST(check_probes(ktests, kprobe_count, devents, true, instance, tep)); + CU_TEST(check_probes(kretests, kretprobe_count, devents, true, instance, tep)); tracefs_dynevent_list_free(devents); devents = NULL; @@ -775,6 +789,7 @@ static void test_kprobes_instance(struct tracefs_instance *instance) get_dynevents_check(TRACEFS_DYNEVENT_KPROBE | TRACEFS_DYNEVENT_KRETPROBE, 0); free(dkretprobe); free(dkprobe); + tep_free(tep); } static void test_kprobes(void) @@ -793,11 +808,15 @@ static void test_eprobes_instance(struct tracefs_instance *instance) int count = sizeof(etests) / sizeof((etests)[0]); struct tracefs_dynevent **deprobes; struct tracefs_dynevent **devents; + struct tep_handle *tep; char *tsys, *tevent; char *tmp, *sav; int ret; int i; + tep = tep_alloc(); + CU_TEST(tep != NULL); + deprobes = calloc(count + 1, sizeof(*deprobes)); /* Invalid parameters */ @@ -821,14 +840,14 @@ static void test_eprobes_instance(struct tracefs_instance *instance) deprobes[i] = NULL; get_dynevents_check(TRACEFS_DYNEVENT_EPROBE, 0); - CU_TEST(check_probes(etests, count, deprobes, false, instance)); + CU_TEST(check_probes(etests, count, deprobes, false, instance, tep)); for (i = 0; i < count; i++) { CU_TEST(tracefs_dynevent_create(deprobes[i]) == 0); } devents = get_dynevents_check(TRACEFS_DYNEVENT_EPROBE, count); - CU_TEST(check_probes(etests, count, devents, true, instance)); + CU_TEST(check_probes(etests, count, devents, true, instance, tep)); tracefs_dynevent_list_free(devents); devents = NULL; @@ -836,12 +855,13 @@ static void test_eprobes_instance(struct tracefs_instance *instance) CU_TEST(tracefs_dynevent_destroy(deprobes[i], false) == 0); } get_dynevents_check(TRACEFS_DYNEVENT_EPROBE, 0); - CU_TEST(check_probes(etests, count, deprobes, false, instance)); + CU_TEST(check_probes(etests, count, deprobes, false, instance, tep)); for (i = 0; i < count; i++) tracefs_dynevent_free(deprobes[i]); free(deprobes); + tep_free(tep); } static void test_eprobes(void) From patchwork Tue Nov 30 05:00:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12646359 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 752ADC433EF for ; Tue, 30 Nov 2021 05:01:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231238AbhK3FE0 (ORCPT ); Tue, 30 Nov 2021 00:04:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230259AbhK3FE0 (ORCPT ); Tue, 30 Nov 2021 00:04:26 -0500 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 570C4C061574 for ; Mon, 29 Nov 2021 21:01:07 -0800 (PST) Received: by mail-ed1-x535.google.com with SMTP id o20so81102813eds.10 for ; Mon, 29 Nov 2021 21:01:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Gcj0J3fBRHssSuSdtbmvDqbgZlYLq9ZwE6299+89U00=; b=JRw/ov1KbuwZnSnujQcUII5Sn1vlZlteYd6rLgE8SyJUS6PoVGTn5C8fzWrtuO5mgu nk0oMtujh77ZUvQy6aho+f0th0P0hOojzrxVYBLCLT1AX5klZsClNFuhET637kbdoTLy lvm9B4yPgWfkyaOoe+vn8mFDBkrKr14A5QZ4TDHncZHgf1EhcRoNWoHEQnAFsfW3QJxo tnuc1kuTtnD80s8OwO24gzrK5di5RS/fEYOFjZ9V/ioX70Y6jDV1kL25oJueFeI8YlNx xpQti3Ym4v8qhHX+RhAxrAY8bSjJ1hUkAi/U7827R0M3euekrXs5FxNMNPBK6pPkWfCR NBtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Gcj0J3fBRHssSuSdtbmvDqbgZlYLq9ZwE6299+89U00=; b=HlgZJ58fPolIHH2fZ+D6hWeEJ0GY2kg7+6n/LTw5ZY/Xz0KpD2apPKFDac5vP/zqsQ aeWHXMQeArovVhASRlhLVRQGLeUeuv5FVk5xNrp02gMycHYPI8ChMx/XIibpXg2y4dgW kF7gGcesSCaG+LW6oSOy2t/r/cPGXsd3WZMFy89MDxoNNmWtF8hwbKVieznjd3m0oWGO DW/Czwoh2cdUQZtFdBZcyw3KRlsFxcRX/5JkB7l20xGspGpRPshCsg1pHITT/hM6xaLP rFm8ThfUvd6p6uwK5C/aYbrorl295APOrfdkpdmvqvcPmmNU7YYPcgQ4wc0ME893BJY4 AzAQ== X-Gm-Message-State: AOAM533izSdJGpYZ414b0ZnZF/+TTWJ/WdyfvsbubquGODowDUsBGS9P XXvUUo2bgEhEodhAxSzUzEyJvEGpa9tjmQ== X-Google-Smtp-Source: ABdhPJwUNHVyB/gm2enHiGRcMYdsT+1XUpvf76xUKT1KLJIEL/J3zYRzElL+wZzDH79vhEgvVvAQgA== X-Received: by 2002:a05:6402:358c:: with SMTP id y12mr83296377edc.44.1638248465967; Mon, 29 Nov 2021 21:01:05 -0800 (PST) Received: from oberon.zico.biz.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id w18sm10385849edx.55.2021.11.29.21.01.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Nov 2021 21:01:05 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org, y.karadz@gmail.com Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 4/4] libtracefs: New API for applying filter on event. Date: Tue, 30 Nov 2021 07:00:57 +0200 Message-Id: <20211130050057.336228-5-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211130050057.336228-1-tz.stoyanov@gmail.com> References: <20211130050057.336228-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org There is no API for applying a filter string on event. Existing APIs only constructs and verifies the filter string. Even though the actual applying is just writing into the event's filter file, it is good to have a dedicated API for that: tracefs_event_apply_filter() Signed-off-by: Tzvetomir Stoyanov (VMware) --- Documentation/libtracefs-filter.txt | 11 ++++++++++- include/tracefs.h | 3 +++ src/tracefs-filter.c | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Documentation/libtracefs-filter.txt b/Documentation/libtracefs-filter.txt index 7e167bc..7532c96 100644 --- a/Documentation/libtracefs-filter.txt +++ b/Documentation/libtracefs-filter.txt @@ -3,7 +3,8 @@ libtracefs(3) NAME ---- -tracefs_event_append_filter, tracefs_event_verify_filter - Add and verify event filters +tracefs_event_append_filter, tracefs_event_verify_filter tracefs_event_apply_filter - +Add, verify and apply event filters SYNOPSIS -------- @@ -15,6 +16,7 @@ int tracefs_event_append_filter(struct tep_event pass:[*]event, char pass:[**] f struct tracefs_filter type, const char pass:[*]field, enum tracefs_synth_compare compare, const char pass:[*]val); int tracefs_event_verify_filter(struct tep_event pass:[*]event, const char pass:[*]filter, char pass:[**]err); +int tracefs_event_apply_filter(struct tracefs_instance pass:[*]instance, struct tep_event pass:[*]event, const char pass:[*]filter); -- @@ -66,6 +68,8 @@ error in the syntax, and _err_ is not NULL, then it will be allocated with an error message stating what was found wrong with the filter. _err_ must be freed with *free*(). +*tracefs_event_apply_filter*() applies given _filter_ string on _event_ in given _instance_. + RETURN VALUE ------------ *tracefs_event_append_filter*() returns 0 on success and -1 on error. @@ -75,6 +79,8 @@ is an error, and _errno_ is not *ENOMEM*, then _err_ is allocated and will contain a string describing what was found wrong with _filter_. _err_ must be freed with *free*(). +*tracefs_event_apply_filter*() returns 0 on success and -1 on error. + EXAMPLE ------- [source,c] @@ -269,6 +275,9 @@ int main (int argc, char **argv) } } + if (tracefs_event_apply_filter(NULL, event, new_filter)) + fprintf(stderr, "Failed to apply filter on event"); + tep_free(tep); printf("Created new filter: '%s'\n", new_filter); diff --git a/include/tracefs.h b/include/tracefs.h index fbd7d31..8ac9694 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -475,6 +475,9 @@ int tracefs_event_append_filter(struct tep_event *event, char **filter, const char *val); int tracefs_event_verify_filter(struct tep_event *event, const char *filter, char **err); +int tracefs_event_apply_filter(struct tracefs_instance *instance, + struct tep_event *event, const char *filter); + #define TRACEFS_TIMESTAMP "common_timestamp" #define TRACEFS_TIMESTAMP_USECS "common_timestamp.usecs" diff --git a/src/tracefs-filter.c b/src/tracefs-filter.c index def8f68..43683d0 100644 --- a/src/tracefs-filter.c +++ b/src/tracefs-filter.c @@ -745,3 +745,22 @@ int tracefs_event_verify_filter(struct tep_event *event, const char *filter, free(str); return 0; } + +/** + * tracefs_event_apply_filter - apply given filter on event in given instance + * @instance: The instance in which the filter will be applied (NULL for toplevel). + * @event: The event to apply the filter on. + * @filter: The filter to apply. + * + * Apply the @filter to given @event in givem @instance. The @filter string + * should be created with tracefs_event_append_filter(). + * + * Returns 0 on succes and -1 on error. + */ +int tracefs_event_apply_filter(struct tracefs_instance *instance, + struct tep_event *event, const char *filter) +{ + return tracefs_event_file_append(instance, event->system, event->name, + "filter", filter); +} +