Add float descriptions (metadata)
[lttng-ust.git] / libust / ltt-events.c
1 /*
2 * ltt-events.c
3 *
4 * Copyright 2010 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * Holds LTTng per-session event registry.
7 *
8 * Dual LGPL v2.1/GPL v2 license.
9 */
10
11 #define _GNU_SOURCE
12 #include <stdio.h>
13 #include <urcu/list.h>
14 #include <pthread.h>
15 #include <urcu-bp.h>
16 #include <urcu/compiler.h>
17 #include <urcu/uatomic.h>
18 #include <uuid/uuid.h>
19 #include <ust/tracepoint.h>
20 #include <errno.h>
21 #include "usterr_signal_safe.h"
22 #include "ust/core.h"
23 #include "ltt-events.h"
24 #include "ltt-tracer.h"
25 #include "ust/wait.h"
26
27 static CDS_LIST_HEAD(sessions);
28 static CDS_LIST_HEAD(ltt_transport_list);
29 static DEFINE_MUTEX(sessions_mutex);
30
31 static void _ltt_event_destroy(struct ltt_event *event);
32 static void _ltt_channel_destroy(struct ltt_channel *chan);
33 static int _ltt_event_unregister(struct ltt_event *event);
34 static
35 int _ltt_event_metadata_statedump(struct ltt_session *session,
36 struct ltt_channel *chan,
37 struct ltt_event *event);
38 static
39 int _ltt_session_metadata_statedump(struct ltt_session *session);
40
41 void synchronize_trace(void)
42 {
43 synchronize_rcu();
44 }
45
46 struct ltt_session *ltt_session_create(void)
47 {
48 struct ltt_session *session;
49
50 pthread_mutex_lock(&sessions_mutex);
51 session = zmalloc(sizeof(struct ltt_session));
52 if (!session)
53 return NULL;
54 CDS_INIT_LIST_HEAD(&session->chan);
55 CDS_INIT_LIST_HEAD(&session->events);
56 uuid_generate(session->uuid);
57 cds_list_add(&session->list, &sessions);
58 pthread_mutex_unlock(&sessions_mutex);
59 return session;
60 }
61
62 void ltt_session_destroy(struct ltt_session *session)
63 {
64 struct ltt_channel *chan, *tmpchan;
65 struct ltt_event *event, *tmpevent;
66 int ret;
67
68 pthread_mutex_lock(&sessions_mutex);
69 CMM_ACCESS_ONCE(session->active) = 0;
70 cds_list_for_each_entry(event, &session->events, list) {
71 ret = _ltt_event_unregister(event);
72 WARN_ON(ret);
73 }
74 synchronize_trace(); /* Wait for in-flight events to complete */
75 cds_list_for_each_entry_safe(event, tmpevent, &session->events, list)
76 _ltt_event_destroy(event);
77 cds_list_for_each_entry_safe(chan, tmpchan, &session->chan, list)
78 _ltt_channel_destroy(chan);
79 cds_list_del(&session->list);
80 pthread_mutex_unlock(&sessions_mutex);
81 free(session);
82 }
83
84 int ltt_session_enable(struct ltt_session *session)
85 {
86 int ret = 0;
87 struct ltt_channel *chan;
88
89 pthread_mutex_lock(&sessions_mutex);
90 if (session->active) {
91 ret = -EBUSY;
92 goto end;
93 }
94
95 /*
96 * Snapshot the number of events per channel to know the type of header
97 * we need to use.
98 */
99 cds_list_for_each_entry(chan, &session->chan, list) {
100 if (chan->header_type)
101 continue; /* don't change it if session stop/restart */
102 if (chan->free_event_id < 31)
103 chan->header_type = 1; /* compact */
104 else
105 chan->header_type = 2; /* large */
106 }
107
108 CMM_ACCESS_ONCE(session->active) = 1;
109 CMM_ACCESS_ONCE(session->been_active) = 1;
110 ret = _ltt_session_metadata_statedump(session);
111 if (ret)
112 CMM_ACCESS_ONCE(session->active) = 0;
113 end:
114 pthread_mutex_unlock(&sessions_mutex);
115 return ret;
116 }
117
118 int ltt_session_disable(struct ltt_session *session)
119 {
120 int ret = 0;
121
122 pthread_mutex_lock(&sessions_mutex);
123 if (!session->active) {
124 ret = -EBUSY;
125 goto end;
126 }
127 CMM_ACCESS_ONCE(session->active) = 0;
128 end:
129 pthread_mutex_unlock(&sessions_mutex);
130 return ret;
131 }
132
133 int ltt_channel_enable(struct ltt_channel *channel)
134 {
135 int old;
136
137 if (channel == channel->session->metadata)
138 return -EPERM;
139 old = uatomic_xchg(&channel->enabled, 1);
140 if (old)
141 return -EEXIST;
142 return 0;
143 }
144
145 int ltt_channel_disable(struct ltt_channel *channel)
146 {
147 int old;
148
149 if (channel == channel->session->metadata)
150 return -EPERM;
151 old = uatomic_xchg(&channel->enabled, 0);
152 if (!old)
153 return -EEXIST;
154 return 0;
155 }
156
157 int ltt_event_enable(struct ltt_event *event)
158 {
159 int old;
160
161 if (event->chan == event->chan->session->metadata)
162 return -EPERM;
163 old = uatomic_xchg(&event->enabled, 1);
164 if (old)
165 return -EEXIST;
166 return 0;
167 }
168
169 int ltt_event_disable(struct ltt_event *event)
170 {
171 int old;
172
173 if (event->chan == event->chan->session->metadata)
174 return -EPERM;
175 old = uatomic_xchg(&event->enabled, 0);
176 if (!old)
177 return -EEXIST;
178 return 0;
179 }
180
181 static struct ltt_transport *ltt_transport_find(const char *name)
182 {
183 struct ltt_transport *transport;
184
185 cds_list_for_each_entry(transport, &ltt_transport_list, node) {
186 if (!strcmp(transport->name, name))
187 return transport;
188 }
189 return NULL;
190 }
191
192 struct ltt_channel *ltt_channel_create(struct ltt_session *session,
193 const char *transport_name,
194 void *buf_addr,
195 size_t subbuf_size, size_t num_subbuf,
196 unsigned int switch_timer_interval,
197 unsigned int read_timer_interval,
198 int *shmid)
199 {
200 struct ltt_channel *chan;
201 struct ltt_transport *transport;
202
203 pthread_mutex_lock(&sessions_mutex);
204 if (session->been_active)
205 goto active; /* Refuse to add channel to active session */
206 transport = ltt_transport_find(transport_name);
207 if (!transport) {
208 DBG("LTTng transport %s not found\n",
209 transport_name);
210 goto notransport;
211 }
212 chan = zmalloc(sizeof(struct ltt_channel));
213 if (!chan)
214 goto nomem;
215 chan->session = session;
216 chan->id = session->free_chan_id++;
217 /*
218 * Note: the channel creation op already writes into the packet
219 * headers. Therefore the "chan" information used as input
220 * should be already accessible.
221 */
222 chan->chan = transport->ops.channel_create("[lttng]", chan, buf_addr,
223 subbuf_size, num_subbuf, switch_timer_interval,
224 read_timer_interval, shmid);
225 if (!chan->chan)
226 goto create_error;
227 chan->enabled = 1;
228 chan->ops = &transport->ops;
229 cds_list_add(&chan->list, &session->chan);
230 pthread_mutex_unlock(&sessions_mutex);
231 return chan;
232
233 create_error:
234 free(chan);
235 nomem:
236 notransport:
237 active:
238 pthread_mutex_unlock(&sessions_mutex);
239 return NULL;
240 }
241
242 /*
243 * Only used internally at session destruction.
244 */
245 static
246 void _ltt_channel_destroy(struct ltt_channel *chan)
247 {
248 chan->ops->channel_destroy(chan->chan);
249 cds_list_del(&chan->list);
250 lttng_destroy_context(chan->ctx);
251 free(chan);
252 }
253
254 /*
255 * Supports event creation while tracing session is active.
256 */
257 struct ltt_event *ltt_event_create(struct ltt_channel *chan,
258 struct lttng_ust_event *event_param,
259 void *filter)
260 {
261 struct ltt_event *event;
262 int ret;
263
264 pthread_mutex_lock(&sessions_mutex);
265 if (chan->free_event_id == -1UL)
266 goto full;
267 /*
268 * This is O(n^2) (for each event, the loop is called at event
269 * creation). Might require a hash if we have lots of events.
270 */
271 cds_list_for_each_entry(event, &chan->session->events, list)
272 if (!strcmp(event->desc->name, event_param->name))
273 goto exist;
274 event = zmalloc(sizeof(struct ltt_event));
275 if (!event)
276 goto cache_error;
277 event->chan = chan;
278 event->filter = filter;
279 event->id = chan->free_event_id++;
280 event->enabled = 1;
281 event->instrumentation = event_param->instrumentation;
282 /* Populate ltt_event structure before tracepoint registration. */
283 cmm_smp_wmb();
284 switch (event_param->instrumentation) {
285 case LTTNG_UST_TRACEPOINT:
286 event->desc = ltt_event_get(event_param->name);
287 if (!event->desc)
288 goto register_error;
289 ret = __tracepoint_probe_register(event_param->name,
290 event->desc->probe_callback,
291 event);
292 if (ret)
293 goto register_error;
294 break;
295 default:
296 WARN_ON_ONCE(1);
297 }
298 ret = _ltt_event_metadata_statedump(chan->session, chan, event);
299 if (ret)
300 goto statedump_error;
301 cds_list_add(&event->list, &chan->session->events);
302 pthread_mutex_unlock(&sessions_mutex);
303 return event;
304
305 statedump_error:
306 WARN_ON_ONCE(__tracepoint_probe_unregister(event_param->name,
307 event->desc->probe_callback,
308 event));
309 ltt_event_put(event->desc);
310 register_error:
311 free(event);
312 cache_error:
313 exist:
314 full:
315 pthread_mutex_unlock(&sessions_mutex);
316 return NULL;
317 }
318
319 /*
320 * Only used internally at session destruction.
321 */
322 int _ltt_event_unregister(struct ltt_event *event)
323 {
324 int ret = -EINVAL;
325
326 switch (event->instrumentation) {
327 case LTTNG_UST_TRACEPOINT:
328 ret = __tracepoint_probe_unregister(event->desc->name,
329 event->desc->probe_callback,
330 event);
331 if (ret)
332 return ret;
333 break;
334 default:
335 WARN_ON_ONCE(1);
336 }
337 return ret;
338 }
339
340 /*
341 * Only used internally at session destruction.
342 */
343 static
344 void _ltt_event_destroy(struct ltt_event *event)
345 {
346 switch (event->instrumentation) {
347 case LTTNG_UST_TRACEPOINT:
348 ltt_event_put(event->desc);
349 break;
350 default:
351 WARN_ON_ONCE(1);
352 }
353 cds_list_del(&event->list);
354 lttng_destroy_context(event->ctx);
355 free(event);
356 }
357
358 /*
359 * We have exclusive access to our metadata buffer (protected by the
360 * sessions_mutex), so we can do racy operations such as looking for
361 * remaining space left in packet and write, since mutual exclusion
362 * protects us from concurrent writes.
363 */
364 int lttng_metadata_printf(struct ltt_session *session,
365 const char *fmt, ...)
366 {
367 struct lib_ring_buffer_ctx ctx;
368 struct ltt_channel *chan = session->metadata;
369 char *str = NULL;
370 int ret = 0, waitret;
371 size_t len, reserve_len, pos;
372 va_list ap;
373
374 WARN_ON_ONCE(!CMM_ACCESS_ONCE(session->active));
375
376 va_start(ap, fmt);
377 ret = vasprintf(&str, fmt, ap);
378 va_end(ap);
379 if (ret < 0)
380 return -ENOMEM;
381
382 len = strlen(str);
383 pos = 0;
384
385 for (pos = 0; pos < len; pos += reserve_len) {
386 reserve_len = min_t(size_t,
387 chan->ops->packet_avail_size(chan->chan),
388 len - pos);
389 lib_ring_buffer_ctx_init(&ctx, chan->chan, NULL, reserve_len,
390 sizeof(char), -1);
391 /*
392 * We don't care about metadata buffer's records lost
393 * count, because we always retry here. Report error if
394 * we need to bail out after timeout or being
395 * interrupted.
396 */
397 waitret = wait_cond_interruptible_timeout(
398 ({
399 ret = chan->ops->event_reserve(&ctx, 0);
400 ret != -ENOBUFS || !ret;
401 }),
402 LTTNG_METADATA_TIMEOUT_MSEC);
403 if (!waitret || waitret == -EINTR || ret) {
404 DBG("LTTng: Failure to write metadata to buffers (%s)\n",
405 waitret == -EINTR ? "interrupted" :
406 (ret == -ENOBUFS ? "timeout" : "I/O error"));
407 if (waitret == -EINTR)
408 ret = waitret;
409 goto end;
410 }
411 chan->ops->event_write(&ctx, &str[pos], reserve_len);
412 chan->ops->event_commit(&ctx);
413 }
414 end:
415 free(str);
416 return ret;
417 }
418
419 static
420 int _ltt_field_statedump(struct ltt_session *session,
421 const struct lttng_event_field *field)
422 {
423 int ret = 0;
424
425 switch (field->type.atype) {
426 case atype_integer:
427 ret = lttng_metadata_printf(session,
428 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } %s;\n",
429 field->type.u.basic.integer.size,
430 field->type.u.basic.integer.alignment,
431 field->type.u.basic.integer.signedness,
432 (field->type.u.basic.integer.encoding == lttng_encode_none)
433 ? "none"
434 : (field->type.u.basic.integer.encoding == lttng_encode_UTF8)
435 ? "UTF8"
436 : "ASCII",
437 field->type.u.basic.integer.base,
438 #ifdef __BIG_ENDIAN
439 field->type.u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
440 #else
441 field->type.u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
442 #endif
443 field->name);
444 break;
445 case atype_float:
446 ret = lttng_metadata_printf(session,
447 " floating_point { exp_dig = %u; mant_dig = %u; align = %u; } %s;\n",
448 field->type.u.basic._float.exp_dig,
449 field->type.u.basic._float.mant_dig,
450 field->type.u.basic._float.alignment,
451 #ifdef __BIG_ENDIAN
452 field->type.u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
453 #else
454 field->type.u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
455 #endif
456 field->name);
457 break;
458 case atype_enum:
459 ret = lttng_metadata_printf(session,
460 " %s %s;\n",
461 field->type.u.basic.enumeration.name,
462 field->name);
463 break;
464 case atype_array:
465 {
466 const struct lttng_basic_type *elem_type;
467
468 elem_type = &field->type.u.array.elem_type;
469 ret = lttng_metadata_printf(session,
470 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } %s[%u];\n",
471 elem_type->u.basic.integer.size,
472 elem_type->u.basic.integer.alignment,
473 elem_type->u.basic.integer.signedness,
474 (elem_type->u.basic.integer.encoding == lttng_encode_none)
475 ? "none"
476 : (elem_type->u.basic.integer.encoding == lttng_encode_UTF8)
477 ? "UTF8"
478 : "ASCII",
479 elem_type->u.basic.integer.base,
480 #ifdef __BIG_ENDIAN
481 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
482 #else
483 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
484 #endif
485 field->name, field->type.u.array.length);
486 break;
487 }
488 case atype_sequence:
489 {
490 const struct lttng_basic_type *elem_type;
491 const struct lttng_basic_type *length_type;
492
493 elem_type = &field->type.u.sequence.elem_type;
494 length_type = &field->type.u.sequence.length_type;
495 ret = lttng_metadata_printf(session,
496 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n",
497 length_type->u.basic.integer.size,
498 (unsigned int) length_type->u.basic.integer.alignment,
499 length_type->u.basic.integer.signedness,
500 (length_type->u.basic.integer.encoding == lttng_encode_none)
501 ? "none"
502 : ((length_type->u.basic.integer.encoding == lttng_encode_UTF8)
503 ? "UTF8"
504 : "ASCII"),
505 length_type->u.basic.integer.base,
506 #ifdef __BIG_ENDIAN
507 length_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
508 #else
509 length_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
510 #endif
511 field->name);
512 if (ret)
513 return ret;
514
515 ret = lttng_metadata_printf(session,
516 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } %s[ __%s_length ];\n",
517 elem_type->u.basic.integer.size,
518 (unsigned int) elem_type->u.basic.integer.alignment,
519 elem_type->u.basic.integer.signedness,
520 (elem_type->u.basic.integer.encoding == lttng_encode_none)
521 ? "none"
522 : ((elem_type->u.basic.integer.encoding == lttng_encode_UTF8)
523 ? "UTF8"
524 : "ASCII"),
525 elem_type->u.basic.integer.base,
526 #ifdef __BIG_ENDIAN
527 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
528 #else
529 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
530 #endif
531 field->name,
532 field->name);
533 break;
534 }
535
536 case atype_string:
537 /* Default encoding is UTF8 */
538 ret = lttng_metadata_printf(session,
539 " string%s %s;\n",
540 field->type.u.basic.string.encoding == lttng_encode_ASCII ?
541 " { encoding = ASCII; }" : "",
542 field->name);
543 break;
544 default:
545 WARN_ON_ONCE(1);
546 return -EINVAL;
547 }
548 return ret;
549 }
550
551 static
552 int _ltt_context_metadata_statedump(struct ltt_session *session,
553 struct lttng_ctx *ctx)
554 {
555 int ret = 0;
556 int i;
557
558 if (!ctx)
559 return 0;
560 for (i = 0; i < ctx->nr_fields; i++) {
561 const struct lttng_ctx_field *field = &ctx->fields[i];
562
563 ret = _ltt_field_statedump(session, &field->event_field);
564 if (ret)
565 return ret;
566 }
567 return ret;
568 }
569
570 static
571 int _ltt_fields_metadata_statedump(struct ltt_session *session,
572 struct ltt_event *event)
573 {
574 const struct lttng_event_desc *desc = event->desc;
575 int ret = 0;
576 int i;
577
578 for (i = 0; i < desc->nr_fields; i++) {
579 const struct lttng_event_field *field = &desc->fields[i];
580
581 ret = _ltt_field_statedump(session, field);
582 if (ret)
583 return ret;
584 }
585 return ret;
586 }
587
588 static
589 int _ltt_event_metadata_statedump(struct ltt_session *session,
590 struct ltt_channel *chan,
591 struct ltt_event *event)
592 {
593 int ret = 0;
594
595 if (event->metadata_dumped || !CMM_ACCESS_ONCE(session->active))
596 return 0;
597 if (chan == session->metadata)
598 return 0;
599
600 ret = lttng_metadata_printf(session,
601 "event {\n"
602 " name = %s;\n"
603 " id = %u;\n"
604 " stream_id = %u;\n",
605 event->desc->name,
606 event->id,
607 event->chan->id);
608 if (ret)
609 goto end;
610
611 if (event->ctx) {
612 ret = lttng_metadata_printf(session,
613 " context := struct {\n");
614 if (ret)
615 goto end;
616 }
617 ret = _ltt_context_metadata_statedump(session, event->ctx);
618 if (ret)
619 goto end;
620 if (event->ctx) {
621 ret = lttng_metadata_printf(session,
622 " };\n");
623 if (ret)
624 goto end;
625 }
626
627 ret = lttng_metadata_printf(session,
628 " fields := struct {\n"
629 );
630 if (ret)
631 goto end;
632
633 ret = _ltt_fields_metadata_statedump(session, event);
634 if (ret)
635 goto end;
636
637 /*
638 * LTTng space reservation can only reserve multiples of the
639 * byte size.
640 */
641 ret = lttng_metadata_printf(session,
642 " };\n"
643 "};\n\n");
644 if (ret)
645 goto end;
646
647 event->metadata_dumped = 1;
648 end:
649 return ret;
650
651 }
652
653 static
654 int _ltt_channel_metadata_statedump(struct ltt_session *session,
655 struct ltt_channel *chan)
656 {
657 int ret = 0;
658
659 if (chan->metadata_dumped || !CMM_ACCESS_ONCE(session->active))
660 return 0;
661 if (chan == session->metadata)
662 return 0;
663
664 WARN_ON_ONCE(!chan->header_type);
665 ret = lttng_metadata_printf(session,
666 "stream {\n"
667 " id = %u;\n"
668 " event.header := %s;\n"
669 " packet.context := struct packet_context;\n",
670 chan->id,
671 chan->header_type == 1 ? "struct event_header_compact" :
672 "struct event_header_large");
673 if (ret)
674 goto end;
675
676 if (chan->ctx) {
677 ret = lttng_metadata_printf(session,
678 " event.context := struct {\n");
679 if (ret)
680 goto end;
681 }
682 ret = _ltt_context_metadata_statedump(session, chan->ctx);
683 if (ret)
684 goto end;
685 if (chan->ctx) {
686 ret = lttng_metadata_printf(session,
687 " };\n");
688 if (ret)
689 goto end;
690 }
691
692 ret = lttng_metadata_printf(session,
693 "};\n\n");
694
695 chan->metadata_dumped = 1;
696 end:
697 return ret;
698 }
699
700 static
701 int _ltt_stream_packet_context_declare(struct ltt_session *session)
702 {
703 return lttng_metadata_printf(session,
704 "struct packet_context {\n"
705 " uint64_t timestamp_begin;\n"
706 " uint64_t timestamp_end;\n"
707 " uint32_t events_discarded;\n"
708 " uint32_t content_size;\n"
709 " uint32_t packet_size;\n"
710 " uint32_t cpu_id;\n"
711 "};\n\n"
712 );
713 }
714
715 /*
716 * Compact header:
717 * id: range: 0 - 30.
718 * id 31 is reserved to indicate an extended header.
719 *
720 * Large header:
721 * id: range: 0 - 65534.
722 * id 65535 is reserved to indicate an extended header.
723 */
724 static
725 int _ltt_event_header_declare(struct ltt_session *session)
726 {
727 return lttng_metadata_printf(session,
728 "struct event_header_compact {\n"
729 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
730 " variant <id> {\n"
731 " struct {\n"
732 " uint27_t timestamp;\n"
733 " } compact;\n"
734 " struct {\n"
735 " uint32_t id;\n"
736 " uint64_t timestamp;\n"
737 " } extended;\n"
738 " } v;\n"
739 "} align(%u);\n"
740 "\n"
741 "struct event_header_large {\n"
742 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
743 " variant <id> {\n"
744 " struct {\n"
745 " uint32_t timestamp;\n"
746 " } compact;\n"
747 " struct {\n"
748 " uint32_t id;\n"
749 " uint64_t timestamp;\n"
750 " } extended;\n"
751 " } v;\n"
752 "} align(%u);\n\n",
753 ltt_alignof(uint32_t) * CHAR_BIT,
754 ltt_alignof(uint16_t) * CHAR_BIT
755 );
756 }
757
758 /*
759 * Output metadata into this session's metadata buffers.
760 */
761 static
762 int _ltt_session_metadata_statedump(struct ltt_session *session)
763 {
764 unsigned char *uuid_c = session->uuid;
765 char uuid_s[37];
766 struct ltt_channel *chan;
767 struct ltt_event *event;
768 int ret = 0;
769
770 if (!CMM_ACCESS_ONCE(session->active))
771 return 0;
772 if (session->metadata_dumped)
773 goto skip_session;
774 if (!session->metadata) {
775 DBG("LTTng: attempt to start tracing, but metadata channel is not found. Operation abort.\n");
776 return -EPERM;
777 }
778
779 snprintf(uuid_s, sizeof(uuid_s),
780 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
781 uuid_c[0], uuid_c[1], uuid_c[2], uuid_c[3],
782 uuid_c[4], uuid_c[5], uuid_c[6], uuid_c[7],
783 uuid_c[8], uuid_c[9], uuid_c[10], uuid_c[11],
784 uuid_c[12], uuid_c[13], uuid_c[14], uuid_c[15]);
785
786 ret = lttng_metadata_printf(session,
787 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
788 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
789 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
790 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
791 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
792 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
793 "\n"
794 "trace {\n"
795 " major = %u;\n"
796 " minor = %u;\n"
797 " uuid = \"%s\";\n"
798 " byte_order = %s;\n"
799 " packet.header := struct {\n"
800 " uint32_t magic;\n"
801 " uint8_t uuid[16];\n"
802 " uint32_t stream_id;\n"
803 " };\n"
804 "};\n\n",
805 ltt_alignof(uint8_t) * CHAR_BIT,
806 ltt_alignof(uint16_t) * CHAR_BIT,
807 ltt_alignof(uint32_t) * CHAR_BIT,
808 ltt_alignof(uint64_t) * CHAR_BIT,
809 CTF_VERSION_MAJOR,
810 CTF_VERSION_MINOR,
811 uuid_s,
812 #ifdef __BIG_ENDIAN
813 "be"
814 #else
815 "le"
816 #endif
817 );
818 if (ret)
819 goto end;
820
821 ret = _ltt_stream_packet_context_declare(session);
822 if (ret)
823 goto end;
824
825 ret = _ltt_event_header_declare(session);
826 if (ret)
827 goto end;
828
829 skip_session:
830 cds_list_for_each_entry(chan, &session->chan, list) {
831 ret = _ltt_channel_metadata_statedump(session, chan);
832 if (ret)
833 goto end;
834 }
835
836 cds_list_for_each_entry(event, &session->events, list) {
837 ret = _ltt_event_metadata_statedump(session, event->chan, event);
838 if (ret)
839 goto end;
840 }
841 session->metadata_dumped = 1;
842 end:
843 return ret;
844 }
845
846 /**
847 * ltt_transport_register - LTT transport registration
848 * @transport: transport structure
849 *
850 * Registers a transport which can be used as output to extract the data out of
851 * LTTng.
852 */
853 void ltt_transport_register(struct ltt_transport *transport)
854 {
855 pthread_mutex_lock(&sessions_mutex);
856 cds_list_add_tail(&transport->node, &ltt_transport_list);
857 pthread_mutex_unlock(&sessions_mutex);
858 }
859
860 /**
861 * ltt_transport_unregister - LTT transport unregistration
862 * @transport: transport structure
863 */
864 void ltt_transport_unregister(struct ltt_transport *transport)
865 {
866 pthread_mutex_lock(&sessions_mutex);
867 cds_list_del(&transport->node);
868 pthread_mutex_unlock(&sessions_mutex);
869 }
870
871 static
872 void __attribute__((destructor)) ltt_events_exit(void)
873 {
874 struct ltt_session *session, *tmpsession;
875
876 cds_list_for_each_entry_safe(session, tmpsession, &sessions, list)
877 ltt_session_destroy(session);
878 }
This page took 0.075101 seconds and 4 git commands to generate.