libtracefs: Add new API for open trace marker file
PATCH v2 1/1 libtracefs: Add new API for open trace marker file
Added new APIs for opening trace_marker file of given instance:
tracefs_marker_init()
tracefs_marker_write()
tracefs_marker_vprint()
tracefs_marker_print()
tracefs_marker_close()
---
Apply on top of "libtracefs: Update filtering functions"
https://lore.kernel.org/linux-trace-devel/[email protected]/
v2 changes:
- Added set of new APIs, instead of the previously proposed API for just opening the file.
include/tracefs-local.h | 1 + include/tracefs.h | 9 +++ src/Makefile | 1 + src/tracefs-instance.c | 3 + src/tracefs-marker.c | 129 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 143 insertions(+) create mode 100644 src/tracefs-marker.c
include/tracefs-local.h +1 -0
@@ -21,6 +21,7 @@ struct tracefs_instance {int flags;int ftrace_filter_fd;int ftrace_notrace_fd; +int ftrace_marker_fd; };extern pthread_mutex_t toplevel_lock;
include/tracefs.h +9 -0
@@ -63,6 +63,15 @@ static inline int tracefs_trace_on_get_fd(struct tracefs_instance *instance)return tracefs_instance_file_open (instance,"tracing_on" ,O_RDWR ); } +/* trace marker */ +int tracefs_marker_init (struct tracefs_instance *instance); +int tracefs_marker_print (struct tracefs_instance *instance, +const char *fmt, ...); +int tracefs_marker_vprint (struct tracefs_instance *instance, +const char *fmt,va_list ap); +int tracefs_marker_write (struct tracefs_instance *instance,void *data,int len); +void tracefs_marker_close (struct tracefs_instance *instance); +/* events */ void tracefs_list_free (char **list);char **tracefs_event_systems (const char *tracing_dir);
src/Makefile +1 -0
@@ -7,6 +7,7 @@ OBJS += tracefs-utils.o OBJS += tracefs-instance.o OBJS += tracefs-events.o OBJS += tracefs-tools.o +OBJS += tracefs-marker.o OBJS := $(OBJS:%.o=$(bdir)/%.o) DEPS := $(OBJS:$(bdir)/%.o=$(bdir)/.%.d)
src/tracefs-instance.c +3 -0
@@ -49,6 +49,7 @@ static struct tracefs_instance *instance_alloc(const char *trace_dir, const char instance->ftrace_filter_fd =-1 ; instance->ftrace_notrace_fd =-1 ; + instance->ftrace_marker_fd =-1 ;return instance;
@@ -74,6 +75,8 @@ void tracefs_instance_free(struct tracefs_instance *instance)free (instance->trace_dir);free (instance->name);pthread_mutex_destroy (&instance->lock); +if (instance->ftrace_marker_fd >=0 ) +close (instance->ftrace_marker_fd);free (instance); }
src/tracefs-marker.c new file +129 -0
129 lines not on this page · raw message
Signature · 1 line
2.30.2
Quoted 6 lines · On Thu, 8 Apr 2021 11:08:21 +0300 "Tzvetomir Stoyanov (VMware)"…
Added new APIs for opening
trace_markerfile of given instance:
tracefs_marker_init()
tracefs_marker_write()
tracefs_marker_vprint()
tracefs_marker_print()
tracefs_marker_close()
I really don't like the name as it's more about the tracefs implementation and not what it's used for. I much rather have:
tracefs_print_init(); tracefs_printf(); tracefs_vprintf(); tracefs_print_close();
And you should never write binary into the trace_marker file, as it always expects ascii strings. That's the trace_marker_raw file. In which case we could have:
tracefs_binary_init(); tracefs_binary_write(); tracefs_binary_close();
For binary writes.
-- Steve
Quoted 23 lines · Steven Rostedt
Quoted 6 lines · On Thu, 8 Apr 2021 11:08:21 +0300 "Tzvetomir Stoyanov (VMware)"…
Added new APIs for opening
trace_markerfile of given instance:
tracefs_marker_init()
tracefs_marker_write()
tracefs_marker_vprint()
tracefs_marker_print()
tracefs_marker_close()I really don't like the name as it's more about the tracefs implementation and not what it's used for. I much rather have:
tracefs_print_init(); tracefs_printf(); tracefs_vprintf(); tracefs_print_close();And you should never write binary into the
trace_markerfile, as it always expects ascii strings. That's thetrace_marker_rawfile. In which case we could have:
Quoted 6 lines
tracefs_binary_init(); tracefs_binary_write(); tracefs_binary_close();For binary writes.
I find "tracefs_print_" a little bit confusing, like printing something on console. I think the name should stress that a user string/data is written in the trace buffer. I would like to combine string and binary APIs into one set, something like:
tracefs_user_trace_init(); /* open both trace_marker andtrace_marker_raw files, or have flags to specify what file to open, string or data*/
tracefs_user_trace_printf(); /* write to trace_marker */ tracefs_user_trace_vprintf(); /* write to trace_marker */ tracefs_user_trace_binary(); /* write to trace_marker_raw */ tracefs_user_trace_init(); /* close both string and data fd, if open */
Quoted 1 line
-- Steve
Signature · 2 lines
Tzvetomir (Ceco) Stoyanov VMware Open Source Technology Center
Quoted 4 lines · On Thu, 8 Apr 2021 16:21:52 +0300 Tzvetomir Stoyanov <[email protected]>…
I find "
tracefs_print_" a little bit confusing, like printing something on console. I think the name should stress that a user string/data is written in the trace buffer. I would like to combine string and binary APIs into one set, something like:
How so? We use it in the kernel "trace_printk()" there's no confusion there.
And to me, "user string written in the trace buffer" is exactly what I think when I see "tracefs_printf()".
Quoted 9 lines
tracefs_user_trace_init(); /* open bothtrace_markerandtrace_marker_rawfiles, or have flags to specify what file to open, string or data*/
tracefs_user_trace_printf(); /* write totrace_marker*/tracefs_user_trace_vprintf(); /* write totrace_marker*/tracefs_user_trace_binary(); /* write totrace_marker_raw*/tracefs_user_trace_init(); /* close both string and data fd, if open */
I have no idea what "user_trace" is. What does that mean? There's no precedence for it.
"tracefs_printf()" is short and to the point, and states exactly what you want. It does a printf() into the tracefs system. How is that confusing?
We have fprintf() which does a printf into a file point. We have sprintf() which does an printf into a string.
Thus, it makes sense to have "tracefs_printf()" which does a printf into the tracefs file system. Just like we have trace_seq_printf() which does a printf() into the trace_seq.
"printf()" means string manipulation, and has nothing to do with consoles.
I personally hate long function names, especially ones that I may use a lot of.
Keeping with the other APIs trace_printf() is the only one that seems reasonable.
-- Steve