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