xref: /aosp_15_r20/external/libtracefs/Documentation/libtracefs-traceon.txt (revision 287e80b3a36113050663245e7f2c00d274188f18)
1libtracefs(3)
2=============
3
4NAME
5----
6tracefs_trace_is_on, tracefs_trace_on, tracefs_trace_off, tracefs_trace_on_get_fd,
7tracefs_trace_on_fd, tracefs_trace_off_fd - Functions to enable or disable tracing.
8
9SYNOPSIS
10--------
11[verse]
12--
13*#include <tracefs.h>*
14
15int *tracefs_trace_is_on*(struct tracefs_instance pass:[*]_instance_);
16int *tracefs_trace_on*(struct tracefs_instance pass:[*]_instance_);
17int *tracefs_trace_off*(struct tracefs_instance pass:[*]_instance_);
18int *tracefs_trace_on_get_fd*(struct tracefs_instance pass:[*]_instance_);
19int *tracefs_trace_on_fd*(int _fd_);
20int *tracefs_trace_off_fd*(int _fd_);
21--
22
23DESCRIPTION
24-----------
25This set of functions can be used to check, enable or disable writing to the ring buffer in
26the given trace instance. The tracing is enabled when writing to the ring buffer is enabled.
27
28The *tracefs_trace_is_on()* function checks if tracing is enabled for the given _instance_. If
29_instance_ is NULL, the top instance is used.
30
31The *tracefs_trace_on()* and *tracefs_trace_off()* functions set the tracing in the _instance_
32to enable or disable state. If _instance_ is NULL, the top instance is used.
33
34The *tracefs_trace_on_get_fd()* function returns a file descriptor to the "tracing_on" file from
35the given _instance_. If _instance_ is NULL, the top trace instance is used. The returned descriptor
36can be used for fast enabling or disabling the tracing of the instance.
37
38The *tracefs_trace_on_fd()* and *tracefs_trace_off_fd()* functions set the tracing state to enable
39or disable using the given _fd_. This file descriptor must be opened for writing with
40*tracefs_trace_on_get_fd*(3) of the desired trace instance. These functions are faster than
41*tracefs_trace_on* and *tracefs_trace_off*.
42
43RETURN VALUE
44------------
45The *tracefs_trace_is_on()* function returns 0 if tracing is disable, 1 if it is enabled or
46-1 in case of an error.
47
48The *tracefs_trace_on_get_fd()* function returns a file descriptor to "tracing_on"
49file for reading and writing, which must be closed wuth close(). In case of an error -1 is returned.
50
51The *tracefs_trace_on()*, *tracefs_trace_off()*, *tracefs_trace_on_fd()* and
52*tracefs_trace_off_fd()* functions return -1 in case of an error or 0 otherwise.
53
54EXAMPLE
55-------
56[source,c]
57--
58#include <tracefs.h>
59
60	int ret;
61
62	ret = tracefs_trace_is_on(NULL);
63	if (ret == 0) {
64		/* Tracing is disabled in the top instance */
65	} else if (ret == 1) {
66		/* Tracing is enabled in the top instance */
67	} else {
68		/* Error getting tracing state of the top instance */
69	}
70
71	...
72
73	if (!tracefs_trace_on(NULL)) {
74	    /* Enabled tracing in the top instance */
75
76	    ...
77
78	    if (!tracefs_trace_off(NULL)) {
79	    	/* Disabled tracing in the top instance */
80	    } else {
81	    	/* Error disabling tracing in the top instance */
82	    }
83	} else {
84		/* Error enabling tracing in the top instance */
85	}
86
87	...
88
89	int fd = tracefs_trace_on_get_fd(NULL);
90
91	if (fd < 0) {
92		/* Error opening tracing_on file */
93	}
94	...
95	if (!tracefs_trace_on_fd(fd)) {
96	    /* Enabled tracing in the top instance */
97
98	    ...
99
100	    if (!tracefs_trace_off_fd(fd)) {
101	    	/* Disabled tracing in the top instance */
102	    } else {
103	    	/* Error disabling tracing in the top instance */
104	    }
105	} else {
106		/* Error enabling tracing in the top instance */
107	}
108
109	...
110
111	close(fd);
112--
113FILES
114-----
115[verse]
116--
117*tracefs.h*
118	Header file to include in order to have access to the library APIs.
119*-ltracefs*
120	Linker switch to add when building a program that uses the library.
121--
122
123SEE ALSO
124--------
125*libtracefs*(3),
126*libtraceevent*(3),
127*trace-cmd*(1)
128
129AUTHOR
130------
131[verse]
132--
133*Steven Rostedt* <[email protected]>
134*Tzvetomir Stoyanov* <[email protected]>
135--
136REPORTING BUGS
137--------------
138Report bugs to  <[email protected]>
139
140LICENSE
141-------
142libtracefs is Free Software licensed under the GNU LGPL 2.1
143
144RESOURCES
145---------
146https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/
147
148COPYING
149-------
150Copyright \(C) 2021 VMware, Inc. Free use of this software is granted under
151the terms of the GNU Public License (GPL).
152