a9aee7233e7307735982c951b937ed5c2012d38e
[lttng-tools.git] / include / lttng / lttng.h
1 /*
2 * lttng.h
3 *
4 * Linux Trace Toolkit Control Library Header File
5 *
6 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
7 *
8 * This library is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License, version 2.1 only,
10 * as published by the Free Software Foundation.
11 *
12 * This library is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #ifndef LTTNG_H
23 #define LTTNG_H
24
25 #include <limits.h>
26 #include <stdint.h>
27 #include <sys/types.h>
28
29 /* Error codes that can be returned by API calls */
30 #include <lttng/lttng-error.h>
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 /*
37 * Event symbol length. Copied from LTTng kernel ABI.
38 */
39 #define LTTNG_SYMBOL_NAME_LEN 256
40
41 /*
42 * Every lttng_event_* structure both apply to kernel event and user-space
43 * event.
44 */
45
46 /*
47 * Domain types: the different possible tracers.
48 */
49 enum lttng_domain_type {
50 LTTNG_DOMAIN_KERNEL = 1,
51 LTTNG_DOMAIN_UST = 2,
52
53 /*
54 * For now, the domains below are not implemented. However, we keep them
55 * here in order to retain their enum values for future development. Note
56 * that it is on the roadmap to implement them.
57 *
58 LTTNG_DOMAIN_UST_EXEC_NAME = 3,
59 LTTNG_DOMAIN_UST_PID = 4,
60 LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN = 5,
61 */
62 };
63
64 /*
65 * Instrumentation type of tracing event.
66 */
67 enum lttng_event_type {
68 LTTNG_EVENT_ALL = -1,
69 LTTNG_EVENT_TRACEPOINT = 0,
70 LTTNG_EVENT_PROBE = 1,
71 LTTNG_EVENT_FUNCTION = 2,
72 LTTNG_EVENT_FUNCTION_ENTRY = 3,
73 LTTNG_EVENT_NOOP = 4,
74 LTTNG_EVENT_SYSCALL = 5,
75 };
76
77 /*
78 * Loglevel information.
79 */
80 enum lttng_loglevel_type {
81 LTTNG_EVENT_LOGLEVEL_ALL = 0,
82 LTTNG_EVENT_LOGLEVEL_RANGE = 1,
83 LTTNG_EVENT_LOGLEVEL_SINGLE = 2,
84 };
85
86 /*
87 * Available loglevels.
88 */
89 enum lttng_loglevel {
90 LTTNG_LOGLEVEL_EMERG = 0,
91 LTTNG_LOGLEVEL_ALERT = 1,
92 LTTNG_LOGLEVEL_CRIT = 2,
93 LTTNG_LOGLEVEL_ERR = 3,
94 LTTNG_LOGLEVEL_WARNING = 4,
95 LTTNG_LOGLEVEL_NOTICE = 5,
96 LTTNG_LOGLEVEL_INFO = 6,
97 LTTNG_LOGLEVEL_DEBUG_SYSTEM = 7,
98 LTTNG_LOGLEVEL_DEBUG_PROGRAM = 8,
99 LTTNG_LOGLEVEL_DEBUG_PROCESS = 9,
100 LTTNG_LOGLEVEL_DEBUG_MODULE = 10,
101 LTTNG_LOGLEVEL_DEBUG_UNIT = 11,
102 LTTNG_LOGLEVEL_DEBUG_FUNCTION = 12,
103 LTTNG_LOGLEVEL_DEBUG_LINE = 13,
104 LTTNG_LOGLEVEL_DEBUG = 14,
105 };
106
107 /*
108 * LTTng consumer mode
109 */
110 enum lttng_event_output {
111 LTTNG_EVENT_SPLICE = 0,
112 LTTNG_EVENT_MMAP = 1,
113 };
114
115 /* Event context possible type */
116 enum lttng_event_context_type {
117 LTTNG_EVENT_CONTEXT_PID = 0,
118 LTTNG_EVENT_CONTEXT_PERF_COUNTER = 1,
119 LTTNG_EVENT_CONTEXT_PROCNAME = 2,
120 LTTNG_EVENT_CONTEXT_PRIO = 3,
121 LTTNG_EVENT_CONTEXT_NICE = 4,
122 LTTNG_EVENT_CONTEXT_VPID = 5,
123 LTTNG_EVENT_CONTEXT_TID = 6,
124 LTTNG_EVENT_CONTEXT_VTID = 7,
125 LTTNG_EVENT_CONTEXT_PPID = 8,
126 LTTNG_EVENT_CONTEXT_VPPID = 9,
127 LTTNG_EVENT_CONTEXT_PTHREAD_ID = 10,
128 LTTNG_EVENT_CONTEXT_HOSTNAME = 11,
129 };
130
131 enum lttng_calibrate_type {
132 LTTNG_CALIBRATE_FUNCTION = 0,
133 };
134
135 /* Health component for the health check function. */
136 enum lttng_health_component {
137 LTTNG_HEALTH_CMD,
138 LTTNG_HEALTH_APP_MANAGE,
139 LTTNG_HEALTH_APP_REG,
140 LTTNG_HEALTH_KERNEL,
141 LTTNG_HEALTH_CONSUMER,
142 LTTNG_HEALTH_ALL,
143 };
144
145 /*
146 * The structures should be initialized to zero before use.
147 */
148 #define LTTNG_DOMAIN_PADDING1 16
149 #define LTTNG_DOMAIN_PADDING2 LTTNG_SYMBOL_NAME_LEN + 32
150 struct lttng_domain {
151 enum lttng_domain_type type;
152 char padding[LTTNG_DOMAIN_PADDING1];
153
154 union {
155 pid_t pid;
156 char exec_name[NAME_MAX];
157 char padding[LTTNG_DOMAIN_PADDING2];
158 } attr;
159 };
160
161 /*
162 * Perf counter attributes
163 *
164 * The structures should be initialized to zero before use.
165 */
166 #define LTTNG_PERF_EVENT_PADDING1 16
167 struct lttng_event_perf_counter_ctx {
168 uint32_t type;
169 uint64_t config;
170 char name[LTTNG_SYMBOL_NAME_LEN];
171
172 char padding[LTTNG_PERF_EVENT_PADDING1];
173 };
174
175 /*
176 * Event/channel context
177 *
178 * The structures should be initialized to zero before use.
179 */
180 #define LTTNG_EVENT_CONTEXT_PADDING1 16
181 #define LTTNG_EVENT_CONTEXT_PADDING2 LTTNG_SYMBOL_NAME_LEN + 32
182 struct lttng_event_context {
183 enum lttng_event_context_type ctx;
184 char padding[LTTNG_EVENT_CONTEXT_PADDING1];
185
186 union {
187 struct lttng_event_perf_counter_ctx perf_counter;
188 char padding[LTTNG_EVENT_CONTEXT_PADDING2];
189 } u;
190 };
191
192 /*
193 * Event probe.
194 *
195 * Either addr is used or symbol_name and offset.
196 *
197 * The structures should be initialized to zero before use.
198 */
199 #define LTTNG_EVENT_PROBE_PADDING1 16
200 struct lttng_event_probe_attr {
201 uint64_t addr;
202
203 uint64_t offset;
204 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
205
206 char padding[LTTNG_EVENT_PROBE_PADDING1];
207 };
208
209 /*
210 * Function tracer
211 *
212 * The structures should be initialized to zero before use.
213 */
214 #define LTTNG_EVENT_FUNCTION_PADDING1 16
215 struct lttng_event_function_attr {
216 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
217
218 char padding[LTTNG_EVENT_FUNCTION_PADDING1];
219 };
220
221 /*
222 * Generic lttng event
223 *
224 * The structures should be initialized to zero before use.
225 */
226 #define LTTNG_EVENT_PADDING1 15
227 #define LTTNG_EVENT_PADDING2 LTTNG_SYMBOL_NAME_LEN + 32
228 struct lttng_event {
229 enum lttng_event_type type;
230 char name[LTTNG_SYMBOL_NAME_LEN];
231
232 enum lttng_loglevel_type loglevel_type;
233 int loglevel;
234
235 int32_t enabled; /* Does not apply: -1 */
236 pid_t pid;
237 unsigned char filter; /* filter enabled ? */
238
239 char padding[LTTNG_EVENT_PADDING1];
240
241 /* Per event type configuration */
242 union {
243 struct lttng_event_probe_attr probe;
244 struct lttng_event_function_attr ftrace;
245
246 char padding[LTTNG_EVENT_PADDING2];
247 } attr;
248 };
249
250 enum lttng_event_field_type {
251 LTTNG_EVENT_FIELD_OTHER = 0,
252 LTTNG_EVENT_FIELD_INTEGER = 1,
253 LTTNG_EVENT_FIELD_ENUM = 2,
254 LTTNG_EVENT_FIELD_FLOAT = 3,
255 LTTNG_EVENT_FIELD_STRING = 4,
256 };
257
258 #define LTTNG_EVENT_FIELD_PADDING LTTNG_SYMBOL_NAME_LEN + 32
259 struct lttng_event_field {
260 char field_name[LTTNG_SYMBOL_NAME_LEN];
261 enum lttng_event_field_type type;
262 char padding[LTTNG_EVENT_FIELD_PADDING];
263 struct lttng_event event;
264 };
265
266 /*
267 * Tracer channel attributes. For both kernel and user-space.
268 *
269 * The structures should be initialized to zero before use.
270 */
271 #define LTTNG_CHANNEL_ATTR_PADDING1 LTTNG_SYMBOL_NAME_LEN + 32
272 struct lttng_channel_attr {
273 int overwrite; /* 1: overwrite, 0: discard */
274 uint64_t subbuf_size; /* bytes */
275 uint64_t num_subbuf; /* power of 2 */
276 unsigned int switch_timer_interval; /* usec */
277 unsigned int read_timer_interval; /* usec */
278 enum lttng_event_output output; /* splice, mmap */
279
280 char padding[LTTNG_CHANNEL_ATTR_PADDING1];
281 };
282
283 /*
284 * Channel information structure. For both kernel and user-space.
285 *
286 * The structures should be initialized to zero before use.
287 */
288 #define LTTNG_CHANNEL_PADDING1 16
289 struct lttng_channel {
290 char name[LTTNG_SYMBOL_NAME_LEN];
291 uint32_t enabled;
292 struct lttng_channel_attr attr;
293
294 char padding[LTTNG_CHANNEL_PADDING1];
295 };
296
297 #define LTTNG_CALIBRATE_PADDING1 16
298 struct lttng_calibrate {
299 enum lttng_calibrate_type type;
300
301 char padding[LTTNG_CALIBRATE_PADDING1];
302 };
303
304 /*
305 * Basic session information.
306 *
307 * This is an 'output data' meaning that it only comes *from* the session
308 * daemon *to* the lttng client. It's basically a 'human' representation of
309 * tracing entities (here a session).
310 *
311 * The structures should be initialized to zero before use.
312 */
313 #define LTTNG_SESSION_PADDING1 16
314 struct lttng_session {
315 char name[NAME_MAX];
316 /* The path where traces are written */
317 char path[PATH_MAX];
318 uint32_t enabled; /* enabled/started: 1, disabled/stopped: 0 */
319
320 char padding[LTTNG_SESSION_PADDING1];
321 };
322
323 /*
324 * Handle used as a context for commands.
325 *
326 * The structures should be initialized to zero before use.
327 */
328 #define LTTNG_HANDLE_PADDING1 16
329 struct lttng_handle {
330 char session_name[NAME_MAX];
331 struct lttng_domain domain;
332
333 char padding[LTTNG_HANDLE_PADDING1];
334 };
335
336 /*
337 * Public LTTng control API
338 *
339 * For functions having an lttng domain type as parameter, if a bad value is
340 * given, NO default is applied and an error is returned.
341 *
342 * On success, all functions of the API return 0 or the size of the allocated
343 * array (in bytes).
344 *
345 * On error, a negative value is returned being a specific lttng-tools error
346 * code which can be humanly interpreted with lttng_strerror(err).
347 *
348 * Exceptions to this are noted below.
349 */
350
351 /*
352 * Create a handle used as a context for every request made to the library.
353 *
354 * This handle contains the session name and lttng domain on which the command
355 * will be executed.
356 * The returned pointer will be NULL in case of malloc() error.
357 */
358 extern struct lttng_handle *lttng_create_handle(const char *session_name,
359 struct lttng_domain *domain);
360
361 /*
362 * Destroy a handle. This will simply free(3) the data pointer returned by
363 * lttng_create_handle(), rendering it unusable.
364 */
365 extern void lttng_destroy_handle(struct lttng_handle *handle);
366
367 /*
368 * Create a tracing session using a name and an optional URL.
369 *
370 * If _url_ is NULL, no consumer is created for the session.
371 */
372 extern int lttng_create_session(const char *name, const char *url);
373
374 /*
375 * Destroy a tracing session.
376 *
377 * The session will not be usable anymore, tracing will be stopped for all
378 * registered traces, and the tracing buffers will be flushed.
379 */
380 extern int lttng_destroy_session(const char *name);
381
382 /*
383 * List all the tracing sessions.
384 *
385 * Return the size (number of entries) of the "lttng_session" array. Caller
386 * must free(3).
387 */
388 extern int lttng_list_sessions(struct lttng_session **sessions);
389
390 /*
391 * List the registered domain(s) of a session.
392 *
393 * Return the size (number of entries) of the "lttng_domain" array. Caller
394 * must free(3).
395 */
396 extern int lttng_list_domains(const char *session_name,
397 struct lttng_domain **domains);
398
399 /*
400 * List the channel(s) of a session.
401 *
402 * Return the size (number of entries) of the "lttng_channel" array. Caller
403 * must free(3).
404 */
405 extern int lttng_list_channels(struct lttng_handle *handle,
406 struct lttng_channel **channels);
407
408 /*
409 * List the event(s) of a session channel.
410 *
411 * Return the size (number of entries) of the "lttng_event" array.
412 * Caller must free(3).
413 */
414 extern int lttng_list_events(struct lttng_handle *handle,
415 const char *channel_name, struct lttng_event **events);
416
417 /*
418 * List the available tracepoints of a specific lttng domain.
419 *
420 * Return the size (number of entries) of the "lttng_event" array.
421 * Caller must free(3).
422 */
423 extern int lttng_list_tracepoints(struct lttng_handle *handle,
424 struct lttng_event **events);
425
426 /*
427 * List the available tracepoints fields of a specific lttng domain.
428 *
429 * Return the size (number of entries) of the "lttng_event_field" array.
430 * Caller must free(3).
431 */
432 extern int lttng_list_tracepoint_fields(struct lttng_handle *handle,
433 struct lttng_event_field **fields);
434
435 /*
436 * Check if a session daemon is alive.
437 *
438 * Return 1 if alive or 0 if not. On error returns a negative value.
439 */
440 extern int lttng_session_daemon_alive(void);
441
442 /*
443 * Set the tracing group for the *current* flow of execution.
444 *
445 * On success, returns 0, on error, returns -1 (null name) or -ENOMEM.
446 */
447 extern int lttng_set_tracing_group(const char *name);
448
449 /*
450 * Return a human-readable error message for an lttng-tools error code.
451 *
452 * Parameter MUST be a negative value or else you'll get a generic message.
453 */
454 extern const char *lttng_strerror(int code);
455
456 /*
457 * This call registers an "outside consumer" for a session and an lttng domain.
458 * No consumer will be spawned and all fds/commands will go through the socket
459 * path given (socket_path).
460 *
461 * NOTE: At the moment, if you use the liblttng-kconsumer, you can only use the
462 * command socket. The error socket is not supported yet for roaming consumers.
463 */
464 extern int lttng_register_consumer(struct lttng_handle *handle,
465 const char *socket_path);
466
467 /*
468 * Start tracing for *all* registered traces (kernel and user-space).
469 */
470 extern int lttng_start_tracing(const char *session_name);
471
472 /*
473 * Stop tracing for *all* registered traces (kernel and user-space).
474 */
475 extern int lttng_stop_tracing(const char *session_name);
476
477 /*
478 * Add context to event(s) for a specific channel (or for all).
479 *
480 * If event_name is NULL, the context is applied to all events of the channel.
481 * If channel_name is NULL, a lookup of the event's channel is done.
482 * If both are NULL, the context is applied to all events of all channels.
483 */
484 extern int lttng_add_context(struct lttng_handle *handle,
485 struct lttng_event_context *ctx, const char *event_name,
486 const char *channel_name);
487
488 /*
489 * Create or enable an event (or events) for a channel.
490 *
491 * If the event you are trying to enable does not exist, it will be created,
492 * else it is enabled.
493 * If event_name is NULL, all events are enabled.
494 * If channel_name is NULL, the default channel is used (channel0).
495 */
496 extern int lttng_enable_event(struct lttng_handle *handle,
497 struct lttng_event *ev, const char *channel_name);
498
499 /*
500 * Apply a filter expression to an event.
501 *
502 * If event_name is NULL, the filter is applied to all events of the channel.
503 * If channel_name is NULL, a lookup of the event's channel is done.
504 * If both are NULL, the filter is applied to all events of all channels.
505 */
506 extern int lttng_set_event_filter(struct lttng_handle *handle,
507 const char *event_name,
508 const char *channel_name,
509 const char *filter_expression);
510 /*
511 * Create or enable a channel.
512 * The channel name cannot be NULL.
513 */
514 extern int lttng_enable_channel(struct lttng_handle *handle,
515 struct lttng_channel *chan);
516
517 /*
518 * Disable event(s) of a channel and domain.
519 *
520 * If event_name is NULL, all events are disabled.
521 * If channel_name is NULL, the default channel is used (channel0).
522 */
523 extern int lttng_disable_event(struct lttng_handle *handle,
524 const char *name, const char *channel_name);
525
526 /*
527 * Disable channel.
528 *
529 * The channel name cannot be NULL.
530 */
531 extern int lttng_disable_channel(struct lttng_handle *handle,
532 const char *name);
533
534 /*
535 * Calibrate LTTng overhead.
536 */
537 extern int lttng_calibrate(struct lttng_handle *handle,
538 struct lttng_calibrate *calibrate);
539
540 /*
541 * Set the default channel attributes for a specific domain and an allocated
542 * lttng_channel_attr pointer.
543 *
544 * If either or both of the arguments are NULL, nothing happens.
545 */
546 extern void lttng_channel_set_default_attr(struct lttng_domain *domain,
547 struct lttng_channel_attr *attr);
548
549 /*
550 * Set URL for a consumer for a session and domain.
551 *
552 * Both data and control URL must be defined. If both URLs are the same, only
553 * the control URL is used even for network streaming.
554 *
555 * Default port are 5342 and 5343 respectively for control and data which uses
556 * the TCP protocol.
557 */
558 extern int lttng_set_consumer_url(struct lttng_handle *handle,
559 const char *control_url, const char *data_url);
560
561 /*
562 * Enable the consumer for a session and domain.
563 */
564 extern int lttng_enable_consumer(struct lttng_handle *handle);
565
566 /*
567 * Disable consumer for a session and domain.
568 */
569 extern int lttng_disable_consumer(struct lttng_handle *handle);
570
571 /*
572 * Check session daemon health for a specific component.
573 *
574 * Return 0 if health is OK or 1 if BAD. A returned value of -1 indicate that
575 * the control library was not able to connect to the session daemon health
576 * socket.
577 *
578 * Any other positive value is an lttcomm error which can be translate with
579 * lttng_strerror().
580 */
581 extern int lttng_health_check(enum lttng_health_component c);
582
583 #ifdef __cplusplus
584 }
585 #endif
586
587 #endif /* LTTNG_H */
This page took 0.039339 seconds and 3 git commands to generate.