libtracefs: An API to set the filtering of functions
PATCH 1/1 libtracefs: An API to set the filtering of functions
This new API will write the function filters into the set_ftrace_filter file, it will write only string as of now, it can't handle kernel glob or regular expressions.
tracefs_function_filter()
https://bugzilla.kernel.org/show_bug.cgi?id=210643
include/tracefs.h +1 -0
@@ -50,6 +50,7 @@ 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); +int tracefs_function_filter (struct tracefs_instance *instance,const char *const *filters,const char *module,bool reset);/** * tracefs_trace_on_get_fd - Get a file descriptor of "tracing_on" in given instance
src/tracefs-tools.c +83 -0
92 lines not on this page · raw message
Signature · 1 line
2.7.4
Quoted 3 lines · On Tue, 2 Mar 2021 22:45:10 +0530 Sameeruddin shaik…
This new API will write the function filters into the
set_ftrace_filterfile, it will write only string as of now, it can't handle kernel glob or regular expressions.
The limitation of no glob or regular expressions is fine. We can add that in future patches.
Quoted 36 lines
tracefs_function_filter()https://bugzilla.kernel.org/show_bug.cgi?id=210643
Signed-off-by Sameeruddin shaik <[email protected]>include/tracefs.h +1
-0@@ -50,6 +50,7 @@ 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); +int tracefs_function_filter (struct tracefs_instance *instance,const char *const *filters,const char *module,bool reset);/** * tracefs_trace_on_get_fd - Get a file descriptor of "tracing_on" in given instance src/tracefs-tools.c +2
-0@@ -18,6 +18,7 @@#include "tracefs-local.h" #define TRACE_CTRL "tracing_on" +#define TRACE_FILTER "set_ftrace_filter"static const char *const options_map[] = {"unknown" ,@@ -387,3 +388,85 @@ void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_optif (options && id >TRACEFS_OPTION_INVALID ) options->mask &= ~(1ULL << (id -1 )); } +
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 401
Quoted 10 lines
src/tracefs-tools.c +10
-0+static int controlled_write (const char *filter_path,const char *const *filters,const char *module,bool reset) +{ +int write_size; +char *each_str; +int size =0 ; +int slen; +int fd; +int i; + +
Only need one empty line between declaration and code.
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 407
Quoted 6 lines
src/tracefs-tools.c +6
-0+if (!filters) +return -1 ; +if (reset) + fd =open (filter_path,O_WRONLY |O_TRUNC ); +else + fd =open (filter_path,O_WRONLY |O_APPEND );
It's usually more robust to have a system call parameter set by an if statement and only call the system call once.
int flags; flags = reset ? O_TRUNC : O_APPEND;
Although O_APPEND isn't really needed here (zero would work), but it's fine to have.
fd = open(filter_path, O_WRONLY | flags);
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 409
Quoted 2 lines
src/tracefs-tools.c +2
-0+if (fd <0 ) +return -1 ;
I would add a blank line between the check and for loop, to space out the logic a bit better.
fd = open(filter_path, O_WRONLY | flags); if (fd < 0) return -1; for (i = 0; filters[i]; i++)
No space between setting the fd and checking it. It gives a visual on how code is related.
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 410
Quoted 1 line
src/tracefs-tools.c +1
-0+for (i =0 ; filters[i] !=NULL ; i++) {
No need for the " != NULL"
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 412
Quoted 2 lines
src/tracefs-tools.c +2
-0+ slen =0 ; + slen =strlen (*(filters + i));
No need for slen = 0 as you set it immediately afterward, also, it is more appropriate to use:
slen = strlen(filters[i]);
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 413
Quoted 1 line
src/tracefs-tools.c +1
-0+if (slen <0 )
The above can't happen, strlen always returns a positive integer (or zero). Now checking for zero would make sense.
if (!slen)
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 417
Quoted 6 lines
src/tracefs-tools.c +4
-0+continue ; + +if (module) + slen +=strlen (module) +5 ;
What's the "+ 5" for? Should be commented.
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 427
Quoted 10 lines
src/tracefs-tools.c +10
-0+/* Adding 2 extra byte for the space and '\0' at the end*/ + slen +=2 ; + each_str =calloc (1 , slen); +if (!each_str) +return -1 ; +if (module) + write_size =snprintf (each_str, slen,"%s:mod:%s " , *(filters + i), module); +else + write_size =snprintf (each_str, slen,"%s " , *(filters + i)); +if (write_size < (slen -1 )) {
This should never happen. If it does, then there's something wrong with this code, not the input.
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 431
Quoted 4 lines
src/tracefs-tools.c +4
-0+free (each_str); +continue ; + } + size +=write (fd, each_str, write_size);
Need to check errors here, and we need a way to report that an error happened for a string. Perhaps the API also needs to have an error message pointer that is passed in? Or a bitmask that lets the user know which filter failed?
Tzvetomir, have any ideas on how to report back to the caller which filter failed? Could just send back an array of strings of the filters that failed.
int tracefs_function_filter(struct tracefs_instance *instance,
const char * const * filters, const char * module, bool reset, const char * const ** errs);
Where if errs points to a pointer, that pointer gets updated with an array.
const char **filters = { "func1", "func2", func3" };
const char **errs;
ret;
ret = tracefs_function_filter(NULL, filters, NULL, &errs);If "func1" and "func3" fail, then ret is < 0 (-2 for number of failures?) and errs would be:
errs = { &filter[0], &filters[2], NULL };
and the users would need to free it as well.
free(errs);if ret is zero, then errs would not be touched, and the caller does not need to do anything with it.
Note, if the user doesn't care about errors, errs could be NULL, in which case the calling function would obviously not set it.
Quoted 20 lines
src/tracefs-tools.c +20
-0+free (each_str); + } +close (fd); +return size; +} + +/** +* tracefs_function_filter - write to set_ftrace_filter file to trace particular functions +* @instance: ftrace instance, can be NULL for top tracing instance +* @filter: An array of function names ending with a NULL pointer +* @module: Module Name to be traced +* @reset: set to true to reset the file before applying the filter +* +* The @filter is an array of strings, where each string will be use 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 @filter. Otherwise, the functions set by @filter +* will be appended to the filter +*
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 461
Quoted 10 lines
src/tracefs-tools.c +10
-0+* Returns the number of bytes written into the filter file or -1 if +* there is any error in writing to filter file +*/ +int tracefs_function_filter (struct tracefs_instance *instance,const char *const *filters,const char *module,bool reset) +{ +char *ftrace_filter_path; +int ret; + +if (!filters) +return -1 ;
You can add a empty line here.
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 465
Quoted 4 lines
src/tracefs-tools.c +4
-0+ ftrace_filter_path =tracefs_instance_get_file (instance,TRACE_FILTER ); + +if (!ftrace_filter_path) + goto gracefully_free;
It should just be "goto out".
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 471
Quoted 6 lines
src/tracefs-tools.c +6
-0+ + ret =controlled_write (ftrace_filter_path, filters, module, reset); + + gracefully_free: +tracefs_put_tracing_file (ftrace_filter_path); +return ret;
Note, you need to initialize ret to -1, otherwise it is undefined if you do the "goto out".
-- Steve
Quoted 1 line
+}
what if we store the indices of the failed filters in an integer array and return them back?
let's return the number of bytes written, also we will calculate the complete filters length and return it, if there is difference, we will loop into the integer array and print the erroneous filters
Let's fix the number of parameters to this function:) Thanks,
sameer.
Quoted 236 lines · Steven Rostedt
Quoted 3 lines · On Tue, 2 Mar 2021 22:45:10 +0530 Sameeruddin shaik…
This new API will write the function filters into the
set_ftrace_filterfile, it will write only string as of now, it can't handle kernel glob or regular expressions.The limitation of no glob or regular expressions is fine. We can add that in future patches.
Quoted 36 lines
tracefs_function_filter()https://bugzilla.kernel.org/show_bug.cgi?id=210643
Signed-off-by Sameeruddin shaik <[email protected]>include/tracefs.h +1
-0@@ -50,6 +50,7 @@ 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); +int tracefs_function_filter (struct tracefs_instance *instance,const char *const *filters,const char *module,bool reset);/** * tracefs_trace_on_get_fd - Get a file descriptor of "tracing_on" in given instance src/tracefs-tools.c +2
-0@@ -18,6 +18,7 @@#include "tracefs-local.h" #define TRACE_CTRL "tracing_on" +#define TRACE_FILTER "set_ftrace_filter"static const char *const options_map[] = {"unknown" ,@@ -387,3 +388,85 @@ void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_optif (options && id >TRACEFS_OPTION_INVALID ) options->mask &= ~(1ULL << (id -1 )); } +src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 401
Quoted 10 lines
src/tracefs-tools.c +10
-0+static int controlled_write (const char *filter_path,const char *const *filters,const char *module,bool reset) +{ +int write_size; +char *each_str; +int size =0 ; +int slen; +int fd; +int i; + +Only need one empty line between declaration and code.
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 407
Quoted 6 lines
src/tracefs-tools.c +6
-0+if (!filters) +return -1 ; +if (reset) + fd =open (filter_path,O_WRONLY |O_TRUNC ); +else + fd =open (filter_path,O_WRONLY |O_APPEND );It's usually more robust to have a system call parameter set by an if statement and only call the system call once.
int flags; flags = reset ? O_TRUNC : O_APPEND;Although
O_APPENDisn't really needed here (zero would work), but it's fine to have.fd = open(filter_path, O_WRONLY | flags);src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 409
Quoted 2 lines
src/tracefs-tools.c +2
-0+if (fd <0 ) +return -1 ;I would add a blank line between the check and for loop, to space out the logic a bit better.
fd = open(filter_path, O_WRONLY | flags); if (fd < 0) return -1; for (i = 0; filters[i]; i++)No space between setting the fd and checking it. It gives a visual on how code is related.
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 410
Quoted 1 line
src/tracefs-tools.c +1
-0+for (i =0 ; filters[i] !=NULL ; i++) {No need for the " != NULL"
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 412
Quoted 2 lines
src/tracefs-tools.c +2
-0+ slen =0 ; + slen =strlen (*(filters + i));No need for slen = 0 as you set it immediately afterward, also, it is more appropriate to use:
slen = strlen(filters[i]);src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 413
Quoted 1 line
src/tracefs-tools.c +1
-0+if (slen <0 )The above can't happen, strlen always returns a positive integer (or zero). Now checking for zero would make sense.
if (!slen)src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 417
Quoted 6 lines
src/tracefs-tools.c +4
-0+continue ; + +if (module) + slen +=strlen (module) +5 ;What's the "+ 5" for? Should be commented.
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 427
Quoted 10 lines
src/tracefs-tools.c +10
-0+/* Adding 2 extra byte for the space and '\0' at the end*/ + slen +=2 ; + each_str =calloc (1 , slen); +if (!each_str) +return -1 ; +if (module) + write_size =snprintf (each_str, slen,"%s:mod:%s " , *(filters + i), module); +else + write_size =snprintf (each_str, slen,"%s " , *(filters + i)); +if (write_size < (slen -1 )) {This should never happen. If it does, then there's something wrong with this code, not the input.
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 431
Quoted 4 lines
src/tracefs-tools.c +4
-0+free (each_str); +continue ; + } + size +=write (fd, each_str, write_size);Need to check errors here, and we need a way to report that an error happened for a string. Perhaps the API also needs to have an error message pointer that is passed in? Or a bitmask that lets the user know which filter failed?
Tzvetomir, have any ideas on how to report back to the caller which filter failed? Could just send back an array of strings of the filters that failed.
int tracefs_function_filter(struct
tracefs_instance*instance,
const char * const * filters, const char * module, bool reset, const char * const ** errs);Where if errs points to a pointer, that pointer gets updated with an array.
const char **filters = { "func1", "func2", func3" }; const char **errs; ret; ret = tracefs_function_filter(NULL, filters, NULL, &errs);If "func1" and "func3" fail, then ret is < 0 (-2 for number of failures?) and errs would be:
errs = { &filter[0], &filters[2], NULL }; and the users would need to free it as well. free(errs);if ret is zero, then errs would not be touched, and the caller does not need to do anything with it.
Note, if the user doesn't care about errors, errs could be NULL, in which case the calling function would obviously not set it.
Quoted 20 lines
src/tracefs-tools.c +20
-0+free (each_str); + } +close (fd); +return size; +} + +/** +* tracefs_function_filter - write to set_ftrace_filter file to trace particular functions +* @instance: ftrace instance, can be NULL for top tracing instance +* @filter: An array of function names ending with a NULL pointer +* @module: Module Name to be traced +* @reset: set to true to reset the file before applying the filter +* +* The @filter is an array of strings, where each string will be use 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 @filter. Otherwise, the functions set by @filter +* will be appended to the filter +* src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 461
Quoted 10 lines
src/tracefs-tools.c +10
-0+* Returns the number of bytes written into the filter file or -1 if +* there is any error in writing to filter file +*/ +int tracefs_function_filter (struct tracefs_instance *instance,const char *const *filters,const char *module,bool reset) +{ +char *ftrace_filter_path; +int ret; + +if (!filters) +return -1 ;You can add a empty line here.
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 465
Quoted 4 lines
src/tracefs-tools.c +4
-0+ ftrace_filter_path =tracefs_instance_get_file (instance,TRACE_FILTER ); + +if (!ftrace_filter_path) + goto gracefully_free;It should just be "goto out".
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 471
Quoted 6 lines
src/tracefs-tools.c +6
-0+ + ret =controlled_write (ftrace_filter_path, filters, module, reset); + + gracefully_free: +tracefs_put_tracing_file (ftrace_filter_path); +return ret;Note, you need to initialize ret to -1, otherwise it is undefined if you do the "goto out".
-- Steve
Quoted 1 line
+}
Quoted 2 lines · On Wed, 3 Mar 2021 06:46:26 +0530 Sameeruddin Shaik…
what if we store the indices of the failed filters in an integer array and return them back?
There's not much difference if we return an array of pointers to the filters or an array of integers to the index. I was just thinking about how I would use the interface. When having a working interface, we should write a few robust programs to see how easy it is to use, and that will help in making the API appropriate. This needs to be done *before* we accept it. This particular API is going to be widely used, and it needs to be simple and robust.
Quoted 3 lines
let's return the number of bytes written, also we will calculate the complete filters length and return it, if there is difference, we will loop into the integer array and print the erroneous filters
Not sure how that is helpful. How would you use the number of bytes written?
Quoted 2 lines
Let's fix the number of parameters to this function:)
Not sure what you mean by that.
Here's how I envision this interface.
char **errs;
char *filters[] = {
"sched*", "spin_*", NULL
};
int ret;
ret = tracefs_function_filter(NULL, filters, NULL, &errs);
if (ret < 0) {
int i;
printf("Failed to apply: ");
for (i = 0; errs[i]; i++) {
if (i)
printf(", ");
printf("'%s'", errs[i]);
}
printf("\n";
exit(ret);
}-- Steve
Quoted 7 lines · Steven Rostedt
Quoted 2 lines · On Wed, 3 Mar 2021 06:46:26 +0530 Sameeruddin Shaik…
what if we store the indices of the failed filters in an integer array and return them back?
Quoted 7 lines
There's not much difference if we return an array of pointers to the filters or an array of integers to the index. I was just thinking about how I would use the interface. When having a working interface, we should write a few robust programs to see how easy it is to use, and that will help in making the API appropriate. This needs to be done *before* we accept it. This particular API is going to be widely used, and it needs to be simple and robust.
One remark, not directly related to this discussion. When the implementation of the API is ready, there should be a unit test (in a separate patch) - as for any of the other APIs. Usually these are the first use cases that I write for the new APIs.
Sameer, please look at utest directory where the unit tests are, each API has a unit test there. We use the cunit framework, ask if there are questions about it. This should be the next step, when the final version of the implementation is
ready.
Thanks!
Quoted 38 lines
Quoted 4 lines
let's return the number of bytes written, also we will calculate the complete filters length and return it, if there is difference, we will loop into the integer array and print the erroneous filters
Not sure how that is helpful. How would you use the number of bytes written?
Quoted 2 lines
Let's fix the number of parameters to this function:)
Not sure what you mean by that.
Here's how I envision this interface.
char **errs; char *filters[] = { "sched*", "spin_*", NULL }; int ret; ret = tracefs_function_filter(NULL, filters, NULL, &errs); if (ret < 0) { int i; printf("Failed to apply: "); for (i = 0; errs[i]; i++) { if (i) printf(", "); printf("'%s'", errs[i]); } printf("\n"; exit(ret); }-- Steve
Signature · 2 lines
Tzvetomir (Ceco) Stoyanov VMware Open Source Technology Center
sure tzvetomir.
Quoted 72 lines · Tzvetomir Stoyanov
Quoted 7 lines · Steven Rostedt
Quoted 2 lines · On Wed, 3 Mar 2021 06:46:26 +0530 Sameeruddin Shaik…
what if we store the indices of the failed filters in an integer array and return them back?
Quoted 7 lines
There's not much difference if we return an array of pointers to the filters or an array of integers to the index. I was just thinking about how I would use the interface. When having a working interface, we should write a few robust programs to see how easy it is to use, and that will help in making the API appropriate. This needs to be done *before* we accept it. This particular API is going to be widely used, and it needs to be simple and robust.
One remark, not directly related to this discussion. When the implementation of the API is ready, there should be a unit test (in a separate patch) - as for any of the other APIs. Usually these are the first use cases that I write for the new APIs.
Sameer, please look at utest directory where the unit tests are, each API has a unit test there. We use the cunit framework, ask if there are questions about it. This should be the next step, when the final version of the implementation is
ready.
Thanks!Quoted 37 lines
Quoted 4 lines
let's return the number of bytes written, also we will calculate the complete filters length and return it, if there is difference, we will loop into the integer array and print the erroneous filters
Not sure how that is helpful. How would you use the number of bytes written?
Quoted 2 lines
Let's fix the number of parameters to this function:)
Not sure what you mean by that.
Here's how I envision this interface.
char **errs; char *filters[] = { "sched*", "spin_*", NULL }; int ret; ret = tracefs_function_filter(NULL, filters, NULL, &errs); if (ret < 0) { int i; printf("Failed to apply: "); for (i = 0; errs[i]; i++) { if (i) printf(", "); printf("'%s'", errs[i]); } printf("\n"; exit(ret); }Quoted 1 line
-- Steve
--
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center
Quoted 18 lines · Steven Rostedt
Quoted 3 lines · On Tue, 2 Mar 2021 22:45:10 +0530 Sameeruddin shaik…
This new API will write the function filters into the
set_ftrace_filterfile, it will write only string as of now, it can't handle kernel glob or regular expressions.The limitation of no glob or regular expressions is fine. We can add that in future patches.
Quoted 7 lines
tracefs_function_filter()https://bugzilla.kernel.org/show_bug.cgi?id=210643
Signed-off-by Sameeruddin shaik <[email protected]>
[ ... ]
Quoted 6 lines
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 431
Quoted 5 lines
src/tracefs-tools.c +4
-0+free (each_str); +continue ; + } + size +=write (fd, each_str, write_size);
Quoted 7 lines
Need to check errors here, and we need a way to report that an error happened for a string. Perhaps the API also needs to have an error message pointer that is passed in? Or a bitmask that lets the user know which filter failed?
Tzvetomir, have any ideas on how to report back to the caller which filter failed? Could just send back an array of strings of the filters that failed.
It is very useful to have a way to report back the failed filters. Using an array
of strings will work for this API, but I was thinking somehow to leverage the error_log file by the ftrace itself. Currently it does not report any error, just
returns EINVAL. In more complex filters it would be useful to log more detailed description of the problem in the error_log file.
[ ... ]
Signature · 2 lines
Tzvetomir (Ceco) Stoyanov VMware Open Source Technology Center
Quoted 3 lines
Let's fix the number of parameters to this function:)
Quoted 1 line
Not sure what you mean by that.
Actually i meant this ""int tracefs_function_filter(struct tracefs_instance *instance,
const char * const * filters, const char * module, bool reset, const char * const ** errs);""
For every patch, a parameter is increasing in this API.
Quoted 6 lines
let's return the number of bytes written, also we will calculate the complete filters length and return it, if there is difference, we will loop into the integer array and print the erroneous filters
Quoted 2 lines
Not sure how that is helpful. How would you use the number of bytes written?
We will return the number of bytes written and we also store the total length of strings
in filters array, in one pointer variable, we will check the difference between bytes written
and the total length of the strings, if there is difference we will print failed filters otherwise
we will not print anything.
Quoted 7 lines
It is very useful to have a way to report back the failed filters. Using an array
of strings will work for this API, but I was thinking somehow to leverage theerror_logfile by the ftrace itself. Currently it does not report any error, just
returns EINVAL. In more complex filters it would be useful to log more detailed description of the problem in theerror_logfile.
This error_log is also a good idea.
If possible let's have a live discussion on this API,so that we can discuss the corner cases in the design
more efficiently and we can close it ASAP.
Thanks,
sameer shaik.
Thanks,
sameer shaik
Quoted 49 lines · Tzvetomir Stoyanov
Quoted 18 lines · Steven Rostedt
Quoted 3 lines · On Tue, 2 Mar 2021 22:45:10 +0530 Sameeruddin shaik…
This new API will write the function filters into the
set_ftrace_filterfile, it will write only string as of now, it can't handle kernel glob or regular expressions.The limitation of no glob or regular expressions is fine. We can add that in future patches.
Quoted 7 lines
tracefs_function_filter()https://bugzilla.kernel.org/show_bug.cgi?id=210643
Signed-off-by Sameeruddin shaik <[email protected]>[ ... ]
Quoted 6 lines
src/tracefs-tools.c void tracefs_option_clear(struct tracefs_options_mask *options, enum tracefs_opt · line 431
Quoted 5 lines
src/tracefs-tools.c +4
-0+free (each_str); +continue ; + } + size +=write (fd, each_str, write_size);Quoted 7 lines
Need to check errors here, and we need a way to report that an error happened for a string. Perhaps the API also needs to have an error message pointer that is passed in? Or a bitmask that lets the user know which filter failed?
Tzvetomir, have any ideas on how to report back to the caller which filter failed? Could just send back an array of strings of the filters that failed.
It is very useful to have a way to report back the failed filters. Using an array
of strings will work for this API, but I was thinking somehow to leverage theerror_logfile by the ftrace itself. Currently it does not report any error, just
returns EINVAL. In more complex filters it would be useful to log more detailed description of the problem in theerror_logfile.[ ... ]
--
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center
Quoted 9 lines · On Tue, 2 Mar 2021 10:44:14 +0530 Sameeruddin Shaik…
Quoted 3 lines
Let's fix the number of parameters to this function:)
Quoted 1 line
Not sure what you mean by that.
Actually i meant this ""int tracefs_function_filter(struct
tracefs_instance*instance,
const char * const * filters, const char * module, bool reset, const char * const ** errs);""
For every patch, a parameter is increasing in this API.
And that's a normal approach to developing APIs. I've been doing this for over 25 years, there's nothing special about this case. In discussion on APIs, parameters grow to handle new cases. That's par for the course. There's only 5 parameters, not too many.
Quoted 8 lines
Quoted 7 lines
let's return the number of bytes written, also we will calculate the complete filters length and return it, if there is difference, we will loop into the integer array and print the erroneous filters
Quoted 2 lines
Not sure how that is helpful. How would you use the number of bytes written?
Quoted 7 lines
We will return the number of bytes written and we also store the total length of strings
in filters array, in one pointer variable, we will check the difference between bytes written
and the total length of the strings, if there is difference we will print failed filters otherwise
we will not print anything.
Please show an example of a use case that you would use this with?
I gave you an example of how I intend on using it, and the user of this interface should not care about number of bytes written. And the interface should not be printing any error messages, it is a library, error messages are for applications to produce. The interface must give the application enough information to be able to produce it.
Quoted 10 lines
Quoted 8 lines
It is very useful to have a way to report back the failed filters. Using an array
of strings will work for this API, but I was thinking somehow to leverage theerror_logfile by the ftrace itself. Currently it does not report any error, just
returns EINVAL. In more complex filters it would be useful to log more detailed description of the problem in theerror_logfile.This
error_logis also a good idea.
It's actually not very useful for this interface. The only error that it would give you is that it could not find any functions that match a filter.
When we create other interfaces that do more than just setting functions (like setting triggers) then we can return to looking at the error log. But since the kernel does not produce anything in the error log at the moment, it must be updated. And kernels take about a year or two after a change to get into distributions. That means, this library can't rely on it being there, and still needs a way to inform the application of errors.
Quoted 5 lines
If possible let's have a live discussion on this API,so that we can discuss the corner cases in the design
more efficiently and we can close it ASAP.
I have a very good idea of what I want from this interface, which is why I created the bugzilla about it. If you want to implement it different than my idea, please show code examples of your use cases.
-- Steve