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 fls(unsigned int x
)
46 if (!(x
& 0xFFFF0000U
)) {
50 if (!(x
& 0xFF000000U
)) {
54 if (!(x
& 0xF0000000U
)) {
58 if (!(x
& 0xC0000000U
)) {
62 if (!(x
& 0x80000000U
)) {
69 int get_count_order(unsigned int count
)
73 order
= fls(count
) - 1;
74 if (count
& (count
- 1)) {
82 * Returns offset where to write in metadata array, or negative error value on error.
85 ssize_t
metadata_reserve(struct ust_registry_session
*session
, size_t len
)
87 size_t new_len
= session
->metadata_len
+ len
;
88 size_t new_alloc_len
= new_len
;
89 size_t old_alloc_len
= session
->metadata_alloc_len
;
92 if (new_alloc_len
> (UINT32_MAX
>> 1))
94 if ((old_alloc_len
<< 1) > (UINT32_MAX
>> 1))
97 if (new_alloc_len
> old_alloc_len
) {
101 max_t(size_t, 1U << get_count_order(new_alloc_len
), old_alloc_len
<< 1);
102 newptr
= realloc(session
->metadata
, new_alloc_len
);
105 session
->metadata
= newptr
;
106 /* We zero directly the memory from start of allocation. */
107 memset(&session
->metadata
[old_alloc_len
], 0, new_alloc_len
- old_alloc_len
);
108 session
->metadata_alloc_len
= new_alloc_len
;
110 ret
= session
->metadata_len
;
111 session
->metadata_len
+= len
;
116 int metadata_file_append(struct ust_registry_session
*session
,
117 const char *str
, size_t len
)
121 if (session
->metadata_fd
< 0) {
124 /* Write to metadata file */
125 written
= lttng_write(session
->metadata_fd
, str
, len
);
126 if (written
!= len
) {
133 * We have exclusive access to our metadata buffer (protected by the
134 * ust_lock), so we can do racy operations such as looking for
135 * remaining space left in packet and write, since mutual exclusion
136 * protects us from concurrent writes.
139 int lttng_metadata_printf(struct ust_registry_session
*session
,
140 const char *fmt
, ...)
149 ret
= vasprintf(&str
, fmt
, ap
);
155 offset
= metadata_reserve(session
, len
);
160 memcpy(&session
->metadata
[offset
], str
, len
);
161 ret
= metadata_file_append(session
, str
, len
);
163 PERROR("Error appending to metadata file");
166 DBG3("Append to metadata: \"%s\"", str
);
175 int print_tabs(struct ust_registry_session
*session
, size_t nesting
)
179 for (i
= 0; i
< nesting
; i
++) {
182 ret
= lttng_metadata_printf(session
, " ");
191 void sanitize_ctf_identifier(char *out
, const char *in
)
195 for (i
= 0; i
< LTTNG_UST_SYM_NAME_LEN
; i
++) {
209 int print_escaped_ctf_string(struct ust_registry_session
*session
, const char *string
)
217 while (cur
!= '\0') {
220 ret
= lttng_metadata_printf(session
, "%s", "\\n");
224 ret
= lttng_metadata_printf(session
, "%c", '\\');
228 /* We still print the current char */
231 ret
= lttng_metadata_printf(session
, "%c", cur
);
245 /* Called with session registry mutex held. */
247 int ust_metadata_enum_statedump(struct ust_registry_session
*session
,
248 const char *enum_name
,
250 const struct ustctl_integer_type
*container_type
,
251 const char *field_name
, size_t *iter_field
, size_t nesting
)
253 struct ust_registry_enum
*reg_enum
;
254 const struct ustctl_enum_entry
*entries
;
258 char identifier
[LTTNG_UST_SYM_NAME_LEN
];
261 reg_enum
= ust_registry_lookup_enum_by_id(session
, enum_name
, enum_id
);
263 /* reg_enum can still be used because session registry mutex is held. */
268 entries
= reg_enum
->entries
;
269 nr_entries
= reg_enum
->nr_entries
;
271 ret
= print_tabs(session
, nesting
);
275 ret
= lttng_metadata_printf(session
,
276 "enum : integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u; } {\n",
277 container_type
->size
,
278 container_type
->alignment
,
279 container_type
->signedness
,
280 (container_type
->encoding
== ustctl_encode_none
)
282 : (container_type
->encoding
== ustctl_encode_UTF8
)
285 container_type
->base
);
290 /* Dump all entries */
291 for (i
= 0; i
< nr_entries
; i
++) {
292 const struct ustctl_enum_entry
*entry
= &entries
[i
];
295 ret
= print_tabs(session
, nesting
);
299 ret
= lttng_metadata_printf(session
,
304 len
= strlen(entry
->string
);
305 /* Escape the character '"' */
306 for (j
= 0; j
< len
; j
++) {
307 char c
= entry
->string
[j
];
311 ret
= lttng_metadata_printf(session
,
315 ret
= lttng_metadata_printf(session
,
319 ret
= lttng_metadata_printf(session
,
327 ret
= lttng_metadata_printf(session
, "\"");
332 if (entry
->u
.extra
.options
&
333 USTCTL_UST_ENUM_ENTRY_OPTION_IS_AUTO
) {
334 ret
= lttng_metadata_printf(session
, ",\n");
339 ret
= lttng_metadata_printf(session
,
345 if (entry
->start
.signedness
) {
346 ret
= lttng_metadata_printf(session
,
347 "%lld", (long long) entry
->start
.value
);
349 ret
= lttng_metadata_printf(session
,
350 "%llu", entry
->start
.value
);
356 if (entry
->start
.signedness
== entry
->end
.signedness
&&
357 entry
->start
.value
==
359 ret
= lttng_metadata_printf(session
, ",\n");
361 if (entry
->end
.signedness
) {
362 ret
= lttng_metadata_printf(session
,
364 (long long) entry
->end
.value
);
366 ret
= lttng_metadata_printf(session
,
377 sanitize_ctf_identifier(identifier
, field_name
);
378 ret
= print_tabs(session
, nesting
);
382 ret
= lttng_metadata_printf(session
, "} _%s;\n",
390 int _lttng_variant_statedump(struct ust_registry_session
*session
,
391 uint32_t nr_choices
, const char *tag_name
,
393 const struct ustctl_field
*fields
, size_t nr_fields
,
394 size_t *iter_field
, size_t nesting
)
396 const struct ustctl_field
*variant
= &fields
[*iter_field
];
399 char identifier
[LTTNG_UST_SYM_NAME_LEN
];
401 if (variant
->type
.atype
!= ustctl_atype_variant
) {
406 sanitize_ctf_identifier(identifier
, tag_name
);
408 ret
= print_tabs(session
, nesting
);
412 ret
= lttng_metadata_printf(session
,
413 "struct { } align(%u) _%s_padding;\n",
414 alignment
* CHAR_BIT
,
420 ret
= print_tabs(session
, nesting
);
424 ret
= lttng_metadata_printf(session
,
431 for (i
= 0; i
< nr_choices
; i
++) {
432 if (*iter_field
>= nr_fields
) {
436 ret
= _lttng_field_statedump(session
,
438 iter_field
, nesting
+ 1);
443 sanitize_ctf_identifier(identifier
, variant
->name
);
444 ret
= print_tabs(session
, nesting
);
448 ret
= lttng_metadata_printf(session
,
459 int _lttng_field_statedump(struct ust_registry_session
*session
,
460 const struct ustctl_field
*fields
, size_t nr_fields
,
461 size_t *iter_field
, size_t nesting
)
464 const char *bo_be
= " byte_order = be;";
465 const char *bo_le
= " byte_order = le;";
466 const char *bo_native
= "";
467 const char *bo_reverse
;
468 const struct ustctl_field
*field
;
470 if (*iter_field
>= nr_fields
) {
474 field
= &fields
[*iter_field
];
476 if (session
->byte_order
== BIG_ENDIAN
) {
482 switch (field
->type
.atype
) {
483 case ustctl_atype_integer
:
484 ret
= print_tabs(session
, nesting
);
488 ret
= lttng_metadata_printf(session
,
489 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n",
490 field
->type
.u
.integer
.size
,
491 field
->type
.u
.integer
.alignment
,
492 field
->type
.u
.integer
.signedness
,
493 (field
->type
.u
.integer
.encoding
== ustctl_encode_none
)
495 : (field
->type
.u
.integer
.encoding
== ustctl_encode_UTF8
)
498 field
->type
.u
.integer
.base
,
499 field
->type
.u
.integer
.reverse_byte_order
? bo_reverse
: bo_native
,
503 case ustctl_atype_enum
:
504 ret
= ust_metadata_enum_statedump(session
,
505 field
->type
.u
.legacy
.basic
.enumeration
.name
,
506 field
->type
.u
.legacy
.basic
.enumeration
.id
,
507 &field
->type
.u
.legacy
.basic
.enumeration
.container_type
,
508 field
->name
, iter_field
, nesting
);
510 case ustctl_atype_float
:
511 ret
= print_tabs(session
, nesting
);
515 ret
= lttng_metadata_printf(session
,
516 "floating_point { exp_dig = %u; mant_dig = %u; align = %u;%s } _%s;\n",
517 field
->type
.u
._float
.exp_dig
,
518 field
->type
.u
._float
.mant_dig
,
519 field
->type
.u
._float
.alignment
,
520 field
->type
.u
._float
.reverse_byte_order
? bo_reverse
: bo_native
,
524 case ustctl_atype_array
:
526 const struct ustctl_basic_type
*elem_type
;
528 ret
= print_tabs(session
, nesting
);
532 elem_type
= &field
->type
.u
.legacy
.array
.elem_type
;
533 /* Only integers are currently supported in arrays. */
534 if (elem_type
->atype
!= ustctl_atype_integer
) {
538 ret
= lttng_metadata_printf(session
,
539 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
540 elem_type
->u
.basic
.integer
.size
,
541 elem_type
->u
.basic
.integer
.alignment
,
542 elem_type
->u
.basic
.integer
.signedness
,
543 (elem_type
->u
.basic
.integer
.encoding
== ustctl_encode_none
)
545 : (elem_type
->u
.basic
.integer
.encoding
== ustctl_encode_UTF8
)
548 elem_type
->u
.basic
.integer
.base
,
549 elem_type
->u
.basic
.integer
.reverse_byte_order
? bo_reverse
: bo_native
,
550 field
->name
, field
->type
.u
.legacy
.array
.length
);
554 case ustctl_atype_array_nestable
:
556 uint32_t array_length
;
557 const struct ustctl_field
*array_nestable
;
558 const struct ustctl_type
*elem_type
;
560 array_length
= field
->type
.u
.array_nestable
.length
;
563 if (*iter_field
>= nr_fields
) {
567 array_nestable
= &fields
[*iter_field
];
568 elem_type
= &array_nestable
->type
;
570 /* Only integers are currently supported in arrays. */
571 if (elem_type
->atype
!= ustctl_atype_integer
) {
576 if (field
->type
.u
.array_nestable
.alignment
) {
577 ret
= print_tabs(session
, nesting
);
581 ret
= lttng_metadata_printf(session
,
582 "struct { } align(%u) _%s_padding;\n",
583 field
->type
.u
.array_nestable
.alignment
* CHAR_BIT
,
590 ret
= print_tabs(session
, nesting
);
594 ret
= lttng_metadata_printf(session
,
595 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
596 elem_type
->u
.integer
.size
,
597 elem_type
->u
.integer
.alignment
,
598 elem_type
->u
.integer
.signedness
,
599 (elem_type
->u
.integer
.encoding
== ustctl_encode_none
)
601 : (elem_type
->u
.integer
.encoding
== ustctl_encode_UTF8
)
604 elem_type
->u
.integer
.base
,
605 elem_type
->u
.integer
.reverse_byte_order
? bo_reverse
: bo_native
,
606 field
->name
, array_length
);
610 case ustctl_atype_sequence
:
612 const struct ustctl_basic_type
*elem_type
;
613 const struct ustctl_basic_type
*length_type
;
615 elem_type
= &field
->type
.u
.legacy
.sequence
.elem_type
;
616 length_type
= &field
->type
.u
.legacy
.sequence
.length_type
;
617 ret
= print_tabs(session
, nesting
);
622 /* Only integers are currently supported in sequences. */
623 if (elem_type
->atype
!= ustctl_atype_integer
) {
628 ret
= lttng_metadata_printf(session
,
629 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n",
630 length_type
->u
.basic
.integer
.size
,
631 (unsigned int) length_type
->u
.basic
.integer
.alignment
,
632 length_type
->u
.basic
.integer
.signedness
,
633 (length_type
->u
.basic
.integer
.encoding
== ustctl_encode_none
)
635 : ((length_type
->u
.basic
.integer
.encoding
== ustctl_encode_UTF8
)
638 length_type
->u
.basic
.integer
.base
,
639 length_type
->u
.basic
.integer
.reverse_byte_order
? bo_reverse
: bo_native
,
645 ret
= print_tabs(session
, nesting
);
649 ret
= lttng_metadata_printf(session
,
650 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n",
651 elem_type
->u
.basic
.integer
.size
,
652 (unsigned int) elem_type
->u
.basic
.integer
.alignment
,
653 elem_type
->u
.basic
.integer
.signedness
,
654 (elem_type
->u
.basic
.integer
.encoding
== ustctl_encode_none
)
656 : ((elem_type
->u
.basic
.integer
.encoding
== ustctl_encode_UTF8
)
659 elem_type
->u
.basic
.integer
.base
,
660 elem_type
->u
.basic
.integer
.reverse_byte_order
? bo_reverse
: bo_native
,
666 case ustctl_atype_sequence_nestable
:
668 const struct ustctl_field
*sequence_nestable
;
669 const struct ustctl_type
*elem_type
;
672 if (*iter_field
>= nr_fields
) {
676 sequence_nestable
= &fields
[*iter_field
];
677 elem_type
= &sequence_nestable
->type
;
679 /* Only integers are currently supported in sequences. */
680 if (elem_type
->atype
!= ustctl_atype_integer
) {
685 if (field
->type
.u
.sequence_nestable
.alignment
) {
686 ret
= print_tabs(session
, nesting
);
690 ret
= lttng_metadata_printf(session
,
691 "struct { } align(%u) _%s_padding;\n",
692 field
->type
.u
.sequence_nestable
.alignment
* CHAR_BIT
,
699 ret
= print_tabs(session
, nesting
);
703 ret
= lttng_metadata_printf(session
,
704 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ _%s ];\n",
705 elem_type
->u
.integer
.size
,
706 (unsigned int) elem_type
->u
.integer
.alignment
,
707 elem_type
->u
.integer
.signedness
,
708 (elem_type
->u
.integer
.encoding
== ustctl_encode_none
)
710 : ((elem_type
->u
.integer
.encoding
== ustctl_encode_UTF8
)
713 elem_type
->u
.integer
.base
,
714 elem_type
->u
.integer
.reverse_byte_order
? bo_reverse
: bo_native
,
716 field
->type
.u
.sequence_nestable
.length_name
);
720 case ustctl_atype_string
:
721 /* Default encoding is UTF8 */
722 ret
= print_tabs(session
, nesting
);
726 ret
= lttng_metadata_printf(session
,
728 field
->type
.u
.string
.encoding
== ustctl_encode_ASCII
?
729 " { encoding = ASCII; }" : "",
733 case ustctl_atype_variant
:
734 ret
= _lttng_variant_statedump(session
,
735 field
->type
.u
.legacy
.variant
.nr_choices
,
736 field
->type
.u
.legacy
.variant
.tag_name
,
738 fields
, nr_fields
, iter_field
, nesting
);
743 case ustctl_atype_variant_nestable
:
744 ret
= _lttng_variant_statedump(session
,
745 field
->type
.u
.variant_nestable
.nr_choices
,
746 field
->type
.u
.variant_nestable
.tag_name
,
747 field
->type
.u
.variant_nestable
.alignment
,
748 fields
, nr_fields
, iter_field
, nesting
);
753 case ustctl_atype_struct
:
754 if (field
->type
.u
.legacy
._struct
.nr_fields
!= 0) {
755 /* Currently only 0-length structures are supported. */
759 ret
= print_tabs(session
, nesting
);
763 ret
= lttng_metadata_printf(session
,
768 case ustctl_atype_struct_nestable
:
769 if (field
->type
.u
.struct_nestable
.nr_fields
!= 0) {
770 /* Currently only 0-length structures are supported. */
774 ret
= print_tabs(session
, nesting
);
778 if (field
->type
.u
.struct_nestable
.alignment
) {
779 ret
= lttng_metadata_printf(session
,
780 "struct {} align(%u) _%s;\n",
781 field
->type
.u
.struct_nestable
.alignment
* CHAR_BIT
,
787 ret
= lttng_metadata_printf(session
,
793 case ustctl_atype_enum_nestable
:
795 const struct ustctl_field
*container_field
;
796 const struct ustctl_type
*container_type
;
799 if (*iter_field
>= nr_fields
) {
803 container_field
= &fields
[*iter_field
];
804 container_type
= &container_field
->type
;
806 /* Only integers are supported as container types. */
807 if (container_type
->atype
!= ustctl_atype_integer
) {
811 ret
= ust_metadata_enum_statedump(session
,
812 field
->type
.u
.enum_nestable
.name
,
813 field
->type
.u
.enum_nestable
.id
,
814 &container_type
->u
.integer
,
815 field
->name
, iter_field
, nesting
);
826 int _lttng_context_metadata_statedump(struct ust_registry_session
*session
,
827 size_t nr_ctx_fields
,
828 struct ustctl_field
*ctx
)
836 if (i
>= nr_ctx_fields
) {
839 ret
= _lttng_field_statedump(session
, ctx
,
840 nr_ctx_fields
, &i
, 2);
849 int _lttng_fields_metadata_statedump(struct ust_registry_session
*session
,
850 struct ust_registry_event
*event
)
856 if (i
>= event
->nr_fields
) {
859 ret
= _lttng_field_statedump(session
, event
->fields
,
860 event
->nr_fields
, &i
, 2);
869 * Should be called with session registry mutex held.
871 int ust_metadata_event_statedump(struct ust_registry_session
*session
,
872 struct ust_registry_channel
*chan
,
873 struct ust_registry_event
*event
)
877 /* Don't dump metadata events */
878 if (chan
->chan_id
== -1U)
881 ret
= lttng_metadata_printf(session
,
885 " stream_id = %u;\n",
893 ret
= lttng_metadata_printf(session
,
895 event
->loglevel_value
);
900 if (event
->model_emf_uri
) {
901 ret
= lttng_metadata_printf(session
,
902 " model.emf.uri = \"%s\";\n",
903 event
->model_emf_uri
);
909 ret
= lttng_metadata_printf(session
,
910 " fields := struct {\n"
916 ret
= _lttng_fields_metadata_statedump(session
, event
);
921 ret
= lttng_metadata_printf(session
,
927 event
->metadata_dumped
= 1;
934 * Should be called with session registry mutex held.
936 int ust_metadata_channel_statedump(struct ust_registry_session
*session
,
937 struct ust_registry_channel
*chan
)
941 /* Don't dump metadata events */
942 if (chan
->chan_id
== -1U)
945 if (!chan
->header_type
)
948 ret
= lttng_metadata_printf(session
,
951 " event.header := %s;\n"
952 " packet.context := struct packet_context;\n",
954 chan
->header_type
== USTCTL_CHANNEL_HEADER_COMPACT
?
955 "struct event_header_compact" :
956 "struct event_header_large");
961 if (chan
->ctx_fields
) {
962 ret
= lttng_metadata_printf(session
,
963 " event.context := struct {\n");
968 ret
= _lttng_context_metadata_statedump(session
,
974 if (chan
->ctx_fields
) {
975 ret
= lttng_metadata_printf(session
,
982 ret
= lttng_metadata_printf(session
,
984 /* Flag success of metadata dump. */
985 chan
->metadata_dumped
= 1;
992 int _lttng_stream_packet_context_declare(struct ust_registry_session
*session
)
994 return lttng_metadata_printf(session
,
995 "struct packet_context {\n"
996 " uint64_clock_monotonic_t timestamp_begin;\n"
997 " uint64_clock_monotonic_t timestamp_end;\n"
998 " uint64_t content_size;\n"
999 " uint64_t packet_size;\n"
1000 " uint64_t packet_seq_num;\n"
1001 " unsigned long events_discarded;\n"
1002 " uint32_t cpu_id;\n"
1009 * id: range: 0 - 30.
1010 * id 31 is reserved to indicate an extended header.
1013 * id: range: 0 - 65534.
1014 * id 65535 is reserved to indicate an extended header.
1017 int _lttng_event_header_declare(struct ust_registry_session
*session
)
1019 return lttng_metadata_printf(session
,
1020 "struct event_header_compact {\n"
1021 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
1024 " uint27_clock_monotonic_t timestamp;\n"
1028 " uint64_clock_monotonic_t timestamp;\n"
1033 "struct event_header_large {\n"
1034 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
1037 " uint32_clock_monotonic_t timestamp;\n"
1041 " uint64_clock_monotonic_t timestamp;\n"
1045 session
->uint32_t_alignment
,
1046 session
->uint16_t_alignment
1051 * The offset between monotonic and realtime clock can be negative if
1052 * the system sets the REALTIME clock to 0 after boot.
1055 int measure_single_clock_offset(struct offset_sample
*sample
)
1057 uint64_t monotonic_avg
, monotonic
[2], measure_delta
, realtime
;
1058 uint64_t tcf
= trace_clock_freq();
1059 struct timespec rts
= { 0, 0 };
1062 monotonic
[0] = trace_clock_read64();
1063 ret
= lttng_clock_gettime(CLOCK_REALTIME
, &rts
);
1067 monotonic
[1] = trace_clock_read64();
1068 measure_delta
= monotonic
[1] - monotonic
[0];
1069 if (measure_delta
> sample
->measure_delta
) {
1071 * Discard value if it took longer to read than the best
1076 monotonic_avg
= (monotonic
[0] + monotonic
[1]) >> 1;
1077 realtime
= (uint64_t) rts
.tv_sec
* tcf
;
1078 if (tcf
== NSEC_PER_SEC
) {
1079 realtime
+= rts
.tv_nsec
;
1081 realtime
+= (uint64_t) rts
.tv_nsec
* tcf
/ NSEC_PER_SEC
;
1083 sample
->offset
= (int64_t) realtime
- monotonic_avg
;
1084 sample
->measure_delta
= measure_delta
;
1089 * Approximation of NTP time of day to clock monotonic correlation,
1090 * taken at start of trace. Keep the measurement that took the less time
1091 * to complete, thus removing imprecision caused by preemption.
1092 * May return a negative offset.
1095 int64_t measure_clock_offset(void)
1098 struct offset_sample offset_best_sample
= {
1100 .measure_delta
= UINT64_MAX
,
1103 for (i
= 0; i
< NR_CLOCK_OFFSET_SAMPLES
; i
++) {
1104 if (measure_single_clock_offset(&offset_best_sample
)) {
1108 return offset_best_sample
.offset
;
1112 int print_metadata_session_information(struct ust_registry_session
*registry
)
1115 struct ltt_session
*session
= NULL
;
1116 char creation_datetime
[ISO8601_STR_LEN
];
1119 session
= session_find_by_id(registry
->tracing_id
);
1125 /* Print the trace name */
1126 ret
= lttng_metadata_printf(registry
, " trace_name = \"");
1132 * This is necessary since the creation time is present in the session
1133 * name when it is generated.
1135 if (session
->has_auto_generated_name
) {
1136 ret
= print_escaped_ctf_string(registry
, DEFAULT_SESSION_NAME
);
1138 ret
= print_escaped_ctf_string(registry
, session
->name
);
1144 ret
= lttng_metadata_printf(registry
, "\";\n");
1149 /* Prepare creation time */
1150 ret
= time_to_iso8601_str(session
->creation_time
, creation_datetime
,
1151 sizeof(creation_datetime
));
1156 /* Output the reste of the information */
1157 ret
= lttng_metadata_printf(registry
,
1158 " trace_creation_datetime = \"%s\";\n"
1159 " hostname = \"%s\";\n",
1160 creation_datetime
, session
->hostname
);
1167 session_put(session
);
1174 int print_metadata_app_information(struct ust_registry_session
*registry
,
1175 struct ust_app
*app
)
1178 char datetime
[ISO8601_STR_LEN
];
1185 ret
= time_to_iso8601_str(
1186 app
->registration_time
, datetime
, sizeof(datetime
));
1191 ret
= lttng_metadata_printf(registry
,
1192 " tracer_patchlevel = %u;\n"
1194 " procname = \"%s\";\n"
1195 " vpid_datetime = \"%s\";\n",
1196 app
->version
.patchlevel
, (int) app
->pid
, app
->name
,
1204 * Should be called with session registry mutex held.
1206 int ust_metadata_session_statedump(struct ust_registry_session
*session
,
1207 struct ust_app
*app
,
1211 char uuid_s
[LTTNG_UUID_STR_LEN
],
1212 clock_uuid_s
[LTTNG_UUID_STR_LEN
];
1217 lttng_uuid_to_str(session
->uuid
, uuid_s
);
1220 ret
= lttng_metadata_printf(session
,
1221 "/* CTF %u.%u */\n\n",
1228 ret
= lttng_metadata_printf(session
,
1229 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
1230 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
1231 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
1232 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
1233 "typealias integer { size = %u; align = %u; signed = false; } := unsigned long;\n"
1234 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
1235 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
1241 " byte_order = %s;\n"
1242 " packet.header := struct {\n"
1243 " uint32_t magic;\n"
1244 " uint8_t uuid[16];\n"
1245 " uint32_t stream_id;\n"
1246 " uint64_t stream_instance_id;\n"
1249 session
->uint8_t_alignment
,
1250 session
->uint16_t_alignment
,
1251 session
->uint32_t_alignment
,
1252 session
->uint64_t_alignment
,
1253 session
->bits_per_long
,
1254 session
->long_alignment
,
1258 session
->byte_order
== BIG_ENDIAN
? "be" : "le"
1264 ret
= lttng_metadata_printf(session
,
1266 " domain = \"ust\";\n"
1267 " tracer_name = \"lttng-ust\";\n"
1268 " tracer_major = %u;\n"
1269 " tracer_minor = %u;\n"
1270 " tracer_buffering_scheme = \"%s\";\n"
1271 " tracer_buffering_id = %u;\n"
1272 " architecture_bit_width = %u;\n",
1275 app
? "pid" : "uid",
1276 app
? (int) app
->pid
: (int) session
->tracing_uid
,
1277 session
->bits_per_long
);
1282 ret
= print_metadata_session_information(session
);
1288 * If per-application registry, we can output extra information
1289 * about the application.
1291 ret
= print_metadata_app_information(session
, app
);
1296 ret
= lttng_metadata_printf(session
,
1303 ret
= lttng_metadata_printf(session
,
1305 " name = \"%s\";\n",
1312 if (!trace_clock_uuid(clock_uuid_s
)) {
1313 ret
= lttng_metadata_printf(session
,
1314 " uuid = \"%s\";\n",
1322 ret
= lttng_metadata_printf(session
,
1323 " description = \"%s\";\n"
1324 " freq = %" PRIu64
"; /* Frequency, in Hz */\n"
1325 " /* clock value offset from Epoch is: offset * (1/freq) */\n"
1326 " offset = %" PRId64
";\n"
1328 trace_clock_description(),
1330 measure_clock_offset()
1336 ret
= lttng_metadata_printf(session
,
1337 "typealias integer {\n"
1338 " size = 27; align = 1; signed = false;\n"
1339 " map = clock.%s.value;\n"
1340 "} := uint27_clock_monotonic_t;\n"
1342 "typealias integer {\n"
1343 " size = 32; align = %u; signed = false;\n"
1344 " map = clock.%s.value;\n"
1345 "} := uint32_clock_monotonic_t;\n"
1347 "typealias integer {\n"
1348 " size = 64; align = %u; signed = false;\n"
1349 " map = clock.%s.value;\n"
1350 "} := uint64_clock_monotonic_t;\n\n",
1352 session
->uint32_t_alignment
,
1354 session
->uint64_t_alignment
,
1361 ret
= _lttng_stream_packet_context_declare(session
);
1366 ret
= _lttng_event_header_declare(session
);