Skip to contentSkip to conversation

libtracefs: Add more tracefs_cpu*() man pages

PATCH New Steven Rostedt 1 participant 4 messages Oct 28, 2022 Documentation

lore
Share & tools
lore
#0 lore raw

cover libtracefs: Add more tracefs_cpu*() man pages

From: "Steven Rostedt (Google)" <[email protected]>

Add the functions:

tracefs_cpu_alloc_fd()
tracefs_cpu_free_fd()
tracefs_cpu_pipe()

to the man pages.

Steven Rostedt (Google) (3):
libtracefs: Move tracefs_cpu_open/close into its own man page
libtracefs: Add man pages for tracefs_cpu_alloc_fd() and
tracefs_cpu_free_fd()
libtracefs: Add man pages for tracefs_cpu_pipe()

 Documentation/libtracefs-cpu-open.txt | 100 ++++++++++++++++++++++++++
 Documentation/libtracefs-cpu.txt      |  27 +++----
 Documentation/libtracefs.txt          |   3 +
 3 files changed, 117 insertions(+), 13 deletions(-)
 create mode 100644 Documentation/libtracefs-cpu-open.txt
Signature · 1 line
2.35.1
#1 lore raw

PATCH 1/3 libtracefs: Move tracefs_cpu_open/close into its own man page

From: "Steven Rostedt (Google)" <[email protected]>

Man pages only allow at most 9 functions to be described in a single man page. The libtracefs-cpu man page is already at that limit. In order to add more tracefs_cpu_* functions, this needs to be split up.

Move the tracefs_cpu_open() and tracefs_cpu_close() functions out into its own man page, to allow more to be added to both.

---
 Documentation/libtracefs-cpu-open.txt | 78 +++++++++++++++++++++++++++
 Documentation/libtracefs-cpu.txt      | 17 ++----
 2 files changed, 82 insertions(+), 13 deletions(-)
 create mode 100644 Documentation/libtracefs-cpu-open.txt
Documentation/libtracefs-cpu-open.txt new file +78 -0
new file mode 100644
index 000000000000..58dde508290d
@@ -0,0 +1,78 @@
+libtracefs(3)
+=============
+
+NAME
+----
+tracefs_cpu_open, tracefs_cpu_close - Opening trace_pipe_raw data for reading
+
+SYNOPSIS
+--------
+[verse]
+--
+*#include <tracefs.h>*
+
+struct tracefs_cpu pass:[*]*tracefs_cpu_open*(struct tracefs_instance pass:[*]_instance_,
+				     int _cpu_, bool _nonblock_);
+void *tracefs_cpu_close*(struct tracefs_cpu pass:[*]_tcpu_);
+--
+
+DESCRIPTION
+-----------
+This set of APIs can be used to open the raw data from the trace_pipe_raw
+files in the tracefs file system in oder to read them with the *tracefs_cpu_read*(3)
+functions.
+
+The *tracefs_cpu_open()* creates a descriptor that can read the tracefs
+trace_pipe_raw file for a given _cpu_ in a given _instance_. If _instance_ is
+NULL than the toplevel trace_pipe_raw file is used.
+
+The *tracefs_cpu_close()* closes all the file descriptors associated to the trace_pipe_raw
+opened by *tracefs_cpu_open()*.
+
+RETURN VALUE
+------------
+The *tracefs_cpu_open()* returns a struct tracefs_cpu descriptor that can be
+used by the other functions or NULL on error.
+
+EXAMPLE
+-------
+See *tracefs_cpu_read*(3) for an example.
+
+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* <[email protected]>
+--
+REPORTING BUGS
+--------------
+Report bugs to  <[email protected]>
+
+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) 2022 Google, Inc. Free use of this software is granted under
+the terms of the GNU Public License (GPL).
Documentation/libtracefs-cpu.txt +4 -13
index d664ebb3082f..8975e6ec5a0b 100644
@@ -3,9 +3,8 @@ libtracefs(3)
 
 NAME
 ----
-tracefs_cpu_open, tracefs_cpu_close, tracefs_cpu_read_size, tracefs_cpu_read,
-tracefs_cpu_buffered_read, tracefs_cpu_write, tracefs_cpu_stop, tracefs_cpu_flush,
-tracefs_cpu_flush_write - Reading trace_pipe_raw data
+tracefs_cpu_read_size, tracefs_cpu_read, tracefs_cpu_buffered_read, tracefs_cpu_write,
+tracefs_cpu_stop, tracefs_cpu_flush, tracefs_cpu_flush_write - Reading trace_pipe_raw data
 
 SYNOPSIS
 --------
@@ -13,9 +12,6 @@ SYNOPSIS
 --
 *#include <tracefs.h>*
 
-struct tracefs_cpu pass:[*]*tracefs_cpu_open*(struct tracefs_instance pass:[*]_instance_,
-				     int _cpu_, bool _nonblock_);
-void *tracefs_cpu_close*(struct tracefs_cpu pass:[*]_tcpu_);
 int *tracefs_cpu_read_size*(struct tracefs_cpu pass:[*]_tcpu_);
 int *tracefs_cpu_read*(struct tracefs_cpu pass:[*]_tcpu_, void pass:[*]_buffer_, bool _nonblock_);
 int *tracefs_cpu_buffered_read*(struct tracefs_cpu pass:[*]_tcpu_, void pass:[*]_buffer_, bool _nonblock_);
@@ -30,13 +26,6 @@ DESCRIPTION
 This set of APIs can be used to read the raw data from the trace_pipe_raw
 files in the tracefs file system.
 
-The *tracefs_cpu_open()* creates a descriptor that can read the tracefs
-trace_pipe_raw file for a given _cpu_ in a given _instance_. If _instance_ is
-NULL than the toplevel trace_pipe_raw file is used.
-
-The *tracefs_cpu_close()* closes all the file descriptors associated to the trace_pipe_raw
-opened by *tracefs_cpu_open()*.
-
 The *tracefs_cpu_read_size()* returns the subbuffer size of the trace_pipe_raw. This
 returns the minimum size of the buffer that is passed to the below functions.
 
@@ -211,6 +200,8 @@ FILES
 
 SEE ALSO
 --------
+*tracefs_cpu_open*(3)
+*tracefs_cpu_close*(3)
 *libtracefs*(3),
 *libtraceevent*(3),
 *trace-cmd*(1)
Signature · 1 line
2.35.1
#2 lore raw

PATCH 2/3 libtracefs: Add man pages for tracefs_cpu_alloc_fd() and tracefs_cpu_free_fd()

In reply to Steven Rostedt

From: "Steven Rostedt (Google)" <[email protected]>

Update the man pages to describe the tracefs_cpu_alloc_fd() and tracefs_cpu_free_fd().

---
 Documentation/libtracefs-cpu-open.txt | 24 +++++++++++++++++++++++-
 Documentation/libtracefs.txt          |  2 ++
 2 files changed, 25 insertions(+), 1 deletion(-)
Documentation/libtracefs-cpu-open.txt +23 -1
index 58dde508290d..c5a900a06e8e 100644
@@ -3,7 +3,7 @@ libtracefs(3)
 
 NAME
 ----
-tracefs_cpu_open, tracefs_cpu_close - Opening trace_pipe_raw data for reading
+tracefs_cpu_open, tracefs_cpu_close, tracefs_cpu_alloc_fd, tracefs_cpu_free_fd - Opening trace_pipe_raw data for reading
 
 SYNOPSIS
 --------
@@ -14,6 +14,9 @@ SYNOPSIS
 struct tracefs_cpu pass:[*]*tracefs_cpu_open*(struct tracefs_instance pass:[*]_instance_,
 				     int _cpu_, bool _nonblock_);
 void *tracefs_cpu_close*(struct tracefs_cpu pass:[*]_tcpu_);
+
+struct tracefs_cpu pass:[*]*tracefs_cpu_alloc_fd*(int _fd_, int _subbuf_size_, bool _nonblock_);
+void *tracefs_cpu_free_fd*(struct tracefs_cpu pass:[*]_tcpu_);
 --
 
 DESCRIPTION
@@ -29,11 +32,30 @@ NULL than the toplevel trace_pipe_raw file is used.
 The *tracefs_cpu_close()* closes all the file descriptors associated to the trace_pipe_raw
 opened by *tracefs_cpu_open()*.
 
+The *tracefs_cpu_alloc_fd()* will create a tracefs_cpu descriptor from an existing
+file descriptor _fd_. This is useful to use when connecting to a socket or pipe where
+the other end is feeding raw tracing data in the same format as the trace_pipe_raw
+file would (like in guest to host tracing). The caller is responsible for determining
+the _subbuf_size_ that will be used to break up the sub-buffers being read by the
+file descriptor. The _nonblock_ is treated the same as the same parameter in
+*tracefs_cpu_open()*.
+
+The *tracefs_cpu_free_fd()* is used to free the descriptor returned by *tracefs_cpu_alloc_fd()*.
+It does all the clean up that *tracefs_cpu_close()* performs, and that could also be
+used to free up the descriptor created by *tracefs_cpu_alloc_fd()* but will also close
+the file descriptor passed in. Note that *tracefs_cpu_free_fd()* should not be used
+on the descriptor returned by *tracefs_cpu_open()* as it will not close the file descriptor
+created by it.
+
 RETURN VALUE
 ------------
 The *tracefs_cpu_open()* returns a struct tracefs_cpu descriptor that can be
 used by the other functions or NULL on error.
 
+The *tracefs_cpu_alloc_fd()* returns a struct tracefs_cpu descriptor that can
+be used by the *tracefs_cpu_read*(3) related functions, where the descriptor
+will be reading the passed in _fd_ file descriptor.
+
 EXAMPLE
 -------
 See *tracefs_cpu_read*(3) for an example.
Documentation/libtracefs.txt +2 -0
index d41c7ab382ee..50af23e33026 100644
@@ -270,7 +270,9 @@ Histograms:
 Recording of trace_pipe_raw files:
 	struct tracefs_cpu pass:[*]*tracefs_cpu_open*(struct tracefs_instance pass:[*]_instance_,
 					     int _cpu_, bool _nonblock_);
+	struct tracefs_cpu pass:[*]*tracefs_cpu_alloc_fd*(int _fd_, int _subbuf_size_, bool _nonblock_);
 	void *tracefs_cpu_close*(struct tracefs_cpu pass:[*]_tcpu_);
+	void *tracefs_cpu_free_fd*(struct tracefs_cpu pass:[*]_tcpu_);
 	int *tracefs_cpu_read_size*(struct tracefs_cpu pass:[*]_tcpu_);
 	int *tracefs_cpu_read*(struct tracefs_cpu pass:[*]_tcpu_, void pass:[*]_buffer_, bool _nonblock_);
 	int *tracefs_cpu_buffered_read*(struct tracefs_cpu pass:[*]_tcpu_, void pass:[*]_buffer_, bool _nonblock_);
Signature · 1 line
2.35.1
#3 lore raw

PATCH 3/3 libtracefs: Add man pages for tracefs_cpu_pipe()

In reply to Steven Rostedt

From: "Steven Rostedt (Google)" <[email protected]>

Update the man pages to describe the tracefs_cpu_pipe() function.

---
 Documentation/libtracefs-cpu.txt | 12 +++++++++++-
 Documentation/libtracefs.txt     |  1 +
 2 files changed, 12 insertions(+), 1 deletion(-)
Documentation/libtracefs-cpu.txt +11 -1
index 8975e6ec5a0b..d6215d9912c0 100644
@@ -4,7 +4,8 @@ libtracefs(3)
 NAME
 ----
 tracefs_cpu_read_size, tracefs_cpu_read, tracefs_cpu_buffered_read, tracefs_cpu_write,
-tracefs_cpu_stop, tracefs_cpu_flush, tracefs_cpu_flush_write - Reading trace_pipe_raw data
+tracefs_cpu_stop, tracefs_cpu_flush, tracefs_cpu_flush_write, tracefs_cpu_pipe
+- Reading trace_pipe_raw data
 
 SYNOPSIS
 --------
@@ -19,6 +20,7 @@ int *tracefs_cpu_write*(struct tracefs_cpu pass:[*]_tcpu_, int _wfd_, bool _nonb
 int *tracefs_cpu_stop*(struct tracefs_cpu pass:[*]_tcpu_);
 int *tracefs_cpu_flush*(struct tracefs_cpu pass:[*]_tcpu_, void pass:[*]_buffer_);
 int *tracefs_cpu_flush_write*(struct tracefs_cpu pass:[*]_tcpu_, int _wfd_);
+int *tracefs_cpu_pipe*(struct tracefs_cpu pass:[*]_tcpu_, int _wfd_, bool _nonblock_);
 --
 
 DESCRIPTION
@@ -66,6 +68,14 @@ trace_pipe_raw into non-blocking mode.
 The *tracefs_cpu_flush_write()* same as *trace_cpu_flush()* except it takes a file
 descriptor _wfd_ to flush the data into.
 
+The *tracefs_cpu_pipe()* is similar to *tracefs_cpu_write()* but the _wfd_ file descriptor
+must be a pipe. This call is an optimization of *tracefs_cpu_write()* that uses two calls
+to *splice*(2) in order to connect the trace_pipe_raw file descriptor with the write file
+descriptor. *splice*(2) requires that one of the passed in file descriptors is a pipe.
+If the application wants to pass the data to an existing pipe, there's no reason for
+there to be two *splice*(2) system calls and *tracefs_cpu_pipe()* can simply use a single
+call to _wfd_.
+
 RETURN VALUE
 ------------
 The *tracefs_cpu_open()* returns a struct tracefs_cpu descriptor that can be
Documentation/libtracefs.txt +1 -0
index 50af23e33026..0081210f8951 100644
@@ -280,6 +280,7 @@ Recording of trace_pipe_raw files:
 	int *tracefs_cpu_stop*(struct tracefs_cpu pass:[*]_tcpu_);
 	int *tracefs_cpu_flush*(struct tracefs_cpu pass:[*]_tcpu_, void pass:[*]_buffer_);
 	int *tracefs_cpu_flush_write*(struct tracefs_cpu pass:[*]_tcpu_, int _wfd_);
+	int *tracefs_cpu_pipe*(struct tracefs_cpu pass:[*]_tcpu_, int _wfd_, bool _nonblock_);
 
 --
 
Signature · 1 line
2.35.1