X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fust-metadata.cpp;h=566799efd08b2016e7ce24edeeadb3cd70937d04;hb=bacc39bbfbccc984d2b558b41cf8ab42a8592d09;hp=abe473f27ce78c6032f4de2b5d1bc869aaa31a0b;hpb=7966af5763c4aaca39df9bbfa9277ff15715c720;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/ust-metadata.cpp b/src/bin/lttng-sessiond/ust-metadata.cpp index abe473f27..566799efd 100644 --- a/src/bin/lttng-sessiond/ust-metadata.cpp +++ b/src/bin/lttng-sessiond/ust-metadata.cpp @@ -13,16 +13,13 @@ #include #include #include -#include -#include +#include +#include +#include -#include "ust-registry.h" -#include "ust-clock.h" -#include "ust-app.h" - -#ifndef max_t -#define max_t(type, a, b) ((type) ((a) > (b) ? (a) : (b))) -#endif +#include "ust-registry.hpp" +#include "ust-clock.hpp" +#include "ust-app.hpp" #define NR_CLOCK_OFFSET_SAMPLES 10 @@ -69,7 +66,7 @@ ssize_t metadata_reserve(struct ust_registry_session *session, size_t len) char *newptr; new_alloc_len = - max_t(size_t, 1U << get_count_order(new_alloc_len), old_alloc_len << 1); + std::max(1U << get_count_order(new_alloc_len), old_alloc_len << 1); newptr = (char *) realloc(session->metadata, new_alloc_len); if (!newptr) return -ENOMEM; @@ -106,7 +103,7 @@ int metadata_file_append(struct ust_registry_session *session, * remaining space left in packet and write, since mutual exclusion * protects us from concurrent writes. */ -static +static ATTR_FORMAT_PRINTF(2, 3) int lttng_metadata_printf(struct ust_registry_session *session, const char *fmt, ...) { @@ -315,10 +312,10 @@ int ust_metadata_enum_statedump(struct ust_registry_session *session, if (entry->start.signedness) { ret = lttng_metadata_printf(session, - "%lld", (long long) entry->start.value); + "%" PRId64, entry->start.value); } else { ret = lttng_metadata_printf(session, - "%llu", entry->start.value); + "%" PRIu64, entry->start.value); } if (ret) { goto end; @@ -331,11 +328,11 @@ int ust_metadata_enum_statedump(struct ust_registry_session *session, } else { if (entry->end.signedness) { ret = lttng_metadata_printf(session, - " ... %lld,\n", - (long long) entry->end.value); + " ... %" PRId64 ",\n", + entry->end.value); } else { ret = lttng_metadata_printf(session, - " ... %llu,\n", + " ... %" PRIu64 ",\n", entry->end.value); } } @@ -369,10 +366,6 @@ int _lttng_variant_statedump(struct ust_registry_session *session, int ret; char identifier[LTTNG_UST_ABI_SYM_NAME_LEN]; - if (variant->type.atype != lttng_ust_ctl_atype_variant) { - ret = -EINVAL; - goto end; - } (*iter_field)++; sanitize_ctf_identifier(identifier, tag_name); if (alignment) { @@ -849,6 +842,16 @@ int ust_metadata_event_statedump(struct ust_registry_session *session, if (chan->chan_id == -1U) return 0; + /* + * We don't want to output an event's metadata before its parent + * stream's metadata. If the stream's metadata hasn't been output yet, + * skip this event. Its metadata will be output when we output the + * stream's metadata. + */ + if (!chan->metadata_dumped || event->metadata_dumped) { + return 0; + } + ret = lttng_metadata_printf(session, "event {\n" " name = \"%s\";\n" @@ -907,7 +910,7 @@ end: int ust_metadata_channel_statedump(struct ust_registry_session *session, struct ust_registry_channel *chan) { - int ret = 0; + int ret; /* Don't dump metadata events */ if (chan->chan_id == -1U) @@ -926,37 +929,65 @@ int ust_metadata_channel_statedump(struct ust_registry_session *session, "struct event_header_compact" : "struct event_header_large"); if (ret) { - goto end; + return ret; } if (chan->ctx_fields) { ret = lttng_metadata_printf(session, " event.context := struct {\n"); if (ret) { - goto end; + return ret; } } ret = _lttng_context_metadata_statedump(session, chan->nr_ctx_fields, chan->ctx_fields); if (ret) { - goto end; + return ret; } if (chan->ctx_fields) { ret = lttng_metadata_printf(session, " };\n"); if (ret) { - goto end; + return ret; } } ret = lttng_metadata_printf(session, "};\n\n"); + if (ret) { + return ret; + } + /* Flag success of metadata dump. */ chan->metadata_dumped = 1; -end: - return ret; + /* + * Output the metadata of any existing event. + * + * Sort the events by id. This is not necessary, but it's nice to have + * a more predictable order in the metadata file. + */ + std::vector events; + { + cds_lfht_iter event_iter; + ust_registry_event *event; + cds_lfht_for_each_entry(chan->events->ht, &event_iter, event, + node.node) { + events.push_back(event); + } + } + + std::sort(events.begin(), events.end(), + [] (ust_registry_event *a, ust_registry_event *b) { + return a->id < b->id; + }); + + for (ust_registry_event *event : events) { + ust_metadata_event_statedump(session, chan, event); + } + + return 0; } static