4 * Linux Trace Toolkit Control Library Header File
6 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <asm/types.h>
27 #include <sys/types.h>
31 /* Default unix group name for tracing. */
32 #define LTTNG_DEFAULT_TRACING_GROUP "tracing"
34 /* Environment variable to set session daemon binary path. */
35 #define LTTNG_SESSIOND_PATH_ENV "LTTNG_SESSIOND_PATH"
37 /* Default trace output directory name */
38 #define LTTNG_DEFAULT_TRACE_DIR_NAME "lttng-traces"
41 * Event symbol length. Copied from LTTng kernel ABI.
43 #define LTTNG_SYMBOL_NAME_LEN 128
46 * Every lttng_event_* structure both apply to kernel event and user-space
51 * Domain type are the different possible tracers.
53 enum lttng_domain_type
{
54 LTTNG_DOMAIN_KERNEL
= 1,
56 LTTNG_DOMAIN_UST_EXEC_NAME
= 3,
57 LTTNG_DOMAIN_UST_PID
= 4,
58 LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
= 5,
62 * Instrumentation type of tracing event.
64 enum lttng_event_type
{
65 LTTNG_EVENT_TRACEPOINT
,
68 LTTNG_EVENT_FUNCTION_ENTRY
,
74 enum lttng_event_output
{
75 LTTNG_EVENT_SPLICE
= 0,
79 /* Event context possible type */
80 enum lttng_event_context_type
{
81 LTTNG_EVENT_CONTEXT_PID
= 0,
82 LTTNG_EVENT_CONTEXT_PERF_COUNTER
= 1,
83 LTTNG_EVENT_CONTEXT_COMM
= 2,
84 LTTNG_EVENT_CONTEXT_PRIO
= 3,
85 LTTNG_EVENT_CONTEXT_NICE
= 4,
86 LTTNG_EVENT_CONTEXT_VPID
= 5,
87 LTTNG_EVENT_CONTEXT_TID
= 6,
88 LTTNG_EVENT_CONTEXT_VTID
= 7,
89 LTTNG_EVENT_CONTEXT_PPID
= 8,
90 LTTNG_EVENT_CONTEXT_VPPID
= 9,
93 enum lttng_calibrate_type
{
94 LTTNG_CALIBRATE_FUNCTION
= 0,
98 enum lttng_domain_type type
;
101 char exec_name
[NAME_MAX
];
105 /* Perf counter attributes */
106 struct lttng_event_perf_counter_ctx
{
109 char name
[LTTNG_SYMBOL_NAME_LEN
];
112 /* Event/Channel context */
113 struct lttng_event_context
{
114 enum lttng_event_context_type ctx
;
116 struct lttng_event_perf_counter_ctx perf_counter
;
123 * Either addr is used or symbol_name and offset.
125 struct lttng_event_probe_attr
{
129 char symbol_name
[LTTNG_SYMBOL_NAME_LEN
];
135 struct lttng_event_function_attr
{
136 char symbol_name
[LTTNG_SYMBOL_NAME_LEN
];
140 * Generic lttng event
143 char name
[LTTNG_SYMBOL_NAME_LEN
];
144 enum lttng_event_type type
;
146 /* Per event type configuration */
148 struct lttng_event_probe_attr probe
;
149 struct lttng_event_function_attr ftrace
;
154 * Tracer channel attributes. For both kernel and user-space.
156 struct lttng_channel_attr
{
157 int overwrite
; /* 1: overwrite, 0: discard */
158 uint64_t subbuf_size
; /* bytes */
159 uint64_t num_subbuf
; /* power of 2 */
160 unsigned int switch_timer_interval
; /* usec */
161 unsigned int read_timer_interval
; /* usec */
162 enum lttng_event_output output
; /* splice, mmap */
166 * Channel information structure. For both kernel and user-space.
168 struct lttng_channel
{
171 struct lttng_channel_attr attr
;
174 struct lttng_calibrate
{
175 enum lttng_calibrate_type type
;
179 * Basic session information.
181 * This is an 'output data' meaning that it only comes *from* the session
182 * daemon *to* the lttng client. It's basically a 'human' representation of
183 * tracing entities (here a session).
185 struct lttng_session
{
187 /* The path where traces are written */
192 * Handle used as a context for commands.
194 struct lttng_handle
{
195 char session_name
[NAME_MAX
];
196 struct lttng_domain domain
;
200 * Public LTTng control API
202 * For functions having a lttng domain type as parameter, if a bad value is
203 * given, NO default is applied and an error is returned.
205 * On success, all functions of the API return 0 or the size of the allocated
208 * On error, a negative value is returned being a specific lttng-tools error
209 * code which can be humanly interpreted with lttng_get_readable_code(err).
213 * Create an handle used as a context for every request made to the library.
215 * This handle contains the session name and lttng domain on which the command
216 * will be executed on.
218 extern struct lttng_handle
*lttng_create_handle(const char *session_name
,
219 struct lttng_domain
*domain
);
222 * Destroy an handle. This will simply free(3) the data pointer returned by
223 * lttng_create_handle() and rendering it unsuable.
225 extern void lttng_destroy_handle(struct lttng_handle
*handle
);
228 * Create tracing session using a name and a path where trace will be written.
230 extern int lttng_create_session(const char *name
, const char *path
);
233 * Destroy tracing session.
235 * The session will not be useable anymore, tracing will stopped for all
236 * registered trace and tracing buffers will be flushed.
238 extern int lttng_destroy_session(struct lttng_handle
*handle
);
241 * List all tracing sessions.
243 * Return the size of the "lttng_session" array. Caller must free(3).
245 extern int lttng_list_sessions(struct lttng_session
**sessions
);
248 * List registered domain(s) of a session.
250 * Return the size of the "lttng_domain" array. Caller must free(3).
252 extern int lttng_list_domains(struct lttng_handle
*handle
,
253 struct lttng_domain
**domains
);
256 * List channel(s) of a session.
258 * Return the size of the "lttng_channel" array. Caller must free(3).
260 extern int lttng_list_channels(struct lttng_handle
*handle
,
261 struct lttng_channel
**channels
);
264 * List event(s) of a session channel.
266 * Return the size of the "lttng_event" array. Caller must free(3).
268 extern int lttng_list_events(struct lttng_handle
*handle
,
269 const char *channel_name
, struct lttng_event
**events
);
272 * List available tracepoints of a specific lttng domain.
274 * Return the size of the "lttng_event" array. Caller must free(3).
276 extern int lttng_list_tracepoints(struct lttng_handle
*handle
,
277 struct lttng_event
**events
);
280 * Check if a session daemon is alive.
282 extern int lttng_session_daemon_alive(void);
285 * Set tracing group for the *current* flow of execution.
287 extern int lttng_set_tracing_group(const char *name
);
290 * Return a human readable error message of a lttng-tools error code.
292 * Parameter MUST be a negative value or else you'll get a generic message.
294 extern const char *lttng_get_readable_code(int code
);
297 * This call permits to register an "outside consumer" to a session and a lttng
298 * domain. No consumer will be spawned and all fds/commands will go through the
299 * socket path given (socket_path).
301 * NOTE: At the moment, if you use the liblttkconsumerd, you can only use the
302 * command socket. The error socket is not supported yet for roaming consumers.
304 extern int lttng_register_consumer(struct lttng_handle
*handle
,
305 const char *socket_path
);
308 * Start tracing for *all* registered trace (kernel and user-space).
310 extern int lttng_start_tracing(struct lttng_handle
*handle
);
313 * Stop tracing for *all* registered trace (kernel and user-space).
315 extern int lttng_stop_tracing(struct lttng_handle
*handle
);
318 * Add context to event for a specific channel.
320 * If event_name is NULL, the context is applied to all event of the channel.
321 * If channel_name is NULL, a lookup of the event's channel is done.
322 * If both are NULL, the context is applied on all events of all channels.
324 extern int lttng_add_context(struct lttng_handle
*handle
,
325 struct lttng_event_context
*ctx
, const char *event_name
,
326 const char *channel_name
);
329 * Create or enable a kernel event.
331 * If the event you are trying to enable does not exist, it will be created,
332 * else it is enabled.
334 * If channel_name is NULL, the default channel is used (channel0).
336 extern int lttng_enable_event(struct lttng_handle
*handle
,
337 struct lttng_event
*ev
, const char *channel_name
);
340 * Create or enable a kernel channel.
342 * If name is NULL, the default channel is enabled (channel0).
344 extern int lttng_enable_channel(struct lttng_handle
*handle
,
345 struct lttng_channel
*chan
);
348 * Disable kernel event.
350 * If channel_name is NULL, the default channel is used (channel0).
352 extern int lttng_disable_event(struct lttng_handle
*handle
,
353 const char *name
, const char *channel_name
);
356 * Disable kernel channel.
358 * If channel_name is NULL, the default channel is disabled (channel0).
360 extern int lttng_disable_channel(struct lttng_handle
*handle
,
364 * Calibrate LTTng overhead.
366 extern int lttng_calibrate(struct lttng_handle
*handle
,
367 struct lttng_calibrate
*calibrate
);
369 #endif /* _LTTNG_H */