SoW-2020-0002: Trace Hit Counters
[deliverable/lttng-ust.git] / include / lttng / ust-abi.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * LTTng-UST ABI header
7 */
8
9 #ifndef _LTTNG_UST_ABI_H
10 #define _LTTNG_UST_ABI_H
11
12 #include <stdint.h>
13 #include <lttng/ust-compiler.h>
14
15 #ifndef LTTNG_PACKED
16 #error "LTTNG_PACKED should be defined"
17 #endif
18
19 #ifndef __ust_stringify
20 #define __ust_stringify1(x) #x
21 #define __ust_stringify(x) __ust_stringify1(x)
22 #endif /* __ust_stringify */
23
24 #define LTTNG_UST_SYM_NAME_LEN 256
25 #define LTTNG_UST_ABI_PROCNAME_LEN 16
26
27 /* UST comm magic number, used to validate protocol and endianness. */
28 #define LTTNG_UST_COMM_MAGIC 0xC57C57C5
29
30 /* Version for ABI between liblttng-ust, sessiond, consumerd */
31 #define LTTNG_UST_ABI_MAJOR_VERSION 9
32 #define LTTNG_UST_ABI_MAJOR_VERSION_OLDEST_COMPATIBLE 8
33 #define LTTNG_UST_ABI_MINOR_VERSION 0
34
35 enum lttng_ust_instrumentation {
36 LTTNG_UST_TRACEPOINT = 0,
37 LTTNG_UST_PROBE = 1,
38 LTTNG_UST_FUNCTION = 2,
39 };
40
41 enum lttng_ust_loglevel_type {
42 LTTNG_UST_LOGLEVEL_ALL = 0,
43 LTTNG_UST_LOGLEVEL_RANGE = 1,
44 LTTNG_UST_LOGLEVEL_SINGLE = 2,
45 };
46
47 enum lttng_ust_output {
48 LTTNG_UST_MMAP = 0,
49 };
50
51 enum lttng_ust_chan_type {
52 LTTNG_UST_CHAN_PER_CPU = 0,
53 LTTNG_UST_CHAN_METADATA = 1,
54 };
55
56 struct lttng_ust_tracer_version {
57 uint32_t major;
58 uint32_t minor;
59 uint32_t patchlevel;
60 } LTTNG_PACKED;
61
62 #define LTTNG_UST_CHANNEL_PADDING (LTTNG_UST_SYM_NAME_LEN + 32)
63 /*
64 * Given that the consumerd is limited to 64k file descriptors, we
65 * cannot expect much more than 1MB channel structure size. This size is
66 * depends on the number of streams within a channel, which depends on
67 * the number of possible CPUs on the system.
68 */
69 #define LTTNG_UST_CHANNEL_DATA_MAX_LEN 1048576U
70 struct lttng_ust_channel {
71 uint64_t len;
72 enum lttng_ust_chan_type type;
73 char padding[LTTNG_UST_CHANNEL_PADDING];
74 char data[]; /* variable sized data */
75 } LTTNG_PACKED;
76
77 #define LTTNG_UST_STREAM_PADDING1 (LTTNG_UST_SYM_NAME_LEN + 32)
78 struct lttng_ust_stream {
79 uint64_t len; /* shm len */
80 uint32_t stream_nr; /* stream number */
81 char padding[LTTNG_UST_STREAM_PADDING1];
82 /*
83 * shm_fd and wakeup_fd are send over unix socket as file
84 * descriptors after this structure.
85 */
86 } LTTNG_PACKED;
87
88 #define LTTNG_UST_EVENT_PADDING1 8
89 #define LTTNG_UST_EVENT_PADDING2 (LTTNG_UST_SYM_NAME_LEN + 32)
90 struct lttng_ust_event {
91 enum lttng_ust_instrumentation instrumentation;
92 char name[LTTNG_UST_SYM_NAME_LEN]; /* event name */
93
94 enum lttng_ust_loglevel_type loglevel_type;
95 int loglevel; /* value, -1: all */
96 uint64_t token; /* User-provided token */
97 char padding[LTTNG_UST_EVENT_PADDING1];
98
99 /* Per instrumentation type configuration */
100 union {
101 char padding[LTTNG_UST_EVENT_PADDING2];
102 } u;
103 } LTTNG_PACKED;
104
105 #define LTTNG_UST_EVENT_NOTIFIER_PADDING 32
106 struct lttng_ust_event_notifier {
107 struct lttng_ust_event event;
108 uint64_t error_counter_index;
109
110 char padding[LTTNG_UST_EVENT_NOTIFIER_PADDING];
111 } LTTNG_PACKED;
112
113 #define LTTNG_UST_EVENT_NOTIFIER_NOTIFICATION_PADDING 32
114 struct lttng_ust_event_notifier_notification {
115 uint64_t token;
116 uint16_t capture_buf_size;
117 char padding[LTTNG_UST_EVENT_NOTIFIER_NOTIFICATION_PADDING];
118 } LTTNG_PACKED;
119
120 enum lttng_ust_key_token_type {
121 LTTNG_UST_KEY_TOKEN_STRING = 0, /* arg: strtab_offset. */
122 LTTNG_UST_KEY_TOKEN_EVENT_NAME = 1, /* no arg. */
123 LTTNG_UST_KEY_TOKEN_PROVIDER_NAME = 2, /* no arg. */
124 };
125
126 #define LTTNG_UST_KEY_ARG_PADDING1 256
127 #define LTTNG_UST_KEY_TOKEN_STRING_LEN_MAX 256
128 struct lttng_ust_key_token {
129 uint32_t type; /* enum lttng_ust_key_token_type */
130 union {
131 char string[LTTNG_UST_KEY_TOKEN_STRING_LEN_MAX];
132 char padding[LTTNG_UST_KEY_ARG_PADDING1];
133 } arg;
134 } LTTNG_PACKED;
135
136 #define LTTNG_UST_NR_KEY_TOKEN 4
137 struct lttng_ust_counter_key_dimension {
138 uint32_t nr_key_tokens;
139 struct lttng_ust_key_token key_tokens[LTTNG_UST_NR_KEY_TOKEN];
140 } LTTNG_PACKED;
141
142 #define LTTNG_UST_COUNTER_DIMENSION_MAX 4
143 struct lttng_ust_counter_key {
144 uint32_t nr_dimensions;
145 struct lttng_ust_counter_key_dimension key_dimensions[LTTNG_UST_COUNTER_DIMENSION_MAX];
146 } LTTNG_PACKED;
147
148 #define LTTNG_UST_COUNTER_EVENT_PADDING1 16
149 struct lttng_ust_counter_event {
150 struct lttng_ust_event event;
151 struct lttng_ust_counter_key key;
152 char padding[LTTNG_UST_COUNTER_EVENT_PADDING1];
153 } LTTNG_PACKED;
154
155 enum lttng_ust_counter_arithmetic {
156 LTTNG_UST_COUNTER_ARITHMETIC_MODULAR = 0,
157 LTTNG_UST_COUNTER_ARITHMETIC_SATURATION = 1,
158 };
159
160 enum lttng_ust_counter_bitness {
161 LTTNG_UST_COUNTER_BITNESS_32 = 0,
162 LTTNG_UST_COUNTER_BITNESS_64 = 1,
163 };
164
165 struct lttng_ust_counter_dimension {
166 uint64_t size;
167 uint64_t underflow_index;
168 uint64_t overflow_index;
169 uint8_t has_underflow;
170 uint8_t has_overflow;
171 } LTTNG_PACKED;
172
173 #define LTTNG_UST_COUNTER_CONF_PADDING1 67
174 struct lttng_ust_counter_conf {
175 uint32_t arithmetic; /* enum lttng_ust_counter_arithmetic */
176 uint32_t bitness; /* enum lttng_ust_counter_bitness */
177 uint32_t number_dimensions;
178 int64_t global_sum_step;
179 struct lttng_ust_counter_dimension dimensions[LTTNG_UST_COUNTER_DIMENSION_MAX];
180 uint8_t coalesce_hits;
181 char padding[LTTNG_UST_COUNTER_CONF_PADDING1];
182 } LTTNG_PACKED;
183
184 struct lttng_ust_counter_value {
185 uint32_t number_dimensions;
186 uint64_t dimension_indexes[LTTNG_UST_COUNTER_DIMENSION_MAX];
187 int64_t value;
188 } LTTNG_PACKED;
189
190 #define LTTNG_UST_COUNTER_PADDING1 (LTTNG_UST_SYM_NAME_LEN + 32)
191 #define LTTNG_UST_COUNTER_DATA_MAX_LEN 4096U
192 struct lttng_ust_counter {
193 uint64_t len;
194 char padding[LTTNG_UST_COUNTER_PADDING1];
195 char data[]; /* variable sized data */
196 } LTTNG_PACKED;
197
198 #define LTTNG_UST_COUNTER_GLOBAL_PADDING1 (LTTNG_UST_SYM_NAME_LEN + 32)
199 struct lttng_ust_counter_global {
200 uint64_t len; /* shm len */
201 char padding[LTTNG_UST_COUNTER_GLOBAL_PADDING1];
202 } LTTNG_PACKED;
203
204 #define LTTNG_UST_COUNTER_CPU_PADDING1 (LTTNG_UST_SYM_NAME_LEN + 32)
205 struct lttng_ust_counter_cpu {
206 uint64_t len; /* shm len */
207 uint32_t cpu_nr;
208 char padding[LTTNG_UST_COUNTER_CPU_PADDING1];
209 } LTTNG_PACKED;
210
211 enum lttng_ust_field_type {
212 LTTNG_UST_FIELD_OTHER = 0,
213 LTTNG_UST_FIELD_INTEGER = 1,
214 LTTNG_UST_FIELD_ENUM = 2,
215 LTTNG_UST_FIELD_FLOAT = 3,
216 LTTNG_UST_FIELD_STRING = 4,
217 };
218
219 #define LTTNG_UST_FIELD_ITER_PADDING (LTTNG_UST_SYM_NAME_LEN + 28)
220 struct lttng_ust_field_iter {
221 char event_name[LTTNG_UST_SYM_NAME_LEN];
222 char field_name[LTTNG_UST_SYM_NAME_LEN];
223 enum lttng_ust_field_type type;
224 int loglevel; /* event loglevel */
225 int nowrite;
226 char padding[LTTNG_UST_FIELD_ITER_PADDING];
227 } LTTNG_PACKED;
228
229 enum lttng_ust_context_type {
230 LTTNG_UST_CONTEXT_VTID = 0,
231 LTTNG_UST_CONTEXT_VPID = 1,
232 LTTNG_UST_CONTEXT_PTHREAD_ID = 2,
233 LTTNG_UST_CONTEXT_PROCNAME = 3,
234 LTTNG_UST_CONTEXT_IP = 4,
235 LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER = 5,
236 LTTNG_UST_CONTEXT_CPU_ID = 6,
237 LTTNG_UST_CONTEXT_APP_CONTEXT = 7,
238 LTTNG_UST_CONTEXT_CGROUP_NS = 8,
239 LTTNG_UST_CONTEXT_IPC_NS = 9,
240 LTTNG_UST_CONTEXT_MNT_NS = 10,
241 LTTNG_UST_CONTEXT_NET_NS = 11,
242 LTTNG_UST_CONTEXT_PID_NS = 12,
243 LTTNG_UST_CONTEXT_USER_NS = 13,
244 LTTNG_UST_CONTEXT_UTS_NS = 14,
245 LTTNG_UST_CONTEXT_VUID = 15,
246 LTTNG_UST_CONTEXT_VEUID = 16,
247 LTTNG_UST_CONTEXT_VSUID = 17,
248 LTTNG_UST_CONTEXT_VGID = 18,
249 LTTNG_UST_CONTEXT_VEGID = 19,
250 LTTNG_UST_CONTEXT_VSGID = 20,
251 LTTNG_UST_CONTEXT_TIME_NS = 21,
252 };
253
254 struct lttng_ust_perf_counter_ctx {
255 uint32_t type;
256 uint64_t config;
257 char name[LTTNG_UST_SYM_NAME_LEN];
258 } LTTNG_PACKED;
259
260 #define LTTNG_UST_CONTEXT_PADDING1 16
261 #define LTTNG_UST_CONTEXT_PADDING2 (LTTNG_UST_SYM_NAME_LEN + 32)
262 struct lttng_ust_context {
263 enum lttng_ust_context_type ctx;
264 char padding[LTTNG_UST_CONTEXT_PADDING1];
265
266 union {
267 struct lttng_ust_perf_counter_ctx perf_counter;
268 struct {
269 /* Includes trailing '\0'. */
270 uint32_t provider_name_len;
271 uint32_t ctx_name_len;
272 } app_ctx;
273 char padding[LTTNG_UST_CONTEXT_PADDING2];
274 } u;
275 } LTTNG_PACKED;
276
277 /*
278 * Tracer channel attributes.
279 */
280 #define LTTNG_UST_CHANNEL_ATTR_PADDING (LTTNG_UST_SYM_NAME_LEN + 32)
281 struct lttng_ust_channel_attr {
282 uint64_t subbuf_size; /* bytes */
283 uint64_t num_subbuf; /* power of 2 */
284 int overwrite; /* 1: overwrite, 0: discard */
285 unsigned int switch_timer_interval; /* usec */
286 unsigned int read_timer_interval; /* usec */
287 enum lttng_ust_output output; /* splice, mmap */
288 union {
289 struct {
290 int64_t blocking_timeout; /* Blocking timeout (usec) */
291 } s;
292 char padding[LTTNG_UST_CHANNEL_ATTR_PADDING];
293 } u;
294 } LTTNG_PACKED;
295
296 #define LTTNG_UST_TRACEPOINT_ITER_PADDING 16
297 struct lttng_ust_tracepoint_iter {
298 char name[LTTNG_UST_SYM_NAME_LEN]; /* provider:name */
299 int loglevel;
300 char padding[LTTNG_UST_TRACEPOINT_ITER_PADDING];
301 } LTTNG_PACKED;
302
303 enum lttng_ust_object_type {
304 LTTNG_UST_OBJECT_TYPE_UNKNOWN = -1,
305 LTTNG_UST_OBJECT_TYPE_CHANNEL = 0,
306 LTTNG_UST_OBJECT_TYPE_STREAM = 1,
307 LTTNG_UST_OBJECT_TYPE_EVENT = 2,
308 LTTNG_UST_OBJECT_TYPE_CONTEXT = 3,
309 LTTNG_UST_OBJECT_TYPE_EVENT_NOTIFIER_GROUP = 4,
310 LTTNG_UST_OBJECT_TYPE_EVENT_NOTIFIER = 5,
311 LTTNG_UST_OBJECT_TYPE_COUNTER = 6,
312 LTTNG_UST_OBJECT_TYPE_COUNTER_GLOBAL = 7,
313 LTTNG_UST_OBJECT_TYPE_COUNTER_CPU = 8,
314 LTTNG_UST_OBJECT_TYPE_COUNTER_EVENT = 9,
315 };
316
317 #define LTTNG_UST_OBJECT_DATA_PADDING1 32
318 #define LTTNG_UST_OBJECT_DATA_PADDING2 (LTTNG_UST_SYM_NAME_LEN + 32)
319
320 struct lttng_ust_object_data {
321 enum lttng_ust_object_type type;
322 int handle;
323 uint64_t size;
324 char padding1[LTTNG_UST_OBJECT_DATA_PADDING1];
325 union {
326 struct {
327 void *data;
328 enum lttng_ust_chan_type type;
329 int wakeup_fd;
330 } channel;
331 struct {
332 int shm_fd;
333 int wakeup_fd;
334 uint32_t stream_nr;
335 } stream;
336 struct {
337 void *data;
338 } counter;
339 struct {
340 int shm_fd;
341 } counter_global;
342 struct {
343 int shm_fd;
344 uint32_t cpu_nr;
345 } counter_cpu;
346 char padding2[LTTNG_UST_OBJECT_DATA_PADDING2];
347 } u;
348 } LTTNG_PACKED;
349
350 enum lttng_ust_calibrate_type {
351 LTTNG_UST_CALIBRATE_TRACEPOINT,
352 };
353
354 #define LTTNG_UST_CALIBRATE_PADDING1 16
355 #define LTTNG_UST_CALIBRATE_PADDING2 (LTTNG_UST_SYM_NAME_LEN + 32)
356 struct lttng_ust_calibrate {
357 enum lttng_ust_calibrate_type type; /* type (input) */
358 char padding[LTTNG_UST_CALIBRATE_PADDING1];
359
360 union {
361 char padding[LTTNG_UST_CALIBRATE_PADDING2];
362 } u;
363 } LTTNG_PACKED;
364
365 #define FILTER_BYTECODE_MAX_LEN 65536
366 #define LTTNG_UST_FILTER_PADDING 32
367 struct lttng_ust_filter_bytecode {
368 uint32_t len;
369 uint32_t reloc_offset;
370 uint64_t seqnum;
371 char padding[LTTNG_UST_FILTER_PADDING];
372 char data[0];
373 } LTTNG_PACKED;
374
375 #define CAPTURE_BYTECODE_MAX_LEN 65536
376 #define LTTNG_UST_CAPTURE_PADDING 32
377 struct lttng_ust_capture_bytecode {
378 uint32_t len;
379 uint32_t reloc_offset;
380 uint64_t seqnum;
381 char padding[LTTNG_UST_CAPTURE_PADDING];
382 char data[0];
383 } LTTNG_PACKED;
384
385 #define LTTNG_UST_EXCLUSION_PADDING 32
386 struct lttng_ust_event_exclusion {
387 uint32_t count;
388 char padding[LTTNG_UST_EXCLUSION_PADDING];
389 char names[LTTNG_UST_SYM_NAME_LEN][0];
390 } LTTNG_PACKED;
391
392 #define _UST_CMD(minor) (minor)
393 #define _UST_CMDR(minor, type) (minor)
394 #define _UST_CMDW(minor, type) (minor)
395
396 /* Handled by object descriptor */
397 #define LTTNG_UST_RELEASE _UST_CMD(0x1)
398
399 /* Handled by object cmd */
400
401 /* LTTng-UST commands */
402 #define LTTNG_UST_SESSION _UST_CMD(0x40)
403 #define LTTNG_UST_TRACER_VERSION \
404 _UST_CMDR(0x41, struct lttng_ust_tracer_version)
405 #define LTTNG_UST_TRACEPOINT_LIST _UST_CMD(0x42)
406 #define LTTNG_UST_WAIT_QUIESCENT _UST_CMD(0x43)
407 #define LTTNG_UST_REGISTER_DONE _UST_CMD(0x44)
408 #define LTTNG_UST_TRACEPOINT_FIELD_LIST _UST_CMD(0x45)
409 #define LTTNG_UST_EVENT_NOTIFIER_GROUP_CREATE _UST_CMD(0x46)
410
411 /* Session commands */
412 #define LTTNG_UST_CHANNEL \
413 _UST_CMDW(0x51, struct lttng_ust_channel)
414 #define LTTNG_UST_SESSION_START _UST_CMD(0x52)
415 #define LTTNG_UST_SESSION_STOP _UST_CMD(0x53)
416 #define LTTNG_UST_SESSION_STATEDUMP _UST_CMD(0x54)
417
418 /* Channel commands */
419 #define LTTNG_UST_STREAM _UST_CMD(0x60)
420 #define LTTNG_UST_EVENT \
421 _UST_CMDW(0x61, struct lttng_ust_event)
422
423 /* Event and channel commands */
424 #define LTTNG_UST_CONTEXT \
425 _UST_CMDW(0x70, struct lttng_ust_context)
426 #define LTTNG_UST_FLUSH_BUFFER \
427 _UST_CMD(0x71)
428
429 /* Event, event notifier, channel and session commands */
430 #define LTTNG_UST_ENABLE _UST_CMD(0x80)
431 #define LTTNG_UST_DISABLE _UST_CMD(0x81)
432
433 /* Tracepoint list commands */
434 #define LTTNG_UST_TRACEPOINT_LIST_GET _UST_CMD(0x90)
435 #define LTTNG_UST_TRACEPOINT_FIELD_LIST_GET _UST_CMD(0x91)
436
437 /* Event and event notifier commands */
438 #define LTTNG_UST_FILTER _UST_CMD(0xA0)
439 #define LTTNG_UST_EXCLUSION _UST_CMD(0xA1)
440
441 /* Event notifier group commands */
442 #define LTTNG_UST_EVENT_NOTIFIER_CREATE \
443 _UST_CMDW(0xB0, struct lttng_ust_event_notifier)
444
445 /* Event notifier commands */
446 #define LTTNG_UST_CAPTURE _UST_CMD(0xB6)
447
448 /* Session and event notifier group commands */
449 #define LTTNG_UST_COUNTER \
450 _UST_CMDW(0xC0, struct lttng_ust_counter)
451
452 /* Counter commands */
453 #define LTTNG_UST_COUNTER_GLOBAL \
454 _UST_CMDW(0xD0, struct lttng_ust_counter_global)
455 #define LTTNG_UST_COUNTER_CPU \
456 _UST_CMDW(0xD1, struct lttng_ust_counter_cpu)
457 #define LTTNG_UST_COUNTER_EVENT \
458 _UST_CMDW(0xD2, struct lttng_ust_counter_event)
459
460 #define LTTNG_UST_ROOT_HANDLE 0
461
462 struct lttng_ust_obj;
463
464 union ust_args {
465 struct {
466 void *chan_data;
467 int wakeup_fd;
468 } channel;
469 struct {
470 int shm_fd;
471 int wakeup_fd;
472 } stream;
473 struct {
474 struct lttng_ust_field_iter entry;
475 } field_list;
476 struct {
477 char *ctxname;
478 } app_context;
479 struct {
480 int event_notifier_notif_fd;
481 } event_notifier_handle;
482 struct {
483 void *counter_data;
484 } counter;
485 struct {
486 int shm_fd;
487 } counter_shm;
488 };
489
490 struct lttng_ust_objd_ops {
491 long (*cmd)(int objd, unsigned int cmd, unsigned long arg,
492 union ust_args *args, void *owner);
493 int (*release)(int objd);
494 };
495
496 /* Create root handle. Always ID 0. */
497 int lttng_abi_create_root_handle(void);
498
499 const struct lttng_ust_objd_ops *objd_ops(int id);
500 int lttng_ust_objd_unref(int id, int is_owner);
501
502 void lttng_ust_abi_exit(void);
503 void lttng_ust_events_exit(void);
504 void lttng_ust_objd_table_owner_cleanup(void *owner);
505
506 #endif /* _LTTNG_UST_ABI_H */
This page took 0.042863 seconds and 5 git commands to generate.