xref: /aosp_15_r20/external/libtracefs/Documentation/libtracefs-instances-manage.txt (revision 287e80b3a36113050663245e7f2c00d274188f18)
1*287e80b3SSadaf Ebrahimilibtracefs(3)
2*287e80b3SSadaf Ebrahimi=============
3*287e80b3SSadaf Ebrahimi
4*287e80b3SSadaf EbrahimiNAME
5*287e80b3SSadaf Ebrahimi----
6*287e80b3SSadaf Ebrahimitracefs_instance_create, tracefs_instance_destroy, tracefs_instance_alloc, tracefs_instance_free,
7*287e80b3SSadaf Ebrahimitracefs_instance_is_new, tracefs_instances - Manage trace 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 Ebrahimistruct tracefs_instance pass:[*]*tracefs_instance_create*(const char pass:[*]_name_);
16*287e80b3SSadaf Ebrahimiint *tracefs_instance_destroy*(struct tracefs_instance pass:[*]_instance_);
17*287e80b3SSadaf Ebrahimistruct tracefs_instance pass:[*]*tracefs_instance_alloc*(const char pass:[*]_tracing_dir_, const char pass:[*]_name_);
18*287e80b3SSadaf Ebrahimivoid *tracefs_instance_free*(struct tracefs_instance pass:[*]_instance_);
19*287e80b3SSadaf Ebrahimibool *tracefs_instance_is_new*(struct tracefs_instance pass:[*]_instance_);
20*287e80b3SSadaf Ebrahimichar pass:[**]*tracefs_instances*(const char pass:[*]_regex_);
21*287e80b3SSadaf Ebrahimi
22*287e80b3SSadaf Ebrahimi--
23*287e80b3SSadaf Ebrahimi
24*287e80b3SSadaf EbrahimiDESCRIPTION
25*287e80b3SSadaf Ebrahimi-----------
26*287e80b3SSadaf EbrahimiThis set of functions can be used to manage trace instances. A trace
27*287e80b3SSadaf Ebrahimiinstance is a sub buffer used by the Linux tracing system. Given a unique
28*287e80b3SSadaf Ebrahiminame, the events enabled in an instance do not affect the main tracing
29*287e80b3SSadaf Ebrahimisystem, nor other instances, as events enabled in the main tracing system
30*287e80b3SSadaf Ebrahimior other instances do not affect the given instance.
31*287e80b3SSadaf Ebrahimi
32*287e80b3SSadaf EbrahimiThe *tracefs_instance_create()* function allocates and initializes a new
33*287e80b3SSadaf Ebrahimitracefs_instance structure and returns it. If the instance with _name_ does
34*287e80b3SSadaf Ebrahiminot yet exist in the system, it will be created. The _name_ could be NULL,
35*287e80b3SSadaf Ebrahimithen the new tracefs_instance structure is initialized for the top instance.
36*287e80b3SSadaf EbrahimiNote that the top instance cannot be created in the system, if it does not
37*287e80b3SSadaf Ebrahimiexist.
38*287e80b3SSadaf Ebrahimi
39*287e80b3SSadaf EbrahimiThe *tracefs_instance_destroy()* removes the instance from the system, but
40*287e80b3SSadaf Ebrahimidoes not free the structure. *tracefs_instance_free()* must still be called
41*287e80b3SSadaf Ebrahimion _instance_.
42*287e80b3SSadaf Ebrahimi
43*287e80b3SSadaf EbrahimiThe tracefs_instance_alloc()* function allocates a new tracefs_instance structure
44*287e80b3SSadaf Ebrahimifor existing trace instance. If the instance does not exist in the system, the function
45*287e80b3SSadaf Ebrahimifails. The _tracing_dir_ parameter points to the system trace directory. It can be
46*287e80b3SSadaf EbrahimiNULL, then default system trace directory is used. This parameter is useful to allocate
47*287e80b3SSadaf Ebrahimiinstances to trace directories, copied from another machine. The _name_ is the name of
48*287e80b3SSadaf Ebrahimithe instance, or NULL for the top instance in the given _tracing_dir_.
49*287e80b3SSadaf Ebrahimi
50*287e80b3SSadaf EbrahimiThe *tracefs_instance_free()* function frees the tracefs_instance structure,
51*287e80b3SSadaf Ebrahimiwithout removing the trace instance from the system.
52*287e80b3SSadaf Ebrahimi
53*287e80b3SSadaf EbrahimiThe *tracefs_instance_is_new()* function checks if the given _instance_ is
54*287e80b3SSadaf Ebrahiminewly created by *tracefs_instance_create()*, or it has been in the system
55*287e80b3SSadaf Ebrahimibefore that.
56*287e80b3SSadaf Ebrahimi
57*287e80b3SSadaf EbrahimiThe *tracefs_instances*() function returns a list of instances that exist in
58*287e80b3SSadaf Ebrahimithe system that match the regular expression _regex_. If _regex_ is NULL, then
59*287e80b3SSadaf Ebrahimiit will match all instances that exist. The returned list must be freed with
60*287e80b3SSadaf Ebrahimi*tracefs_list_free*(3). Note, if no instances are found an empty list is returned
61*287e80b3SSadaf Ebrahimiand that too needs to be free with *tracefs_list_free*(3).
62*287e80b3SSadaf Ebrahimi
63*287e80b3SSadaf EbrahimiRETURN VALUE
64*287e80b3SSadaf Ebrahimi------------
65*287e80b3SSadaf EbrahimiThe *tracefs_instance_create()* and *tracefs_instance_alloc()* functions return a pointer to
66*287e80b3SSadaf Ebrahimia newly allocated tracefs_instance structure. It must be freed with *tracefs_instance_free()*.
67*287e80b3SSadaf Ebrahimi
68*287e80b3SSadaf EbrahimiThe *tracefs_instance_destroy()* function returns 0 if it succeeds to remove
69*287e80b3SSadaf Ebrahimithe instance, otherwise it returns -1 if the instance does not exist or it
70*287e80b3SSadaf Ebrahimifails to remove it.
71*287e80b3SSadaf Ebrahimi
72*287e80b3SSadaf EbrahimiThe *tracefs_instance_is_new()* function returns true if the
73*287e80b3SSadaf Ebrahimi*tracefs_instance_create()* that allocated _instance_ also created the
74*287e80b3SSadaf Ebrahimitrace instance in the system, or false if the trace instance already
75*287e80b3SSadaf Ebrahimiexisted in the system when _instance_ was allocated by
76*287e80b3SSadaf Ebrahimi*tracefs_instance_create()* or *tracefs_instance_alloc()*.
77*287e80b3SSadaf Ebrahimi
78*287e80b3SSadaf EbrahimiThe *tracefs_instances()* returns a list of instance names that exist on the system.
79*287e80b3SSadaf EbrahimiThe list must be freed with *tracefs_list_free*(3). An empty list is returned if
80*287e80b3SSadaf Ebrahimino instance exists that matches _regex_, and this needs to be freed with
81*287e80b3SSadaf Ebrahimi*tracefs_list_free*(3) as well. NULL is returned on error.
82*287e80b3SSadaf Ebrahimi
83*287e80b3SSadaf EbrahimiEXAMPLE
84*287e80b3SSadaf Ebrahimi-------
85*287e80b3SSadaf Ebrahimi[source,c]
86*287e80b3SSadaf Ebrahimi--
87*287e80b3SSadaf Ebrahimi#include <tracefs.h>
88*287e80b3SSadaf Ebrahimi
89*287e80b3SSadaf Ebrahimistruct tracefs_instance *inst = tracefs_instance_create("foo");
90*287e80b3SSadaf Ebrahimi	if (!inst) {
91*287e80b3SSadaf Ebrahimi		/* Error creating a new trace instance */
92*287e80b3SSadaf Ebrahimi		...
93*287e80b3SSadaf Ebrahimi	}
94*287e80b3SSadaf Ebrahimi
95*287e80b3SSadaf Ebrahimi	...
96*287e80b3SSadaf Ebrahimi
97*287e80b3SSadaf Ebrahimi	if (tracefs_instance_is_new(inst))
98*287e80b3SSadaf Ebrahimi		tracefs_instance_destroy(inst);
99*287e80b3SSadaf Ebrahimi	tracefs_instance_free(inst);
100*287e80b3SSadaf Ebrahimi...
101*287e80b3SSadaf Ebrahimi
102*287e80b3SSadaf Ebrahimistruct tracefs_instance *inst = tracefs_instance_alloc(NULL, "bar");
103*287e80b3SSadaf Ebrahimi	if (!inst) {
104*287e80b3SSadaf Ebrahimi		/* Error allocating 'bar' trace instance */
105*287e80b3SSadaf Ebrahimi		...
106*287e80b3SSadaf Ebrahimi	}
107*287e80b3SSadaf Ebrahimi
108*287e80b3SSadaf Ebrahimi	...
109*287e80b3SSadaf Ebrahimi
110*287e80b3SSadaf Ebrahimi	tracefs_instance_free(inst);
111*287e80b3SSadaf Ebrahimi--
112*287e80b3SSadaf EbrahimiFILES
113*287e80b3SSadaf Ebrahimi-----
114*287e80b3SSadaf Ebrahimi[verse]
115*287e80b3SSadaf Ebrahimi--
116*287e80b3SSadaf Ebrahimi*tracefs.h*
117*287e80b3SSadaf Ebrahimi	Header file to include in order to have access to the library APIs.
118*287e80b3SSadaf Ebrahimi*-ltracefs*
119*287e80b3SSadaf Ebrahimi	Linker switch to add when building a program that uses the library.
120*287e80b3SSadaf Ebrahimi--
121*287e80b3SSadaf Ebrahimi
122*287e80b3SSadaf EbrahimiSEE ALSO
123*287e80b3SSadaf Ebrahimi--------
124*287e80b3SSadaf Ebrahimi*libtracefs*(3),
125*287e80b3SSadaf Ebrahimi*libtraceevent*(3),
126*287e80b3SSadaf Ebrahimi*trace-cmd*(1)
127*287e80b3SSadaf Ebrahimi
128*287e80b3SSadaf EbrahimiAUTHOR
129*287e80b3SSadaf Ebrahimi------
130*287e80b3SSadaf Ebrahimi[verse]
131*287e80b3SSadaf Ebrahimi--
132*287e80b3SSadaf Ebrahimi*Steven Rostedt* <[email protected]>
133*287e80b3SSadaf Ebrahimi*Tzvetomir Stoyanov* <[email protected]>
134*287e80b3SSadaf Ebrahimi--
135*287e80b3SSadaf EbrahimiREPORTING BUGS
136*287e80b3SSadaf Ebrahimi--------------
137*287e80b3SSadaf EbrahimiReport bugs to  <[email protected]>
138*287e80b3SSadaf Ebrahimi
139*287e80b3SSadaf EbrahimiLICENSE
140*287e80b3SSadaf Ebrahimi-------
141*287e80b3SSadaf Ebrahimilibtracefs is Free Software licensed under the GNU LGPL 2.1
142*287e80b3SSadaf Ebrahimi
143*287e80b3SSadaf EbrahimiRESOURCES
144*287e80b3SSadaf Ebrahimi---------
145*287e80b3SSadaf Ebrahimihttps://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/
146*287e80b3SSadaf Ebrahimi
147*287e80b3SSadaf EbrahimiCOPYING
148*287e80b3SSadaf Ebrahimi-------
149*287e80b3SSadaf EbrahimiCopyright \(C) 2020 VMware, Inc. Free use of this software is granted under
150*287e80b3SSadaf Ebrahimithe terms of the GNU Public License (GPL).
151