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