X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fust-metadata.cpp;h=3a2eb5ca2446b5042884d5917c468df281cb3bf5;hb=f149493493fbd8a3efa4748832c03278c96c38ca;hp=d08cb40ae7f10ade8a8add223997a2e7aa884bed;hpb=e4589ae2396a53ed0b17251616694afeefba2986;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/ust-metadata.cpp b/src/bin/lttng-sessiond/ust-metadata.cpp index d08cb40ae..3a2eb5ca2 100644 --- a/src/bin/lttng-sessiond/ust-metadata.cpp +++ b/src/bin/lttng-sessiond/ust-metadata.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include "ust-registry.hpp" #include "ust-clock.hpp" @@ -22,10 +23,14 @@ #define NR_CLOCK_OFFSET_SAMPLES 10 +namespace { struct offset_sample { - int64_t offset; /* correlation offset */ - uint64_t measure_delta; /* lower is better */ + /* correlation offset */ + int64_t offset; + /* lower is better */ + uint64_t measure_delta; }; +} /* namespace */ static int _lttng_field_statedump(struct ust_registry_session *session, @@ -841,6 +846,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" @@ -895,12 +910,16 @@ end: /* * Should be called with session registry mutex held. + * + * RCU read lock must be held by the caller. */ int ust_metadata_channel_statedump(struct ust_registry_session *session, struct ust_registry_channel *chan) { int ret; + ASSERT_RCU_READ_LOCKED(); + /* Don't dump metadata events */ if (chan->chan_id == -1U) return 0; @@ -951,6 +970,31 @@ int ust_metadata_channel_statedump(struct ust_registry_session *session, /* Flag success of metadata dump. */ chan->metadata_dumped = 1; + /* + * 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; }