Docs: document new lttng_event methods
[lttng-tools.git] / include / lttng / event.h
1 /*
2 * Copyright (C) 2014 - David Goulet <dgoulet@efficios.com>
3 * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 *
5 * This library is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License, version 2.1 only,
7 * as published by the Free Software Foundation.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #ifndef LTTNG_EVENT_H
20 #define LTTNG_EVENT_H
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 #include <lttng/handle.h>
27 #include <lttng/userspace-probe.h>
28
29 /*
30 * Instrumentation type of tracing event.
31 */
32 enum lttng_event_type {
33 LTTNG_EVENT_ALL = -1,
34 LTTNG_EVENT_TRACEPOINT = 0,
35 LTTNG_EVENT_PROBE = 1,
36 LTTNG_EVENT_FUNCTION = 2,
37 LTTNG_EVENT_FUNCTION_ENTRY = 3,
38 LTTNG_EVENT_NOOP = 4,
39 LTTNG_EVENT_SYSCALL = 5,
40 LTTNG_EVENT_USERSPACE_PROBE = 6,
41 };
42
43 /*
44 * Loglevel information.
45 */
46 enum lttng_loglevel_type {
47 LTTNG_EVENT_LOGLEVEL_ALL = 0,
48 LTTNG_EVENT_LOGLEVEL_RANGE = 1,
49 LTTNG_EVENT_LOGLEVEL_SINGLE = 2,
50 };
51
52 /*
53 * Available loglevels.
54 */
55 enum lttng_loglevel {
56 LTTNG_LOGLEVEL_EMERG = 0,
57 LTTNG_LOGLEVEL_ALERT = 1,
58 LTTNG_LOGLEVEL_CRIT = 2,
59 LTTNG_LOGLEVEL_ERR = 3,
60 LTTNG_LOGLEVEL_WARNING = 4,
61 LTTNG_LOGLEVEL_NOTICE = 5,
62 LTTNG_LOGLEVEL_INFO = 6,
63 LTTNG_LOGLEVEL_DEBUG_SYSTEM = 7,
64 LTTNG_LOGLEVEL_DEBUG_PROGRAM = 8,
65 LTTNG_LOGLEVEL_DEBUG_PROCESS = 9,
66 LTTNG_LOGLEVEL_DEBUG_MODULE = 10,
67 LTTNG_LOGLEVEL_DEBUG_UNIT = 11,
68 LTTNG_LOGLEVEL_DEBUG_FUNCTION = 12,
69 LTTNG_LOGLEVEL_DEBUG_LINE = 13,
70 LTTNG_LOGLEVEL_DEBUG = 14,
71 };
72
73 /*
74 * Available loglevels for the JUL domain. Those are an exact map from the
75 * class java.util.logging.Level.
76 */
77 enum lttng_loglevel_jul {
78 LTTNG_LOGLEVEL_JUL_OFF = INT32_MAX,
79 LTTNG_LOGLEVEL_JUL_SEVERE = 1000,
80 LTTNG_LOGLEVEL_JUL_WARNING = 900,
81 LTTNG_LOGLEVEL_JUL_INFO = 800,
82 LTTNG_LOGLEVEL_JUL_CONFIG = 700,
83 LTTNG_LOGLEVEL_JUL_FINE = 500,
84 LTTNG_LOGLEVEL_JUL_FINER = 400,
85 LTTNG_LOGLEVEL_JUL_FINEST = 300,
86 LTTNG_LOGLEVEL_JUL_ALL = INT32_MIN,
87 };
88
89 /*
90 * Available loglevels for the LOG4j domain. Those are an exact map from the
91 * class org.apache.log4j.Level.
92 */
93 enum lttng_loglevel_log4j {
94 LTTNG_LOGLEVEL_LOG4J_OFF = INT32_MAX,
95 LTTNG_LOGLEVEL_LOG4J_FATAL = 50000,
96 LTTNG_LOGLEVEL_LOG4J_ERROR = 40000,
97 LTTNG_LOGLEVEL_LOG4J_WARN = 30000,
98 LTTNG_LOGLEVEL_LOG4J_INFO = 20000,
99 LTTNG_LOGLEVEL_LOG4J_DEBUG = 10000,
100 LTTNG_LOGLEVEL_LOG4J_TRACE = 5000,
101 LTTNG_LOGLEVEL_LOG4J_ALL = INT32_MIN,
102 };
103
104 /*
105 * Available loglevels for the Python domain. Those are an exact map from the
106 * Level class.
107 */
108 enum lttng_loglevel_python {
109 LTTNG_LOGLEVEL_PYTHON_CRITICAL = 50,
110 LTTNG_LOGLEVEL_PYTHON_ERROR = 40,
111 LTTNG_LOGLEVEL_PYTHON_WARNING = 30,
112 LTTNG_LOGLEVEL_PYTHON_INFO = 20,
113 LTTNG_LOGLEVEL_PYTHON_DEBUG = 10,
114 LTTNG_LOGLEVEL_PYTHON_NOTSET = 0,
115 };
116
117 /*
118 * LTTng consumer mode
119 */
120 enum lttng_event_output {
121 LTTNG_EVENT_SPLICE = 0,
122 LTTNG_EVENT_MMAP = 1,
123 };
124
125 /* Event context possible type */
126 enum lttng_event_context_type {
127 LTTNG_EVENT_CONTEXT_PID = 0,
128 LTTNG_EVENT_CONTEXT_PERF_COUNTER = 1, /* Backward compat. */
129 LTTNG_EVENT_CONTEXT_PROCNAME = 2,
130 LTTNG_EVENT_CONTEXT_PRIO = 3,
131 LTTNG_EVENT_CONTEXT_NICE = 4,
132 LTTNG_EVENT_CONTEXT_VPID = 5,
133 LTTNG_EVENT_CONTEXT_TID = 6,
134 LTTNG_EVENT_CONTEXT_VTID = 7,
135 LTTNG_EVENT_CONTEXT_PPID = 8,
136 LTTNG_EVENT_CONTEXT_VPPID = 9,
137 LTTNG_EVENT_CONTEXT_PTHREAD_ID = 10,
138 LTTNG_EVENT_CONTEXT_HOSTNAME = 11,
139 LTTNG_EVENT_CONTEXT_IP = 12,
140 LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER = 13,
141 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER = 14,
142 LTTNG_EVENT_CONTEXT_APP_CONTEXT = 15,
143 LTTNG_EVENT_CONTEXT_INTERRUPTIBLE = 16,
144 LTTNG_EVENT_CONTEXT_PREEMPTIBLE = 17,
145 LTTNG_EVENT_CONTEXT_NEED_RESCHEDULE = 18,
146 LTTNG_EVENT_CONTEXT_MIGRATABLE = 19,
147 LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL = 20,
148 LTTNG_EVENT_CONTEXT_CALLSTACK_USER = 21, /* Supported on x86_32 and x86_64 only. */
149 };
150
151 enum lttng_event_field_type {
152 LTTNG_EVENT_FIELD_OTHER = 0,
153 LTTNG_EVENT_FIELD_INTEGER = 1,
154 LTTNG_EVENT_FIELD_ENUM = 2,
155 LTTNG_EVENT_FIELD_FLOAT = 3,
156 LTTNG_EVENT_FIELD_STRING = 4,
157 };
158
159 enum lttng_event_flag {
160 LTTNG_EVENT_FLAG_SYSCALL_32 = (1U << 0),
161 LTTNG_EVENT_FLAG_SYSCALL_64 = (1U << 1),
162 };
163
164 /*
165 * Perf counter attributes
166 *
167 * The structures should be initialized to zero before use.
168 */
169 #define LTTNG_PERF_EVENT_PADDING1 16
170 struct lttng_event_perf_counter_ctx {
171 uint32_t type;
172 uint64_t config;
173 char name[LTTNG_SYMBOL_NAME_LEN];
174
175 char padding[LTTNG_PERF_EVENT_PADDING1];
176 };
177
178 /*
179 * Event/channel context
180 *
181 * The structures should be initialized to zero before use.
182 */
183 #define LTTNG_EVENT_CONTEXT_PADDING1 16
184 #define LTTNG_EVENT_CONTEXT_PADDING2 LTTNG_SYMBOL_NAME_LEN + 32
185 struct lttng_event_context {
186 enum lttng_event_context_type ctx;
187 char padding[LTTNG_EVENT_CONTEXT_PADDING1];
188
189 union {
190 struct lttng_event_perf_counter_ctx perf_counter;
191 struct {
192 char *provider_name;
193 char *ctx_name;
194 } app_ctx;
195 char padding[LTTNG_EVENT_CONTEXT_PADDING2];
196 } u;
197 };
198
199 /*
200 * Event probe.
201 *
202 * Either addr is used or symbol_name and offset.
203 *
204 * The structures should be initialized to zero before use.
205 */
206 #define LTTNG_EVENT_PROBE_PADDING1 16
207 struct lttng_event_probe_attr {
208 uint64_t addr;
209
210 uint64_t offset;
211 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
212
213 char padding[LTTNG_EVENT_PROBE_PADDING1];
214 };
215
216 /*
217 * Function tracer
218 *
219 * The structures should be initialized to zero before use.
220 */
221 #define LTTNG_EVENT_FUNCTION_PADDING1 16
222 struct lttng_event_function_attr {
223 char symbol_name[LTTNG_SYMBOL_NAME_LEN];
224
225 char padding[LTTNG_EVENT_FUNCTION_PADDING1];
226 };
227
228 /*
229 * Generic lttng event
230 *
231 * The structures should be initialized to zero before use.
232 */
233 #define LTTNG_EVENT_PADDING1 12
234 #define LTTNG_EVENT_PADDING2 LTTNG_SYMBOL_NAME_LEN + 32
235 struct lttng_event {
236 /* Offset 0 */
237 enum lttng_event_type type;
238
239 /* Offset 4 */
240 char name[LTTNG_SYMBOL_NAME_LEN];
241
242 /* Offset 260 */
243 enum lttng_loglevel_type loglevel_type;
244
245 /* Offset 264 */
246 int loglevel;
247
248 /* Offset 268 */
249 int32_t enabled; /* Does not apply: -1 */
250
251 /* Offset 272 */
252 pid_t pid;
253
254 /* Offset 276 */
255 unsigned char filter; /* filter enabled ? */
256
257 /* Offset 277 */
258 unsigned char exclusion; /* exclusions added ? */
259
260 /* Offset 278 */
261 char padding2[2];
262
263 /* Offset 280 */
264 /* Event flag, from 2.6 and above. */
265 enum lttng_event_flag flags;
266
267 /* Offset 284 */
268 char padding[4];
269
270 /* Offset 288 */
271 union {
272 uint64_t padding;
273 void *ptr;
274 } extended;
275
276 /* Offset 296 */
277 /* Per event type configuration */
278 union {
279 struct lttng_event_probe_attr probe;
280 struct lttng_event_function_attr ftrace;
281
282 char padding[LTTNG_EVENT_PADDING2];
283 } attr;
284 };
285
286 #define LTTNG_EVENT_FIELD_PADDING LTTNG_SYMBOL_NAME_LEN + 32
287 struct lttng_event_field {
288 char field_name[LTTNG_SYMBOL_NAME_LEN];
289 enum lttng_event_field_type type;
290 char padding[LTTNG_EVENT_FIELD_PADDING];
291 struct lttng_event event;
292 int nowrite;
293 };
294
295 /*
296 * List the event(s) of a session channel.
297 *
298 * Both handle and channel_name CAN NOT be NULL.
299 *
300 * Return the size (number of entries) of the "lttng_event" array. Caller must
301 * free events. On error a negative LTTng error code is returned.
302 */
303 extern int lttng_list_events(struct lttng_handle *handle,
304 const char *channel_name, struct lttng_event **events);
305
306 /*
307 * Create an lttng_event.
308 *
309 * This creation function, introduced in LTTng 2.11, works around
310 * the fact that the layout of the 'lttng_event' is publicly exposed.
311 *
312 * It allocates a larger object which exposes the same public fields
313 * as a 'struct lttng_event', but also allows the use of the following extended
314 * attribute setters:
315 * - lttng_event_set_userspace_probe_location();
316 *
317 * Events created through this function must be destroyed using
318 * lttng_event_destroy().
319 *
320 * Returns a zeroed lttng_event on success, NULL on error.
321 */
322 extern struct lttng_event *lttng_event_create(void);
323
324 extern struct lttng_event *lttng_event_copy(const struct lttng_event *event);
325
326 /*
327 * Destroy an lttng_event.
328 *
329 * This destruction function, introduced in LTTng 2.11, should only
330 * be used with events created by lttng_event_create().
331 */
332 extern void lttng_event_destroy(struct lttng_event *event);
333
334 /*
335 * Get the filter expression of a specific LTTng event.
336 *
337 * If the call is successful, then the filter expression's address is put
338 * in *filter_expression. If the event has no filter expression,
339 * *filter_expression is set to NULL. The caller does NOT own
340 * *filter_expression.
341 *
342 * Returns 0 on success, or a negative LTTng error code on error.
343 */
344 extern int lttng_event_get_filter_expression(struct lttng_event *event,
345 const char **filter_string);
346
347 /*
348 * Get the number of exclusion names of a specific LTTng event.
349 *
350 * Returns the number of exclusion names on success, or a negative
351 * LTTng error code on error.
352 */
353 extern int lttng_event_get_exclusion_name_count(struct lttng_event *event);
354
355 /*
356 * Get an LTTng event's exclusion name at a given index.
357 *
358 * If the call is successful, then the exclusion name string's address
359 * is put in *exclusion_name. The caller does NOT own *exclusion_name.
360 *
361 * Returns 0 on success, or a negative LTTng error code on error.
362 */
363 extern int lttng_event_get_exclusion_name(struct lttng_event *event,
364 size_t index, const char **exclusion_name);
365
366 /*
367 * Get the userspace probe location of a specific LTTng event.
368 * If the call is successful, then a pointer to the probe location is returned.
369 * If the event has no probe location a NULL pointer is returned. The caller
370 * does not own the returned probe location.
371 */
372 extern const struct lttng_userspace_probe_location *
373 lttng_event_get_userspace_probe_location(const struct lttng_event *event);
374
375 /*
376 * Set an LTTng event's userspace probe location.
377 *
378 * If the call is successful, then the probe location is set to the event. The
379 * ownership of the probe_location is given to the event.
380 *
381 * Note that the event must have been created using 'lttng_event_create()' in
382 * order for this call to succeed.
383 *
384 * Returns 0 on success, or a negative LTTng error code on error.
385 */
386 extern int lttng_event_set_userspace_probe_location(struct lttng_event *event,
387 struct lttng_userspace_probe_location *probe_location);
388
389 /*
390 * List the available tracepoints of a specific lttng domain.
391 *
392 * The handle CAN NOT be NULL.
393 *
394 * Return the size (number of entries) of the "lttng_event" array. Caller must
395 * free events. On error a negative LTTng error code is returned.
396 */
397 extern int lttng_list_tracepoints(struct lttng_handle *handle,
398 struct lttng_event **events);
399
400 /*
401 * List the available tracepoints fields of a specific lttng domain.
402 *
403 * The handle CAN NOT be NULL.
404 *
405 * Return the size (number of entries) of the "lttng_event_field" array.
406 * Caller must free fields. On error a negative LTTng error code is
407 * returned.
408 */
409 extern int lttng_list_tracepoint_fields(struct lttng_handle *handle,
410 struct lttng_event_field **fields);
411
412 /*
413 * List the available kernel syscall.
414 *
415 * Return the size (number of entries) of the allocated "lttng_event" array.
416 * All events in will be of type syscall. Caller must free events. On error a
417 * negative LTTng error code is returned.
418 */
419 extern int lttng_list_syscalls(struct lttng_event **events);
420
421 /*
422 * Add context to event(s) for a specific channel (or for all).
423 *
424 * If the channel_name is NULL and they are no channel for the domain, the
425 * default channel is created (channel0). The context is then added on ALL
426 * channels since no name was specified.
427 *
428 * The event_name is ignored since adding a context to an event is not possible
429 * for now.
430 *
431 * Return 0 on success else a negative LTTng error code.
432 */
433 extern int lttng_add_context(struct lttng_handle *handle,
434 struct lttng_event_context *ctx, const char *event_name,
435 const char *channel_name);
436
437 /*
438 * Create or enable an event (or events) for a channel.
439 *
440 * If the event you are trying to enable does not exist, it will be created,
441 * else it is enabled. If channel_name is NULL, the default channel is used
442 * (channel0).
443 *
444 * The handle and ev params can not be NULL.
445 *
446 * Return 0 on success else a negative LTTng error code.
447 */
448 extern int lttng_enable_event(struct lttng_handle *handle,
449 struct lttng_event *ev, const char *channel_name);
450
451 /*
452 * Create or enable an event with a specific filter.
453 *
454 * If the event you are trying to enable does not exist, it will be created,
455 * else it is enabled.
456 * If ev is NULL, all events are enabled with that filter.
457 * If channel_name is NULL, the default channel is used (channel0) and created
458 * if not found.
459 * If filter_expression is NULL, an event without associated filter is
460 * created.
461 *
462 * Return 0 on success else a negative LTTng error code.
463 */
464 extern int lttng_enable_event_with_filter(struct lttng_handle *handle,
465 struct lttng_event *event, const char *channel_name,
466 const char *filter_expression);
467
468 /*
469 * Create or enable an event with a filter and/or exclusions.
470 *
471 * If the event you are trying to enable does not exist, it will be created,
472 * else it is enabled.
473 * If ev is NULL, all events are enabled with the filter and exclusion options.
474 * If channel_name is NULL, the default channel is used (channel0) and created
475 * if not found.
476 * If filter_expression is NULL, an event without associated filter is
477 * created.
478 * If exclusion count is zero, the event will be created without exclusions.
479 *
480 * Return 0 on success else a negative LTTng error code.
481 */
482 extern int lttng_enable_event_with_exclusions(struct lttng_handle *handle,
483 struct lttng_event *event, const char *channel_name,
484 const char *filter_expression,
485 int exclusion_count, char **exclusion_names);
486
487 /*
488 * Disable event(s) of a channel and domain.
489 *
490 * If name is NULL, all events are disabled.
491 * If channel_name is NULL, the default channel is used (channel0).
492 *
493 * Return 0 on success else a negative LTTng error code.
494 */
495 extern int lttng_disable_event(struct lttng_handle *handle,
496 const char *name, const char *channel_name);
497
498 /*
499 * Disable event(s) of a channel and domain.
500 *
501 * Takes a struct lttng_event as parameter.
502 * If channel_name is NULL, the default channel is used (channel0).
503 *
504 * Currently, @filter_expression must be NULL. (disabling specific
505 * filter expressions not implemented)
506 * Currently, only LTTNG_EVENT_ALL and LTTNG_EVENT_SYSCALL event types
507 * are implemented for field @ev.
508 *
509 * Return 0 on success else a negative LTTng error code.
510 */
511 int lttng_disable_event_ext(struct lttng_handle *handle,
512 struct lttng_event *ev, const char *channel_name,
513 const char *filter_expression);
514
515 #ifdef __cplusplus
516 }
517 #endif
518
519 #endif /* LTTNG_EVENT_H */
This page took 0.061698 seconds and 4 git commands to generate.