xref: /aosp_15_r20/external/libtracefs/Documentation/libtracefs-instances-utils.txt (revision 287e80b3a36113050663245e7f2c00d274188f18)
1*287e80b3SSadaf Ebrahimilibtracefs(3)
2*287e80b3SSadaf Ebrahimi=============
3*287e80b3SSadaf Ebrahimi
4*287e80b3SSadaf EbrahimiNAME
5*287e80b3SSadaf Ebrahimi----
6*287e80b3SSadaf Ebrahimitracefs_instance_get_name, tracefs_instance_get_trace_dir, tracefs_instances_walk, tracefs_instance_exists,
7*287e80b3SSadaf Ebrahimitracefs_instance_get_buffer_size, tracefs_instance_set_buffer_size - Helper functions for working with tracing instances.
8*287e80b3SSadaf Ebrahimi
9*287e80b3SSadaf EbrahimiSYNOPSIS
10*287e80b3SSadaf Ebrahimi--------
11*287e80b3SSadaf Ebrahimi[verse]
12*287e80b3SSadaf Ebrahimi--
13*287e80b3SSadaf Ebrahimi*#include <tracefs.h>*
14*287e80b3SSadaf Ebrahimi
15*287e80b3SSadaf Ebrahimiconst char pass:[*]*tracefs_instance_get_name*(struct tracefs_instance pass:[*]_instance_);
16*287e80b3SSadaf Ebrahimiconst char pass:[*]*tracefs_instance_get_trace_dir*(struct tracefs_instance pass:[*]_instance_);
17*287e80b3SSadaf Ebrahimiint *tracefs_instances_walk*(int (pass:[*]_callback_)(const char pass:[*], void pass:[*]), void pass:[*]_context)_;
18*287e80b3SSadaf Ebrahimibool *tracefs_instance_exists*(const char pass:[*]_name_);
19*287e80b3SSadaf Ebrahimisize_t *tracefs_instance_get_buffer_size*(struct tracefs_instance pass:[*]_instance_, int _cpu_);
20*287e80b3SSadaf Ebrahimiint *tracefs_instance_set_buffer_size*(struct tracefs_instance pass:[*]_instance_, size_t _size_, int _cpu_);
21*287e80b3SSadaf Ebrahimi--
22*287e80b3SSadaf Ebrahimi
23*287e80b3SSadaf EbrahimiDESCRIPTION
24*287e80b3SSadaf Ebrahimi-----------
25*287e80b3SSadaf EbrahimiHelper functions for working with trace instances.
26*287e80b3SSadaf Ebrahimi
27*287e80b3SSadaf EbrahimiThe *tracefs_instance_get_name()* function returns the name of the given _instance_.
28*287e80b3SSadaf EbrahimiNote that the top instance has no name, the function returns NULL for it.
29*287e80b3SSadaf Ebrahimi
30*287e80b3SSadaf EbrahimiThe *tracefs_instance_get_trace_dir()* function returns the tracing directory, where
31*287e80b3SSadaf Ebrahimithe given _instance_ is configured.
32*287e80b3SSadaf Ebrahimi
33*287e80b3SSadaf EbrahimiThe *tracefs_instances_walk()* function walks through all configured tracing
34*287e80b3SSadaf Ebrahimiinstances in the system and calls _callback_ for each one of them. The _context_
35*287e80b3SSadaf Ebrahimiargument is passed to the _callback_, together with the instance name. If the
36*287e80b3SSadaf Ebrahimi_callback_ returns non-zero, the iteration stops. Note, the _callback_ is not
37*287e80b3SSadaf Ebrahimicalled for the top top instance.
38*287e80b3SSadaf Ebrahimi
39*287e80b3SSadaf EbrahimiThe *tracefs_instance_exists()* function checks if an instance with the given
40*287e80b3SSadaf Ebrahimi_name_ exists in the system.
41*287e80b3SSadaf Ebrahimi
42*287e80b3SSadaf EbrahimiThe *tracefs_instace_get_buffer_size()* returns the size of the ring buffer. If _cpu_
43*287e80b3SSadaf Ebrahimiis negative, it returns the total size of all the per CPU ring buffers, otherwise
44*287e80b3SSadaf Ebrahimiit returns the size of the per CPU ring buffer for _cpu_.
45*287e80b3SSadaf Ebrahimi
46*287e80b3SSadaf EbrahimiThe *tracefs_instance_set_buffer_size()* function sets the size of the ring buffer.
47*287e80b3SSadaf EbrahimiIf _cpu_ is negative, then it sets all the per CPU ring buffers to _size_ (note
48*287e80b3SSadaf Ebrahimithe total size is the number of CPUs * _size_). If _cpu_ is specified, then it only
49*287e80b3SSadaf Ebrahimisets the size of the per CPU ring buffer.
50*287e80b3SSadaf Ebrahimi
51*287e80b3SSadaf EbrahimiRETURN VALUE
52*287e80b3SSadaf Ebrahimi------------
53*287e80b3SSadaf EbrahimiThe *tracefs_instance_get_name()* returns a string or NULL in case of the top
54*287e80b3SSadaf Ebrahimiinstance. The returned string must _not_ be freed.
55*287e80b3SSadaf Ebrahimi
56*287e80b3SSadaf EbrahimiThe *tracefs_instance_get_trace_dir()* returns a string or NULL in case of an error.
57*287e80b3SSadaf EbrahimiThe returned string must _not_ be freed.
58*287e80b3SSadaf Ebrahimi
59*287e80b3SSadaf EbrahimiThe *tracefs_instances_walk()* function returns 0, if all instances were iterated, 1
60*287e80b3SSadaf Ebrahimiif the iteration was stopped by the _callback_, or -1 in case of an error.
61*287e80b3SSadaf Ebrahimi
62*287e80b3SSadaf EbrahimiThe *tracefs_instance_exists()* returns true if an instance with the given _name_
63*287e80b3SSadaf Ebrahimiexists in the system or false otherwise.
64*287e80b3SSadaf Ebrahimi
65*287e80b3SSadaf EbrahimiThe *tracefs_instance_get_buffer_size()* returns the size of the ring buffer depending on
66*287e80b3SSadaf Ebrahimithe _cpu_ value passed in, or -1 on error.
67*287e80b3SSadaf Ebrahimi
68*287e80b3SSadaf EbrahimiThe *tracefs_instance_set_buffer_size()* returns zero on success and -1 on error.
69*287e80b3SSadaf Ebrahimi
70*287e80b3SSadaf EbrahimiEXAMPLE
71*287e80b3SSadaf Ebrahimi-------
72*287e80b3SSadaf Ebrahimi[source,c]
73*287e80b3SSadaf Ebrahimi--
74*287e80b3SSadaf Ebrahimi#include <tracefs.h>
75*287e80b3SSadaf Ebrahimi
76*287e80b3SSadaf Ebrahimistruct tracefs_instance *inst;
77*287e80b3SSadaf Ebrahimi....
78*287e80b3SSadaf Ebrahimichar *name = tracefs_instance_get_name(inst);
79*287e80b3SSadaf Ebrahimi	if(name) {
80*287e80b3SSadaf Ebrahimi		/* Got name of the instance */
81*287e80b3SSadaf Ebrahimi	}
82*287e80b3SSadaf Ebrahimichar *dir = tracefs_instance_get_trace_dir(inst);
83*287e80b3SSadaf Ebrahimi	if(dir) {
84*287e80b3SSadaf Ebrahimi		/* Got tracing directory of the instance */
85*287e80b3SSadaf Ebrahimi	}
86*287e80b3SSadaf Ebrahimi...
87*287e80b3SSadaf Ebrahimistatic int instance_walk(char *name, void *context)
88*287e80b3SSadaf Ebrahimi{
89*287e80b3SSadaf Ebrahimi	/* Got instance with name */
90*287e80b3SSadaf Ebrahimi	return 0;
91*287e80b3SSadaf Ebrahimi}
92*287e80b3SSadaf Ebrahimi...
93*287e80b3SSadaf Ebrahimi	if (tracefs_instances_walk(instance_walk, NULL) < 0) {
94*287e80b3SSadaf Ebrahimi		/* Error walking through the instances */
95*287e80b3SSadaf Ebrahimi	}
96*287e80b3SSadaf Ebrahimi...
97*287e80b3SSadaf Ebrahimi	if (tracefs_instance_exists("foo")) {
98*287e80b3SSadaf Ebrahimi		/* There is instance with name foo in the system */
99*287e80b3SSadaf Ebrahimi	} else {
100*287e80b3SSadaf Ebrahimi		/* There is no instance with name foo in the system */
101*287e80b3SSadaf Ebrahimi	}
102*287e80b3SSadaf Ebrahimi--
103*287e80b3SSadaf EbrahimiFILES
104*287e80b3SSadaf Ebrahimi-----
105*287e80b3SSadaf Ebrahimi[verse]
106*287e80b3SSadaf Ebrahimi--
107*287e80b3SSadaf Ebrahimi*tracefs.h*
108*287e80b3SSadaf Ebrahimi	Header file to include in order to have access to the library APIs.
109*287e80b3SSadaf Ebrahimi*-ltracefs*
110*287e80b3SSadaf Ebrahimi	Linker switch to add when building a program that uses the library.
111*287e80b3SSadaf Ebrahimi--
112*287e80b3SSadaf Ebrahimi
113*287e80b3SSadaf EbrahimiSEE ALSO
114*287e80b3SSadaf Ebrahimi--------
115*287e80b3SSadaf Ebrahimi*libtracefs*(3),
116*287e80b3SSadaf Ebrahimi*libtraceevent*(3),
117*287e80b3SSadaf Ebrahimi*trace-cmd*(1)
118*287e80b3SSadaf Ebrahimi
119*287e80b3SSadaf EbrahimiAUTHOR
120*287e80b3SSadaf Ebrahimi------
121*287e80b3SSadaf Ebrahimi[verse]
122*287e80b3SSadaf Ebrahimi--
123*287e80b3SSadaf Ebrahimi*Steven Rostedt* <[email protected]>
124*287e80b3SSadaf Ebrahimi*Tzvetomir Stoyanov* <[email protected]>
125*287e80b3SSadaf Ebrahimi--
126*287e80b3SSadaf EbrahimiREPORTING BUGS
127*287e80b3SSadaf Ebrahimi--------------
128*287e80b3SSadaf EbrahimiReport bugs to  <[email protected]>
129*287e80b3SSadaf Ebrahimi
130*287e80b3SSadaf EbrahimiLICENSE
131*287e80b3SSadaf Ebrahimi-------
132*287e80b3SSadaf Ebrahimilibtracefs is Free Software licensed under the GNU LGPL 2.1
133*287e80b3SSadaf Ebrahimi
134*287e80b3SSadaf EbrahimiRESOURCES
135*287e80b3SSadaf Ebrahimi---------
136*287e80b3SSadaf Ebrahimihttps://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/
137*287e80b3SSadaf Ebrahimi
138*287e80b3SSadaf EbrahimiCOPYING
139*287e80b3SSadaf Ebrahimi-------
140*287e80b3SSadaf EbrahimiCopyright \(C) 2020 VMware, Inc. Free use of this software is granted under
141*287e80b3SSadaf Ebrahimithe terms of the GNU Public License (GPL).
142