From: Steven Rostedt <rostedt@goodmis.org>
To: linux-trace-devel@vger.kernel.org
Cc: Sameeruddin shaik <sameeruddin.shaik8@gmail.com>
Subject: [PATCH 10/13 v2] libtracefs: Pass in reset via flags to tracefs_function_filter()
Date: Mon, 29 Mar 2021 20:51:33 -0400 [thread overview]
Message-ID: <20210330005248.694899644@goodmis.org> (raw)
In-Reply-To: 20210330005123.151740983@goodmis.org
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
Instead of having a separate boolean to tell tracefs_function_filter() to
reset the file upon opening, make it a flag instead. This way other
booleans can be passed into the function without having to extend the
parameters.
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
Documentation/libtracefs-function-filter.txt | 26 ++++++++++++++------
include/tracefs.h | 10 +++++++-
src/tracefs-tools.c | 19 ++++++++------
3 files changed, 38 insertions(+), 17 deletions(-)
diff --git a/Documentation/libtracefs-function-filter.txt b/Documentation/libtracefs-function-filter.txt
index 88aa3b923d54..5b55a72727c8 100644
--- a/Documentation/libtracefs-function-filter.txt
+++ b/Documentation/libtracefs-function-filter.txt
@@ -11,7 +11,7 @@ SYNOPSIS
--
*#include <tracefs.h>*
-int *tracefs_function_filter*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]pass:[*]_filters_, const char pass:[*]_module_, bool _reset_, const char pass:[*]pass:[*]pass:[*]_errs_);
+int *tracefs_function_filter*(struct tracefs_instance pass:[*]_instance_, const char pass:[*]pass:[*]_filters_, const char pass:[*]_module_, int _flags_, const char pass:[*]pass:[*]pass:[*]_errs_);
--
DESCRIPTION
@@ -25,18 +25,17 @@ _filters_, which is an array of the strings that represent a list of filters tha
be applied to define what functions are to be traced and The array must end
with a NULL pointer.
_module_ , name of the module to be traced (or NULL for all functions),
-_reset_ if set will clear the current set of filters and then apply the
-filter list, otherwise the list of filters are added to the current set of
-filters,
+_flags_ which holds control knobs on how the filters will be handled (see *FLAGS*)
+section below,
_errs_, is a pointer to an array of strings, which will be allocated if
any of filters fail to match any available function, If _errs_ is NULL, it will
be ignored.
A filter in the array of _filters_ may be either a straight match of a
-function, a glob or regex(3). a glob is where '*' matches zero or more
+function, a glob or regex(3). a glob is where 'pass:[*]' matches zero or more
characters, '?' will match zero or one character, and '.' only matches a
period. If the filter is determined to be a regex (where it contains
-anything other than alpha numeric characters, or '.', '*', '?') the filter
+anything other than alpha numeric characters, or '.', 'pass:[*]', '?') the filter
will be processed as a regex(3) following the rules of regex(3), and '.' is
not a period, but will match any one character. To force a regular
expression, either prefix the filter with a '^' or append it with a '$' as
@@ -44,6 +43,17 @@ all filters will act as complete matches of functions anyway.
returns 0 on success, 1 or -x (where x is an integer) on error.
+FLAGS
+-----
+
+The _flags_ parameter may have the following set, or be zero.
+
+*TRACEFS_FL_RESET* :
+If _flags_ contains *TRACEFS_FL_RESET*, then it will clear the filters that
+are currently set before applying the list of filters from _filters_. Otherwise,
+the list of filters from _filters_ will be added to the current set of filters
+already enabled.
+
RETURN VALUE
------------
return 0 on success, if there is error, it will return 1 for general errors or
@@ -66,7 +76,7 @@ int main(int argc, char *argv[])
{
struct tracefs_instance *inst = tracefs_instance_create(INST);
const char **errs = NULL;
- bool reset = 1;
+ int flags = TRACEFS_FL_RESET;
int ret;
int i = 0;
@@ -74,7 +84,7 @@ int main(int argc, char *argv[])
/* Error creating new trace instance */
}
- ret = tracefs_function_filter(inst, filters, NULL, reset, &errs);
+ ret = tracefs_function_filter(inst, filters, NULL, flags, &errs);
if (ret < 0 && errs) {
while (errs[i])
diff --git a/include/tracefs.h b/include/tracefs.h
index 9477fdb14c5a..5193d46f41f5 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -145,6 +145,14 @@ bool tracefs_option_is_enabled(struct tracefs_instance *instance, enum tracefs_o
int tracefs_option_enable(struct tracefs_instance *instance, enum tracefs_option_id id);
int tracefs_option_diasble(struct tracefs_instance *instance, enum tracefs_option_id id);
const char *tracefs_option_name(enum tracefs_option_id id);
+
+/*
+ * RESET - Reset on opening filter file (O_TRUNC)
+ */
+enum {
+ TRACEFS_FL_RESET = (1 << 0),
+};
+
int tracefs_function_filter(struct tracefs_instance *instance, const char **filters,
- const char *module, bool reset, const char ***errs);
+ const char *module, unsigned int flags, const char ***errs);
#endif /* _TRACE_FS_H */
diff --git a/src/tracefs-tools.c b/src/tracefs-tools.c
index 8f2130948fe0..6d03b4856a63 100644
--- a/src/tracefs-tools.c
+++ b/src/tracefs-tools.c
@@ -835,7 +835,7 @@ static int write_func_list(int fd, struct func_list *list)
* @instance: ftrace instance, can be NULL for top tracing instance
* @filters: An array of function names ending with a NULL pointer
* @module: Module to be traced
- * @reset: set to true to reset the file before applying the filter
+ * @flags: flags on modifying the filter file
* @errs: A pointer to array of constant strings that will be allocated
* on negative return of this function, pointing to the filters that
* failed.May be NULL, in which case this field will be ignored.
@@ -843,9 +843,11 @@ static int write_func_list(int fd, struct func_list *list)
* The @filters is an array of strings, where each string will be used
* to set a function or functions to be traced.
*
- * If @reset is true, then all functions in the filter are cleared
- * before adding functions from @filters. Otherwise, the functions set
- * by @filters will be appended to the filter file
+ * @flags:
+ * TRACEFS_FL_RESET - will clear the functions in the filter file
+ * before applying the @filters. This flag is ignored
+ * if this function is called again when the previous
+ * call had TRACEFS_FL_CONTINUE set.
*
* returns -x on filter errors (where x is number of failed filter
* srtings) and if @errs is not NULL will be an allocated string array
@@ -858,12 +860,13 @@ static int write_func_list(int fd, struct func_list *list)
* return 0 on success and @errs is not set.
*/
int tracefs_function_filter(struct tracefs_instance *instance, const char **filters,
- const char *module, bool reset, const char ***errs)
+ const char *module, unsigned int flags, const char ***errs)
{
struct func_filter *func_filters;
struct func_list *func_list = NULL;
char *ftrace_filter_path;
- int flags;
+ bool reset = flags & TRACEFS_FL_RESET;
+ int open_flags;
int ret;
int fd;
@@ -887,9 +890,9 @@ int tracefs_function_filter(struct tracefs_instance *instance, const char **filt
if (!ftrace_filter_path)
goto out_free;
- flags = reset ? O_TRUNC : O_APPEND;
+ open_flags = reset ? O_TRUNC : O_APPEND;
- fd = open(ftrace_filter_path, O_WRONLY | flags);
+ fd = open(ftrace_filter_path, O_WRONLY | open_flags);
tracefs_put_tracing_file(ftrace_filter_path);
if (fd < 0)
goto out_free;
--
2.30.1
next prev parent reply other threads:[~2021-03-30 0:53 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-30 0:51 [PATCH 00/13 v2] libtracefs: Add tracefs_function_filter() Steven Rostedt
2021-03-30 0:51 ` [PATCH 01/13 v2] libtracefs: An API to set the filtering of functions Steven Rostedt
2021-03-30 0:51 ` [PATCH 02/13 v2] libtracefs: Document function_filter API Steven Rostedt
2021-03-30 0:51 ` [PATCH 03/13 v2] libtracefs: Fix notations of tracefs_function_filter() and module parameter Steven Rostedt
2021-03-30 0:51 ` [PATCH 04/13 v2] libtracefs: Move opening of file out of controlled_write() Steven Rostedt
2021-03-30 0:51 ` [PATCH 05/13 v2] libtracefs: Add add_errors() helper function for control_write() Steven Rostedt
2021-03-30 0:51 ` [PATCH 06/13 v2] libtracefs: Add checking of available_filter_functions to tracefs_function_filter() Steven Rostedt
2021-03-30 0:51 ` [PATCH 07/13 v2] libtracefs: Add write_filter() helper function Steven Rostedt
2021-03-30 0:51 ` [PATCH 08/13 v2] libtracefs: Allow for setting filters with regex expressions Steven Rostedt
2021-04-01 16:33 ` sameeruddin shaik
2021-03-31 16:39 ` Steven Rostedt
2021-04-02 1:59 ` sameeruddin shaik
2021-04-01 2:41 ` Steven Rostedt
2021-03-30 0:51 ` [PATCH 09/13 v2] libtracefs: Add indexing to set functions in tracefs_function_filter() Steven Rostedt
2021-03-30 0:51 ` Steven Rostedt [this message]
2021-03-30 14:29 ` [PATCH 10/13 v2] libtracefs: Pass in reset via flags to tracefs_function_filter() Tzvetomir Stoyanov
2021-03-30 14:53 ` Steven Rostedt
2021-03-30 0:51 ` [PATCH 11/13 v2] libtracefs: Add pthread_mutex_lock() around tracefs_function_filter() Steven Rostedt
2021-03-30 0:51 ` [PATCH 12/13 v2] libtracefs: Move struct tracefs_instance to tracefs-local.h Steven Rostedt
2021-03-30 0:51 ` [PATCH 13/13 v2] libtracefs: Add CONTINUE to tracefs_function_filter() Steven Rostedt
2021-03-30 14:29 ` Tzvetomir Stoyanov
2021-03-30 14:52 ` Steven Rostedt
2021-03-30 15:14 ` Steven Rostedt
2021-03-30 15:32 ` Tzvetomir Stoyanov
2021-03-30 16:03 ` Steven Rostedt
2021-03-30 1:03 ` [RFC][PATCH 14/13 v2] libtracefs: Just past one filter in for tracefs_function_filter() Steven Rostedt
2021-03-30 14:31 ` Tzvetomir Stoyanov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210330005248.694899644@goodmis.org \
--to=rostedt@goodmis.org \
--cc=linux-trace-devel@vger.kernel.org \
--cc=sameeruddin.shaik8@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).