Fix: handle negative clock offset for lttng-ust metadata
[lttng-tools.git] / src / bin / lttng-sessiond / ust-metadata.c
CommitLineData
d0b96690
DG
1/*
2 * ust-metadata.c
3 *
4 * LTTng-UST metadata generation
5 *
6 * Copyright (C) 2010-2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License, version 2 only,
10 * as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
6c1c0768 22#define _LGPL_SOURCE
d0b96690
DG
23#include <stdint.h>
24#include <string.h>
25#include <stdarg.h>
26#include <stdio.h>
27#include <limits.h>
28#include <unistd.h>
29#include <inttypes.h>
30#include <common/common.h>
31
32#include "ust-registry.h"
33#include "ust-clock.h"
34#include "ust-app.h"
35
36#ifndef max_t
37#define max_t(type, a, b) ((type) ((a) > (b) ? (a) : (b)))
38#endif
39
6e1b0543 40#define NSEC_PER_SEC 1000000000ULL
8c645bb0
MD
41#define NR_CLOCK_OFFSET_SAMPLES 10
42
43struct offset_sample {
44 uint64_t offset; /* correlation offset */
45 uint64_t measure_delta; /* lower is better */
46};
47
d0b96690
DG
48static inline
49int fls(unsigned int x)
50{
51 int r = 32;
52
53 if (!x)
54 return 0;
55 if (!(x & 0xFFFF0000U)) {
56 x <<= 16;
57 r -= 16;
58 }
59 if (!(x & 0xFF000000U)) {
60 x <<= 8;
61 r -= 8;
62 }
63 if (!(x & 0xF0000000U)) {
64 x <<= 4;
65 r -= 4;
66 }
67 if (!(x & 0xC0000000U)) {
68 x <<= 2;
69 r -= 2;
70 }
71 if (!(x & 0x80000000U)) {
72 x <<= 1;
73 r -= 1;
74 }
75 return r;
76}
77
78static inline
79int get_count_order(unsigned int count)
80{
81 int order;
82
83 order = fls(count) - 1;
84 if (count & (count - 1))
85 order++;
86 return order;
87}
88
89/*
90 * Returns offset where to write in metadata array, or negative error value on error.
91 */
92static
93ssize_t metadata_reserve(struct ust_registry_session *session, size_t len)
94{
95 size_t new_len = session->metadata_len + len;
96 size_t new_alloc_len = new_len;
97 size_t old_alloc_len = session->metadata_alloc_len;
98 ssize_t ret;
99
100 if (new_alloc_len > (UINT32_MAX >> 1))
101 return -EINVAL;
102 if ((old_alloc_len << 1) > (UINT32_MAX >> 1))
103 return -EINVAL;
104
105 if (new_alloc_len > old_alloc_len) {
106 char *newptr;
107
108 new_alloc_len =
109 max_t(size_t, 1U << get_count_order(new_alloc_len), old_alloc_len << 1);
110 newptr = realloc(session->metadata, new_alloc_len);
111 if (!newptr)
112 return -ENOMEM;
113 session->metadata = newptr;
114 /* We zero directly the memory from start of allocation. */
115 memset(&session->metadata[old_alloc_len], 0, new_alloc_len - old_alloc_len);
116 session->metadata_alloc_len = new_alloc_len;
117 }
118 ret = session->metadata_len;
119 session->metadata_len += len;
120 return ret;
121}
122
d7ba1388
MD
123static
124int metadata_file_append(struct ust_registry_session *session,
125 const char *str, size_t len)
126{
127 ssize_t written;
128
129 if (session->metadata_fd < 0) {
130 return 0;
131 }
132 /* Write to metadata file */
133 written = lttng_write(session->metadata_fd, str, len);
134 if (written != len) {
135 return -1;
136 }
137 return 0;
138}
139
d0b96690
DG
140/*
141 * We have exclusive access to our metadata buffer (protected by the
142 * ust_lock), so we can do racy operations such as looking for
143 * remaining space left in packet and write, since mutual exclusion
144 * protects us from concurrent writes.
145 */
146static
147int lttng_metadata_printf(struct ust_registry_session *session,
148 const char *fmt, ...)
149{
150 char *str = NULL;
151 size_t len;
152 va_list ap;
153 ssize_t offset;
154 int ret;
155
156 va_start(ap, fmt);
157 ret = vasprintf(&str, fmt, ap);
158 va_end(ap);
159 if (ret < 0)
160 return -ENOMEM;
161
162 len = strlen(str);
163 offset = metadata_reserve(session, len);
164 if (offset < 0) {
165 ret = offset;
166 goto end;
167 }
168 memcpy(&session->metadata[offset], str, len);
d7ba1388
MD
169 ret = metadata_file_append(session, str, len);
170 if (ret) {
171 PERROR("Error appending to metadata file");
172 goto end;
173 }
d0b96690
DG
174 DBG3("Append to metadata: \"%s\"", str);
175 ret = 0;
176
177end:
178 free(str);
179 return ret;
180}
181
10b56aef
MD
182/* Called with session registry mutex held. */
183static
184int ust_metadata_enum_statedump(struct ust_registry_session *session,
185 const char *enum_name,
186 uint64_t enum_id,
187 const struct ustctl_integer_type *container_type,
188 const char *field_name)
189{
190 struct ust_registry_enum *reg_enum;
191 const struct ustctl_enum_entry *entries;
192 size_t nr_entries;
193 int ret = 0;
194 size_t i;
195
196 rcu_read_lock();
197 reg_enum = ust_registry_lookup_enum_by_id(session, enum_name, enum_id);
198 rcu_read_unlock();
199 /* reg_enum can still be used because session registry mutex is held. */
200 if (!reg_enum) {
201 ret = -ENOENT;
202 goto end;
203 }
204 entries = reg_enum->entries;
205 nr_entries = reg_enum->nr_entries;
206
207 ret = lttng_metadata_printf(session,
208 " enum : integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u; } {\n",
209 container_type->size,
210 container_type->alignment,
211 container_type->signedness,
212 (container_type->encoding == ustctl_encode_none)
213 ? "none"
214 : (container_type->encoding == ustctl_encode_UTF8)
215 ? "UTF8"
216 : "ASCII",
217 container_type->base);
218 if (ret) {
219 goto end;
220 }
221 /* Dump all entries */
222 for (i = 0; i < nr_entries; i++) {
223 const struct ustctl_enum_entry *entry = &entries[i];
224 int j, len;
225
226 ret = lttng_metadata_printf(session,
227 " \"");
228 if (ret) {
229 goto end;
230 }
231 len = strlen(entry->string);
232 /* Escape the character '"' */
233 for (j = 0; j < len; j++) {
234 char c = entry->string[j];
235
236 switch (c) {
237 case '"':
238 ret = lttng_metadata_printf(session,
239 "\\\"");
240 break;
241 case '\\':
242 ret = lttng_metadata_printf(session,
243 "\\\\");
244 break;
245 default:
246 ret = lttng_metadata_printf(session,
247 "%c", c);
248 break;
249 }
250 if (ret) {
251 goto end;
252 }
253 }
254 ret = lttng_metadata_printf(session,
255 "\" = ");
256 if (ret) {
257 goto end;
258 }
259 if (entry->start == entry->end) {
260 ret = lttng_metadata_printf(session,
261 "%d,\n",
262 entry->start);
263 } else {
264 ret = lttng_metadata_printf(session,
265 "%d ... %d,\n",
266 entry->start, entry->end);
267 }
268 if (ret) {
269 goto end;
270 }
271 }
272 ret = lttng_metadata_printf(session, " } _%s;\n",
273 field_name);
274end:
275 return ret;
276}
277
d0b96690
DG
278static
279int _lttng_field_statedump(struct ust_registry_session *session,
280 const struct ustctl_field *field)
281{
282 int ret = 0;
283 const char *bo_be = " byte_order = be;";
284 const char *bo_le = " byte_order = le;";
285 const char *bo_native = "";
286 const char *bo_reverse;
287
288 if (session->byte_order == BIG_ENDIAN)
289 bo_reverse = bo_le;
290 else
291 bo_reverse = bo_be;
292
293 switch (field->type.atype) {
294 case ustctl_atype_integer:
295 ret = lttng_metadata_printf(session,
296 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n",
297 field->type.u.basic.integer.size,
298 field->type.u.basic.integer.alignment,
299 field->type.u.basic.integer.signedness,
300 (field->type.u.basic.integer.encoding == ustctl_encode_none)
301 ? "none"
302 : (field->type.u.basic.integer.encoding == ustctl_encode_UTF8)
303 ? "UTF8"
304 : "ASCII",
305 field->type.u.basic.integer.base,
306 field->type.u.basic.integer.reverse_byte_order ? bo_reverse : bo_native,
307 field->name);
308 break;
10b56aef
MD
309 case ustctl_atype_enum:
310 ret = ust_metadata_enum_statedump(session,
311 field->type.u.basic.enumeration.name,
312 field->type.u.basic.enumeration.id,
313 &field->type.u.basic.enumeration.container_type,
314 field->name);
315 break;
d0b96690
DG
316 case ustctl_atype_float:
317 ret = lttng_metadata_printf(session,
318 " floating_point { exp_dig = %u; mant_dig = %u; align = %u;%s } _%s;\n",
319 field->type.u.basic._float.exp_dig,
320 field->type.u.basic._float.mant_dig,
321 field->type.u.basic._float.alignment,
322 field->type.u.basic.integer.reverse_byte_order ? bo_reverse : bo_native,
323 field->name);
324 break;
d0b96690
DG
325 case ustctl_atype_array:
326 {
327 const struct ustctl_basic_type *elem_type;
328
329 elem_type = &field->type.u.array.elem_type;
330 ret = lttng_metadata_printf(session,
331 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
332 elem_type->u.basic.integer.size,
333 elem_type->u.basic.integer.alignment,
334 elem_type->u.basic.integer.signedness,
335 (elem_type->u.basic.integer.encoding == ustctl_encode_none)
336 ? "none"
337 : (elem_type->u.basic.integer.encoding == ustctl_encode_UTF8)
338 ? "UTF8"
339 : "ASCII",
340 elem_type->u.basic.integer.base,
341 elem_type->u.basic.integer.reverse_byte_order ? bo_reverse : bo_native,
342 field->name, field->type.u.array.length);
343 break;
344 }
345 case ustctl_atype_sequence:
346 {
347 const struct ustctl_basic_type *elem_type;
348 const struct ustctl_basic_type *length_type;
349
350 elem_type = &field->type.u.sequence.elem_type;
351 length_type = &field->type.u.sequence.length_type;
352 ret = lttng_metadata_printf(session,
353 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n",
354 length_type->u.basic.integer.size,
355 (unsigned int) length_type->u.basic.integer.alignment,
356 length_type->u.basic.integer.signedness,
357 (length_type->u.basic.integer.encoding == ustctl_encode_none)
358 ? "none"
359 : ((length_type->u.basic.integer.encoding == ustctl_encode_UTF8)
360 ? "UTF8"
361 : "ASCII"),
362 length_type->u.basic.integer.base,
363 length_type->u.basic.integer.reverse_byte_order ? bo_reverse : bo_native,
364 field->name);
365 if (ret)
366 return ret;
367
368 ret = lttng_metadata_printf(session,
369 " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n",
370 elem_type->u.basic.integer.size,
371 (unsigned int) elem_type->u.basic.integer.alignment,
372 elem_type->u.basic.integer.signedness,
373 (elem_type->u.basic.integer.encoding == ustctl_encode_none)
374 ? "none"
375 : ((elem_type->u.basic.integer.encoding == ustctl_encode_UTF8)
376 ? "UTF8"
377 : "ASCII"),
378 elem_type->u.basic.integer.base,
379 elem_type->u.basic.integer.reverse_byte_order ? bo_reverse : bo_native,
380 field->name,
381 field->name);
382 break;
383 }
384
385 case ustctl_atype_string:
386 /* Default encoding is UTF8 */
387 ret = lttng_metadata_printf(session,
388 " string%s _%s;\n",
389 field->type.u.basic.string.encoding == ustctl_encode_ASCII ?
390 " { encoding = ASCII; }" : "",
391 field->name);
392 break;
393 default:
394 return -EINVAL;
395 }
396 return ret;
397}
398
399static
400int _lttng_context_metadata_statedump(struct ust_registry_session *session,
401 size_t nr_ctx_fields,
402 struct ustctl_field *ctx)
403{
404 int ret = 0;
405 int i;
406
407 if (!ctx)
408 return 0;
409 for (i = 0; i < nr_ctx_fields; i++) {
410 const struct ustctl_field *field = &ctx[i];
411
412 ret = _lttng_field_statedump(session, field);
413 if (ret)
414 return ret;
415 }
416 return ret;
417}
418
419static
420int _lttng_fields_metadata_statedump(struct ust_registry_session *session,
421 struct ust_registry_event *event)
422{
423 int ret = 0;
424 int i;
425
426 for (i = 0; i < event->nr_fields; i++) {
427 const struct ustctl_field *field = &event->fields[i];
428
429 ret = _lttng_field_statedump(session, field);
430 if (ret)
431 return ret;
432 }
433 return ret;
434}
435
436/*
437 * Should be called with session registry mutex held.
438 */
439int ust_metadata_event_statedump(struct ust_registry_session *session,
440 struct ust_registry_channel *chan,
441 struct ust_registry_event *event)
442{
443 int ret = 0;
444
445 /* Don't dump metadata events */
446 if (chan->chan_id == -1U)
447 return 0;
448
449 ret = lttng_metadata_printf(session,
450 "event {\n"
451 " name = \"%s\";\n"
452 " id = %u;\n"
453 " stream_id = %u;\n",
454 event->name,
455 event->id,
456 chan->chan_id);
457 if (ret)
458 goto end;
459
460 ret = lttng_metadata_printf(session,
461 " loglevel = %d;\n",
2106efa0 462 event->loglevel_value);
d0b96690
DG
463 if (ret)
464 goto end;
465
466 if (event->model_emf_uri) {
467 ret = lttng_metadata_printf(session,
468 " model.emf.uri = \"%s\";\n",
469 event->model_emf_uri);
470 if (ret)
471 goto end;
472 }
473
d0b96690
DG
474 ret = lttng_metadata_printf(session,
475 " fields := struct {\n"
476 );
477 if (ret)
478 goto end;
479
480 ret = _lttng_fields_metadata_statedump(session, event);
481 if (ret)
482 goto end;
483
484 ret = lttng_metadata_printf(session,
485 " };\n"
486 "};\n\n");
487 if (ret)
488 goto end;
7972aab2 489 event->metadata_dumped = 1;
d0b96690
DG
490
491end:
492 return ret;
493}
494
495/*
496 * Should be called with session registry mutex held.
497 */
498int ust_metadata_channel_statedump(struct ust_registry_session *session,
499 struct ust_registry_channel *chan)
500{
501 int ret = 0;
502
503 /* Don't dump metadata events */
504 if (chan->chan_id == -1U)
505 return 0;
506
507 if (!chan->header_type)
508 return -EINVAL;
509
510 ret = lttng_metadata_printf(session,
511 "stream {\n"
512 " id = %u;\n"
513 " event.header := %s;\n"
514 " packet.context := struct packet_context;\n",
515 chan->chan_id,
516 chan->header_type == USTCTL_CHANNEL_HEADER_COMPACT ?
517 "struct event_header_compact" :
518 "struct event_header_large");
519 if (ret)
520 goto end;
521
522 if (chan->ctx_fields) {
523 ret = lttng_metadata_printf(session,
524 " event.context := struct {\n");
525 if (ret)
526 goto end;
527 }
528 ret = _lttng_context_metadata_statedump(session,
529 chan->nr_ctx_fields,
530 chan->ctx_fields);
531 if (ret)
532 goto end;
533 if (chan->ctx_fields) {
534 ret = lttng_metadata_printf(session,
535 " };\n");
536 if (ret)
537 goto end;
538 }
539
540 ret = lttng_metadata_printf(session,
541 "};\n\n");
7972aab2
DG
542 /* Flag success of metadata dump. */
543 chan->metadata_dumped = 1;
d0b96690
DG
544
545end:
546 return ret;
547}
548
549static
550int _lttng_stream_packet_context_declare(struct ust_registry_session *session)
551{
552 return lttng_metadata_printf(session,
553 "struct packet_context {\n"
554 " uint64_clock_monotonic_t timestamp_begin;\n"
555 " uint64_clock_monotonic_t timestamp_end;\n"
556 " uint64_t content_size;\n"
557 " uint64_t packet_size;\n"
558 " unsigned long events_discarded;\n"
559 " uint32_t cpu_id;\n"
560 "};\n\n"
561 );
562}
563
564/*
565 * Compact header:
566 * id: range: 0 - 30.
567 * id 31 is reserved to indicate an extended header.
568 *
569 * Large header:
570 * id: range: 0 - 65534.
571 * id 65535 is reserved to indicate an extended header.
572 */
573static
574int _lttng_event_header_declare(struct ust_registry_session *session)
575{
576 return lttng_metadata_printf(session,
577 "struct event_header_compact {\n"
578 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
579 " variant <id> {\n"
580 " struct {\n"
581 " uint27_clock_monotonic_t timestamp;\n"
582 " } compact;\n"
583 " struct {\n"
584 " uint32_t id;\n"
585 " uint64_clock_monotonic_t timestamp;\n"
586 " } extended;\n"
587 " } v;\n"
588 "} align(%u);\n"
589 "\n"
590 "struct event_header_large {\n"
591 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
592 " variant <id> {\n"
593 " struct {\n"
594 " uint32_clock_monotonic_t timestamp;\n"
595 " } compact;\n"
596 " struct {\n"
597 " uint32_t id;\n"
598 " uint64_clock_monotonic_t timestamp;\n"
599 " } extended;\n"
600 " } v;\n"
601 "} align(%u);\n\n",
602 session->uint32_t_alignment,
603 session->uint16_t_alignment
604 );
605}
606
dc113ec7
MD
607/*
608 * The offset between monotonic and realtime clock can be negative if
609 * the system sets the REALTIME clock to 0 after boot.
610 * Currently handle this by flooring the offset at 0.
611 */
d0b96690 612static
8c645bb0 613int measure_single_clock_offset(struct offset_sample *sample)
d0b96690 614{
dc113ec7 615 uint64_t monotonic_avg, monotonic[2], measure_delta, realtime;
fc0bb9fa 616 uint64_t tcf = trace_clock_freq();
dc113ec7 617 int64_t offset;
d0b96690
DG
618 struct timespec rts = { 0, 0 };
619 int ret;
620
621 monotonic[0] = trace_clock_read64();
622 ret = clock_gettime(CLOCK_REALTIME, &rts);
8c645bb0
MD
623 if (ret < 0) {
624 return ret;
625 }
d0b96690 626 monotonic[1] = trace_clock_read64();
8c645bb0
MD
627 measure_delta = monotonic[1] - monotonic[0];
628 if (measure_delta > sample->measure_delta) {
629 /*
630 * Discard value if it took longer to read than the best
631 * sample so far.
632 */
633 return 0;
634 }
dc113ec7 635 monotonic_avg = (monotonic[0] + monotonic[1]) >> 1;
6e1b0543
MD
636 realtime = (uint64_t) rts.tv_sec * tcf;
637 if (tcf == NSEC_PER_SEC) {
638 realtime += rts.tv_nsec;
639 } else {
640 realtime += (uint64_t) rts.tv_nsec * tcf / NSEC_PER_SEC;
fc0bb9fa 641 }
dc113ec7
MD
642 offset = (int64_t) realtime - monotonic_avg;
643 sample->offset = max(offset, 0);
8c645bb0
MD
644 sample->measure_delta = measure_delta;
645 return 0;
d0b96690
DG
646}
647
8c645bb0
MD
648/*
649 * Approximation of NTP time of day to clock monotonic correlation,
650 * taken at start of trace. Keep the measurement that took the less time
651 * to complete, thus removing imprecision caused by preemption.
652 */
653static
654uint64_t measure_clock_offset(void)
655{
656 int i;
657 struct offset_sample offset_best_sample = {
658 .offset = 0,
659 .measure_delta = UINT64_MAX,
660 };
661
662 for (i = 0; i < NR_CLOCK_OFFSET_SAMPLES; i++) {
663 if (measure_single_clock_offset(&offset_best_sample)) {
664 return 0;
665 }
666 }
667 return offset_best_sample.offset;
668}
d0b96690
DG
669
670/*
671 * Should be called with session registry mutex held.
672 */
673int ust_metadata_session_statedump(struct ust_registry_session *session,
af6142cf
MD
674 struct ust_app *app,
675 uint32_t major,
676 uint32_t minor)
d0b96690
DG
677{
678 unsigned char *uuid_c;
679 char uuid_s[UUID_STR_LEN],
680 clock_uuid_s[UUID_STR_LEN];
681 int ret = 0;
682 char hostname[HOST_NAME_MAX];
683
7972aab2 684 assert(session);
7972aab2 685
d0b96690
DG
686 uuid_c = session->uuid;
687
688 snprintf(uuid_s, sizeof(uuid_s),
689 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
690 uuid_c[0], uuid_c[1], uuid_c[2], uuid_c[3],
691 uuid_c[4], uuid_c[5], uuid_c[6], uuid_c[7],
692 uuid_c[8], uuid_c[9], uuid_c[10], uuid_c[11],
693 uuid_c[12], uuid_c[13], uuid_c[14], uuid_c[15]);
694
d7ba1388
MD
695 /* For crash ABI */
696 ret = lttng_metadata_printf(session,
697 "/* CTF %u.%u */\n\n",
698 CTF_SPEC_MAJOR,
699 CTF_SPEC_MINOR);
700 if (ret) {
701 goto end;
702 }
703
d0b96690
DG
704 ret = lttng_metadata_printf(session,
705 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
706 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
707 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
708 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
709 "typealias integer { size = %u; align = %u; signed = false; } := unsigned long;\n"
710 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
711 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
712 "\n"
713 "trace {\n"
714 " major = %u;\n"
715 " minor = %u;\n"
716 " uuid = \"%s\";\n"
717 " byte_order = %s;\n"
718 " packet.header := struct {\n"
719 " uint32_t magic;\n"
720 " uint8_t uuid[16];\n"
721 " uint32_t stream_id;\n"
722 " };\n"
723 "};\n\n",
724 session->uint8_t_alignment,
725 session->uint16_t_alignment,
726 session->uint32_t_alignment,
727 session->uint64_t_alignment,
728 session->bits_per_long,
729 session->long_alignment,
730 CTF_SPEC_MAJOR,
731 CTF_SPEC_MINOR,
732 uuid_s,
733 session->byte_order == BIG_ENDIAN ? "be" : "le"
734 );
735 if (ret)
736 goto end;
737
738 /* ignore error, just use empty string if error. */
739 hostname[0] = '\0';
740 ret = gethostname(hostname, sizeof(hostname));
741 if (ret && errno == ENAMETOOLONG)
742 hostname[HOST_NAME_MAX - 1] = '\0';
743 ret = lttng_metadata_printf(session,
744 "env {\n"
745 " hostname = \"%s\";\n"
746 " domain = \"ust\";\n"
747 " tracer_name = \"lttng-ust\";\n"
748 " tracer_major = %u;\n"
af6142cf 749 " tracer_minor = %u;\n",
d0b96690 750 hostname,
af6142cf
MD
751 major,
752 minor
d0b96690
DG
753 );
754 if (ret)
755 goto end;
756
757 /*
758 * If per-application registry, we can output extra information
759 * about the application.
760 */
761 if (app) {
762 ret = lttng_metadata_printf(session,
af6142cf 763 " tracer_patchlevel = %u;\n"
d0b96690 764 " vpid = %d;\n"
d88aee68 765 " procname = \"%s\";\n",
af6142cf 766 app->version.patchlevel,
d0b96690
DG
767 (int) app->pid,
768 app->name
769 );
770 if (ret)
771 goto end;
772 }
773
774 ret = lttng_metadata_printf(session,
775 "};\n\n"
776 );
777 if (ret)
778 goto end;
779
780
781 ret = lttng_metadata_printf(session,
782 "clock {\n"
fc0bb9fa
MD
783 " name = \"%s\";\n",
784 trace_clock_name()
d0b96690
DG
785 );
786 if (ret)
787 goto end;
788
789 if (!trace_clock_uuid(clock_uuid_s)) {
790 ret = lttng_metadata_printf(session,
791 " uuid = \"%s\";\n",
792 clock_uuid_s
793 );
794 if (ret)
795 goto end;
796 }
797
798 ret = lttng_metadata_printf(session,
fc0bb9fa 799 " description = \"%s\";\n"
d0b96690
DG
800 " freq = %" PRIu64 "; /* Frequency, in Hz */\n"
801 " /* clock value offset from Epoch is: offset * (1/freq) */\n"
802 " offset = %" PRIu64 ";\n"
803 "};\n\n",
fc0bb9fa 804 trace_clock_description(),
d0b96690
DG
805 trace_clock_freq(),
806 measure_clock_offset()
807 );
808 if (ret)
809 goto end;
810
811 ret = lttng_metadata_printf(session,
812 "typealias integer {\n"
813 " size = 27; align = 1; signed = false;\n"
fc0bb9fa 814 " map = clock.%s.value;\n"
d0b96690
DG
815 "} := uint27_clock_monotonic_t;\n"
816 "\n"
817 "typealias integer {\n"
818 " size = 32; align = %u; signed = false;\n"
fc0bb9fa 819 " map = clock.%s.value;\n"
d0b96690
DG
820 "} := uint32_clock_monotonic_t;\n"
821 "\n"
822 "typealias integer {\n"
823 " size = 64; align = %u; signed = false;\n"
fc0bb9fa 824 " map = clock.%s.value;\n"
d0b96690 825 "} := uint64_clock_monotonic_t;\n\n",
fc0bb9fa 826 trace_clock_name(),
d0b96690 827 session->uint32_t_alignment,
fc0bb9fa
MD
828 trace_clock_name(),
829 session->uint64_t_alignment,
830 trace_clock_name()
d0b96690
DG
831 );
832 if (ret)
833 goto end;
834
835 ret = _lttng_stream_packet_context_declare(session);
836 if (ret)
837 goto end;
838
839 ret = _lttng_event_header_declare(session);
840 if (ret)
841 goto end;
842
843end:
844 return ret;
845}
This page took 0.066304 seconds and 4 git commands to generate.