From patchwork Tue Jan 12 09:20:18 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: 12012851 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5728C433E0 for ; Tue, 12 Jan 2021 09:21:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A0CD922EBE for ; Tue, 12 Jan 2021 09:21:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727308AbhALJVK (ORCPT ); Tue, 12 Jan 2021 04:21:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390589AbhALJVK (ORCPT ); Tue, 12 Jan 2021 04:21:10 -0500 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8846DC061794 for ; Tue, 12 Jan 2021 01:20:29 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id f4so1394666ejx.7 for ; Tue, 12 Jan 2021 01:20:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CJhW/KrXWYGV+GkPUysTu7VogU8uThk+O/ZrLvtDg2w=; b=a9y8Xq1TDAE3CdCYOUb5SC7B5K0fIP3HAD0DflbtHxNpPFlIZdZ7N7Fej18BIhx7x5 vJTEeg0YYCwcGSZ/04cqE/6cdXyfFyYfowrtrySdgE+czZ5CUAz+v9oOVeGNVIkxsdm8 ISsZjaohwNhsRH5S3aUU78+FUL6fBpAu9YlMygvUBQ4K/65raQu4M5wGxYktx61mUIrz HSouIcEVr8QLwVGwKuRmHATUa7hjaP/ZJBhSHfbjRK3IN2GKJHbOZnPHh3nVOvyzcGar fW0yMNjCDMserwbpyMIVJIgMv1hn0TWFpo/uck9Rp/hQAAUz+jtUfJjppPclUKLop0n8 /eFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CJhW/KrXWYGV+GkPUysTu7VogU8uThk+O/ZrLvtDg2w=; b=JKGxD8Mqr99cSUKHri4iw4qWJxETIX0NwHk3MYsUCYg+KYsbRRKwvkaUC8Dw/57FP6 Y2L3bj1n1csYFLlleUQySqd6Rm1qNrKBU2P4LqKBsvHJaAFOJ7cievqLfOlp2ytQWKfC PtkSkzN5b4X1oAQANefH1k4qE33QuUD1cNH9dFhmi/ug2znhlfsjQMbMgIqhlsjL7Tlq jaY4VMoogdLZpExC8kHIVIT6gM3SC+Mb4rfgGxlXT4n9kcgIavCEUsSaN6PNnLCj1ACU aaK/AOIIwGsBSbBKT6j/3Ih3DC8P9SFNQf6ZhbIPCYnycePLQjGhEsMykc+2zw5tC796 QJQA== X-Gm-Message-State: AOAM5329108w14TRqBscQcMWSSYkFNkebiyd8n1rlkWUDHl4BBcT+EzA rQJ1fio0d36mIb3Bz+7Gev8sWC64uh9HmQOd X-Google-Smtp-Source: ABdhPJzUMUrbU7MtYI8f+6uaHA4IM5IWh8CZQ0FSDVIUjkvvJy/gngTa8r59M2Pc5XoUGKcRrl4aeA== X-Received: by 2002:a17:906:1194:: with SMTP id n20mr2481756eja.269.1610443228075; Tue, 12 Jan 2021 01:20:28 -0800 (PST) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id rl7sm929187ejb.107.2021.01.12.01.20.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 01:20:27 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 1/7] libtracefs: tracefs_instance_file_read() get a const file name Date: Tue, 12 Jan 2021 11:20:18 +0200 Message-Id: <20210112092024.605705-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210112092024.605705-1-tz.stoyanov@gmail.com> References: <20210112092024.605705-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The file name input parameter of tracefs_instance_file_read() API should be a pointer to a constat string, as this file name must not be changed by the API. Signed-off-by: Tzvetomir Stoyanov (VMware) --- Documentation/libtracefs-instances-files.txt | 2 +- Documentation/libtracefs.txt | 2 +- include/tracefs.h | 2 +- src/tracefs-instance.c | 2 +- utest/tracefs-utest.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Documentation/libtracefs-instances-files.txt b/Documentation/libtracefs-instances-files.txt index 9b18b73..a9af1f7 100644 --- a/Documentation/libtracefs-instances-files.txt +++ b/Documentation/libtracefs-instances-files.txt @@ -18,7 +18,7 @@ bool *tracefs_dir_exists*(struct tracefs_instance pass:[*]_instance_, char pass: char pass:[*]*tracefs_instance_get_file*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_file_); char pass:[*]*tracefs_instance_get_dir*(struct tracefs_instance pass:[*]_instance_); int *tracefs_instance_file_write*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_file_, const char pass:[*]_str_); -char pass:[*]*tracefs_instance_file_read*(struct tracefs_instance pass:[*]_instance_, char pass:[*]_file_, int pass:[*]_psize_); +char pass:[*]*tracefs_instance_file_read*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_file_, int pass:[*]_psize_); -- diff --git a/Documentation/libtracefs.txt b/Documentation/libtracefs.txt index ddbf783..bf3882f 100644 --- a/Documentation/libtracefs.txt +++ b/Documentation/libtracefs.txt @@ -26,7 +26,7 @@ Trace instances: char pass:[*]*tracefs_instance_get_file*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_file_); char pass:[*]*tracefs_instance_get_dir*(struct tracefs_instance pass:[*]_instance_); int *tracefs_instance_file_write*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_file_, const char pass:[*]_str_); - char pass:[*]*tracefs_instance_file_read*(struct tracefs_instance pass:[*]_instance_, char pass:[*]_file_, int pass:[*]_psize_); + char pass:[*]*tracefs_instance_file_read*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_file_, int pass:[*]_psize_); const char pass:[*]*tracefs_instance_get_name*(struct tracefs_instance pass:[*]_instance_); int *tracefs_instances_walk*(int (pass:[*]_callback_)(const char pass:[*], void pass:[*]), void pass:[*]_context)_; bool *tracefs_instance_exists*(const char pass:[*]_name_); diff --git a/include/tracefs.h b/include/tracefs.h index 3d70aca..06e2130 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -29,7 +29,7 @@ char *tracefs_instance_get_dir(struct tracefs_instance *instance); int tracefs_instance_file_write(struct tracefs_instance *instance, const char *file, const char *str); char *tracefs_instance_file_read(struct tracefs_instance *instance, - char *file, int *psize); + const char *file, int *psize); int tracefs_instances_walk(int (*callback)(const char *, void *), void *context); bool tracefs_instance_exists(const char *name); diff --git a/src/tracefs-instance.c b/src/tracefs-instance.c index bf3de7c..6dc85ee 100644 --- a/src/tracefs-instance.c +++ b/src/tracefs-instance.c @@ -282,7 +282,7 @@ int tracefs_instance_file_write(struct tracefs_instance *instance, * The return string must be freed by free() */ char *tracefs_instance_file_read(struct tracefs_instance *instance, - char *file, int *psize) + const char *file, int *psize) { char *buf = NULL; int size = 0; diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c index b45a3c6..a8e8f67 100644 --- a/utest/tracefs-utest.c +++ b/utest/tracefs-utest.c @@ -181,7 +181,7 @@ static void test_trace_file(void) tracefs_put_tracing_file(file); } -static void test_instance_file_read(struct tracefs_instance *inst, char *fname) +static void test_instance_file_read(struct tracefs_instance *inst, const char *fname) { const char *tdir = tracefs_tracing_dir(); char buf[BUFSIZ]; From patchwork Tue Jan 12 09:20:19 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: 12012853 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12453C433E0 for ; Tue, 12 Jan 2021 09:21:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C845C22E03 for ; Tue, 12 Jan 2021 09:21:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390592AbhALJVM (ORCPT ); Tue, 12 Jan 2021 04:21:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390589AbhALJVL (ORCPT ); Tue, 12 Jan 2021 04:21:11 -0500 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E6A2C061795 for ; Tue, 12 Jan 2021 01:20:30 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id t16so2428852ejf.13 for ; Tue, 12 Jan 2021 01:20:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CGhx8KRs4ZRB0rmZ70t4SlriLR8QQVI5iZDuvM+X5GI=; b=WXAsV/b3ylObNgtN1sOWzzbLXaZt2g3OpVBk82MaCthDadDs7ayhTWM1fkAG05Sly4 Cl556gc19HWhVQ5UbsMsMTyk6Ehbv8gcL5rw2gujYtBtDwR9RZuWr2CR8hN4NUvowtED P7t9dgVsnIDCIQaI4QWMKHtRBqRrlZ51H6bIuiioU4bYQyzJY3RcqmXvdWWb7tK0YGh9 G2VDlZnt5doCRANxyh1OwEnlzIFsc7YgWyVF301XSbaRp7T/B4J4OQiR/4nBKHQzKkTW JBlfPELlHApBSYXnM86epJ7Ksn7xQcxHhA/JJRhXwN770nKtGQWDyXmpSbnozuJZVVKu +CTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CGhx8KRs4ZRB0rmZ70t4SlriLR8QQVI5iZDuvM+X5GI=; b=FDMg/rm5XD2QTmMjDyHrG3Bd8rOj09y9jr9KGjPk7gD3Mx2aDuLTkfo9Exw48X+aFJ uM9Wq5J8V2AQAs891d5mI2DIo+5+tDDT2kruRM46+Iz2V/pAt4bbHB7Q4lrS9Y2aAg/d sZtCZNKeP1YrcqkeBCoFbzjiHQC3KCvxzb9myl+qwOKACEvMkO6y8BAft/0L6UMqGv/7 eEVlBZRv1zX2nzC7ZLtV0OHIxJVX8dOcBx/Cxicn56vpOH7DSBidYJhoBthAW4nsG5kq d3kvTDN35isklBWFEfDVMUXQjh6KJ1ch+H1xo1+f5E+SuQjz/ITDbIUugHP/xZ3k9lnn m5xg== X-Gm-Message-State: AOAM531LOcWactTRx+aOx8SnJm1WS5ItlrBuFdqj48FYVMKJoy5NiaGi KCs+LwwexX4x6lpWbBFibr8= X-Google-Smtp-Source: ABdhPJyixxOdZbFWfTlo7qeiYpt0WnhhCBbuvOWfksS3eS6SJrjhh7onwUgyfQWx9q5BEigp1OdAmw== X-Received: by 2002:a17:906:cc9c:: with SMTP id oq28mr2540867ejb.224.1610443229364; Tue, 12 Jan 2021 01:20:29 -0800 (PST) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id rl7sm929187ejb.107.2021.01.12.01.20.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 01:20:28 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 2/7] libtracefs: New APIs for opening and reading ftrace files Date: Tue, 12 Jan 2021 11:20:19 +0200 Message-Id: <20210112092024.605705-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210112092024.605705-1-tz.stoyanov@gmail.com> References: <20210112092024.605705-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org These new APIs can be used to read long long integer from frtace file and to open ftrace file: tracefs_instance_file_read_number(); tracefs_instance_file_open(); Signed-off-by: Tzvetomir Stoyanov (VMware) --- include/tracefs.h | 4 +++ src/tracefs-instance.c | 60 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/include/tracefs.h b/include/tracefs.h index 06e2130..bec8369 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -30,6 +30,10 @@ int tracefs_instance_file_write(struct tracefs_instance *instance, const char *file, const char *str); char *tracefs_instance_file_read(struct tracefs_instance *instance, const char *file, int *psize); +int tracefs_instance_file_read_number(struct tracefs_instance *instance, + const char *file, long long *res); +int tracefs_instance_file_open(struct tracefs_instance *instance, + const char *file, int mode); int tracefs_instances_walk(int (*callback)(const char *, void *), void *context); bool tracefs_instance_exists(const char *name); diff --git a/src/tracefs-instance.c b/src/tracefs-instance.c index 6dc85ee..97bbb00 100644 --- a/src/tracefs-instance.c +++ b/src/tracefs-instance.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include "tracefs.h" #include "tracefs-local.h" @@ -301,6 +301,64 @@ char *tracefs_instance_file_read(struct tracefs_instance *instance, return buf; } +/** + * tracefs_instance_file_read_number - Read long long integer from a trace file. + * @instance: ftrace instance, can be NULL for the top instance + * @file: name of the file + * @res: The integer from the file. + * + * Returns 0 if the reading is successful and the result is stored in res, -1 + * in case of an error. + */ +int tracefs_instance_file_read_number(struct tracefs_instance *instance, + const char *file, long long *res) +{ + long long num; + int ret = -1; + int size = 0; + char *str; + + str = tracefs_instance_file_read(instance, file, &size); + if (size && str) { + errno = 0; + num = strtoll(str, NULL, 0); + if (errno == 0) { + *res = num; + ret = 0; + } + } + free(str); + return ret; +} + +/** + * tracefs_instance_file_open - Open a trace file for reading and writing + * @instance: ftrace instance, can be NULL for the top instance + * @file: name of the file + * @mode: file open flags, -1 for default O_RDWR + * + * Returns -1 in case of an error, or a valid file descriptor otherwise. + * The returned FD must be closed with close() + */ +int tracefs_instance_file_open(struct tracefs_instance *instance, + const char *file, int mode) +{ + int flags = O_RDWR; + int fd = -1; + char *path; + + path = tracefs_instance_get_file(instance, file); + if (!path) + return -1; + + if (mode >= 0) + flags = mode; + fd = open(path, flags); + tracefs_put_tracing_file(path); + + return fd; +} + static bool check_file_exists(struct tracefs_instance *instance, char *name, bool dir) { From patchwork Tue Jan 12 09:20:20 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: 12012855 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90340C433DB for ; Tue, 12 Jan 2021 09:21:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 52F5E22E03 for ; Tue, 12 Jan 2021 09:21:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731388AbhALJVN (ORCPT ); Tue, 12 Jan 2021 04:21:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390337AbhALJVM (ORCPT ); Tue, 12 Jan 2021 04:21:12 -0500 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9327C06179F for ; Tue, 12 Jan 2021 01:20:31 -0800 (PST) Received: by mail-ej1-x632.google.com with SMTP id e18so1024245ejt.12 for ; Tue, 12 Jan 2021 01:20:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tUQ0teJNmXs4LnMIulH/DxSFSPK5bzfPxMGc5g6wftw=; b=oOWYc4lI8VRlVrr6MNGCoResg3EP+TRP4oLSmURknbqa6PGRGmCyB9qSkivrKHs+nL UN6NcHQ/D6qn02jhdUzECtiNgHoigxyUgWk21yGi9NMvvGthTjv7KUZ+g8g+/dhm3XD2 28jhTtINABKtc9spATrWwrqGKiLnH/Z2G9JxGK1JRo0jjy6wCpitRC2SeegE/5HvFPDE 2eIbBjkaBK4kWG5u49XkpkDF/4VYvJ5ZN/1+94lA6ktOLSFCRYBp9DUM+vXBLASbiwrA tR3BRU87sXtBtnhE6PkfEGVWtK/nYa8NVTBSOhD31B7omb0fTwsXSq0JTSW/VH6V3Ni8 vrJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tUQ0teJNmXs4LnMIulH/DxSFSPK5bzfPxMGc5g6wftw=; b=XQ94pLNrWb/gcxhnNxRzp3YE9yVJED5knQ78+8pw97+yRcwRYpYcqZKv1VvYa3YcbC 0rE9ZLw7R/M1bV9D/XiXBK6lUuNS3z9/MPS7eH6PSlOJvrJD+n1MBWmBKlUye46H8yxI LKJyq3bl5Gj+7CzCJy0KwODA8KrpQfb9mKRVvrdceKQZYBli6oyrZQS47bGufGjRCrUM e9p4b5s4t5Y0zsly+wn12uj8Sfwl6rSLmD4gxBE2L99sLfUyfq5hUujMgMehWVoZl6Ep eZNtrh2bd626KLNYV1ojCYUFL+AAFwNB5BPI9R32Cb4avfFpBQsmJrHg/nVkBn/P7hwm uPsA== X-Gm-Message-State: AOAM533a5Yiq82vIopSqXsTW51LLEG2i046pOUgFehlGdOs98IzeG5AK lqBlYo0reLY8uHbsiyZbM94YEymDMfJt0D94 X-Google-Smtp-Source: ABdhPJwLomWrkcKCj2AE4bZoNNgDgD0Toepr3oXMKrvYmpyLL466zCN7cAe6QKAJNIjLgkRjUja2YQ== X-Received: by 2002:a17:906:2257:: with SMTP id 23mr2602160ejr.497.1610443230465; Tue, 12 Jan 2021 01:20:30 -0800 (PST) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id rl7sm929187ejb.107.2021.01.12.01.20.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 01:20:29 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 3/7] libtracefs: New APIs for enable / disable tracing Date: Tue, 12 Jan 2021 11:20:20 +0200 Message-Id: <20210112092024.605705-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210112092024.605705-1-tz.stoyanov@gmail.com> References: <20210112092024.605705-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org These new APIs can be used to enable / disable tracing in given ftrace instance: tracefs_trace_is_on(); tracefs_trace_on(); tracefs_trace_off(); tracefs_trace_on_get_fd(); tracefs_trace_on_fd(); tracefs_trace_off_fd(); Signed-off-by: Tzvetomir Stoyanov (VMware) --- include/tracefs.h | 18 ++++++++ src/Makefile | 1 + src/tracefs-tools.c | 109 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 src/tracefs-tools.c diff --git a/include/tracefs.h b/include/tracefs.h index bec8369..85a776e 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -40,6 +40,24 @@ bool tracefs_instance_exists(const char *name); bool tracefs_file_exists(struct tracefs_instance *instance, char *name); bool tracefs_dir_exists(struct tracefs_instance *instance, char *name); +int tracefs_trace_is_on(struct tracefs_instance *instance); +int tracefs_trace_on(struct tracefs_instance *instance); +int tracefs_trace_off(struct tracefs_instance *instance); +int tracefs_trace_on_fd(int fd); +int tracefs_trace_off_fd(int fd); + +/** + * tracefs_trace_on_get_fd - Get a file descriptor of "tracing_on" in given instance + * @instance: ftrace instance, can be NULL for the top instance + * + * Returns -1 in case of an error, or a valid file descriptor to "tracing_on" + * file for reading and writing.The returned FD must be closed with close(). + */ +static inline int tracefs_trace_on_get_fd(struct tracefs_instance *instance) +{ + return tracefs_instance_file_open(instance, "tracing_on", O_RDWR); +} + /* events */ void tracefs_list_free(char **list); char **tracefs_event_systems(const char *tracing_dir); diff --git a/src/Makefile b/src/Makefile index 3f64905..dabdbb4 100644 --- a/src/Makefile +++ b/src/Makefile @@ -6,6 +6,7 @@ OBJS = OBJS += tracefs-utils.o OBJS += tracefs-instance.o OBJS += tracefs-events.o +OBJS += tracefs-tools.o OBJS := $(OBJS:%.o=$(bdir)/%.o) DEPS := $(OBJS:$(bdir)/%.o=$(bdir)/.%.d) diff --git a/src/tracefs-tools.c b/src/tracefs-tools.c new file mode 100644 index 0000000..101f389 --- /dev/null +++ b/src/tracefs-tools.c @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: LGPL-2.1 +/* + * Copyright (C) 2008, 2009, 2010 Red Hat Inc, Steven Rostedt + * + * Updates: + * Copyright (C) 2021, VMware, Tzvetomir Stoyanov + * + */ +#include +#include +#include + +#include "tracefs.h" +#include "tracefs-local.h" + +#define TRACE_CTRL "tracing_on" + +static int trace_on_off(int fd, bool on) +{ + const char *val = on ? "1" : "0"; + int ret; + + ret = write(fd, val, 1); + if (ret == 1) + return 0; + + return -1; +} + +static int trace_on_off_file(struct tracefs_instance *instance, bool on) +{ + int ret; + int fd; + + fd = tracefs_instance_file_open(instance, TRACE_CTRL, O_WRONLY); + if (fd < 0) + return -1; + ret = trace_on_off(fd, on); + close(fd); + + return ret; +} + +/** + * tracefs_trace_is_on - Check if writing traces to the ring buffer is enabled + * @instance: ftrace instance, can be NULL for the top instance + * + * Returns -1 in case of an error, 0 if tracing is disable or 1 if tracing + * is enabled. + */ +int tracefs_trace_is_on(struct tracefs_instance *instance) +{ + long long res; + + if (tracefs_instance_file_read_number(instance, TRACE_CTRL, &res) == 0) + return (int)res; + + return -1; +} + +/** + * tracefs_trace_on - Enable writing traces to the ring buffer of the given instance + * @instance: ftrace instance, can be NULL for the top instance + * + * Returns -1 in case of an error or 0 otherwise + */ +int tracefs_trace_on(struct tracefs_instance *instance) +{ + return trace_on_off_file(instance, true); +} + +/** + * tracefs_trace_off - Disable writing traces to the ring buffer of the given instance + * @instance: ftrace instance, can be NULL for the top instance + * + * Returns -1 in case of an error or 0 otherwise + */ +int tracefs_trace_off(struct tracefs_instance *instance) +{ + return trace_on_off_file(instance, false); +} + +/** + * tracefs_trace_on_fd - Enable writing traces to the ring buffer + * @fd: File descriptor to ftrace tracing_on file, previously opened + * with tracefs_trace_on_get_fd() + * + * Returns -1 in case of an error or 0 otherwise + */ +int tracefs_trace_on_fd(int fd) +{ + if (fd < 0) + return -1; + return trace_on_off(fd, true); +} + +/** + * tracefs_trace_off_fd - Disable writing traces to the ring buffer + * @fd: File descriptor to ftrace tracing_on file, previously opened + * with tracefs_trace_on_get_fd() + * + * Returns -1 in case of an error or 0 otherwise + */ +int tracefs_trace_off_fd(int fd) +{ + if (fd < 0) + return -1; + return trace_on_off(fd, false); +} From patchwork Tue Jan 12 09:20:21 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: 12012857 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0D62C433DB for ; Tue, 12 Jan 2021 09:21:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7871122E01 for ; Tue, 12 Jan 2021 09:21:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390589AbhALJVX (ORCPT ); Tue, 12 Jan 2021 04:21:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732377AbhALJVW (ORCPT ); Tue, 12 Jan 2021 04:21:22 -0500 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7338C0617A2 for ; Tue, 12 Jan 2021 01:20:32 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id g12so308334ejf.8 for ; Tue, 12 Jan 2021 01:20:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YC8+W9IviYLVe4KAzoDQWXwIO0NEa4o48S06NExlU0g=; b=Rc6RGmYCweqw6kOSejajW3mYTGLj7EFbxafvhWaGQLtABV7V5nTIw+oJzVM7shd/Nv E70GQ1zP97N56dkCgKUIqGlWGbf8vpM5UE6WcFkFX4orIFN7pJbblM9juFPcUWXtYHHO ruKQe7twfvYxKjW13EwOoPMCjmxP3PDRtngvmpCWQyYXBof5aIlU024nFc7EFiFwiHy1 bnbVBHBm8/w8iqZEbGKuRg1czE4xgK4sdbpxIoqQrzxjOdP5PHPtMxM4ozARc4ZPE1Ux VArrCW0djNBJMa9ETKzNguQ733Y41gQZ9tmi5FgeLLv9T65zQ7VvXj0hlLVDqLeWHAW7 S6hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YC8+W9IviYLVe4KAzoDQWXwIO0NEa4o48S06NExlU0g=; b=E3Fy+Wt4Kh47vNLZo4sWf+P3lDO3E8wVJgIwmMvYBzElX3W1rhB+d/rGsJ4IxDHwmP NO5/KGuKCstmz9dqP77uEydGfH+1N45LJ5OGpCw3seL9X8GE2UTuXDyusV2TTU19Zmor yrZwFNuDwzEOQNfkajfDFw+qsNjWn/zljhtxmLWI/yRy6IAPpv7LNwPbTdwlYHj7mV+g D3wVFCrwu5MI/g/p6WLlNtVmftTPB/wlnOcIQVRhfVagS41T9xNxYfX3YL2coD4my6Bf ftnwQFEBRnKv8c4w9xEub33lQo5kKck05Iec78BwPupFcmNcX/OAIeFOrNRfzSksMhEe wY2A== X-Gm-Message-State: AOAM531fvnHSb58hEpp1aFnyFJoxTVoKJOIixJPVS/RckYX95eUsxHF8 jxij6iQPZYsSlnFhhCnlR0BYEQl5z0zr636S X-Google-Smtp-Source: ABdhPJwuo6qTRkVL1L+lHy88SmuBYbclvw0epX/MGRArF/24toq5+qY0wT8MsU6tT88oTXvfeTtrzg== X-Received: by 2002:a17:906:87c3:: with SMTP id zb3mr1352942ejb.244.1610443231539; Tue, 12 Jan 2021 01:20:31 -0800 (PST) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id rl7sm929187ejb.107.2021.01.12.01.20.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 01:20:30 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 4/7] libtracefs: Documentation for the new APIs for opening and reading ftrace files Date: Tue, 12 Jan 2021 11:20:21 +0200 Message-Id: <20210112092024.605705-5-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210112092024.605705-1-tz.stoyanov@gmail.com> References: <20210112092024.605705-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Man pages updated with documentation about: tracefs_instance_file_open(); tracefs_instance_file_read_number(); Signed-off-by: Tzvetomir Stoyanov (VMware) --- Documentation/libtracefs-instances-files.txt | 45 ++++++++++++++++++-- Documentation/libtracefs.txt | 2 + 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Documentation/libtracefs-instances-files.txt b/Documentation/libtracefs-instances-files.txt index a9af1f7..124ef52 100644 --- a/Documentation/libtracefs-instances-files.txt +++ b/Documentation/libtracefs-instances-files.txt @@ -4,8 +4,8 @@ libtracefs(3) NAME ---- tracefs_file_exists, tracefs_dir_exists, tracefs_instance_get_file, -tracefs_instance_get_dir, tracefs_instance_file_write, -tracefs_instance_file_read - Work with files in tracing instances. +tracefs_instance_get_dir, tracefs_instance_file_open, tracefs_instance_file_write, +tracefs_instance_file_read, tracefs_instance_file_read_number - Work with files in tracing instances. SYNOPSIS -------- @@ -17,8 +17,10 @@ bool *tracefs_file_exists*(struct tracefs_instance pass:[*]_instance_, char pass bool *tracefs_dir_exists*(struct tracefs_instance pass:[*]_instance_, char pass:[*]_name_); char pass:[*]*tracefs_instance_get_file*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_file_); char pass:[*]*tracefs_instance_get_dir*(struct tracefs_instance pass:[*]_instance_); +int *tracefs_instance_file_open*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_file_, int _mode_); int *tracefs_instance_file_write*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_file_, const char pass:[*]_str_); char pass:[*]*tracefs_instance_file_read*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_file_, int pass:[*]_psize_); +int *tracefs_instance_file_read_number*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_file_, long long int pass:[*]_res_); -- @@ -41,12 +43,19 @@ The _tracefs_instance_get_dir()_ function returns the full path of the director with given _name_ in _instance_. Note, it does not check if the directory exists in the instance. +The _tracefs_instance_file_open()_ function opens trace _file_ from given _instance_ and returns +a file descriptor to it. The file access _mode_ can be specified, see *open*(3) for more details. +If -1 is passed as _mode_, default O_RDWR is used. + The _tracefs_instance_file_write()_ function writes a string _str_ in a _file_ from the given _instance_, without the terminating NULL character. -The _tracefs_instance_file_read()_ function reads the content of a _file_ from +The _tracefs_instance_file_read()_ function reads the content of a _file_ from the given _instance_. +The _tracefs_instance_file_read_number()_ function reads the content of a _file_ from +the given _instance_ and converts it to a long long integer, which is stored in _res_. + RETURN VALUE ------------ The _tracefs_file_exists()_ and _tracefs_dir_exists()_ functions return true if the @@ -56,6 +65,9 @@ The _tracefs_instance_get_file()_ and _tracefs_instance_get_dir()_ functions ret a string or NULL in case of an error. The returned string must be freed with _tracefs_put_tracing_file()_. +The _tracefs_instance_file_open()_ function returns a file descriptor to the opened file. It must be +closed with *close*(3). In case of an error, -1 is returned. + The _tracefs_instance_file_write()_ function returns the number of written bytes, or -1 in case of an error. @@ -63,6 +75,9 @@ The _tracefs_instance_file_read()_ function returns a pointer to a NULL terminat string, read from the file, or NULL in case of an error. The returned string must be freed with free(). +The _tracefs_instance_file_read_number()_ function returns 0 if a valid integer is read from +the file and stored in _res_ or -1 in case of an error. + EXAMPLE ------- [source,c] @@ -123,6 +138,30 @@ struct tracefs_instance *inst = tracefs_instance_create("foo"); tracefs_instance_destroy(inst); else tracefs_instance_free(inst); + ... + + long long int res; + if (tracefs_instance_file_read_number(NULL, "tracing_on", &res) == 0) { + if (res == 0) { + /* tracing is disabled in the top instance */ + } else if (res == 1) { + /* tracing is enabled in the top instance */ + } else { + /* Unknown tracing state of the top instance */ + } + } else { + /* Failed to read integer from tracing_on file */ + } + + ... + + int fd; + fd = tracefs_instance_file_open(NULL, "tracing_on", O_WRONLY); + if (fd >= 0) { + /* Got file descriptor to the tracing_on file from the top instance for writing */ + ... + close(fd); + } -- FILES ----- diff --git a/Documentation/libtracefs.txt b/Documentation/libtracefs.txt index bf3882f..0350416 100644 --- a/Documentation/libtracefs.txt +++ b/Documentation/libtracefs.txt @@ -25,8 +25,10 @@ Trace instances: bool *tracefs_dir_exists*(struct tracefs_instance pass:[*]_instance_, char pass:[*]_name_); char pass:[*]*tracefs_instance_get_file*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_file_); char pass:[*]*tracefs_instance_get_dir*(struct tracefs_instance pass:[*]_instance_); + int *tracefs_instance_file_open*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_file_, int _mode_); int *tracefs_instance_file_write*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_file_, const char pass:[*]_str_); char pass:[*]*tracefs_instance_file_read*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_file_, int pass:[*]_psize_); + int *tracefs_instance_file_read_number*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]_file_, long long int pass:[*]_res_); const char pass:[*]*tracefs_instance_get_name*(struct tracefs_instance pass:[*]_instance_); int *tracefs_instances_walk*(int (pass:[*]_callback_)(const char pass:[*], void pass:[*]), void pass:[*]_context)_; bool *tracefs_instance_exists*(const char pass:[*]_name_); From patchwork Tue Jan 12 09:20:22 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: 12012859 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E831CC433E6 for ; Tue, 12 Jan 2021 09:21:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A266622E03 for ; Tue, 12 Jan 2021 09:21:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732377AbhALJVX (ORCPT ); Tue, 12 Jan 2021 04:21:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390543AbhALJVW (ORCPT ); Tue, 12 Jan 2021 04:21:22 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0F6BC0617A3 for ; Tue, 12 Jan 2021 01:20:33 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id f4so1394950ejx.7 for ; Tue, 12 Jan 2021 01:20:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v08s1omr+8XwvYUQgddTC+/0kdixtXlEPSBk19NV3/I=; b=oDnNbailWc+uovs0TrcWdzE6y7GVqu1v2ckU+DPKXIZqpv4ZVjBeO7yyARm3yDg7Tg 12n38dWDPQXmJUpKlXx28ltxd0hHRcphJAmILXNGgNNo6hxf1l9dDMEZWB61ZaDGf2p5 oapwER9XLO4HkFPEICugxuGy+dZBo0D2wtf0/OMtHZxJOQqoTsAb09wQYyl+Gf2jsmEY 7hVYY3jm0iIFgcSV0gtqagDjLkfIacF595/u0u9kFfGsP1ydTSmmoiENDAn3Kq+1Hxe+ X97gyO38mZs9bdwxa52MlSVfIhugd7PzooFf1YyFYQRESVfyxpMr0ftRv1s/NvobbAJm a9pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v08s1omr+8XwvYUQgddTC+/0kdixtXlEPSBk19NV3/I=; b=MFTna6RpILlzECmx4+0RcChh2e0ouRaL/4o+m/i4YK0RbWu/8+Rs+yNFo9RpSV8UVN +tBKX/SA8tokCgJOE0lKH+D1zfo99IyoAmokV2+0GdWsGoOtNvEapZm64GWnTpIvbZyT g3445/f4ZuylZwodOxON81y8jpcC5XgLzsFw+GzI76tYtu5A18Xp+OvBZvzGKt32Qq5p yQGNpY81SwMCp9BZHtfwkjVpkUDheFDIvc8Ih8DQmKOwsGqv103HQOSUWvzG6ewKPkU8 byKHUU10GhxrbKnazqTTBJn1HTnKajIbZIvpSmHN6S4GJbOHphL5LMgqkmp+WGyuIXeN hqEw== X-Gm-Message-State: AOAM533Av6CIWmIbparthdVZWjcb/F8ojDHAReeyzvraZXRzK5Mw06UK COdsp+Aa0eVw7KunptXAuiQ= X-Google-Smtp-Source: ABdhPJx9fnixv0M20VFZwnqmY3PmTp5xdm9h92LWF3+osi+bltw2X10VWiAX30vuEdp1W8Z+2jfHfg== X-Received: by 2002:a17:906:8617:: with SMTP id o23mr2586969ejx.274.1610443232628; Tue, 12 Jan 2021 01:20:32 -0800 (PST) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id rl7sm929187ejb.107.2021.01.12.01.20.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 01:20:31 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 5/7] libtracefs: Documentation for enable / disable tracing APIs Date: Tue, 12 Jan 2021 11:20:22 +0200 Message-Id: <20210112092024.605705-6-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210112092024.605705-1-tz.stoyanov@gmail.com> References: <20210112092024.605705-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org New man pages with documentation about: tracefs_trace_is_on(); tracefs_trace_on(); tracefs_trace_off(); tracefs_trace_on_fd(); tracefs_trace_off_fd(); Signed-off-by: Tzvetomir Stoyanov (VMware) --- Documentation/libtracefs-traceon.txt | 151 +++++++++++++++++++++++++++ Documentation/libtracefs.txt | 6 ++ 2 files changed, 157 insertions(+) create mode 100644 Documentation/libtracefs-traceon.txt diff --git a/Documentation/libtracefs-traceon.txt b/Documentation/libtracefs-traceon.txt new file mode 100644 index 0000000..d7fc239 --- /dev/null +++ b/Documentation/libtracefs-traceon.txt @@ -0,0 +1,151 @@ +libtracefs(3) +============= + +NAME +---- +tracefs_trace_is_on, tracefs_trace_on, tracefs_trace_off, tracefs_trace_on_get_fd, +tracefs_trace_on_fd, tracefs_trace_off_fd - Functions to enable or disable tracing. + +SYNOPSIS +-------- +[verse] +-- +*#include * + +int *tracefs_trace_is_on*(struct tracefs_instance pass:[*]_instance_); +int *tracefs_trace_on*(struct tracefs_instance pass:[*]_instance_); +int *tracefs_trace_off*(struct tracefs_instance pass:[*]_instance_); +int _tracefs_trace_on_get_fd_(struct tracefs_instance pass:[*]_instance_); +int *tracefs_trace_on_fd*(int _fd_); +int *tracefs_trace_off_fd*(int _fd_); +-- + +DESCRIPTION +----------- +This set of functions can be used to check, enable or disable writing to the ring buffer in +the given trace instance. The tracing is enabled when writing to the ring buffer is enabled. + +The _tracefs_trace_is_on()_ function checks if tracing is enabled for the given _instance_. If +_instance_ is NULL, the top instance is used. + +The _tracefs_trace_on()_ and _tracefs_trace_off()_ functions set the tracing in the _instance_ +to enable or disable state. If _instance_ is NULL, the top instance is used. + +The _tracefs_trace_on_get_fd()_ function returns a file deascriptor to the "tracing_on" file from +the given _instance_. If _instance_ is NULL, the top trace instance is used. The returned descriptor +can be used for fast enabling or disabling the tracing of the instance. + +The _tracefs_trace_on_fd()_ and _tracefs_trace_off_fd()_ functions set the tracing state to enable +or disable using the given _fd_. This file descriptor must be opened for writing with +*tracefs_trace_on_get_fd*(3) of the desired trace instance. These functions are faster than +*tracefs_trace_on* and *tracefs_trace_off*. + +RETURN VALUE +------------ +The _tracefs_trace_is_on()_ function returns 0 if tracing is disable, 1 if it is enabled or +-1 in case of an error. + +The _tracefs_trace_on_get_fd()_ function returns a file descriptor to "tracing_on" +file for reading and writing, which must be closed wuth close(). In case of an error -1 is returned. + +The _tracefs_trace_on()_, _tracefs_trace_off()_, _tracefs_trace_on_fd()_ and +_tracefs_trace_off_fd()_ functions return -1 in case of an error or 0 otherwise. + +EXAMPLE +------- +[source,c] +-- +#include + + int ret; + + ret = tracefs_trace_is_on(NULL); + if (ret == 0) { + /* Tracing is disabled in the top instance */ + } else if (ret == 1) {" + /* Tracing is enabled in the top instance */ + } else { + /* Error getting tracing state of the top instance */ + } + + ... + + if (!tracefs_trace_on(NULL)) { + /* Enabled tracing in the top instance */ + + ... + + if (!tracefs_trace_off(NULL)) { + /* Disabled tracing in the top instance */ + } else { + /* Error disabling tracing in the top instance */ + } + } else { + /* Error enabling tracing in the top instance */ + } + + ... + + int fd = tracefs_trace_on_get_fd(NULL); + + if (fd < 0) { + /* Error opening tracing_on file */ + } + ... + if (!tracefs_trace_on_fd(fd)) { + /* Enabled tracing in the top instance */ + + ... + + if (!tracefs_trace_off_fd(fd)) { + /* Disabled tracing in the top instance */ + } else { + /* Error disabling tracing in the top instance */ + } + } else { + /* Error enabling tracing in the top instance */ + } + + ... + + close(fd); +-- +FILES +----- +[verse] +-- +*tracefs.h* + Header file to include in order to have access to the library APIs. +*-ltracefs* + Linker switch to add when building a program that uses the library. +-- + +SEE ALSO +-------- +_libtracefs(3)_, +_libtraceevent(3)_, +_trace-cmd(1)_ + +AUTHOR +------ +[verse] +-- +*Steven Rostedt* +*Tzvetomir Stoyanov* +-- +REPORTING BUGS +-------------- +Report bugs to + +LICENSE +------- +libtracefs is Free Software licensed under the GNU LGPL 2.1 + +RESOURCES +--------- +https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/ + +COPYING +------- +Copyright \(C) 2021 VMware, Inc. Free use of this software is granted under +the terms of the GNU Public License (GPL). diff --git a/Documentation/libtracefs.txt b/Documentation/libtracefs.txt index 0350416..cea21fe 100644 --- a/Documentation/libtracefs.txt +++ b/Documentation/libtracefs.txt @@ -45,6 +45,12 @@ Trace helper functions: void *tracefs_list_free*(char pass:[*]pass:[*]_list_); char pass:[*]pass:[*]*tracefs_tracers*(const char pass:[*]_tracing_dir_); char pass:[*]*tracefs_get_clock*(struct tracefs_instance pass:[*]_instance_); + int *tracefs_trace_is_on*(struct tracefs_instance pass:[*]_instance_); + int *tracefs_trace_on*(struct tracefs_instance pass:[*]_instance_); + int *tracefs_trace_off*(struct tracefs_instance pass:[*]_instance_); + int _tracefs_trace_on_get_fd_(struct tracefs_instance pass:[*]_instance_); + int *tracefs_trace_on_fd*(int _fd_); + int *tracefs_trace_off_fd*(int _fd_); -- DESCRIPTION From patchwork Tue Jan 12 09:20:23 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: 12012863 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8AA5C433E6 for ; Tue, 12 Jan 2021 09:21:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E74022E01 for ; Tue, 12 Jan 2021 09:21:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390755AbhALJVt (ORCPT ); Tue, 12 Jan 2021 04:21:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390542AbhALJVt (ORCPT ); Tue, 12 Jan 2021 04:21:49 -0500 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0AE3C0617A4 for ; Tue, 12 Jan 2021 01:20:34 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id t16so2429187ejf.13 for ; Tue, 12 Jan 2021 01:20:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YUbWQbjxxAko+8hvUqXQyq9S/8eClQ9L2CYVZy6Pcig=; b=NvGDB0C+Y1lndZMwjH6Wr3IYs1M2DYnOF4hd9wkht9YaqXKBMkceEe7BMwR/XXJI+a jLjWjZ1SPldV/NwfynvlZzwMpcQlSZdN3+NE4jWlTm+s/0Y/AMTMBIAgDL3WDzexp9tD uvwIvWBqmlEfzr549MOMEie2KPjq5kE/N4oW/Msa4RKf3U+KrAHL4vBy5RSAem7kIHGU SlIqM0eqe+gm6DvvJYRa2SwmVV6iV3lPO5QnCNjXbShe+kOA9aETyVlgzgui9iA+wm1U ET3kmdJKy4VpxYAYYwcjb7tQ0gdl9dFl0IW4CyFwhNETYKP339F4qxeSJnq9H7hpt7wa kRrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YUbWQbjxxAko+8hvUqXQyq9S/8eClQ9L2CYVZy6Pcig=; b=Wf8Hc6JG3DQOrMawkisDdoSmX8dKhhErZ6IgRAB5FzwryIrpTmFuLVDfhJkO1jzDF8 KzUr2HNSE3jouGZlmVlpD68r2TZa3aH0HWkhX3jXtuiXiCTi7exYPJSkMOwfH7Ldz2eC 99QrxsJaLJ0QfPQs+5vbXqtPrnZqyXQIemPRiMDVp2fa8Gers1TXczu4K1z0UkfPampn MvhFwh75vdJEgUTWKdYLF92Na++Qv9D3Lc5D83Tj7amnepVdTlCbCMPtYboBurGUtNSJ FoXUbaN6u76YlJpkJmAO5mZOpQs5IGxadaMig+noLiu7H/0WcJnl3QMlr0Id1QR3uDH8 Oj6A== X-Gm-Message-State: AOAM532h+Xzf6tLRlLyqNUjTtOKY5uFx0fpmVUmWyD/EisOinZwPy74n 4X+3/0Kv4XUayoAR/ypJX/jY6zPn/Qb1znOK X-Google-Smtp-Source: ABdhPJz4tpsxWu/9T8Q0yjvcU6sRia4d9sO5QPWRRTUaTBYGRGezQ282Uf3M4162pHTa1GGep4XH/g== X-Received: by 2002:a17:906:3111:: with SMTP id 17mr2415626ejx.152.1610443233714; Tue, 12 Jan 2021 01:20:33 -0800 (PST) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id rl7sm929187ejb.107.2021.01.12.01.20.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 01:20:33 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 6/7] libtracefs: Unit tests for the new APIs for opening and reading ftrace files Date: Tue, 12 Jan 2021 11:20:23 +0200 Message-Id: <20210112092024.605705-7-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210112092024.605705-1-tz.stoyanov@gmail.com> References: <20210112092024.605705-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Added unit tests for: tracefs_instance_file_open(); tracefs_instance_file_read_number(); Signed-off-by: Tzvetomir Stoyanov (VMware) --- utest/tracefs-utest.c | 94 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c index a8e8f67..bbe653c 100644 --- a/utest/tracefs-utest.c +++ b/utest/tracefs-utest.c @@ -218,6 +218,7 @@ static void test_instance_file_read(struct tracefs_instance *inst, const char *f #define ALL_TRACERS "available_tracers" #define CUR_TRACER "current_tracer" #define PER_CPU "per_cpu" +#define TRACE_ON "tracing_on" static void test_instance_file(void) { struct tracefs_instance *instance = NULL; @@ -322,6 +323,97 @@ static void test_instance_file(void) free(inst_dir); } +static bool check_fd_name(int fd, char *name) +{ + char link[PATH_MAX + 1]; + char path[PATH_MAX + 1]; + struct stat st; + char *file; + int ret; + + snprintf(link, PATH_MAX, "/proc/self/fd/%d", fd); + ret = lstat(link, &st); + CU_TEST(ret == 0); + if (ret < 0) + return false; + CU_TEST(S_ISLNK(st.st_mode)); + if (!S_ISLNK(st.st_mode)) + return false; + ret = readlink(link, path, PATH_MAX); + CU_TEST(ret > 0); + if (ret > PATH_MAX || ret < 0) + return false; + path[ret] = 0; + file = basename(path); + CU_TEST(file != NULL); + if (!file) + return false; + ret = strcmp(file, name); + CU_TEST(ret == 0); + if (ret) + return false; + return true; +} + +#define FLAGS_STR "flags:" +static bool check_fd_mode(int fd, int mode) +{ + char path[PATH_MAX + 1]; + long fmode = -1; + char *line = NULL; + struct stat st; + size_t len = 0; + ssize_t size; + FILE *file; + int ret; + + snprintf(path, PATH_MAX, "/proc/self/fdinfo/%d", fd); + ret = stat(path, &st); + CU_TEST(ret == 0); + if (ret < 0) + return false; + file = fopen(path, "r"); + if (!file) + return false; + while ((size = getline(&line, &len, file)) > 0) { + if (strncmp(line, FLAGS_STR, strlen(FLAGS_STR))) + continue; + fmode = strtol(line + strlen(FLAGS_STR), NULL, 8); + break; + } + free(line); + fclose(file); + if (fmode < 0 || + (O_ACCMODE & fmode) != (O_ACCMODE & mode)) + return false; + return true; +} + +static void test_instance_file_fd(void) +{ + const char *name = get_rand_str(); + long long res = -1; + char rd[2]; + int fd; + + fd = tracefs_instance_file_open(test_instance, name, -1); + CU_TEST(fd == -1); + fd = tracefs_instance_file_open(test_instance, TRACE_ON, O_RDONLY); + CU_TEST(fd >= 0); + CU_TEST(check_fd_name(fd, TRACE_ON)); + CU_TEST(check_fd_mode(fd, O_RDONLY)); + + CU_TEST(tracefs_instance_file_read_number(test_instance, "available_tracer", &res) != 0); + CU_TEST(tracefs_instance_file_read_number(test_instance, name, &res) != 0); + CU_TEST(tracefs_instance_file_read_number(test_instance, TRACE_ON, &res) == 0); + CU_TEST((res == 0 || res == 1)); + CU_TEST(read(fd, &rd, 1) == 1); + rd[1] = 0; + CU_TEST(res == atoi(rd)); + + close(fd); +} + static void exclude_string(char **strings, char *name) { int i; @@ -614,6 +706,8 @@ void test_tracefs_lib(void) CU_add_test(suite, "tracing file / directory APIs", test_trace_file); CU_add_test(suite, "instance file / directory APIs", + test_instance_file_fd); + CU_add_test(suite, "instance file descriptor", test_instance_file); CU_add_test(suite, "systems and events APIs", test_system_event); From patchwork Tue Jan 12 09:20:24 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: 12012861 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C6E4C43381 for ; Tue, 12 Jan 2021 09:21:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC12C22DFB for ; Tue, 12 Jan 2021 09:21:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390542AbhALJVu (ORCPT ); Tue, 12 Jan 2021 04:21:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390713AbhALJVt (ORCPT ); Tue, 12 Jan 2021 04:21:49 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E195C0617A5 for ; Tue, 12 Jan 2021 01:20:36 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id q22so2507017eja.2 for ; Tue, 12 Jan 2021 01:20:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kdqBTxwJ61ZHvf08XPUPelAlkHvuNFbl5SueVAFhgaA=; b=pAP4rH9JHZPCj5XDHLEF3a/6axFE8rFtMQLzuOCr15yngl6e+GflOCryWO4+p7otmn MBoDLUCtqIKKzPjaDWNBLU5oXjKkBXrOu5UCJjbr1xD1/G+1KwtNz64yuU7MD3HCCsUv wmiNjsokk0A/rZ0dP3lrU8g8/EjI2EjTMxIT5//rqcjLrDRaRXuRCBAxAzcnCuAkpVou FmZXQ/gDdhZd88X6tJX5N1xW0FgW5e/VWdFQnigdRGdrRi9bccqvzYGv7VexXg4INVVz AA76UEc7s/YO9eHKfSv2co75SJHKMH1l1mmFscwQUI6rGtPMYugVKOPORyiHX0ELS0yD vlgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kdqBTxwJ61ZHvf08XPUPelAlkHvuNFbl5SueVAFhgaA=; b=d/mkLCp/lw3dFc6WrY3BM0frusxkG0M4g+bjyM5sEI6wTxdhwpSbUEQC2ZQsb9LiJE dyW3Z7EJCxdIl+eVuCgRkQDZg5WYhWKtZ8xaiL6qk8x94i0JSHw5iQRpEbHtZg/J59OH gdUCjYaCPG5qZlthN1TmtwtYNu6fzSFX6bgZc56oT3iJpYXZaivN4HLZ50h2XSGjHK98 g4F08vx0sYim0wgqiyaoQ3JF8r4se1uVEW8jy1Uz9WyKLPoKgdjKB+/E8fYBV5botSLH 9XFtZdYlk0d6QspQFDSumPJxYig7T6pwT04dUCjgvJYEOL86DCE0YI/hvl2bJAwUbuIs Qsvg== X-Gm-Message-State: AOAM533KX7eImFc7UHPj17RRUCB20DPdnuR/JgGDGI8IxI8GW4bwdXMm j1AdodxhkUbDCSii2hKpmro= X-Google-Smtp-Source: ABdhPJxnBtK5YcG5QUoEc3159VEKlYpZyRqY8gMdC43MhHRLD5/JOTvV3wGta5HyNU7ecBGks4qoIA== X-Received: by 2002:a17:906:7797:: with SMTP id s23mr481397ejm.84.1610443235046; Tue, 12 Jan 2021 01:20:35 -0800 (PST) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id rl7sm929187ejb.107.2021.01.12.01.20.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Jan 2021 01:20:34 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2 7/7] libtracefs: Unit tests for enable / disable tracing APIs Date: Tue, 12 Jan 2021 11:20:24 +0200 Message-Id: <20210112092024.605705-8-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210112092024.605705-1-tz.stoyanov@gmail.com> References: <20210112092024.605705-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org New unit tests for these APIs: tracefs_trace_is_on(); tracefs_trace_on(); tracefs_trace_off(); tracefs_trace_on_fd(); tracefs_trace_off_fd(); Signed-off-by: Tzvetomir Stoyanov (VMware) --- utest/tracefs-utest.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c index bbe653c..0520f49 100644 --- a/utest/tracefs-utest.c +++ b/utest/tracefs-utest.c @@ -414,6 +414,44 @@ static void test_instance_file_fd(void) close(fd); } +static void test_tracing_onoff(void) +{ + long long res = -1; + int fd; + + fd = tracefs_trace_on_get_fd(test_instance); + CU_TEST(fd >= 0); + CU_TEST(check_fd_name(fd, TRACE_ON)); + CU_TEST(check_fd_mode(fd, O_RDWR)); + CU_TEST(tracefs_instance_file_read_number(test_instance, TRACE_ON, &res) == 0); + if (res == 1) { + CU_TEST(tracefs_trace_is_on(test_instance) == 1); + CU_TEST(tracefs_trace_off(test_instance) == 0); + CU_TEST(tracefs_trace_is_on(test_instance) == 0); + CU_TEST(tracefs_trace_on(test_instance) == 0); + CU_TEST(tracefs_trace_is_on(test_instance) == 1); + + CU_TEST(tracefs_trace_off_fd(fd) == 0); + CU_TEST(tracefs_trace_is_on(test_instance) == 0); + CU_TEST(tracefs_trace_on_fd(fd) == 0); + CU_TEST(tracefs_trace_is_on(test_instance) == 1); + } else { + CU_TEST(tracefs_trace_is_on(test_instance) == 0); + CU_TEST(tracefs_trace_on(test_instance) == 0); + CU_TEST(tracefs_trace_is_on(test_instance) == 1); + CU_TEST(tracefs_trace_off(test_instance) == 0); + CU_TEST(tracefs_trace_is_on(test_instance) == 0); + + CU_TEST(tracefs_trace_on_fd(fd) == 0); + CU_TEST(tracefs_trace_is_on(test_instance) == 1); + CU_TEST(tracefs_trace_off_fd(fd) == 0); + CU_TEST(tracefs_trace_is_on(test_instance) == 0); + } + + if (fd >= 0) + close(fd); +} + static void exclude_string(char **strings, char *name) { int i; @@ -721,4 +759,7 @@ void test_tracefs_lib(void) test_instances_walk); CU_add_test(suite, "tracefs_get_clock API", test_get_clock); + CU_add_test(suite, "tracing on / off", + test_tracing_onoff); + }