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