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 lttng_ust_ctl_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)) {
48 LTTNG_ASSERT(order
>= 0);
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
= (char *) 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.
109 static ATTR_FORMAT_PRINTF(2, 3)
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 lttng_ust_ctl_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 lttng_ust_ctl_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
== lttng_ust_ctl_encode_none
)
253 : (container_type
->encoding
== lttng_ust_ctl_encode_UTF8
)
256 container_type
->base
);
261 /* Dump all entries */
262 for (i
= 0; i
< nr_entries
; i
++) {
263 const struct lttng_ust_ctl_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 LTTNG_UST_CTL_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 "%" PRId64
, entry
->start
.value
);
320 ret
= lttng_metadata_printf(session
,
321 "%" PRIu64
, 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
,
334 " ... %" PRId64
",\n",
337 ret
= lttng_metadata_printf(session
,
338 " ... %" PRIu64
",\n",
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 lttng_ust_ctl_field
*fields
, size_t nr_fields
,
365 size_t *iter_field
, size_t nesting
)
367 const struct lttng_ust_ctl_field
*variant
= &fields
[*iter_field
];
370 char identifier
[LTTNG_UST_ABI_SYM_NAME_LEN
];
373 sanitize_ctf_identifier(identifier
, tag_name
);
375 ret
= print_tabs(session
, nesting
);
379 ret
= lttng_metadata_printf(session
,
380 "struct { } align(%u) _%s_padding;\n",
381 alignment
* CHAR_BIT
,
387 ret
= print_tabs(session
, nesting
);
391 ret
= lttng_metadata_printf(session
,
398 for (i
= 0; i
< nr_choices
; i
++) {
399 if (*iter_field
>= nr_fields
) {
403 ret
= _lttng_field_statedump(session
,
405 iter_field
, nesting
+ 1);
410 sanitize_ctf_identifier(identifier
, variant
->name
);
411 ret
= print_tabs(session
, nesting
);
415 ret
= lttng_metadata_printf(session
,
426 int _lttng_field_statedump(struct ust_registry_session
*session
,
427 const struct lttng_ust_ctl_field
*fields
, size_t nr_fields
,
428 size_t *iter_field
, size_t nesting
)
431 const char *bo_be
= " byte_order = be;";
432 const char *bo_le
= " byte_order = le;";
433 const char *bo_native
= "";
434 const char *bo_reverse
;
435 const struct lttng_ust_ctl_field
*field
;
437 if (*iter_field
>= nr_fields
) {
441 field
= &fields
[*iter_field
];
443 if (session
->byte_order
== BIG_ENDIAN
) {
449 switch (field
->type
.atype
) {
450 case lttng_ust_ctl_atype_integer
:
451 ret
= print_tabs(session
, nesting
);
455 ret
= lttng_metadata_printf(session
,
456 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n",
457 field
->type
.u
.integer
.size
,
458 field
->type
.u
.integer
.alignment
,
459 field
->type
.u
.integer
.signedness
,
460 (field
->type
.u
.integer
.encoding
== lttng_ust_ctl_encode_none
)
462 : (field
->type
.u
.integer
.encoding
== lttng_ust_ctl_encode_UTF8
)
465 field
->type
.u
.integer
.base
,
466 field
->type
.u
.integer
.reverse_byte_order
? bo_reverse
: bo_native
,
470 case lttng_ust_ctl_atype_enum
:
471 ret
= ust_metadata_enum_statedump(session
,
472 field
->type
.u
.legacy
.basic
.enumeration
.name
,
473 field
->type
.u
.legacy
.basic
.enumeration
.id
,
474 &field
->type
.u
.legacy
.basic
.enumeration
.container_type
,
475 field
->name
, iter_field
, nesting
);
477 case lttng_ust_ctl_atype_float
:
478 ret
= print_tabs(session
, nesting
);
482 ret
= lttng_metadata_printf(session
,
483 "floating_point { exp_dig = %u; mant_dig = %u; align = %u;%s } _%s;\n",
484 field
->type
.u
._float
.exp_dig
,
485 field
->type
.u
._float
.mant_dig
,
486 field
->type
.u
._float
.alignment
,
487 field
->type
.u
._float
.reverse_byte_order
? bo_reverse
: bo_native
,
491 case lttng_ust_ctl_atype_array
:
493 const struct lttng_ust_ctl_basic_type
*elem_type
;
495 ret
= print_tabs(session
, nesting
);
499 elem_type
= &field
->type
.u
.legacy
.array
.elem_type
;
500 /* Only integers are currently supported in arrays. */
501 if (elem_type
->atype
!= lttng_ust_ctl_atype_integer
) {
505 ret
= lttng_metadata_printf(session
,
506 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
507 elem_type
->u
.basic
.integer
.size
,
508 elem_type
->u
.basic
.integer
.alignment
,
509 elem_type
->u
.basic
.integer
.signedness
,
510 (elem_type
->u
.basic
.integer
.encoding
== lttng_ust_ctl_encode_none
)
512 : (elem_type
->u
.basic
.integer
.encoding
== lttng_ust_ctl_encode_UTF8
)
515 elem_type
->u
.basic
.integer
.base
,
516 elem_type
->u
.basic
.integer
.reverse_byte_order
? bo_reverse
: bo_native
,
517 field
->name
, field
->type
.u
.legacy
.array
.length
);
521 case lttng_ust_ctl_atype_array_nestable
:
523 uint32_t array_length
;
524 const struct lttng_ust_ctl_field
*array_nestable
;
525 const struct lttng_ust_ctl_type
*elem_type
;
527 array_length
= field
->type
.u
.array_nestable
.length
;
530 if (*iter_field
>= nr_fields
) {
534 array_nestable
= &fields
[*iter_field
];
535 elem_type
= &array_nestable
->type
;
537 /* Only integers are currently supported in arrays. */
538 if (elem_type
->atype
!= lttng_ust_ctl_atype_integer
) {
543 if (field
->type
.u
.array_nestable
.alignment
) {
544 ret
= print_tabs(session
, nesting
);
548 ret
= lttng_metadata_printf(session
,
549 "struct { } align(%u) _%s_padding;\n",
550 field
->type
.u
.array_nestable
.alignment
* CHAR_BIT
,
557 ret
= print_tabs(session
, nesting
);
561 ret
= lttng_metadata_printf(session
,
562 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
563 elem_type
->u
.integer
.size
,
564 elem_type
->u
.integer
.alignment
,
565 elem_type
->u
.integer
.signedness
,
566 (elem_type
->u
.integer
.encoding
== lttng_ust_ctl_encode_none
)
568 : (elem_type
->u
.integer
.encoding
== lttng_ust_ctl_encode_UTF8
)
571 elem_type
->u
.integer
.base
,
572 elem_type
->u
.integer
.reverse_byte_order
? bo_reverse
: bo_native
,
573 field
->name
, array_length
);
577 case lttng_ust_ctl_atype_sequence
:
579 const struct lttng_ust_ctl_basic_type
*elem_type
;
580 const struct lttng_ust_ctl_basic_type
*length_type
;
582 elem_type
= &field
->type
.u
.legacy
.sequence
.elem_type
;
583 length_type
= &field
->type
.u
.legacy
.sequence
.length_type
;
584 ret
= print_tabs(session
, nesting
);
589 /* Only integers are currently supported in sequences. */
590 if (elem_type
->atype
!= lttng_ust_ctl_atype_integer
) {
595 ret
= lttng_metadata_printf(session
,
596 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n",
597 length_type
->u
.basic
.integer
.size
,
598 (unsigned int) length_type
->u
.basic
.integer
.alignment
,
599 length_type
->u
.basic
.integer
.signedness
,
600 (length_type
->u
.basic
.integer
.encoding
== lttng_ust_ctl_encode_none
)
602 : ((length_type
->u
.basic
.integer
.encoding
== lttng_ust_ctl_encode_UTF8
)
605 length_type
->u
.basic
.integer
.base
,
606 length_type
->u
.basic
.integer
.reverse_byte_order
? bo_reverse
: bo_native
,
612 ret
= print_tabs(session
, nesting
);
616 ret
= lttng_metadata_printf(session
,
617 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n",
618 elem_type
->u
.basic
.integer
.size
,
619 (unsigned int) elem_type
->u
.basic
.integer
.alignment
,
620 elem_type
->u
.basic
.integer
.signedness
,
621 (elem_type
->u
.basic
.integer
.encoding
== lttng_ust_ctl_encode_none
)
623 : ((elem_type
->u
.basic
.integer
.encoding
== lttng_ust_ctl_encode_UTF8
)
626 elem_type
->u
.basic
.integer
.base
,
627 elem_type
->u
.basic
.integer
.reverse_byte_order
? bo_reverse
: bo_native
,
633 case lttng_ust_ctl_atype_sequence_nestable
:
635 const struct lttng_ust_ctl_field
*sequence_nestable
;
636 const struct lttng_ust_ctl_type
*elem_type
;
639 if (*iter_field
>= nr_fields
) {
643 sequence_nestable
= &fields
[*iter_field
];
644 elem_type
= &sequence_nestable
->type
;
646 /* Only integers are currently supported in sequences. */
647 if (elem_type
->atype
!= lttng_ust_ctl_atype_integer
) {
652 if (field
->type
.u
.sequence_nestable
.alignment
) {
653 ret
= print_tabs(session
, nesting
);
657 ret
= lttng_metadata_printf(session
,
658 "struct { } align(%u) _%s_padding;\n",
659 field
->type
.u
.sequence_nestable
.alignment
* CHAR_BIT
,
666 ret
= print_tabs(session
, nesting
);
670 ret
= lttng_metadata_printf(session
,
671 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ _%s ];\n",
672 elem_type
->u
.integer
.size
,
673 (unsigned int) elem_type
->u
.integer
.alignment
,
674 elem_type
->u
.integer
.signedness
,
675 (elem_type
->u
.integer
.encoding
== lttng_ust_ctl_encode_none
)
677 : ((elem_type
->u
.integer
.encoding
== lttng_ust_ctl_encode_UTF8
)
680 elem_type
->u
.integer
.base
,
681 elem_type
->u
.integer
.reverse_byte_order
? bo_reverse
: bo_native
,
683 field
->type
.u
.sequence_nestable
.length_name
);
687 case lttng_ust_ctl_atype_string
:
688 /* Default encoding is UTF8 */
689 ret
= print_tabs(session
, nesting
);
693 ret
= lttng_metadata_printf(session
,
695 field
->type
.u
.string
.encoding
== lttng_ust_ctl_encode_ASCII
?
696 " { encoding = ASCII; }" : "",
700 case lttng_ust_ctl_atype_variant
:
701 ret
= _lttng_variant_statedump(session
,
702 field
->type
.u
.legacy
.variant
.nr_choices
,
703 field
->type
.u
.legacy
.variant
.tag_name
,
705 fields
, nr_fields
, iter_field
, nesting
);
710 case lttng_ust_ctl_atype_variant_nestable
:
711 ret
= _lttng_variant_statedump(session
,
712 field
->type
.u
.variant_nestable
.nr_choices
,
713 field
->type
.u
.variant_nestable
.tag_name
,
714 field
->type
.u
.variant_nestable
.alignment
,
715 fields
, nr_fields
, iter_field
, nesting
);
720 case lttng_ust_ctl_atype_struct
:
721 if (field
->type
.u
.legacy
._struct
.nr_fields
!= 0) {
722 /* Currently only 0-length structures are supported. */
726 ret
= print_tabs(session
, nesting
);
730 ret
= lttng_metadata_printf(session
,
735 case lttng_ust_ctl_atype_struct_nestable
:
736 if (field
->type
.u
.struct_nestable
.nr_fields
!= 0) {
737 /* Currently only 0-length structures are supported. */
741 ret
= print_tabs(session
, nesting
);
745 if (field
->type
.u
.struct_nestable
.alignment
) {
746 ret
= lttng_metadata_printf(session
,
747 "struct {} align(%u) _%s;\n",
748 field
->type
.u
.struct_nestable
.alignment
* CHAR_BIT
,
754 ret
= lttng_metadata_printf(session
,
760 case lttng_ust_ctl_atype_enum_nestable
:
762 const struct lttng_ust_ctl_field
*container_field
;
763 const struct lttng_ust_ctl_type
*container_type
;
766 if (*iter_field
>= nr_fields
) {
770 container_field
= &fields
[*iter_field
];
771 container_type
= &container_field
->type
;
773 /* Only integers are supported as container types. */
774 if (container_type
->atype
!= lttng_ust_ctl_atype_integer
) {
778 ret
= ust_metadata_enum_statedump(session
,
779 field
->type
.u
.enum_nestable
.name
,
780 field
->type
.u
.enum_nestable
.id
,
781 &container_type
->u
.integer
,
782 field
->name
, iter_field
, nesting
);
793 int _lttng_context_metadata_statedump(struct ust_registry_session
*session
,
794 size_t nr_ctx_fields
,
795 struct lttng_ust_ctl_field
*ctx
)
803 if (i
>= nr_ctx_fields
) {
806 ret
= _lttng_field_statedump(session
, ctx
,
807 nr_ctx_fields
, &i
, 2);
816 int _lttng_fields_metadata_statedump(struct ust_registry_session
*session
,
817 struct ust_registry_event
*event
)
823 if (i
>= event
->nr_fields
) {
826 ret
= _lttng_field_statedump(session
, event
->fields
,
827 event
->nr_fields
, &i
, 2);
836 * Should be called with session registry mutex held.
838 int ust_metadata_event_statedump(struct ust_registry_session
*session
,
839 struct ust_registry_channel
*chan
,
840 struct ust_registry_event
*event
)
844 /* Don't dump metadata events */
845 if (chan
->chan_id
== -1U)
848 ret
= lttng_metadata_printf(session
,
852 " stream_id = %u;\n",
860 ret
= lttng_metadata_printf(session
,
862 event
->loglevel_value
);
867 if (event
->model_emf_uri
) {
868 ret
= lttng_metadata_printf(session
,
869 " model.emf.uri = \"%s\";\n",
870 event
->model_emf_uri
);
876 ret
= lttng_metadata_printf(session
,
877 " fields := struct {\n"
883 ret
= _lttng_fields_metadata_statedump(session
, event
);
888 ret
= lttng_metadata_printf(session
,
894 event
->metadata_dumped
= 1;
901 * Should be called with session registry mutex held.
903 int ust_metadata_channel_statedump(struct ust_registry_session
*session
,
904 struct ust_registry_channel
*chan
)
908 /* Don't dump metadata events */
909 if (chan
->chan_id
== -1U)
912 if (!chan
->header_type
)
915 ret
= lttng_metadata_printf(session
,
918 " event.header := %s;\n"
919 " packet.context := struct packet_context;\n",
921 chan
->header_type
== LTTNG_UST_CTL_CHANNEL_HEADER_COMPACT
?
922 "struct event_header_compact" :
923 "struct event_header_large");
928 if (chan
->ctx_fields
) {
929 ret
= lttng_metadata_printf(session
,
930 " event.context := struct {\n");
935 ret
= _lttng_context_metadata_statedump(session
,
941 if (chan
->ctx_fields
) {
942 ret
= lttng_metadata_printf(session
,
949 ret
= lttng_metadata_printf(session
,
951 /* Flag success of metadata dump. */
952 chan
->metadata_dumped
= 1;
959 int _lttng_stream_packet_context_declare(struct ust_registry_session
*session
)
961 return lttng_metadata_printf(session
,
962 "struct packet_context {\n"
963 " uint64_clock_monotonic_t timestamp_begin;\n"
964 " uint64_clock_monotonic_t timestamp_end;\n"
965 " uint64_t content_size;\n"
966 " uint64_t packet_size;\n"
967 " uint64_t packet_seq_num;\n"
968 " unsigned long events_discarded;\n"
969 " uint32_t cpu_id;\n"
977 * id 31 is reserved to indicate an extended header.
980 * id: range: 0 - 65534.
981 * id 65535 is reserved to indicate an extended header.
984 int _lttng_event_header_declare(struct ust_registry_session
*session
)
986 return lttng_metadata_printf(session
,
987 "struct event_header_compact {\n"
988 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
991 " uint27_clock_monotonic_t timestamp;\n"
995 " uint64_clock_monotonic_t timestamp;\n"
1000 "struct event_header_large {\n"
1001 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
1004 " uint32_clock_monotonic_t timestamp;\n"
1008 " uint64_clock_monotonic_t timestamp;\n"
1012 session
->uint32_t_alignment
,
1013 session
->uint16_t_alignment
1018 * The offset between monotonic and realtime clock can be negative if
1019 * the system sets the REALTIME clock to 0 after boot.
1022 int measure_single_clock_offset(struct offset_sample
*sample
)
1024 uint64_t monotonic_avg
, monotonic
[2], measure_delta
, realtime
;
1025 uint64_t tcf
= trace_clock_freq();
1026 struct timespec rts
= { 0, 0 };
1029 monotonic
[0] = trace_clock_read64();
1030 ret
= lttng_clock_gettime(CLOCK_REALTIME
, &rts
);
1034 monotonic
[1] = trace_clock_read64();
1035 measure_delta
= monotonic
[1] - monotonic
[0];
1036 if (measure_delta
> sample
->measure_delta
) {
1038 * Discard value if it took longer to read than the best
1043 monotonic_avg
= (monotonic
[0] + monotonic
[1]) >> 1;
1044 realtime
= (uint64_t) rts
.tv_sec
* tcf
;
1045 if (tcf
== NSEC_PER_SEC
) {
1046 realtime
+= rts
.tv_nsec
;
1048 realtime
+= (uint64_t) rts
.tv_nsec
* tcf
/ NSEC_PER_SEC
;
1050 sample
->offset
= (int64_t) realtime
- monotonic_avg
;
1051 sample
->measure_delta
= measure_delta
;
1056 * Approximation of NTP time of day to clock monotonic correlation,
1057 * taken at start of trace. Keep the measurement that took the less time
1058 * to complete, thus removing imprecision caused by preemption.
1059 * May return a negative offset.
1062 int64_t measure_clock_offset(void)
1065 struct offset_sample offset_best_sample
= {
1067 .measure_delta
= UINT64_MAX
,
1070 for (i
= 0; i
< NR_CLOCK_OFFSET_SAMPLES
; i
++) {
1071 if (measure_single_clock_offset(&offset_best_sample
)) {
1075 return offset_best_sample
.offset
;
1079 int print_metadata_session_information(struct ust_registry_session
*registry
)
1082 struct ltt_session
*session
= NULL
;
1083 char creation_datetime
[ISO8601_STR_LEN
];
1086 session
= session_find_by_id(registry
->tracing_id
);
1092 /* Print the trace name */
1093 ret
= lttng_metadata_printf(registry
, " trace_name = \"");
1099 * This is necessary since the creation time is present in the session
1100 * name when it is generated.
1102 if (session
->has_auto_generated_name
) {
1103 ret
= print_escaped_ctf_string(registry
, DEFAULT_SESSION_NAME
);
1105 ret
= print_escaped_ctf_string(registry
, session
->name
);
1111 ret
= lttng_metadata_printf(registry
, "\";\n");
1116 /* Prepare creation time */
1117 ret
= time_to_iso8601_str(session
->creation_time
, creation_datetime
,
1118 sizeof(creation_datetime
));
1123 /* Output the reste of the information */
1124 ret
= lttng_metadata_printf(registry
,
1125 " trace_creation_datetime = \"%s\";\n"
1126 " hostname = \"%s\";\n",
1127 creation_datetime
, session
->hostname
);
1134 session_put(session
);
1141 int print_metadata_app_information(struct ust_registry_session
*registry
,
1142 struct ust_app
*app
)
1145 char datetime
[ISO8601_STR_LEN
];
1152 ret
= time_to_iso8601_str(
1153 app
->registration_time
, datetime
, sizeof(datetime
));
1158 ret
= lttng_metadata_printf(registry
,
1159 " tracer_patchlevel = %u;\n"
1161 " procname = \"%s\";\n"
1162 " vpid_datetime = \"%s\";\n",
1163 app
->version
.patchlevel
, (int) app
->pid
, app
->name
,
1171 * Should be called with session registry mutex held.
1173 int ust_metadata_session_statedump(struct ust_registry_session
*session
,
1174 struct ust_app
*app
,
1178 char uuid_s
[LTTNG_UUID_STR_LEN
],
1179 clock_uuid_s
[LTTNG_UUID_STR_LEN
];
1182 LTTNG_ASSERT(session
);
1184 lttng_uuid_to_str(session
->uuid
, uuid_s
);
1187 ret
= lttng_metadata_printf(session
,
1188 "/* CTF %u.%u */\n\n",
1195 ret
= lttng_metadata_printf(session
,
1196 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
1197 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
1198 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
1199 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
1200 "typealias integer { size = %u; align = %u; signed = false; } := unsigned long;\n"
1201 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
1202 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
1208 " byte_order = %s;\n"
1209 " packet.header := struct {\n"
1210 " uint32_t magic;\n"
1211 " uint8_t uuid[16];\n"
1212 " uint32_t stream_id;\n"
1213 " uint64_t stream_instance_id;\n"
1216 session
->uint8_t_alignment
,
1217 session
->uint16_t_alignment
,
1218 session
->uint32_t_alignment
,
1219 session
->uint64_t_alignment
,
1220 session
->bits_per_long
,
1221 session
->long_alignment
,
1225 session
->byte_order
== BIG_ENDIAN
? "be" : "le"
1231 ret
= lttng_metadata_printf(session
,
1233 " domain = \"ust\";\n"
1234 " tracer_name = \"lttng-ust\";\n"
1235 " tracer_major = %u;\n"
1236 " tracer_minor = %u;\n"
1237 " tracer_buffering_scheme = \"%s\";\n"
1238 " tracer_buffering_id = %u;\n"
1239 " architecture_bit_width = %u;\n",
1242 app
? "pid" : "uid",
1243 app
? (int) app
->pid
: (int) session
->tracing_uid
,
1244 session
->bits_per_long
);
1249 ret
= print_metadata_session_information(session
);
1255 * If per-application registry, we can output extra information
1256 * about the application.
1258 ret
= print_metadata_app_information(session
, app
);
1263 ret
= lttng_metadata_printf(session
,
1270 ret
= lttng_metadata_printf(session
,
1272 " name = \"%s\";\n",
1279 if (!trace_clock_uuid(clock_uuid_s
)) {
1280 ret
= lttng_metadata_printf(session
,
1281 " uuid = \"%s\";\n",
1289 ret
= lttng_metadata_printf(session
,
1290 " description = \"%s\";\n"
1291 " freq = %" PRIu64
"; /* Frequency, in Hz */\n"
1292 " /* clock value offset from Epoch is: offset * (1/freq) */\n"
1293 " offset = %" PRId64
";\n"
1295 trace_clock_description(),
1297 measure_clock_offset()
1303 ret
= lttng_metadata_printf(session
,
1304 "typealias integer {\n"
1305 " size = 27; align = 1; signed = false;\n"
1306 " map = clock.%s.value;\n"
1307 "} := uint27_clock_monotonic_t;\n"
1309 "typealias integer {\n"
1310 " size = 32; align = %u; signed = false;\n"
1311 " map = clock.%s.value;\n"
1312 "} := uint32_clock_monotonic_t;\n"
1314 "typealias integer {\n"
1315 " size = 64; align = %u; signed = false;\n"
1316 " map = clock.%s.value;\n"
1317 "} := uint64_clock_monotonic_t;\n\n",
1319 session
->uint32_t_alignment
,
1321 session
->uint64_t_alignment
,
1328 ret
= _lttng_stream_packet_context_declare(session
);
1333 ret
= _lttng_event_header_declare(session
);