4 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * Holds LTTng per-session event registry.
8 * Dual LGPL v2.1/GPL v2 license.
14 #include <urcu/list.h>
15 #include <urcu/hlist.h>
17 #include <uuid/uuid.h>
25 #include <urcu/compiler.h>
26 #include <urcu/uatomic.h>
27 #include <urcu/arch.h>
29 #include <lttng/tracepoint.h>
30 #include <lttng/ust-events.h>
32 #include <usterr-signal-safe.h>
36 #include "ltt-tracer.h"
37 #include "ltt-tracer-core.h"
39 #include "../libringbuffer/shm.h"
43 * The sessions mutex is the centralized mutex across UST tracing
44 * control and probe registration. All operations within this file are
45 * called by the communication thread, under ust_lock protection.
47 static pthread_mutex_t sessions_mutex
= PTHREAD_MUTEX_INITIALIZER
;
51 pthread_mutex_lock(&sessions_mutex
);
56 pthread_mutex_unlock(&sessions_mutex
);
59 static CDS_LIST_HEAD(sessions
);
62 * Pending probes hash table, containing the registered ltt events for
63 * which tracepoint probes are still missing. Protected by the sessions
66 #define PENDING_PROBE_HASH_BITS 6
67 #define PENDING_PROBE_HASH_SIZE (1 << PENDING_PROBE_HASH_BITS)
68 static struct cds_hlist_head pending_probe_table
[PENDING_PROBE_HASH_SIZE
];
70 struct ust_pending_probe
{
71 struct ltt_event
*event
;
72 struct cds_hlist_node node
;
76 static void _ltt_event_destroy(struct ltt_event
*event
);
77 static void _ltt_loglevel_destroy(struct session_loglevel
*sl
);
78 static void _ltt_wildcard_destroy(struct session_wildcard
*sw
);
79 static void _ltt_channel_destroy(struct ltt_channel
*chan
);
80 static int _ltt_event_unregister(struct ltt_event
*event
);
82 int _ltt_event_metadata_statedump(struct ltt_session
*session
,
83 struct ltt_channel
*chan
,
84 struct ltt_event
*event
);
86 int _ltt_session_metadata_statedump(struct ltt_session
*session
);
89 * called at event creation if probe is missing.
90 * called with session mutex held.
93 int add_pending_probe(struct ltt_event
*event
, const char *name
)
95 struct cds_hlist_head
*head
;
96 struct ust_pending_probe
*e
;
97 size_t name_len
= strlen(name
);
100 if (name_len
> LTTNG_UST_SYM_NAME_LEN
- 1) {
101 WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name
, LTTNG_UST_SYM_NAME_LEN
- 1);
102 name_len
= LTTNG_UST_SYM_NAME_LEN
- 1;
104 hash
= jhash(name
, name_len
, 0);
105 head
= &pending_probe_table
[hash
& (PENDING_PROBE_HASH_SIZE
- 1)];
106 e
= zmalloc(sizeof(struct ust_pending_probe
) + name_len
);
109 memcpy(&e
->name
[0], name
, name_len
+ 1);
110 e
->name
[name_len
] = '\0';
111 cds_hlist_add_head(&e
->node
, head
);
113 event
->pending_probe
= e
;
118 * remove a pending probe. called when at event teardown and when an
119 * event is fixed (probe is loaded).
120 * called with session mutex held.
123 void remove_pending_probe(struct ust_pending_probe
*e
)
127 cds_hlist_del(&e
->node
);
132 * Called at library load: connect the probe on the events pending on
134 * called with session mutex held.
136 int pending_probe_fix_events(const struct lttng_event_desc
*desc
)
138 struct cds_hlist_head
*head
;
139 struct cds_hlist_node
*node
, *p
;
140 struct ust_pending_probe
*e
;
141 const char *name
= desc
->name
;
143 struct lttng_ust_event event_param
;
144 size_t name_len
= strlen(name
);
148 * For this event, we need to lookup the loglevel. If active (in
149 * the active loglevels hash table), we must create the event.
151 if (desc
->loglevel
) {
152 const struct tracepoint_loglevel_entry
*ev_ll
;
153 struct loglevel_entry
*loglevel
;
155 ev_ll
= *desc
->loglevel
;
156 loglevel
= get_loglevel(ev_ll
->identifier
);
158 loglevel
= get_loglevel_value(ev_ll
->value
);
160 struct session_loglevel
*sl
;
162 cds_list_for_each_entry(sl
, &loglevel
->session_list
,
164 struct ltt_event
*ev
;
167 memcpy(&event_param
, &sl
->event_param
,
168 sizeof(event_param
));
169 memcpy(event_param
.name
,
171 sizeof(event_param
.name
));
173 ret
= ltt_event_create(sl
->chan
,
177 DBG("Error creating event");
180 cds_list_add(&ev
->loglevel_list
,
188 struct wildcard_entry
*wildcard
;
190 wildcard
= match_wildcard(desc
->name
);
191 if (strcmp(desc
->name
, "lttng_ust:metadata") && wildcard
) {
192 struct session_wildcard
*sw
;
194 cds_list_for_each_entry(sw
, &wildcard
->session_list
,
196 struct ltt_event
*ev
;
199 memcpy(&event_param
, &sw
->event_param
,
200 sizeof(event_param
));
201 memcpy(event_param
.name
,
203 sizeof(event_param
.name
));
205 ret
= ltt_event_create(sw
->chan
,
209 DBG("Error creating event");
212 cds_list_add(&ev
->wildcard_list
,
218 if (name_len
> LTTNG_UST_SYM_NAME_LEN
- 1) {
219 WARN("Truncating tracepoint name %s which exceeds size limits of %u chars", name
, LTTNG_UST_SYM_NAME_LEN
- 1);
220 name_len
= LTTNG_UST_SYM_NAME_LEN
- 1;
222 hash
= jhash(name
, name_len
, 0);
223 head
= &pending_probe_table
[hash
& (PENDING_PROBE_HASH_SIZE
- 1)];
224 cds_hlist_for_each_entry_safe(e
, node
, p
, head
, node
) {
225 struct ltt_event
*event
;
226 struct ltt_channel
*chan
;
228 if (strncmp(name
, e
->name
, LTTNG_UST_SYM_NAME_LEN
- 1))
232 assert(!event
->desc
);
234 event
->pending_probe
= NULL
;
235 remove_pending_probe(e
);
236 ret
|= __tracepoint_probe_register(name
,
237 event
->desc
->probe_callback
,
241 event
->id
= chan
->free_event_id
++;
242 ret
|= _ltt_event_metadata_statedump(chan
->session
, chan
,
248 void synchronize_trace(void)
253 struct ltt_session
*ltt_session_create(void)
255 struct ltt_session
*session
;
257 session
= zmalloc(sizeof(struct ltt_session
));
260 CDS_INIT_LIST_HEAD(&session
->chan
);
261 CDS_INIT_LIST_HEAD(&session
->events
);
262 CDS_INIT_LIST_HEAD(&session
->loglevels
);
263 CDS_INIT_LIST_HEAD(&session
->wildcards
);
264 uuid_generate(session
->uuid
);
265 cds_list_add(&session
->list
, &sessions
);
269 void ltt_session_destroy(struct ltt_session
*session
)
271 struct ltt_channel
*chan
, *tmpchan
;
272 struct ltt_event
*event
, *tmpevent
;
273 struct session_loglevel
*loglevel
, *tmploglevel
;
274 struct session_wildcard
*wildcard
, *tmpwildcard
;
277 CMM_ACCESS_ONCE(session
->active
) = 0;
278 cds_list_for_each_entry(event
, &session
->events
, list
) {
279 ret
= _ltt_event_unregister(event
);
282 synchronize_trace(); /* Wait for in-flight events to complete */
283 cds_list_for_each_entry_safe(loglevel
, tmploglevel
, &session
->loglevels
, list
)
284 _ltt_loglevel_destroy(loglevel
);
285 cds_list_for_each_entry_safe(wildcard
, tmpwildcard
, &session
->wildcards
, list
)
286 _ltt_wildcard_destroy(wildcard
);
287 cds_list_for_each_entry_safe(event
, tmpevent
, &session
->events
, list
)
288 _ltt_event_destroy(event
);
289 cds_list_for_each_entry_safe(chan
, tmpchan
, &session
->chan
, list
)
290 _ltt_channel_destroy(chan
);
291 cds_list_del(&session
->list
);
295 int ltt_session_enable(struct ltt_session
*session
)
298 struct ltt_channel
*chan
;
300 if (session
->active
) {
306 * Snapshot the number of events per channel to know the type of header
309 cds_list_for_each_entry(chan
, &session
->chan
, list
) {
310 if (chan
->header_type
)
311 continue; /* don't change it if session stop/restart */
312 if (chan
->free_event_id
< 31)
313 chan
->header_type
= 1; /* compact */
315 chan
->header_type
= 2; /* large */
318 CMM_ACCESS_ONCE(session
->active
) = 1;
319 CMM_ACCESS_ONCE(session
->been_active
) = 1;
320 ret
= _ltt_session_metadata_statedump(session
);
322 CMM_ACCESS_ONCE(session
->active
) = 0;
327 int ltt_session_disable(struct ltt_session
*session
)
331 if (!session
->active
) {
335 CMM_ACCESS_ONCE(session
->active
) = 0;
340 int ltt_channel_enable(struct ltt_channel
*channel
)
344 if (channel
== channel
->session
->metadata
)
346 old
= uatomic_xchg(&channel
->enabled
, 1);
352 int ltt_channel_disable(struct ltt_channel
*channel
)
356 if (channel
== channel
->session
->metadata
)
358 old
= uatomic_xchg(&channel
->enabled
, 0);
364 int ltt_event_enable(struct ltt_event
*event
)
368 if (event
->chan
== event
->chan
->session
->metadata
)
370 old
= uatomic_xchg(&event
->enabled
, 1);
376 int ltt_event_disable(struct ltt_event
*event
)
380 if (event
->chan
== event
->chan
->session
->metadata
)
382 old
= uatomic_xchg(&event
->enabled
, 0);
388 struct ltt_channel
*ltt_channel_create(struct ltt_session
*session
,
389 const char *transport_name
,
391 size_t subbuf_size
, size_t num_subbuf
,
392 unsigned int switch_timer_interval
,
393 unsigned int read_timer_interval
,
394 int **shm_fd
, int **wait_fd
,
395 uint64_t **memory_map_size
,
396 struct ltt_channel
*chan_priv_init
)
398 struct ltt_channel
*chan
= NULL
;
399 struct ltt_transport
*transport
;
401 if (session
->been_active
)
402 goto active
; /* Refuse to add channel to active session */
403 transport
= ltt_transport_find(transport_name
);
405 DBG("LTTng transport %s not found\n",
409 chan_priv_init
->id
= session
->free_chan_id
++;
410 chan_priv_init
->session
= session
;
412 * Note: the channel creation op already writes into the packet
413 * headers. Therefore the "chan" information used as input
414 * should be already accessible.
416 chan
= transport
->ops
.channel_create("[lttng]", buf_addr
,
417 subbuf_size
, num_subbuf
, switch_timer_interval
,
418 read_timer_interval
, shm_fd
, wait_fd
,
419 memory_map_size
, chan_priv_init
);
423 chan
->ops
= &transport
->ops
;
424 cds_list_add(&chan
->list
, &session
->chan
);
434 * Only used internally at session destruction.
437 void _ltt_channel_destroy(struct ltt_channel
*chan
)
439 cds_list_del(&chan
->list
);
440 lttng_destroy_context(chan
->ctx
);
441 chan
->ops
->channel_destroy(chan
);
444 int ltt_loglevel_create(struct ltt_channel
*chan
,
445 struct lttng_ust_event
*event_param
,
446 struct session_loglevel
**_sl
)
448 struct session_loglevel
*sl
;
450 sl
= add_loglevel(event_param
->name
, chan
, event_param
);
451 if (!sl
|| IS_ERR(sl
)) {
459 void _ltt_loglevel_destroy(struct session_loglevel
*sl
)
461 _remove_loglevel(sl
);
464 int ltt_wildcard_create(struct ltt_channel
*chan
,
465 struct lttng_ust_event
*event_param
,
466 struct session_wildcard
**_sw
)
468 struct session_wildcard
*sw
;
470 sw
= add_wildcard(event_param
->name
, chan
, event_param
);
471 if (!sw
|| IS_ERR(sw
)) {
479 void _ltt_wildcard_destroy(struct session_wildcard
*sw
)
481 _remove_wildcard(sw
);
485 * Supports event creation while tracing session is active.
487 int ltt_event_create(struct ltt_channel
*chan
,
488 struct lttng_ust_event
*event_param
,
490 struct ltt_event
**_event
)
492 struct ltt_event
*event
;
495 if (chan
->used_event_id
== -1UL) {
500 * This is O(n^2) (for each event, the loop is called at event
501 * creation). Might require a hash if we have lots of events.
503 cds_list_for_each_entry(event
, &chan
->session
->events
, list
) {
504 if (event
->desc
&& !strncmp(event
->desc
->name
,
506 LTTNG_UST_SYM_NAME_LEN
- 1)) {
511 event
= zmalloc(sizeof(struct ltt_event
));
517 event
->filter
= filter
;
519 * used_event_id counts the maximum number of event IDs that can
520 * register if all probes register.
522 chan
->used_event_id
++;
524 event
->instrumentation
= event_param
->instrumentation
;
525 /* Populate ltt_event structure before tracepoint registration. */
527 switch (event_param
->instrumentation
) {
528 case LTTNG_UST_TRACEPOINT
:
529 event
->desc
= ltt_event_get(event_param
->name
);
531 ret
= __tracepoint_probe_register(event_param
->name
,
532 event
->desc
->probe_callback
,
536 event
->id
= chan
->free_event_id
++;
539 * If the probe is not present, event->desc stays NULL,
540 * waiting for the probe to register, and the event->id
543 ret
= add_pending_probe(event
, event_param
->name
);
545 goto add_pending_error
;
548 case LTTNG_UST_TRACEPOINT_LOGLEVEL
:
555 ret
= _ltt_event_metadata_statedump(chan
->session
, chan
, event
);
557 goto statedump_error
;
559 cds_list_add(&event
->list
, &chan
->session
->events
);
565 WARN_ON_ONCE(__tracepoint_probe_unregister(event_param
->name
,
566 event
->desc
->probe_callback
,
568 ltt_event_put(event
->desc
);
580 * Only used internally at session destruction.
582 int _ltt_event_unregister(struct ltt_event
*event
)
586 switch (event
->instrumentation
) {
587 case LTTNG_UST_TRACEPOINT
:
589 ret
= __tracepoint_probe_unregister(event
->desc
->name
,
590 event
->desc
->probe_callback
,
595 remove_pending_probe(event
->pending_probe
);
606 * Only used internally at session destruction.
609 void _ltt_event_destroy(struct ltt_event
*event
)
611 switch (event
->instrumentation
) {
612 case LTTNG_UST_TRACEPOINT
:
614 ltt_event_put(event
->desc
);
620 cds_list_del(&event
->list
);
621 lttng_destroy_context(event
->ctx
);
626 * We have exclusive access to our metadata buffer (protected by the
627 * ust_lock), so we can do racy operations such as looking for
628 * remaining space left in packet and write, since mutual exclusion
629 * protects us from concurrent writes.
631 int lttng_metadata_printf(struct ltt_session
*session
,
632 const char *fmt
, ...)
634 struct lttng_ust_lib_ring_buffer_ctx ctx
;
635 struct ltt_channel
*chan
= session
->metadata
;
637 int ret
= 0, waitret
;
638 size_t len
, reserve_len
, pos
;
641 WARN_ON_ONCE(!CMM_ACCESS_ONCE(session
->active
));
644 ret
= vasprintf(&str
, fmt
, ap
);
652 for (pos
= 0; pos
< len
; pos
+= reserve_len
) {
653 reserve_len
= min_t(size_t,
654 chan
->ops
->packet_avail_size(chan
->chan
, chan
->handle
),
656 lib_ring_buffer_ctx_init(&ctx
, chan
->chan
, NULL
, reserve_len
,
657 sizeof(char), -1, chan
->handle
);
659 * We don't care about metadata buffer's records lost
660 * count, because we always retry here. Report error if
661 * we need to bail out after timeout or being
664 waitret
= wait_cond_interruptible_timeout(
666 ret
= chan
->ops
->event_reserve(&ctx
, 0);
667 ret
!= -ENOBUFS
|| !ret
;
669 LTTNG_METADATA_TIMEOUT_MSEC
);
670 if (waitret
== -ETIMEDOUT
|| waitret
== -EINTR
|| ret
) {
671 DBG("LTTng: Failure to write metadata to buffers (%s)\n",
672 waitret
== -EINTR
? "interrupted" :
673 (ret
== -ENOBUFS
? "timeout" : "I/O error"));
674 if (waitret
== -EINTR
)
678 chan
->ops
->event_write(&ctx
, &str
[pos
], reserve_len
);
679 chan
->ops
->event_commit(&ctx
);
687 int _ltt_field_statedump(struct ltt_session
*session
,
688 const struct lttng_event_field
*field
)
692 switch (field
->type
.atype
) {
694 ret
= lttng_metadata_printf(session
,
695 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n",
696 field
->type
.u
.basic
.integer
.size
,
697 field
->type
.u
.basic
.integer
.alignment
,
698 field
->type
.u
.basic
.integer
.signedness
,
699 (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_none
)
701 : (field
->type
.u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
704 field
->type
.u
.basic
.integer
.base
,
705 #if (BYTE_ORDER == BIG_ENDIAN)
706 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
708 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
713 ret
= lttng_metadata_printf(session
,
714 " floating_point { exp_dig = %u; mant_dig = %u; align = %u;%s } _%s;\n",
715 field
->type
.u
.basic
._float
.exp_dig
,
716 field
->type
.u
.basic
._float
.mant_dig
,
717 field
->type
.u
.basic
._float
.alignment
,
718 #if (BYTE_ORDER == BIG_ENDIAN)
719 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
721 field
->type
.u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
726 ret
= lttng_metadata_printf(session
,
728 field
->type
.u
.basic
.enumeration
.name
,
733 const struct lttng_basic_type
*elem_type
;
735 elem_type
= &field
->type
.u
.array
.elem_type
;
736 ret
= lttng_metadata_printf(session
,
737 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
738 elem_type
->u
.basic
.integer
.size
,
739 elem_type
->u
.basic
.integer
.alignment
,
740 elem_type
->u
.basic
.integer
.signedness
,
741 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
743 : (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
746 elem_type
->u
.basic
.integer
.base
,
747 #if (BYTE_ORDER == BIG_ENDIAN)
748 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
750 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
752 field
->name
, field
->type
.u
.array
.length
);
757 const struct lttng_basic_type
*elem_type
;
758 const struct lttng_basic_type
*length_type
;
760 elem_type
= &field
->type
.u
.sequence
.elem_type
;
761 length_type
= &field
->type
.u
.sequence
.length_type
;
762 ret
= lttng_metadata_printf(session
,
763 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n",
764 length_type
->u
.basic
.integer
.size
,
765 (unsigned int) length_type
->u
.basic
.integer
.alignment
,
766 length_type
->u
.basic
.integer
.signedness
,
767 (length_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
769 : ((length_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
772 length_type
->u
.basic
.integer
.base
,
773 #if (BYTE_ORDER == BIG_ENDIAN)
774 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
776 length_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
782 ret
= lttng_metadata_printf(session
,
783 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n",
784 elem_type
->u
.basic
.integer
.size
,
785 (unsigned int) elem_type
->u
.basic
.integer
.alignment
,
786 elem_type
->u
.basic
.integer
.signedness
,
787 (elem_type
->u
.basic
.integer
.encoding
== lttng_encode_none
)
789 : ((elem_type
->u
.basic
.integer
.encoding
== lttng_encode_UTF8
)
792 elem_type
->u
.basic
.integer
.base
,
793 #if (BYTE_ORDER == BIG_ENDIAN)
794 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = le;" : "",
796 elem_type
->u
.basic
.integer
.reverse_byte_order
? " byte_order = be;" : "",
804 /* Default encoding is UTF8 */
805 ret
= lttng_metadata_printf(session
,
807 field
->type
.u
.basic
.string
.encoding
== lttng_encode_ASCII
?
808 " { encoding = ASCII; }" : "",
819 int _ltt_context_metadata_statedump(struct ltt_session
*session
,
820 struct lttng_ctx
*ctx
)
827 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
828 const struct lttng_ctx_field
*field
= &ctx
->fields
[i
];
830 ret
= _ltt_field_statedump(session
, &field
->event_field
);
838 int _ltt_fields_metadata_statedump(struct ltt_session
*session
,
839 struct ltt_event
*event
)
841 const struct lttng_event_desc
*desc
= event
->desc
;
845 for (i
= 0; i
< desc
->nr_fields
; i
++) {
846 const struct lttng_event_field
*field
= &desc
->fields
[i
];
848 ret
= _ltt_field_statedump(session
, field
);
856 int _ltt_event_metadata_statedump(struct ltt_session
*session
,
857 struct ltt_channel
*chan
,
858 struct ltt_event
*event
)
862 if (event
->metadata_dumped
|| !CMM_ACCESS_ONCE(session
->active
))
864 if (chan
== session
->metadata
)
867 * Don't print events for which probe load is pending.
872 ret
= lttng_metadata_printf(session
,
876 " stream_id = %u;\n",
883 if (event
->desc
->loglevel
) {
884 const struct tracepoint_loglevel_entry
*ll_entry
;
886 ll_entry
= *event
->desc
->loglevel
;
887 ret
= lttng_metadata_printf(session
,
888 " loglevel.identifier = \"%s\";\n"
889 " loglevel.value = %lld;\n",
890 ll_entry
->identifier
,
891 (long long) ll_entry
->value
);
897 ret
= lttng_metadata_printf(session
,
898 " context := struct {\n");
902 ret
= _ltt_context_metadata_statedump(session
, event
->ctx
);
906 ret
= lttng_metadata_printf(session
,
912 ret
= lttng_metadata_printf(session
,
913 " fields := struct {\n"
918 ret
= _ltt_fields_metadata_statedump(session
, event
);
923 * LTTng space reservation can only reserve multiples of the
926 ret
= lttng_metadata_printf(session
,
932 event
->metadata_dumped
= 1;
939 int _ltt_channel_metadata_statedump(struct ltt_session
*session
,
940 struct ltt_channel
*chan
)
944 if (chan
->metadata_dumped
|| !CMM_ACCESS_ONCE(session
->active
))
946 if (chan
== session
->metadata
)
949 WARN_ON_ONCE(!chan
->header_type
);
950 ret
= lttng_metadata_printf(session
,
953 " event.header := %s;\n"
954 " packet.context := struct packet_context;\n",
956 chan
->header_type
== 1 ? "struct event_header_compact" :
957 "struct event_header_large");
962 ret
= lttng_metadata_printf(session
,
963 " event.context := struct {\n");
967 ret
= _ltt_context_metadata_statedump(session
, chan
->ctx
);
971 ret
= lttng_metadata_printf(session
,
977 ret
= lttng_metadata_printf(session
,
980 chan
->metadata_dumped
= 1;
986 int _ltt_stream_packet_context_declare(struct ltt_session
*session
)
988 return lttng_metadata_printf(session
,
989 "struct packet_context {\n"
990 " uint64_t timestamp_begin;\n"
991 " uint64_t timestamp_end;\n"
992 " uint32_t events_discarded;\n"
993 " uint32_t content_size;\n"
994 " uint32_t packet_size;\n"
995 " uint32_t cpu_id;\n"
1002 * id: range: 0 - 30.
1003 * id 31 is reserved to indicate an extended header.
1006 * id: range: 0 - 65534.
1007 * id 65535 is reserved to indicate an extended header.
1010 int _ltt_event_header_declare(struct ltt_session
*session
)
1012 return lttng_metadata_printf(session
,
1013 "struct event_header_compact {\n"
1014 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
1017 " uint27_t timestamp;\n"
1021 " uint64_t timestamp;\n"
1026 "struct event_header_large {\n"
1027 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
1030 " uint32_t timestamp;\n"
1034 " uint64_t timestamp;\n"
1038 lttng_alignof(uint32_t) * CHAR_BIT
,
1039 lttng_alignof(uint16_t) * CHAR_BIT
1044 * Output metadata into this session's metadata buffers.
1047 int _ltt_session_metadata_statedump(struct ltt_session
*session
)
1049 unsigned char *uuid_c
= session
->uuid
;
1051 struct ltt_channel
*chan
;
1052 struct ltt_event
*event
;
1055 if (!CMM_ACCESS_ONCE(session
->active
))
1057 if (session
->metadata_dumped
)
1059 if (!session
->metadata
) {
1060 DBG("LTTng: attempt to start tracing, but metadata channel is not found. Operation abort.\n");
1064 snprintf(uuid_s
, sizeof(uuid_s
),
1065 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1066 uuid_c
[0], uuid_c
[1], uuid_c
[2], uuid_c
[3],
1067 uuid_c
[4], uuid_c
[5], uuid_c
[6], uuid_c
[7],
1068 uuid_c
[8], uuid_c
[9], uuid_c
[10], uuid_c
[11],
1069 uuid_c
[12], uuid_c
[13], uuid_c
[14], uuid_c
[15]);
1071 ret
= lttng_metadata_printf(session
,
1072 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
1073 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
1074 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
1075 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
1076 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
1077 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
1083 " byte_order = %s;\n"
1084 " packet.header := struct {\n"
1085 " uint32_t magic;\n"
1086 " uint8_t uuid[16];\n"
1087 " uint32_t stream_id;\n"
1090 lttng_alignof(uint8_t) * CHAR_BIT
,
1091 lttng_alignof(uint16_t) * CHAR_BIT
,
1092 lttng_alignof(uint32_t) * CHAR_BIT
,
1093 lttng_alignof(uint64_t) * CHAR_BIT
,
1097 #if (BYTE_ORDER == BIG_ENDIAN)
1106 ret
= _ltt_stream_packet_context_declare(session
);
1110 ret
= _ltt_event_header_declare(session
);
1115 cds_list_for_each_entry(chan
, &session
->chan
, list
) {
1116 ret
= _ltt_channel_metadata_statedump(session
, chan
);
1121 cds_list_for_each_entry(event
, &session
->events
, list
) {
1122 ret
= _ltt_event_metadata_statedump(session
, event
->chan
, event
);
1126 session
->metadata_dumped
= 1;
1131 void lttng_ust_events_exit(void)
1133 struct ltt_session
*session
, *tmpsession
;
1135 cds_list_for_each_entry_safe(session
, tmpsession
, &sessions
, list
)
1136 ltt_session_destroy(session
);