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