Added new API for opening trace_marker file of given instance: tracefs_trace_marker_get_fd(); Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@xxxxxxxxx> --- Documentation/libtracefs-utils.txt | 20 +++++++++++++++++++- include/tracefs.h | 13 +++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Documentation/libtracefs-utils.txt b/Documentation/libtracefs-utils.txt index 41544ab..0935199 100644 --- a/Documentation/libtracefs-utils.txt +++ b/Documentation/libtracefs-utils.txt @@ -3,7 +3,8 @@ libtracefs(3) NAME ---- -tracefs_tracers, tracefs_get_clock, tracefs_list_free - +tracefs_tracers, tracefs_get_clock, tracefs_list_free, +tracefs_trace_marker_get_fd - Helper functions for working with trace file system. SYNOPSIS @@ -15,6 +16,7 @@ SYNOPSIS char pass:[*]pass:[*]*tracefs_tracers*(const char pass:[*]_tracing_dir_); char pass:[*]*tracefs_get_clock*(struct tracefs_instance pass:[*]_instance_); void *tracefs_list_free*(char pass:[*]pass:[*]_list_); +int *tracefs_trace_marker_get_fd*(struct tracefs_instance pass:[*]_instance_); -- DESCRIPTION @@ -36,6 +38,10 @@ The _tracefs_list_free()_ function frees an array of strings, returned by _tracefs_event_systems()_, _tracefs_system_events()_ and _tracefs_tracers()_ APIs. +The _tracefs_trace_marker_get_fd()_ function returns a file deascriptor to the "trace_marker" file +from the given _instance_. If _instance_ is NULL, the top trace instance is used. The returned +descriptor can be used for writing trace markers in the trace buffer of the instance. + RETURN VALUE ------------ The _tracefs_tracers()_ returns array of strings. The last element in that @@ -45,6 +51,10 @@ In case of an error, NULL is returned. The _tracefs_get_clock()_ returns string, that must be freed with free(), or NULL in case of an error. +The _tracefs_trace_marker_get_fd()_ function returns a file descriptor to "trace_marker" +file for reading and writing, which must be closed wuth close(). In case of an error -1 is returned. + + EXAMPLE ------- [source,c] @@ -66,6 +76,14 @@ char *clock = tracefs_get_clock(NULL); ... free(clock); } +... +int marker_fd = tracefs_trace_marker_get_fd(NULL); +char *my_marker = "User tarce event"; + if (marker_fd < 0) { + /* Failed to open marker file */ + } + write(marker_fd, my_marker, strlen(my_marker)); + close(marker_fd); -- FILES ----- diff --git a/include/tracefs.h b/include/tracefs.h index f3eec62..dff365a 100644 --- a/include/tracefs.h +++ b/include/tracefs.h @@ -63,6 +63,19 @@ static inline int tracefs_trace_on_get_fd(struct tracefs_instance *instance) return tracefs_instance_file_open(instance, "tracing_on", O_RDWR); } +/** + * tracefs_trace_marker_get_fd - Get a file descriptor of "trace_marker" 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 "trace_marker" + * file for reading and writing. The returned FD must be closed with close(). + */ +static inline int tracefs_trace_marker_get_fd(struct tracefs_instance *instance) +{ + return tracefs_instance_file_open(instance, "trace_marker", O_RDWR); +} + /* events */ void tracefs_list_free(char **list); char **tracefs_event_systems(const char *tracing_dir); -- 2.29.2