Coverity warning: sessiond: uncaught exception in main
[lttng-tools.git] / include / lttng / event.h
CommitLineData
1239a312 1/*
ab5be9fa
MJ
2 * Copyright (C) 2014 David Goulet <dgoulet@efficios.com>
3 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
1239a312 4 *
ab5be9fa 5 * SPDX-License-Identifier: LGPL-2.1-only
1239a312 6 *
1239a312
DG
7 */
8
9#ifndef LTTNG_EVENT_H
10#define LTTNG_EVENT_H
11
4bd69c5f
SM
12#include <lttng/handle.h>
13#include <lttng/lttng-export.h>
14#include <lttng/userspace-probe.h>
15
1239a312
DG
16#ifdef __cplusplus
17extern "C" {
18#endif
19
1239a312
DG
20/*
21 * Instrumentation type of tracing event.
22 */
23enum lttng_event_type {
28f23191
JG
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,
1239a312
DG
32};
33
34/*
35 * Loglevel information.
36 */
37enum lttng_loglevel_type {
28f23191
JG
38 LTTNG_EVENT_LOGLEVEL_ALL = 0,
39 LTTNG_EVENT_LOGLEVEL_RANGE = 1,
40 LTTNG_EVENT_LOGLEVEL_SINGLE = 2,
1239a312
DG
41};
42
43/*
44 * Available loglevels.
45 */
46enum lttng_loglevel {
28f23191
JG
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,
1239a312
DG
62};
63
64/*
65 * Available loglevels for the JUL domain. Those are an exact map from the
66 * class java.util.logging.Level.
67 */
68enum lttng_loglevel_jul {
28f23191
JG
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,
1239a312
DG
78};
79
5cdb6027
DG
80/*
81 * Available loglevels for the LOG4j domain. Those are an exact map from the
82 * class org.apache.log4j.Level.
83 */
84enum lttng_loglevel_log4j {
28f23191
JG
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,
5cdb6027
DG
93};
94
0e115563
DG
95/*
96 * Available loglevels for the Python domain. Those are an exact map from the
97 * Level class.
98 */
99enum lttng_loglevel_python {
28f23191
JG
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,
0e115563
DG
106};
107
1239a312
DG
108/*
109 * LTTng consumer mode
110 */
111enum lttng_event_output {
28f23191
JG
112 LTTNG_EVENT_SPLICE = 0,
113 LTTNG_EVENT_MMAP = 1,
1239a312
DG
114};
115
116/* Event context possible type */
117enum lttng_event_context_type {
28f23191
JG
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,
1239a312 132 LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER = 14,
28f23191
JG
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,
1239a312
DG
160};
161
162enum lttng_event_field_type {
28f23191
JG
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,
1239a312
DG
168};
169
834978fd 170enum lttng_event_flag {
28f23191
JG
171 LTTNG_EVENT_FLAG_SYSCALL_32 = (1U << 0),
172 LTTNG_EVENT_FLAG_SYSCALL_64 = (1U << 1),
834978fd
DG
173};
174
1239a312
DG
175/*
176 * Perf counter attributes
177 *
178 * The structures should be initialized to zero before use.
179 */
28f23191 180#define LTTNG_PERF_EVENT_PADDING1 16
1239a312
DG
181struct 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 */
28f23191
JG
194#define LTTNG_EVENT_CONTEXT_PADDING1 16
195#define LTTNG_EVENT_CONTEXT_PADDING2 LTTNG_SYMBOL_NAME_LEN + 32
1239a312
DG
196struct 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;
2001793c
JG
202 struct {
203 char *provider_name;
204 char *ctx_name;
205 } app_ctx;
1239a312
DG
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 */
28f23191 217#define LTTNG_EVENT_PROBE_PADDING1 16
1239a312
DG
218struct 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 */
28f23191 232#define LTTNG_EVENT_FUNCTION_PADDING1 16
1239a312
DG
233struct 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 */
28f23191
JG
244#define LTTNG_EVENT_PADDING1 12
245#define LTTNG_EVENT_PADDING2 LTTNG_SYMBOL_NAME_LEN + 32
1239a312 246struct lttng_event {
fe9ecacb 247 /* Offset 0 */
1239a312 248 enum lttng_event_type type;
fe9ecacb
PP
249
250 /* Offset 4 */
1239a312
DG
251 char name[LTTNG_SYMBOL_NAME_LEN];
252
fe9ecacb 253 /* Offset 260 */
1239a312 254 enum lttng_loglevel_type loglevel_type;
fe9ecacb
PP
255
256 /* Offset 264 */
1239a312
DG
257 int loglevel;
258
fe9ecacb 259 /* Offset 268 */
28f23191 260 int32_t enabled; /* Does not apply: -1 */
fe9ecacb
PP
261
262 /* Offset 272 */
1239a312 263 pid_t pid;
fe9ecacb
PP
264
265 /* Offset 276 */
28f23191 266 unsigned char filter; /* filter enabled ? */
fe9ecacb
PP
267
268 /* Offset 277 */
1239a312
DG
269 unsigned char exclusion; /* exclusions added ? */
270
fe9ecacb
PP
271 /* Offset 278 */
272 char padding2[2];
273
274 /* Offset 280 */
834978fd
DG
275 /* Event flag, from 2.6 and above. */
276 enum lttng_event_flag flags;
277
fe9ecacb 278 /* Offset 284 */
b4e3ceb9
PP
279 char padding[4];
280
281 /* Offset 288 */
282 union {
4829ae55 283 uint64_t padding;
b4e3ceb9
PP
284 void *ptr;
285 } extended;
1239a312 286
fe9ecacb 287 /* Offset 296 */
1239a312
DG
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
28f23191 297#define LTTNG_EVENT_FIELD_PADDING LTTNG_SYMBOL_NAME_LEN + 32
1239a312
DG
298struct 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 */
4bd69c5f 314LTTNG_EXPORT extern int lttng_list_events(struct lttng_handle *handle,
28f23191
JG
315 const char *channel_name,
316 struct lttng_event **events);
1239a312 317
c8282375
JG
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 */
4bd69c5f 334LTTNG_EXPORT extern struct lttng_event *lttng_event_create(void);
ef0e06bc 335
c8282375
JG
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().
28f23191 341 */
4bd69c5f 342LTTNG_EXPORT extern void lttng_event_destroy(struct lttng_event *event);
ef0e06bc 343
d31d3e8c 344/*
134e72ed 345 * Get the filter expression of a specific LTTng event.
d31d3e8c 346 *
134e72ed
JG
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.
d31d3e8c
PP
351 *
352 * Returns 0 on success, or a negative LTTng error code on error.
353 */
4bd69c5f 354LTTNG_EXPORT extern int lttng_event_get_filter_expression(struct lttng_event *event,
28f23191 355 const char **filter_string);
d31d3e8c 356
f086e50e
PP
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 */
4bd69c5f 363LTTNG_EXPORT extern int lttng_event_get_exclusion_name_count(struct lttng_event *event);
f086e50e
PP
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 */
4bd69c5f 373LTTNG_EXPORT extern int lttng_event_get_exclusion_name(struct lttng_event *event,
28f23191
JG
374 size_t index,
375 const char **exclusion_name);
f086e50e 376
ef0e06bc
JG
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 */
4bd69c5f 383LTTNG_EXPORT extern const struct lttng_userspace_probe_location *
87597c2c 384lttng_event_get_userspace_probe_location(const struct lttng_event *event);
ef0e06bc
JG
385
386/*
387 * Set an LTTng event's userspace probe location.
c8282375 388 *
ef0e06bc
JG
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 *
c8282375
JG
392 * Note that the event must have been created using 'lttng_event_create()' in
393 * order for this call to succeed.
394 *
ef0e06bc
JG
395 * Returns 0 on success, or a negative LTTng error code on error.
396 */
28f23191
JG
397LTTNG_EXPORT extern int
398lttng_event_set_userspace_probe_location(struct lttng_event *event,
399 struct lttng_userspace_probe_location *probe_location);
ef0e06bc 400
1239a312
DG
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 */
4bd69c5f 409LTTNG_EXPORT extern int lttng_list_tracepoints(struct lttng_handle *handle,
28f23191 410 struct lttng_event **events);
1239a312
DG
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 */
4bd69c5f 421LTTNG_EXPORT extern int lttng_list_tracepoint_fields(struct lttng_handle *handle,
28f23191 422 struct lttng_event_field **fields);
1239a312 423
834978fd
DG
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 */
4bd69c5f 431LTTNG_EXPORT extern int lttng_list_syscalls(struct lttng_event **events);
834978fd 432
1239a312
DG
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 */
4bd69c5f 445LTTNG_EXPORT extern int lttng_add_context(struct lttng_handle *handle,
28f23191
JG
446 struct lttng_event_context *ctx,
447 const char *event_name,
448 const char *channel_name);
1239a312
DG
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 */
28f23191
JG
461LTTNG_EXPORT extern int
462lttng_enable_event(struct lttng_handle *handle, struct lttng_event *ev, const char *channel_name);
1239a312
DG
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 */
4bd69c5f 477LTTNG_EXPORT extern int lttng_enable_event_with_filter(struct lttng_handle *handle,
28f23191
JG
478 struct lttng_event *event,
479 const char *channel_name,
480 const char *filter_expression);
1239a312
DG
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 */
4bd69c5f 496LTTNG_EXPORT extern int lttng_enable_event_with_exclusions(struct lttng_handle *handle,
28f23191
JG
497 struct lttng_event *event,
498 const char *channel_name,
499 const char *filter_expression,
500 int exclusion_count,
501 char **exclusion_names);
1239a312
DG
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 */
28f23191
JG
511LTTNG_EXPORT extern int
512lttng_disable_event(struct lttng_handle *handle, const char *name, const char *channel_name);
1239a312 513
6e911cad
MD
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 */
4bd69c5f 527LTTNG_EXPORT extern int lttng_disable_event_ext(struct lttng_handle *handle,
28f23191
JG
528 struct lttng_event *ev,
529 const char *channel_name,
530 const char *filter_expression);
6e911cad 531
1239a312
DG
532#ifdef __cplusplus
533}
534#endif
535
536#endif /* LTTNG_EVENT_H */
This page took 0.067429 seconds and 4 git commands to generate.