2 * Copyright (C) 2010-2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
16 #include <common/common.h>
17 #include <common/time.h>
19 #include "ust-registry.h"
20 #include "ust-clock.h"
24 #define max_t(type, a, b) ((type) ((a) > (b) ? (a) : (b)))
27 #define NR_CLOCK_OFFSET_SAMPLES 10
29 struct offset_sample
{
30 int64_t offset
; /* correlation offset */
31 uint64_t measure_delta
; /* lower is better */
35 int _lttng_field_statedump(struct ust_registry_session
*session
,
36 const struct ustctl_field
*fields
, size_t nr_fields
,
37 size_t *iter_field
, size_t nesting
);
40 int get_count_order(unsigned int count
)
44 order
= lttng_fls(count
) - 1;
45 if (count
& (count
- 1)) {
53 * Returns offset where to write in metadata array, or negative error value on error.
56 ssize_t
metadata_reserve(struct ust_registry_session
*session
, size_t len
)
58 size_t new_len
= session
->metadata_len
+ len
;
59 size_t new_alloc_len
= new_len
;
60 size_t old_alloc_len
= session
->metadata_alloc_len
;
63 if (new_alloc_len
> (UINT32_MAX
>> 1))
65 if ((old_alloc_len
<< 1) > (UINT32_MAX
>> 1))
68 if (new_alloc_len
> old_alloc_len
) {
72 max_t(size_t, 1U << get_count_order(new_alloc_len
), old_alloc_len
<< 1);
73 newptr
= realloc(session
->metadata
, new_alloc_len
);
76 session
->metadata
= newptr
;
77 /* We zero directly the memory from start of allocation. */
78 memset(&session
->metadata
[old_alloc_len
], 0, new_alloc_len
- old_alloc_len
);
79 session
->metadata_alloc_len
= new_alloc_len
;
81 ret
= session
->metadata_len
;
82 session
->metadata_len
+= len
;
87 int metadata_file_append(struct ust_registry_session
*session
,
88 const char *str
, size_t len
)
92 if (session
->metadata_fd
< 0) {
95 /* Write to metadata file */
96 written
= lttng_write(session
->metadata_fd
, str
, len
);
104 * We have exclusive access to our metadata buffer (protected by the
105 * ust_lock), so we can do racy operations such as looking for
106 * remaining space left in packet and write, since mutual exclusion
107 * protects us from concurrent writes.
110 int lttng_metadata_printf(struct ust_registry_session
*session
,
111 const char *fmt
, ...)
120 ret
= vasprintf(&str
, fmt
, ap
);
126 offset
= metadata_reserve(session
, len
);
131 memcpy(&session
->metadata
[offset
], str
, len
);
132 ret
= metadata_file_append(session
, str
, len
);
134 PERROR("Error appending to metadata file");
137 DBG3("Append to metadata: \"%s\"", str
);
146 int print_tabs(struct ust_registry_session
*session
, size_t nesting
)
150 for (i
= 0; i
< nesting
; i
++) {
153 ret
= lttng_metadata_printf(session
, " ");
162 void sanitize_ctf_identifier(char *out
, const char *in
)
166 for (i
= 0; i
< LTTNG_UST_ABI_SYM_NAME_LEN
; i
++) {
180 int print_escaped_ctf_string(struct ust_registry_session
*session
, const char *string
)
188 while (cur
!= '\0') {
191 ret
= lttng_metadata_printf(session
, "%s", "\\n");
195 ret
= lttng_metadata_printf(session
, "%c", '\\');
199 /* We still print the current char */
202 ret
= lttng_metadata_printf(session
, "%c", cur
);
216 /* Called with session registry mutex held. */
218 int ust_metadata_enum_statedump(struct ust_registry_session
*session
,
219 const char *enum_name
,
221 const struct ustctl_integer_type
*container_type
,
222 const char *field_name
, size_t *iter_field
, size_t nesting
)
224 struct ust_registry_enum
*reg_enum
;
225 const struct ustctl_enum_entry
*entries
;
229 char identifier
[LTTNG_UST_ABI_SYM_NAME_LEN
];
232 reg_enum
= ust_registry_lookup_enum_by_id(session
, enum_name
, enum_id
);
234 /* reg_enum can still be used because session registry mutex is held. */
239 entries
= reg_enum
->entries
;
240 nr_entries
= reg_enum
->nr_entries
;
242 ret
= print_tabs(session
, nesting
);
246 ret
= lttng_metadata_printf(session
,
247 "enum : integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u; } {\n",
248 container_type
->size
,
249 container_type
->alignment
,
250 container_type
->signedness
,
251 (container_type
->encoding
== ustctl_encode_none
)
253 : (container_type
->encoding
== ustctl_encode_UTF8
)
256 container_type
->base
);
261 /* Dump all entries */
262 for (i
= 0; i
< nr_entries
; i
++) {
263 const struct ustctl_enum_entry
*entry
= &entries
[i
];
266 ret
= print_tabs(session
, nesting
);
270 ret
= lttng_metadata_printf(session
,
275 len
= strlen(entry
->string
);
276 /* Escape the character '"' */
277 for (j
= 0; j
< len
; j
++) {
278 char c
= entry
->string
[j
];
282 ret
= lttng_metadata_printf(session
,
286 ret
= lttng_metadata_printf(session
,
290 ret
= lttng_metadata_printf(session
,
298 ret
= lttng_metadata_printf(session
, "\"");
303 if (entry
->u
.extra
.options
&
304 USTCTL_UST_ENUM_ENTRY_OPTION_IS_AUTO
) {
305 ret
= lttng_metadata_printf(session
, ",\n");
310 ret
= lttng_metadata_printf(session
,
316 if (entry
->start
.signedness
) {
317 ret
= lttng_metadata_printf(session
,
318 "%lld", (long long) entry
->start
.value
);
320 ret
= lttng_metadata_printf(session
,
321 "%llu", entry
->start
.value
);
327 if (entry
->start
.signedness
== entry
->end
.signedness
&&
328 entry
->start
.value
==
330 ret
= lttng_metadata_printf(session
, ",\n");
332 if (entry
->end
.signedness
) {
333 ret
= lttng_metadata_printf(session
,
335 (long long) entry
->end
.value
);
337 ret
= lttng_metadata_printf(session
,
348 sanitize_ctf_identifier(identifier
, field_name
);
349 ret
= print_tabs(session
, nesting
);
353 ret
= lttng_metadata_printf(session
, "} _%s;\n",
361 int _lttng_variant_statedump(struct ust_registry_session
*session
,
362 uint32_t nr_choices
, const char *tag_name
,
364 const struct ustctl_field
*fields
, size_t nr_fields
,
365 size_t *iter_field
, size_t nesting
)
367 const struct ustctl_field
*variant
= &fields
[*iter_field
];
370 char identifier
[LTTNG_UST_ABI_SYM_NAME_LEN
];
372 if (variant
->type
.atype
!= ustctl_atype_variant
) {
377 sanitize_ctf_identifier(identifier
, tag_name
);
379 ret
= print_tabs(session
, nesting
);
383 ret
= lttng_metadata_printf(session
,
384 "struct { } align(%u) _%s_padding;\n",
385 alignment
* CHAR_BIT
,
391 ret
= print_tabs(session
, nesting
);
395 ret
= lttng_metadata_printf(session
,
402 for (i
= 0; i
< nr_choices
; i
++) {
403 if (*iter_field
>= nr_fields
) {
407 ret
= _lttng_field_statedump(session
,
409 iter_field
, nesting
+ 1);
414 sanitize_ctf_identifier(identifier
, variant
->name
);
415 ret
= print_tabs(session
, nesting
);
419 ret
= lttng_metadata_printf(session
,
430 int _lttng_field_statedump(struct ust_registry_session
*session
,
431 const struct ustctl_field
*fields
, size_t nr_fields
,
432 size_t *iter_field
, size_t nesting
)
435 const char *bo_be
= " byte_order = be;";
436 const char *bo_le
= " byte_order = le;";
437 const char *bo_native
= "";
438 const char *bo_reverse
;
439 const struct ustctl_field
*field
;
441 if (*iter_field
>= nr_fields
) {
445 field
= &fields
[*iter_field
];
447 if (session
->byte_order
== BIG_ENDIAN
) {
453 switch (field
->type
.atype
) {
454 case ustctl_atype_integer
:
455 ret
= print_tabs(session
, nesting
);
459 ret
= lttng_metadata_printf(session
,
460 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n",
461 field
->type
.u
.integer
.size
,
462 field
->type
.u
.integer
.alignment
,
463 field
->type
.u
.integer
.signedness
,
464 (field
->type
.u
.integer
.encoding
== ustctl_encode_none
)
466 : (field
->type
.u
.integer
.encoding
== ustctl_encode_UTF8
)
469 field
->type
.u
.integer
.base
,
470 field
->type
.u
.integer
.reverse_byte_order
? bo_reverse
: bo_native
,
474 case ustctl_atype_enum
:
475 ret
= ust_metadata_enum_statedump(session
,
476 field
->type
.u
.legacy
.basic
.enumeration
.name
,
477 field
->type
.u
.legacy
.basic
.enumeration
.id
,
478 &field
->type
.u
.legacy
.basic
.enumeration
.container_type
,
479 field
->name
, iter_field
, nesting
);
481 case ustctl_atype_float
:
482 ret
= print_tabs(session
, nesting
);
486 ret
= lttng_metadata_printf(session
,
487 "floating_point { exp_dig = %u; mant_dig = %u; align = %u;%s } _%s;\n",
488 field
->type
.u
._float
.exp_dig
,
489 field
->type
.u
._float
.mant_dig
,
490 field
->type
.u
._float
.alignment
,
491 field
->type
.u
._float
.reverse_byte_order
? bo_reverse
: bo_native
,
495 case ustctl_atype_array
:
497 const struct ustctl_basic_type
*elem_type
;
499 ret
= print_tabs(session
, nesting
);
503 elem_type
= &field
->type
.u
.legacy
.array
.elem_type
;
504 /* Only integers are currently supported in arrays. */
505 if (elem_type
->atype
!= ustctl_atype_integer
) {
509 ret
= lttng_metadata_printf(session
,
510 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
511 elem_type
->u
.basic
.integer
.size
,
512 elem_type
->u
.basic
.integer
.alignment
,
513 elem_type
->u
.basic
.integer
.signedness
,
514 (elem_type
->u
.basic
.integer
.encoding
== ustctl_encode_none
)
516 : (elem_type
->u
.basic
.integer
.encoding
== ustctl_encode_UTF8
)
519 elem_type
->u
.basic
.integer
.base
,
520 elem_type
->u
.basic
.integer
.reverse_byte_order
? bo_reverse
: bo_native
,
521 field
->name
, field
->type
.u
.legacy
.array
.length
);
525 case ustctl_atype_array_nestable
:
527 uint32_t array_length
;
528 const struct ustctl_field
*array_nestable
;
529 const struct ustctl_type
*elem_type
;
531 array_length
= field
->type
.u
.array_nestable
.length
;
534 if (*iter_field
>= nr_fields
) {
538 array_nestable
= &fields
[*iter_field
];
539 elem_type
= &array_nestable
->type
;
541 /* Only integers are currently supported in arrays. */
542 if (elem_type
->atype
!= ustctl_atype_integer
) {
547 if (field
->type
.u
.array_nestable
.alignment
) {
548 ret
= print_tabs(session
, nesting
);
552 ret
= lttng_metadata_printf(session
,
553 "struct { } align(%u) _%s_padding;\n",
554 field
->type
.u
.array_nestable
.alignment
* CHAR_BIT
,
561 ret
= print_tabs(session
, nesting
);
565 ret
= lttng_metadata_printf(session
,
566 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
567 elem_type
->u
.integer
.size
,
568 elem_type
->u
.integer
.alignment
,
569 elem_type
->u
.integer
.signedness
,
570 (elem_type
->u
.integer
.encoding
== ustctl_encode_none
)
572 : (elem_type
->u
.integer
.encoding
== ustctl_encode_UTF8
)
575 elem_type
->u
.integer
.base
,
576 elem_type
->u
.integer
.reverse_byte_order
? bo_reverse
: bo_native
,
577 field
->name
, array_length
);
581 case ustctl_atype_sequence
:
583 const struct ustctl_basic_type
*elem_type
;
584 const struct ustctl_basic_type
*length_type
;
586 elem_type
= &field
->type
.u
.legacy
.sequence
.elem_type
;
587 length_type
= &field
->type
.u
.legacy
.sequence
.length_type
;
588 ret
= print_tabs(session
, nesting
);
593 /* Only integers are currently supported in sequences. */
594 if (elem_type
->atype
!= ustctl_atype_integer
) {
599 ret
= lttng_metadata_printf(session
,
600 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n",
601 length_type
->u
.basic
.integer
.size
,
602 (unsigned int) length_type
->u
.basic
.integer
.alignment
,
603 length_type
->u
.basic
.integer
.signedness
,
604 (length_type
->u
.basic
.integer
.encoding
== ustctl_encode_none
)
606 : ((length_type
->u
.basic
.integer
.encoding
== ustctl_encode_UTF8
)
609 length_type
->u
.basic
.integer
.base
,
610 length_type
->u
.basic
.integer
.reverse_byte_order
? bo_reverse
: bo_native
,
616 ret
= print_tabs(session
, nesting
);
620 ret
= lttng_metadata_printf(session
,
621 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n",
622 elem_type
->u
.basic
.integer
.size
,
623 (unsigned int) elem_type
->u
.basic
.integer
.alignment
,
624 elem_type
->u
.basic
.integer
.signedness
,
625 (elem_type
->u
.basic
.integer
.encoding
== ustctl_encode_none
)
627 : ((elem_type
->u
.basic
.integer
.encoding
== ustctl_encode_UTF8
)
630 elem_type
->u
.basic
.integer
.base
,
631 elem_type
->u
.basic
.integer
.reverse_byte_order
? bo_reverse
: bo_native
,
637 case ustctl_atype_sequence_nestable
:
639 const struct ustctl_field
*sequence_nestable
;
640 const struct ustctl_type
*elem_type
;
643 if (*iter_field
>= nr_fields
) {
647 sequence_nestable
= &fields
[*iter_field
];
648 elem_type
= &sequence_nestable
->type
;
650 /* Only integers are currently supported in sequences. */
651 if (elem_type
->atype
!= ustctl_atype_integer
) {
656 if (field
->type
.u
.sequence_nestable
.alignment
) {
657 ret
= print_tabs(session
, nesting
);
661 ret
= lttng_metadata_printf(session
,
662 "struct { } align(%u) _%s_padding;\n",
663 field
->type
.u
.sequence_nestable
.alignment
* CHAR_BIT
,
670 ret
= print_tabs(session
, nesting
);
674 ret
= lttng_metadata_printf(session
,
675 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ _%s ];\n",
676 elem_type
->u
.integer
.size
,
677 (unsigned int) elem_type
->u
.integer
.alignment
,
678 elem_type
->u
.integer
.signedness
,
679 (elem_type
->u
.integer
.encoding
== ustctl_encode_none
)
681 : ((elem_type
->u
.integer
.encoding
== ustctl_encode_UTF8
)
684 elem_type
->u
.integer
.base
,
685 elem_type
->u
.integer
.reverse_byte_order
? bo_reverse
: bo_native
,
687 field
->type
.u
.sequence_nestable
.length_name
);
691 case ustctl_atype_string
:
692 /* Default encoding is UTF8 */
693 ret
= print_tabs(session
, nesting
);
697 ret
= lttng_metadata_printf(session
,
699 field
->type
.u
.string
.encoding
== ustctl_encode_ASCII
?
700 " { encoding = ASCII; }" : "",
704 case ustctl_atype_variant
:
705 ret
= _lttng_variant_statedump(session
,
706 field
->type
.u
.legacy
.variant
.nr_choices
,
707 field
->type
.u
.legacy
.variant
.tag_name
,
709 fields
, nr_fields
, iter_field
, nesting
);
714 case ustctl_atype_variant_nestable
:
715 ret
= _lttng_variant_statedump(session
,
716 field
->type
.u
.variant_nestable
.nr_choices
,
717 field
->type
.u
.variant_nestable
.tag_name
,
718 field
->type
.u
.variant_nestable
.alignment
,
719 fields
, nr_fields
, iter_field
, nesting
);
724 case ustctl_atype_struct
:
725 if (field
->type
.u
.legacy
._struct
.nr_fields
!= 0) {
726 /* Currently only 0-length structures are supported. */
730 ret
= print_tabs(session
, nesting
);
734 ret
= lttng_metadata_printf(session
,
739 case ustctl_atype_struct_nestable
:
740 if (field
->type
.u
.struct_nestable
.nr_fields
!= 0) {
741 /* Currently only 0-length structures are supported. */
745 ret
= print_tabs(session
, nesting
);
749 if (field
->type
.u
.struct_nestable
.alignment
) {
750 ret
= lttng_metadata_printf(session
,
751 "struct {} align(%u) _%s;\n",
752 field
->type
.u
.struct_nestable
.alignment
* CHAR_BIT
,
758 ret
= lttng_metadata_printf(session
,
764 case ustctl_atype_enum_nestable
:
766 const struct ustctl_field
*container_field
;
767 const struct ustctl_type
*container_type
;
770 if (*iter_field
>= nr_fields
) {
774 container_field
= &fields
[*iter_field
];
775 container_type
= &container_field
->type
;
777 /* Only integers are supported as container types. */
778 if (container_type
->atype
!= ustctl_atype_integer
) {
782 ret
= ust_metadata_enum_statedump(session
,
783 field
->type
.u
.enum_nestable
.name
,
784 field
->type
.u
.enum_nestable
.id
,
785 &container_type
->u
.integer
,
786 field
->name
, iter_field
, nesting
);
797 int _lttng_context_metadata_statedump(struct ust_registry_session
*session
,
798 size_t nr_ctx_fields
,
799 struct ustctl_field
*ctx
)
807 if (i
>= nr_ctx_fields
) {
810 ret
= _lttng_field_statedump(session
, ctx
,
811 nr_ctx_fields
, &i
, 2);
820 int _lttng_fields_metadata_statedump(struct ust_registry_session
*session
,
821 struct ust_registry_event
*event
)
827 if (i
>= event
->nr_fields
) {
830 ret
= _lttng_field_statedump(session
, event
->fields
,
831 event
->nr_fields
, &i
, 2);
840 * Should be called with session registry mutex held.
842 int ust_metadata_event_statedump(struct ust_registry_session
*session
,
843 struct ust_registry_channel
*chan
,
844 struct ust_registry_event
*event
)
848 /* Don't dump metadata events */
849 if (chan
->chan_id
== -1U)
852 ret
= lttng_metadata_printf(session
,
856 " stream_id = %u;\n",
864 ret
= lttng_metadata_printf(session
,
866 event
->loglevel_value
);
871 if (event
->model_emf_uri
) {
872 ret
= lttng_metadata_printf(session
,
873 " model.emf.uri = \"%s\";\n",
874 event
->model_emf_uri
);
880 ret
= lttng_metadata_printf(session
,
881 " fields := struct {\n"
887 ret
= _lttng_fields_metadata_statedump(session
, event
);
892 ret
= lttng_metadata_printf(session
,
898 event
->metadata_dumped
= 1;
905 * Should be called with session registry mutex held.
907 int ust_metadata_channel_statedump(struct ust_registry_session
*session
,
908 struct ust_registry_channel
*chan
)
912 /* Don't dump metadata events */
913 if (chan
->chan_id
== -1U)
916 if (!chan
->header_type
)
919 ret
= lttng_metadata_printf(session
,
922 " event.header := %s;\n"
923 " packet.context := struct packet_context;\n",
925 chan
->header_type
== USTCTL_CHANNEL_HEADER_COMPACT
?
926 "struct event_header_compact" :
927 "struct event_header_large");
932 if (chan
->ctx_fields
) {
933 ret
= lttng_metadata_printf(session
,
934 " event.context := struct {\n");
939 ret
= _lttng_context_metadata_statedump(session
,
945 if (chan
->ctx_fields
) {
946 ret
= lttng_metadata_printf(session
,
953 ret
= lttng_metadata_printf(session
,
955 /* Flag success of metadata dump. */
956 chan
->metadata_dumped
= 1;
963 int _lttng_stream_packet_context_declare(struct ust_registry_session
*session
)
965 return lttng_metadata_printf(session
,
966 "struct packet_context {\n"
967 " uint64_clock_monotonic_t timestamp_begin;\n"
968 " uint64_clock_monotonic_t timestamp_end;\n"
969 " uint64_t content_size;\n"
970 " uint64_t packet_size;\n"
971 " uint64_t packet_seq_num;\n"
972 " unsigned long events_discarded;\n"
973 " uint32_t cpu_id;\n"
981 * id 31 is reserved to indicate an extended header.
984 * id: range: 0 - 65534.
985 * id 65535 is reserved to indicate an extended header.
988 int _lttng_event_header_declare(struct ust_registry_session
*session
)
990 return lttng_metadata_printf(session
,
991 "struct event_header_compact {\n"
992 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
995 " uint27_clock_monotonic_t timestamp;\n"
999 " uint64_clock_monotonic_t timestamp;\n"
1004 "struct event_header_large {\n"
1005 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
1008 " uint32_clock_monotonic_t timestamp;\n"
1012 " uint64_clock_monotonic_t timestamp;\n"
1016 session
->uint32_t_alignment
,
1017 session
->uint16_t_alignment
1022 * The offset between monotonic and realtime clock can be negative if
1023 * the system sets the REALTIME clock to 0 after boot.
1026 int measure_single_clock_offset(struct offset_sample
*sample
)
1028 uint64_t monotonic_avg
, monotonic
[2], measure_delta
, realtime
;
1029 uint64_t tcf
= trace_clock_freq();
1030 struct timespec rts
= { 0, 0 };
1033 monotonic
[0] = trace_clock_read64();
1034 ret
= lttng_clock_gettime(CLOCK_REALTIME
, &rts
);
1038 monotonic
[1] = trace_clock_read64();
1039 measure_delta
= monotonic
[1] - monotonic
[0];
1040 if (measure_delta
> sample
->measure_delta
) {
1042 * Discard value if it took longer to read than the best
1047 monotonic_avg
= (monotonic
[0] + monotonic
[1]) >> 1;
1048 realtime
= (uint64_t) rts
.tv_sec
* tcf
;
1049 if (tcf
== NSEC_PER_SEC
) {
1050 realtime
+= rts
.tv_nsec
;
1052 realtime
+= (uint64_t) rts
.tv_nsec
* tcf
/ NSEC_PER_SEC
;
1054 sample
->offset
= (int64_t) realtime
- monotonic_avg
;
1055 sample
->measure_delta
= measure_delta
;
1060 * Approximation of NTP time of day to clock monotonic correlation,
1061 * taken at start of trace. Keep the measurement that took the less time
1062 * to complete, thus removing imprecision caused by preemption.
1063 * May return a negative offset.
1066 int64_t measure_clock_offset(void)
1069 struct offset_sample offset_best_sample
= {
1071 .measure_delta
= UINT64_MAX
,
1074 for (i
= 0; i
< NR_CLOCK_OFFSET_SAMPLES
; i
++) {
1075 if (measure_single_clock_offset(&offset_best_sample
)) {
1079 return offset_best_sample
.offset
;
1083 int print_metadata_session_information(struct ust_registry_session
*registry
)
1086 struct ltt_session
*session
= NULL
;
1087 char creation_datetime
[ISO8601_STR_LEN
];
1090 session
= session_find_by_id(registry
->tracing_id
);
1096 /* Print the trace name */
1097 ret
= lttng_metadata_printf(registry
, " trace_name = \"");
1103 * This is necessary since the creation time is present in the session
1104 * name when it is generated.
1106 if (session
->has_auto_generated_name
) {
1107 ret
= print_escaped_ctf_string(registry
, DEFAULT_SESSION_NAME
);
1109 ret
= print_escaped_ctf_string(registry
, session
->name
);
1115 ret
= lttng_metadata_printf(registry
, "\";\n");
1120 /* Prepare creation time */
1121 ret
= time_to_iso8601_str(session
->creation_time
, creation_datetime
,
1122 sizeof(creation_datetime
));
1127 /* Output the reste of the information */
1128 ret
= lttng_metadata_printf(registry
,
1129 " trace_creation_datetime = \"%s\";\n"
1130 " hostname = \"%s\";\n",
1131 creation_datetime
, session
->hostname
);
1138 session_put(session
);
1145 int print_metadata_app_information(struct ust_registry_session
*registry
,
1146 struct ust_app
*app
)
1149 char datetime
[ISO8601_STR_LEN
];
1156 ret
= time_to_iso8601_str(
1157 app
->registration_time
, datetime
, sizeof(datetime
));
1162 ret
= lttng_metadata_printf(registry
,
1163 " tracer_patchlevel = %u;\n"
1165 " procname = \"%s\";\n"
1166 " vpid_datetime = \"%s\";\n",
1167 app
->version
.patchlevel
, (int) app
->pid
, app
->name
,
1175 * Should be called with session registry mutex held.
1177 int ust_metadata_session_statedump(struct ust_registry_session
*session
,
1178 struct ust_app
*app
,
1182 char uuid_s
[LTTNG_UUID_STR_LEN
],
1183 clock_uuid_s
[LTTNG_UUID_STR_LEN
];
1188 lttng_uuid_to_str(session
->uuid
, uuid_s
);
1191 ret
= lttng_metadata_printf(session
,
1192 "/* CTF %u.%u */\n\n",
1199 ret
= lttng_metadata_printf(session
,
1200 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
1201 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
1202 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
1203 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
1204 "typealias integer { size = %u; align = %u; signed = false; } := unsigned long;\n"
1205 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
1206 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
1212 " byte_order = %s;\n"
1213 " packet.header := struct {\n"
1214 " uint32_t magic;\n"
1215 " uint8_t uuid[16];\n"
1216 " uint32_t stream_id;\n"
1217 " uint64_t stream_instance_id;\n"
1220 session
->uint8_t_alignment
,
1221 session
->uint16_t_alignment
,
1222 session
->uint32_t_alignment
,
1223 session
->uint64_t_alignment
,
1224 session
->bits_per_long
,
1225 session
->long_alignment
,
1229 session
->byte_order
== BIG_ENDIAN
? "be" : "le"
1235 ret
= lttng_metadata_printf(session
,
1237 " domain = \"ust\";\n"
1238 " tracer_name = \"lttng-ust\";\n"
1239 " tracer_major = %u;\n"
1240 " tracer_minor = %u;\n"
1241 " tracer_buffering_scheme = \"%s\";\n"
1242 " tracer_buffering_id = %u;\n"
1243 " architecture_bit_width = %u;\n",
1246 app
? "pid" : "uid",
1247 app
? (int) app
->pid
: (int) session
->tracing_uid
,
1248 session
->bits_per_long
);
1253 ret
= print_metadata_session_information(session
);
1259 * If per-application registry, we can output extra information
1260 * about the application.
1262 ret
= print_metadata_app_information(session
, app
);
1267 ret
= lttng_metadata_printf(session
,
1274 ret
= lttng_metadata_printf(session
,
1276 " name = \"%s\";\n",
1283 if (!trace_clock_uuid(clock_uuid_s
)) {
1284 ret
= lttng_metadata_printf(session
,
1285 " uuid = \"%s\";\n",
1293 ret
= lttng_metadata_printf(session
,
1294 " description = \"%s\";\n"
1295 " freq = %" PRIu64
"; /* Frequency, in Hz */\n"
1296 " /* clock value offset from Epoch is: offset * (1/freq) */\n"
1297 " offset = %" PRId64
";\n"
1299 trace_clock_description(),
1301 measure_clock_offset()
1307 ret
= lttng_metadata_printf(session
,
1308 "typealias integer {\n"
1309 " size = 27; align = 1; signed = false;\n"
1310 " map = clock.%s.value;\n"
1311 "} := uint27_clock_monotonic_t;\n"
1313 "typealias integer {\n"
1314 " size = 32; align = %u; signed = false;\n"
1315 " map = clock.%s.value;\n"
1316 "} := uint32_clock_monotonic_t;\n"
1318 "typealias integer {\n"
1319 " size = 64; align = %u; signed = false;\n"
1320 " map = clock.%s.value;\n"
1321 "} := uint64_clock_monotonic_t;\n\n",
1323 session
->uint32_t_alignment
,
1325 session
->uint64_t_alignment
,
1332 ret
= _lttng_stream_packet_context_declare(session
);
1337 ret
= _lttng_event_header_declare(session
);