X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fust-registry-channel.cpp;fp=src%2Fbin%2Flttng-sessiond%2Fust-registry-channel.cpp;h=ceba9a8963ab333bd381e6a6a6e87a6419be1ae6;hp=f8295df4513806d60fb66a7b0903b47a49626894;hb=28ab034a2c3582d07d3423d2d746731f87d3969f;hpb=52e345b9ac912d033c2a2c25a170a01cf209839d diff --git a/src/bin/lttng-sessiond/ust-registry-channel.cpp b/src/bin/lttng-sessiond/ust-registry-channel.cpp index f8295df45..ceba9a896 100644 --- a/src/bin/lttng-sessiond/ust-registry-channel.cpp +++ b/src/bin/lttng-sessiond/ust-registry-channel.cpp @@ -5,8 +5,8 @@ * */ -#include "ust-registry-channel.hpp" #include "ust-app.hpp" +#include "ust-registry-channel.hpp" #include "ust-registry-event.hpp" #include @@ -29,7 +29,7 @@ unsigned long ht_hash_event(const void *_key, unsigned long seed) { uint64_t hashed_key; const lttng::sessiond::ust::registry_event *key = - (lttng::sessiond::ust::registry_event *) _key; + (lttng::sessiond::ust::registry_event *) _key; LTTNG_ASSERT(key); @@ -79,136 +79,162 @@ no_match: return 0; } -lst::type::cuptr create_event_header(const lst::abi& trace_abi, lst::stream_class::header_type header_type) +lst::type::cuptr create_event_header(const lst::abi& trace_abi, + lst::stream_class::header_type header_type) { lst::structure_type::fields event_header_fields; if (header_type == lst::stream_class::header_type::COMPACT) { auto enum_mappings = std::make_shared(); lst::unsigned_enumeration_type::mapping compact_mapping{ - "compact", lst::unsigned_enumeration_type::mapping::range_t(0, 30)}; - lst::unsigned_enumeration_type::mapping extended_mapping{"extended", 31}; + "compact", lst::unsigned_enumeration_type::mapping::range_t(0, 30) + }; + lst::unsigned_enumeration_type::mapping extended_mapping{ "extended", 31 }; enum_mappings->emplace_back(compact_mapping); enum_mappings->emplace_back(extended_mapping); - lst::type::cuptr choice_enum = lttng::make_unique(1, - trace_abi.byte_order, 5, lst::integer_type::base::DECIMAL, - std::move(enum_mappings), - std::initializer_list( - {lst::integer_type::role::EVENT_RECORD_CLASS_ID})); + lst::type::cuptr choice_enum = lttng::make_unique( + 1, + trace_abi.byte_order, + 5, + lst::integer_type::base::DECIMAL, + std::move(enum_mappings), + std::initializer_list( + { lst::integer_type::role::EVENT_RECORD_CLASS_ID })); - lst::variant_type:: - choices variant_choices; + lst::variant_type< + lst::unsigned_enumeration_type::mapping::range_t::range_integer_t>::choices + variant_choices; lst::structure_type::fields compact_fields; - compact_fields.emplace_back(lttng::make_unique("timestamp", - lttng::make_unique(1, trace_abi.byte_order, 27, - lst::integer_type::signedness::UNSIGNED, - lst::integer_type::base::DECIMAL, - std::initializer_list({lst::integer_type::role:: - DEFAULT_CLOCK_TIMESTAMP})))); - - auto compact_type = lttng::make_unique( - 0, std::move(compact_fields)); + compact_fields.emplace_back(lttng::make_unique( + "timestamp", + lttng::make_unique( + 1, + trace_abi.byte_order, + 27, + lst::integer_type::signedness::UNSIGNED, + lst::integer_type::base::DECIMAL, + std::initializer_list( + { lst::integer_type::role::DEFAULT_CLOCK_TIMESTAMP })))); + + auto compact_type = + lttng::make_unique(0, std::move(compact_fields)); variant_choices.emplace_back(std::move(compact_mapping), std::move(compact_type)); lst::structure_type::fields extended_fields; - extended_fields.emplace_back(lttng::make_unique("id", - lttng::make_unique(trace_abi.uint32_t_alignment, - trace_abi.byte_order, 32, - lst::integer_type::signedness::UNSIGNED, - lst::integer_type::base::DECIMAL, - std::initializer_list({lst::integer_type::role:: - EVENT_RECORD_CLASS_ID})))); - extended_fields.emplace_back(lttng::make_unique("timestamp", - lttng::make_unique(trace_abi.uint64_t_alignment, - trace_abi.byte_order, 64, - lst::integer_type::signedness::UNSIGNED, - lst::integer_type::base::DECIMAL, - std::initializer_list({lst::integer_type::role:: - DEFAULT_CLOCK_TIMESTAMP})))); - - lst::type::cuptr extended_type = lttng::make_unique(0, std::move(extended_fields)); + extended_fields.emplace_back(lttng::make_unique( + "id", + lttng::make_unique( + trace_abi.uint32_t_alignment, + trace_abi.byte_order, + 32, + lst::integer_type::signedness::UNSIGNED, + lst::integer_type::base::DECIMAL, + std::initializer_list( + { lst::integer_type::role::EVENT_RECORD_CLASS_ID })))); + extended_fields.emplace_back(lttng::make_unique( + "timestamp", + lttng::make_unique( + trace_abi.uint64_t_alignment, + trace_abi.byte_order, + 64, + lst::integer_type::signedness::UNSIGNED, + lst::integer_type::base::DECIMAL, + std::initializer_list( + { lst::integer_type::role::DEFAULT_CLOCK_TIMESTAMP })))); + + lst::type::cuptr extended_type = + lttng::make_unique(0, std::move(extended_fields)); variant_choices.emplace_back(std::move(extended_mapping), std::move(extended_type)); auto variant = lttng::make_unique>( - 0, - lst::field_location(lst::field_location::root::EVENT_RECORD_HEADER, - {"id"}), - std::move(variant_choices)); + lst::unsigned_enumeration_type::mapping::range_t::range_integer_t>>( + 0, + lst::field_location(lst::field_location::root::EVENT_RECORD_HEADER, + { "id" }), + std::move(variant_choices)); - event_header_fields.emplace_back(lttng::make_unique("id", std::move(choice_enum))); event_header_fields.emplace_back( - lttng::make_unique("v", std::move(variant))); + lttng::make_unique("id", std::move(choice_enum))); + event_header_fields.emplace_back( + lttng::make_unique("v", std::move(variant))); } else { auto enum_mappings = std::make_shared(); - lst::unsigned_enumeration_type::mapping compact_mapping{"compact", - lst::unsigned_enumeration_type::mapping::range_t(0, 65534)}; - lst::unsigned_enumeration_type::mapping extended_mapping{"extended", 65535}; + lst::unsigned_enumeration_type::mapping compact_mapping{ + "compact", lst::unsigned_enumeration_type::mapping::range_t(0, 65534) + }; + lst::unsigned_enumeration_type::mapping extended_mapping{ "extended", 65535 }; enum_mappings->emplace_back(compact_mapping); enum_mappings->emplace_back(extended_mapping); auto choice_enum = lttng::make_unique( - trace_abi.uint16_t_alignment, trace_abi.byte_order, 16, - lst::integer_type::base::DECIMAL, std::move(enum_mappings), - std::initializer_list( - {lst::integer_type::role::EVENT_RECORD_CLASS_ID})); - - lst::variant_type:: - choices variant_choices; + trace_abi.uint16_t_alignment, + trace_abi.byte_order, + 16, + lst::integer_type::base::DECIMAL, + std::move(enum_mappings), + std::initializer_list( + { lst::integer_type::role::EVENT_RECORD_CLASS_ID })); + + lst::variant_type< + lst::unsigned_enumeration_type::mapping::range_t::range_integer_t>::choices + variant_choices; lst::structure_type::fields compact_fields; - compact_fields.emplace_back(lttng::make_unique("timestamp", - lttng::make_unique(trace_abi.uint32_t_alignment, - trace_abi.byte_order, 32, - lst::integer_type::signedness::UNSIGNED, - lst::integer_type::base::DECIMAL, - std::initializer_list({lst::integer_type::role:: - DEFAULT_CLOCK_TIMESTAMP})))); - - lst::type::cuptr compact_type = lttng::make_unique( - 0, std::move(compact_fields)); + compact_fields.emplace_back(lttng::make_unique( + "timestamp", + lttng::make_unique( + trace_abi.uint32_t_alignment, + trace_abi.byte_order, + 32, + lst::integer_type::signedness::UNSIGNED, + lst::integer_type::base::DECIMAL, + std::initializer_list( + { lst::integer_type::role::DEFAULT_CLOCK_TIMESTAMP })))); + + lst::type::cuptr compact_type = + lttng::make_unique(0, std::move(compact_fields)); variant_choices.emplace_back(std::move(compact_mapping), std::move(compact_type)); lst::structure_type::fields extended_fields; - extended_fields.emplace_back(lttng::make_unique("id", - lttng::make_unique(trace_abi.uint32_t_alignment, - trace_abi.byte_order, 32, - lst::integer_type::signedness::UNSIGNED, - lst::integer_type::base::DECIMAL, - std::initializer_list({lst::integer_type::role:: - EVENT_RECORD_CLASS_ID})))); - extended_fields.emplace_back(lttng::make_unique("timestamp", - lttng::make_unique(trace_abi.uint64_t_alignment, - trace_abi.byte_order, 64, - lst::integer_type::signedness::UNSIGNED, - lst::integer_type::base::DECIMAL, - std::initializer_list({lst::integer_type::role:: - DEFAULT_CLOCK_TIMESTAMP})))); - - auto extended_type = lttng::make_unique( - 0, std::move(extended_fields)); + extended_fields.emplace_back(lttng::make_unique( + "id", + lttng::make_unique( + trace_abi.uint32_t_alignment, + trace_abi.byte_order, + 32, + lst::integer_type::signedness::UNSIGNED, + lst::integer_type::base::DECIMAL, + std::initializer_list( + { lst::integer_type::role::EVENT_RECORD_CLASS_ID })))); + extended_fields.emplace_back(lttng::make_unique( + "timestamp", + lttng::make_unique( + trace_abi.uint64_t_alignment, + trace_abi.byte_order, + 64, + lst::integer_type::signedness::UNSIGNED, + lst::integer_type::base::DECIMAL, + std::initializer_list( + { lst::integer_type::role::DEFAULT_CLOCK_TIMESTAMP })))); + + auto extended_type = + lttng::make_unique(0, std::move(extended_fields)); variant_choices.emplace_back(std::move(extended_mapping), std::move(extended_type)); auto variant = lttng::make_unique>( - 0, - lst::field_location(lst::field_location::root::EVENT_RECORD_HEADER, - {"id"}), - std::move(variant_choices)); + lst::unsigned_enumeration_type::mapping::range_t::range_integer_t>>( + 0, + lst::field_location(lst::field_location::root::EVENT_RECORD_HEADER, + { "id" }), + std::move(variant_choices)); event_header_fields.emplace_back( - lttng::make_unique("id", std::move(choice_enum))); + lttng::make_unique("id", std::move(choice_enum))); event_header_fields.emplace_back( - lttng::make_unique("v", std::move(variant))); + lttng::make_unique("v", std::move(variant))); } return lttng::make_unique(0, std::move(event_header_fields)); @@ -219,78 +245,106 @@ lst::type::cuptr create_packet_context(const lst::abi& trace_abi) lst::structure_type::fields packet_context_fields; /* uint64_t timestamp_begin */ - packet_context_fields.emplace_back(lttng::make_unique("timestamp_begin", - lttng::make_unique(trace_abi.uint64_t_alignment, - trace_abi.byte_order, 64, - lst::integer_type::signedness::UNSIGNED, - lst::integer_type::base::DECIMAL, - std::initializer_list({lst::integer_type::role::DEFAULT_CLOCK_TIMESTAMP})))); + packet_context_fields.emplace_back(lttng::make_unique( + "timestamp_begin", + lttng::make_unique( + trace_abi.uint64_t_alignment, + trace_abi.byte_order, + 64, + lst::integer_type::signedness::UNSIGNED, + lst::integer_type::base::DECIMAL, + std::initializer_list( + { lst::integer_type::role::DEFAULT_CLOCK_TIMESTAMP })))); /* uint64_t timestamp_end */ - packet_context_fields.emplace_back(lttng::make_unique("timestamp_end", - lttng::make_unique(trace_abi.uint64_t_alignment, - trace_abi.byte_order, 64, - lst::integer_type::signedness::UNSIGNED, - lst::integer_type::base::DECIMAL, - std::initializer_list({lst::integer_type::role::PACKET_END_DEFAULT_CLOCK_TIMESTAMP})))); + packet_context_fields.emplace_back(lttng::make_unique( + "timestamp_end", + lttng::make_unique( + trace_abi.uint64_t_alignment, + trace_abi.byte_order, + 64, + lst::integer_type::signedness::UNSIGNED, + lst::integer_type::base::DECIMAL, + std::initializer_list( + { lst::integer_type::role::PACKET_END_DEFAULT_CLOCK_TIMESTAMP })))); /* uint64_t content_size */ - packet_context_fields.emplace_back(lttng::make_unique("content_size", - lttng::make_unique(trace_abi.uint64_t_alignment, - trace_abi.byte_order, 64, - lst::integer_type::signedness::UNSIGNED, - lst::integer_type::base::DECIMAL, - std::initializer_list({lst::integer_type::role::PACKET_CONTENT_LENGTH})))); + packet_context_fields.emplace_back(lttng::make_unique( + "content_size", + lttng::make_unique( + trace_abi.uint64_t_alignment, + trace_abi.byte_order, + 64, + lst::integer_type::signedness::UNSIGNED, + lst::integer_type::base::DECIMAL, + std::initializer_list( + { lst::integer_type::role::PACKET_CONTENT_LENGTH })))); /* uint64_t packet_size */ - packet_context_fields.emplace_back(lttng::make_unique("packet_size", - lttng::make_unique(trace_abi.uint64_t_alignment, - trace_abi.byte_order, 64, - lst::integer_type::signedness::UNSIGNED, - lst::integer_type::base::DECIMAL, - std::initializer_list({lst::integer_type::role::PACKET_TOTAL_LENGTH})))); + packet_context_fields.emplace_back(lttng::make_unique( + "packet_size", + lttng::make_unique( + trace_abi.uint64_t_alignment, + trace_abi.byte_order, + 64, + lst::integer_type::signedness::UNSIGNED, + lst::integer_type::base::DECIMAL, + std::initializer_list( + { lst::integer_type::role::PACKET_TOTAL_LENGTH })))); /* uint64_t packet_seq_num */ - packet_context_fields.emplace_back(lttng::make_unique("packet_seq_num", - lttng::make_unique(trace_abi.uint64_t_alignment, - trace_abi.byte_order, 64, - lst::integer_type::signedness::UNSIGNED, - lst::integer_type::base::DECIMAL, - std::initializer_list({lst::integer_type::role::PACKET_SEQUENCE_NUMBER})))); + packet_context_fields.emplace_back(lttng::make_unique( + "packet_seq_num", + lttng::make_unique( + trace_abi.uint64_t_alignment, + trace_abi.byte_order, + 64, + lst::integer_type::signedness::UNSIGNED, + lst::integer_type::base::DECIMAL, + std::initializer_list( + { lst::integer_type::role::PACKET_SEQUENCE_NUMBER })))); /* unsigned long events_discarded */ - packet_context_fields.emplace_back(lttng::make_unique("events_discarded", - lttng::make_unique(trace_abi.long_alignment, - trace_abi.byte_order, trace_abi.bits_per_long, - lst::integer_type::signedness::UNSIGNED, - lst::integer_type::base::DECIMAL, - std::initializer_list({lst::integer_type::role::DISCARDED_EVENT_RECORD_COUNTER_SNAPSHOT})))); + packet_context_fields.emplace_back(lttng::make_unique( + "events_discarded", + lttng::make_unique( + trace_abi.long_alignment, + trace_abi.byte_order, + trace_abi.bits_per_long, + lst::integer_type::signedness::UNSIGNED, + lst::integer_type::base::DECIMAL, + std::initializer_list( + { lst::integer_type::role:: + DISCARDED_EVENT_RECORD_COUNTER_SNAPSHOT })))); /* uint32_t cpu_id */ - packet_context_fields.emplace_back(lttng::make_unique("cpu_id", - lttng::make_unique(trace_abi.uint32_t_alignment, - trace_abi.byte_order, 32, - lst::integer_type::signedness::UNSIGNED, - lst::integer_type::base::DECIMAL))); + packet_context_fields.emplace_back(lttng::make_unique( + "cpu_id", + lttng::make_unique(trace_abi.uint32_t_alignment, + trace_abi.byte_order, + 32, + lst::integer_type::signedness::UNSIGNED, + lst::integer_type::base::DECIMAL))); return lttng::make_unique(0, std::move(packet_context_fields)); } }; /* namespace */ -lsu::registry_channel::registry_channel(unsigned int channel_id, - const lst::abi& trace_abi, - std::string in_default_clock_class_name, - lsu::registry_channel::registered_listener_fn channel_registered_listener, - lsu::registry_channel::event_added_listener_fn event_added_listener) : +lsu::registry_channel::registry_channel( + unsigned int channel_id, + const lst::abi& trace_abi, + std::string in_default_clock_class_name, + lsu::registry_channel::registered_listener_fn channel_registered_listener, + lsu::registry_channel::event_added_listener_fn event_added_listener) : lst::stream_class(channel_id, - lst::stream_class::header_type::LARGE, - std::move(in_default_clock_class_name)), - _key{-1ULL}, - _consumer_key{-1ULL}, - _next_event_id{0}, - _is_registered_listener{channel_registered_listener}, - _event_added_listener{event_added_listener}, - _is_registered{false} + lst::stream_class::header_type::LARGE, + std::move(in_default_clock_class_name)), + _key{ -1ULL }, + _consumer_key{ -1ULL }, + _next_event_id{ 0 }, + _is_registered_listener{ channel_registered_listener }, + _event_added_listener{ event_added_listener }, + _is_registered{ false } { _events = lttng_ht_new(0, LTTNG_HT_TYPE_STRING); if (!_events) { @@ -312,17 +366,16 @@ lsu::registry_channel::registry_channel(unsigned int channel_id, _event_header = create_event_header(trace_abi, header_type_); } -void lsu::registry_channel::add_event( - int session_objd, - int channel_objd, - std::string name, - std::string signature, - std::vector event_fields, - int loglevel_value, - nonstd::optional model_emf_uri, - lttng_buffer_type buffer_type, - const ust_app& app, - uint32_t& out_event_id) +void lsu::registry_channel::add_event(int session_objd, + int channel_objd, + std::string name, + std::string signature, + std::vector event_fields, + int loglevel_value, + nonstd::optional model_emf_uri, + lttng_buffer_type buffer_type, + const ust_app& app, + uint32_t& out_event_id) { uint32_t event_id; struct cds_lfht_node *nptr; @@ -334,27 +387,33 @@ void lsu::registry_channel::add_event( */ if (session_objd < 0) { LTTNG_THROW_INVALID_ARGUMENT_ERROR(fmt::format( - "Invalid session object descriptor provided by application: session descriptor = {}, app = {}", - session_objd, app)); + "Invalid session object descriptor provided by application: session descriptor = {}, app = {}", + session_objd, + app)); } if (channel_objd < 0) { LTTNG_THROW_INVALID_ARGUMENT_ERROR(fmt::format( - "Invalid channel object descriptor provided by application: channel descriptor = {}, app = {}", - channel_objd, app)); + "Invalid channel object descriptor provided by application: channel descriptor = {}, app = {}", + channel_objd, + app)); } /* Check if we've reached the maximum possible id. */ if (is_max_event_id(_next_event_id)) { LTTNG_THROW_ERROR(fmt::format( - "Failed to allocate new event id (id would overflow): app = {}", - app)); + "Failed to allocate new event id (id would overflow): app = {}", app)); } auto event = lttng::make_unique_wrapper( - new lsu::registry_event(_next_event_id, id, session_objd, channel_objd, - std::move(name), std::move(signature), - std::move(event_fields), loglevel_value, + new lsu::registry_event(_next_event_id, + id, + session_objd, + channel_objd, + std::move(name), + std::move(signature), + std::move(event_fields), + loglevel_value, std::move(model_emf_uri))); DBG3("%s", fmt::format("UST registry creating event: event = {}", *event).c_str()); @@ -363,8 +422,11 @@ void lsu::registry_channel::add_event( * This is an add unique with a custom match function for event. The node * are matched using the event name and signature. */ - nptr = cds_lfht_add_unique(_events->ht, _events->hash_fct(event.get(), lttng_ht_seed), - _events->match_fct, event.get(), &event->_node); + nptr = cds_lfht_add_unique(_events->ht, + _events->hash_fct(event.get(), lttng_ht_seed), + _events->match_fct, + event.get(), + &event->_node); if (nptr != &event->_node) { if (buffer_type == LTTNG_BUFFER_PER_UID) { /* @@ -372,12 +434,12 @@ void lsu::registry_channel::add_event( * returned node. */ const auto existing_event = lttng::utils::container_of( - nptr, <tng::sessiond::ust::registry_event::_node); + nptr, <tng::sessiond::ust::registry_event::_node); event_id = existing_event->id; } else { LTTNG_THROW_INVALID_ARGUMENT_ERROR(fmt::format( - "UST registry create event add unique failed for event: event = {}", - *event)); + "UST registry create event add unique failed for event: event = {}", + *event)); } } else { const auto& event_ref = *event; @@ -404,7 +466,7 @@ lsu::registry_channel::~registry_channel() lttng_ht_destroy(_events); } -const lttng::sessiond::trace::type* lsu::registry_channel::event_context() const +const lttng::sessiond::trace::type *lsu::registry_channel::event_context() const { LTTNG_ASSERT(_is_registered); return lst::stream_class::event_context(); @@ -431,7 +493,7 @@ void lsu::registry_channel::set_as_registered() } void lsu::registry_channel::_accept_on_event_classes( - lttng::sessiond::trace::trace_class_visitor& visitor) const + lttng::sessiond::trace::trace_class_visitor& visitor) const { std::vector sorted_event_classes; @@ -442,17 +504,16 @@ void lsu::registry_channel::_accept_on_event_classes( DIAGNOSTIC_PUSH DIAGNOSTIC_IGNORE_INVALID_OFFSETOF - cds_lfht_for_each_entry(_events->ht, &iter.iter, event, _node) { + cds_lfht_for_each_entry (_events->ht, &iter.iter, event, _node) { sorted_event_classes.emplace_back(event); } DIAGNOSTIC_POP } - std::sort(sorted_event_classes.begin(), sorted_event_classes.end(), - [](const lttng::sessiond::ust::registry_event *a, - const lttng::sessiond::ust::registry_event *b) { - return a->id < b->id; - }); + std::sort(sorted_event_classes.begin(), + sorted_event_classes.end(), + [](const lttng::sessiond::ust::registry_event *a, + const lttng::sessiond::ust::registry_event *b) { return a->id < b->id; }); for (const auto event : sorted_event_classes) { event->accept(visitor);