X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Ftsdl-trace-class-visitor.cpp;h=7e45f0a8a1fdbd4c0081d5b51ae7b816ca61345c;hb=f9a4135756da1947c2aa00e5b1e3c8e572d02107;hp=3c628fb412f813974dc541c8b53dfdbc6fd44837;hpb=28ab034a2c3582d07d3423d2d746731f87d3969f;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/tsdl-trace-class-visitor.cpp b/src/bin/lttng-sessiond/tsdl-trace-class-visitor.cpp index 3c628fb41..7e45f0a8a 100644 --- a/src/bin/lttng-sessiond/tsdl-trace-class-visitor.cpp +++ b/src/bin/lttng-sessiond/tsdl-trace-class-visitor.cpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace lst = lttng::sessiond::trace; namespace tsdl = lttng::sessiond::tsdl; @@ -138,7 +139,7 @@ public: variant_tsdl_keyword_sanitizer(tsdl::details::type_overrider& type_overrides, type_lookup_function lookup_type) : - _type_overrides{ type_overrides }, _lookup_type(lookup_type) + _type_overrides(type_overrides), _lookup_type(std::move(lookup_type)) { } @@ -152,56 +153,48 @@ private: }; using unsafe_names = std::set; - virtual void visit(const lst::field& field) override final + void visit(const lst::field& field) final { _type_overrides.type(field.get_type()).accept(*this); } - virtual void visit(const lst::integer_type& type __attribute__((unused))) override final + void visit(const lst::integer_type& type __attribute__((unused))) final { } - virtual void visit(const lst::floating_point_type& type - __attribute__((unused))) override final + void visit(const lst::floating_point_type& type __attribute__((unused))) final { } - virtual void visit(const lst::signed_enumeration_type& type - __attribute__((unused))) override final + void visit(const lst::signed_enumeration_type& type __attribute__((unused))) final { } - virtual void visit(const lst::unsigned_enumeration_type& type - __attribute__((unused))) override final + void visit(const lst::unsigned_enumeration_type& type __attribute__((unused))) final { } - virtual void visit(const lst::static_length_array_type& type - __attribute__((unused))) override final + void visit(const lst::static_length_array_type& type __attribute__((unused))) final { } - virtual void visit(const lst::dynamic_length_array_type& type - __attribute__((unused))) override final + void visit(const lst::dynamic_length_array_type& type __attribute__((unused))) final { } - virtual void visit(const lst::static_length_blob_type& type - __attribute__((unused))) override final + void visit(const lst::static_length_blob_type& type __attribute__((unused))) final { } - virtual void visit(const lst::dynamic_length_blob_type& type - __attribute__((unused))) override final + void visit(const lst::dynamic_length_blob_type& type __attribute__((unused))) final { } - virtual void visit(const lst::null_terminated_string_type& type - __attribute__((unused))) override final + void visit(const lst::null_terminated_string_type& type __attribute__((unused))) final { } - virtual void visit(const lst::structure_type& type) override final + void visit(const lst::structure_type& type) final { /* Recurse into structure attributes. */ for (const auto& field : type.fields_) { @@ -229,7 +222,7 @@ private: new_mappings->emplace_back(mapping); } else { /* Unsafe mapping, rename it and keep the rest of its attributes. */ - new_mappings->emplace_back(fmt::format("_{}", mapping.name), + new_mappings->emplace_back(lttng::format("_{}", mapping.name), mapping.range); } } @@ -255,7 +248,7 @@ private: } } - LTTNG_THROW_ERROR(fmt::format( + LTTNG_THROW_ERROR(lttng::format( "Failed to find mapping by range in enumeration while sanitizing a variant: target_mapping_range={}", target_mapping_range)); } @@ -343,27 +336,23 @@ private: _type_overrides.publish(type, std::move(sanitized_variant_type)); } - virtual void visit(const lst::variant_type< - lst::signed_enumeration_type::mapping::range_t::range_integer_t>& type) - override final + void visit(const lst::variant_type< + lst::signed_enumeration_type::mapping::range_t::range_integer_t>& type) final { visit_variant(type); } - virtual void visit(const lst::variant_type< - lst::unsigned_enumeration_type::mapping::range_t::range_integer_t>& type) - override final + void visit(const lst::variant_type< + lst::unsigned_enumeration_type::mapping::range_t::range_integer_t>& type) final { visit_variant(type); } - virtual void visit(const lst::static_length_string_type& type - __attribute__((unused))) override final + void visit(const lst::static_length_string_type& type __attribute__((unused))) final { } - virtual void visit(const lst::dynamic_length_string_type& type - __attribute__((unused))) override final + void visit(const lst::dynamic_length_string_type& type __attribute__((unused))) final { } @@ -379,13 +368,13 @@ public: const tsdl::details::type_overrider& type_overrides, const nonstd::optional& in_default_clock_class_name = nonstd::nullopt) : - _indentation_level{ indentation_level }, - _trace_abi{ abi }, - _bypass_identifier_escape{ false }, - _default_clock_class_name{ in_default_clock_class_name ? - in_default_clock_class_name->c_str() : - nullptr }, - _type_overrides{ type_overrides } + _indentation_level(indentation_level), + _trace_abi(abi), + + _default_clock_class_name(in_default_clock_class_name ? + in_default_clock_class_name->c_str() : + nullptr), + _type_overrides(type_overrides) { } @@ -396,7 +385,7 @@ public: } private: - virtual void visit(const lst::field& field) override final + void visit(const lst::field& field) final { /* * Hack: keep the name of the field being visited since @@ -425,14 +414,14 @@ private: _description += ";"; } - virtual void visit(const lst::integer_type& type) override final + void visit(const lst::integer_type& type) final { _description += "integer { "; /* Mandatory properties (no defaults). */ - _description += fmt::format("size = {size}; align = {alignment};", - fmt::arg("size", type.size), - fmt::arg("alignment", type.alignment)); + _description += lttng::format("size = {size}; align = {alignment};", + fmt::arg("size", type.size), + fmt::arg("alignment", type.alignment)); /* Defaults to unsigned. */ if (type.signedness_ == lst::integer_type::signedness::SIGNED) { @@ -454,12 +443,12 @@ private: base = 16; break; default: - LTTNG_THROW_ERROR(fmt::format( + LTTNG_THROW_ERROR(lttng::format( "Unexpected base encountered while serializing integer type to TSDL: base = {}", (int) type.base_)); } - _description += fmt::format(" base = {};", base); + _description += lttng::format(" base = {};", base); } /* Defaults to the trace's native byte order. */ @@ -467,7 +456,7 @@ private: const auto byte_order_str = type.byte_order == lst::byte_order::BIG_ENDIAN_ ? "be" : "le"; - _description += fmt::format(" byte_order = {};", byte_order_str); + _description += lttng::format(" byte_order = {};", byte_order_str); } if (_current_integer_encoding_override) { @@ -481,12 +470,12 @@ private: encoding_str = "UTF8"; break; default: - LTTNG_THROW_ERROR(fmt::format( + LTTNG_THROW_ERROR(lttng::format( "Unexpected encoding encountered while serializing integer type to TSDL: encoding = {}", (int) *_current_integer_encoding_override)); } - _description += fmt::format(" encoding = {};", encoding_str); + _description += lttng::format(" encoding = {};", encoding_str); _current_integer_encoding_override.reset(); } @@ -500,15 +489,15 @@ private: type.roles_.end()) { LTTNG_ASSERT(_default_clock_class_name); _description += - fmt::format(" map = clock.{}.value;", _default_clock_class_name); + lttng::format(" map = clock.{}.value;", _default_clock_class_name); } _description += " }"; } - virtual void visit(const lst::floating_point_type& type) override final + void visit(const lst::floating_point_type& type) final { - _description += fmt::format( + _description += lttng::format( "floating_point {{ align = {alignment}; mant_dig = {mantissa_digits}; exp_dig = {exponent_digits};", fmt::arg("alignment", type.alignment), fmt::arg("mantissa_digits", type.mantissa_digits), @@ -519,7 +508,7 @@ private: const auto byte_order_str = type.byte_order == lst::byte_order::BIG_ENDIAN_ ? "be" : "le"; - _description += fmt::format(" byte_order = {};", byte_order_str); + _description += lttng::format(" byte_order = {};", byte_order_str); } _description += " }"; @@ -544,12 +533,12 @@ private: _description.resize(_description.size() + mappings_indentation_level, '\t'); if (mapping.range.begin == mapping.range.end) { - _description += - fmt::format("\"{mapping_name}\" = {mapping_value}", - fmt::arg("mapping_name", mapping.name), - fmt::arg("mapping_value", mapping.range.begin)); + _description += lttng::format( + "\"{mapping_name}\" = {mapping_value}", + fmt::arg("mapping_name", mapping.name), + fmt::arg("mapping_value", mapping.range.begin)); } else { - _description += fmt::format( + _description += lttng::format( "\"{mapping_name}\" = {mapping_range_begin} ... {mapping_range_end}", fmt::arg("mapping_name", mapping.name), fmt::arg("mapping_range_begin", mapping.range.begin), @@ -564,21 +553,21 @@ private: _description += "}"; } - virtual void visit(const lst::signed_enumeration_type& type) override final + void visit(const lst::signed_enumeration_type& type) final { visit_enumeration(type); } - virtual void visit(const lst::unsigned_enumeration_type& type) override final + void visit(const lst::unsigned_enumeration_type& type) final { visit_enumeration(type); } - virtual void visit(const lst::static_length_array_type& type) override final + void visit(const lst::static_length_array_type& type) final { if (type.alignment != 0) { LTTNG_ASSERT(_current_field_name.size() > 0); - _description += fmt::format( + _description += lttng::format( "struct {{ }} align({alignment}) {field_name}_padding;\n", fmt::arg("alignment", type.alignment), fmt::arg("field_name", _current_field_name.top())); @@ -586,10 +575,10 @@ private: } type.element_type->accept(*this); - _type_suffixes.emplace(fmt::format("[{}]", type.length)); + _type_suffixes.emplace(lttng::format("[{}]", type.length)); } - virtual void visit(const lst::dynamic_length_array_type& type) override final + void visit(const lst::dynamic_length_array_type& type) final { if (type.alignment != 0) { /* @@ -599,7 +588,7 @@ private: * would allow us to express alignment constraints. */ LTTNG_ASSERT(_current_field_name.size() > 0); - _description += fmt::format( + _description += lttng::format( "struct {{ }} align({alignment}) {field_name}_padding;\n", fmt::arg("alignment", type.alignment), fmt::arg("field_name", _current_field_name.top())); @@ -607,7 +596,7 @@ private: } type.element_type->accept(*this); - _type_suffixes.emplace(fmt::format( + _type_suffixes.emplace(lttng::format( "[{}]", _bypass_identifier_escape ? *(type.length_field_location.elements_.end() - 1) : @@ -615,7 +604,7 @@ private: *(type.length_field_location.elements_.end() - 1)))); } - virtual void visit(const lst::static_length_blob_type& type) override final + void visit(const lst::static_length_blob_type& type) final { /* This type doesn't exist in CTF 1.x, express it as a static length array of * uint8_t. */ @@ -632,7 +621,7 @@ private: visit(*array); } - virtual void visit(const lst::dynamic_length_blob_type& type) override final + void visit(const lst::dynamic_length_blob_type& type) final { /* This type doesn't exist in CTF 1.x, express it as a dynamic length array of * uint8_t. */ @@ -649,7 +638,7 @@ private: visit(*array); } - virtual void visit(const lst::null_terminated_string_type& type) override final + void visit(const lst::null_terminated_string_type& type) final { /* Defaults to UTF-8. */ if (type.encoding_ == lst::null_terminated_string_type::encoding::ASCII) { @@ -659,7 +648,7 @@ private: } } - virtual void visit(const lst::structure_type& type) override final + void visit(const lst::structure_type& type) final { _indentation_level++; _description += "struct {"; @@ -688,7 +677,7 @@ private: { if (type.alignment != 0) { LTTNG_ASSERT(_current_field_name.size() > 0); - _description += fmt::format( + _description += lttng::format( "struct {{ }} align({alignment}) {field_name}_padding;\n", fmt::arg("alignment", type.alignment), fmt::arg("field_name", _current_field_name.top())); @@ -696,7 +685,7 @@ private: } _indentation_level++; - _description += fmt::format( + _description += lttng::format( "variant <{}> {{\n", _bypass_identifier_escape ? *(type.selector_field_location.elements_.end() - 1) : @@ -714,7 +703,7 @@ private: for (const auto& field : type.choices_) { _description.resize(_description.size() + _indentation_level, '\t'); field.second->accept(*this); - _description += fmt::format(" {};\n", field.first.name); + _description += lttng::format(" {};\n", field.first.name); } _bypass_identifier_escape = previous_bypass_identifier_escape; @@ -724,16 +713,14 @@ private: _description += "}"; } - virtual void visit(const lst::variant_type< - lst::signed_enumeration_type::mapping::range_t::range_integer_t>& type) - override final + void visit(const lst::variant_type< + lst::signed_enumeration_type::mapping::range_t::range_integer_t>& type) final { visit_variant(type); } - virtual void visit(const lst::variant_type< - lst::unsigned_enumeration_type::mapping::range_t::range_integer_t>& type) - override final + void visit(const lst::variant_type< + lst::unsigned_enumeration_type::mapping::range_t::range_integer_t>& type) final { visit_variant(type); } @@ -749,7 +736,7 @@ private: lst::integer_type::base::DECIMAL); } - virtual void visit(const lst::static_length_string_type& type) override final + void visit(const lst::static_length_string_type& type) final { /* * TSDL expresses static-length strings as arrays of 8-bit integer with @@ -761,7 +748,7 @@ private: visit(*char_array); } - virtual void visit(const lst::dynamic_length_string_type& type) override final + void visit(const lst::dynamic_length_string_type& type) final { /* * TSDL expresses dynamic-length strings as arrays of 8-bit integer with @@ -792,25 +779,23 @@ private: /* Description in TSDL format. */ std::string _description; - bool _bypass_identifier_escape; + bool _bypass_identifier_escape{ false }; const char *_default_clock_class_name; const tsdl::details::type_overrider& _type_overrides; }; class tsdl_trace_environment_visitor : public lst::trace_class_environment_visitor { public: - tsdl_trace_environment_visitor() : _environment{ "env {\n" } - { - } + tsdl_trace_environment_visitor() = default; - virtual void visit(const lst::environment_field& field) override + void visit(const lst::environment_field& field) override { - _environment += fmt::format(" {} = {};\n", field.name, field.value); + _environment += lttng::format(" {} = {};\n", field.name, field.value); } - virtual void visit(const lst::environment_field& field) override + void visit(const lst::environment_field& field) override { - _environment += fmt::format( + _environment += lttng::format( " {} = \"{}\";\n", field.name, escape_tsdl_env_string_value(field.value)); } @@ -822,14 +807,14 @@ public: } private: - std::string _environment; + std::string _environment{ "env {\n" }; }; } /* namespace */ tsdl::trace_class_visitor::trace_class_visitor( const lst::abi& trace_abi, tsdl::append_metadata_fragment_function append_metadata_fragment) : - _trace_abi{ trace_abi }, _append_metadata_fragment(append_metadata_fragment) + _trace_abi(trace_abi), _append_metadata_fragment(std::move(append_metadata_fragment)) { } @@ -849,7 +834,7 @@ void tsdl::trace_class_visitor::visit(const lttng::sessiond::trace::trace_class& trace_class.packet_header()->accept(packet_header_visitor); /* Declare type aliases, trace class, and packet header. */ - auto trace_class_tsdl = fmt::format( + auto trace_class_tsdl = lttng::format( "/* CTF {ctf_major}.{ctf_minor} */\n\n" "trace {{\n" " major = {ctf_major};\n" @@ -883,24 +868,24 @@ void tsdl::trace_class_visitor::visit(const lttng::sessiond::trace::trace_class& void tsdl::trace_class_visitor::visit(const lttng::sessiond::trace::clock_class& clock_class) { auto uuid_str = clock_class.uuid ? - fmt::format(" uuid = \"{}\";\n", lttng::utils::uuid_to_str(*clock_class.uuid)) : + lttng::format(" uuid = \"{}\";\n", lttng::utils::uuid_to_str(*clock_class.uuid)) : ""; /* Assumes a single clock that maps to specific stream class fields/roles. */ - auto clock_class_str = fmt::format("clock {{\n" - " name = \"{name}\";\n" - /* Optional uuid. */ - "{uuid}" - " description = \"{description}\";\n" - " freq = {frequency};\n" - " offset = {offset};\n" - "}};\n" - "\n", - fmt::arg("name", clock_class.name), - fmt::arg("uuid", uuid_str), - fmt::arg("description", clock_class.description), - fmt::arg("frequency", clock_class.frequency), - fmt::arg("offset", clock_class.offset)); + auto clock_class_str = lttng::format("clock {{\n" + " name = \"{name}\";\n" + /* Optional uuid. */ + "{uuid}" + " description = \"{description}\";\n" + " freq = {frequency};\n" + " offset = {offset};\n" + "}};\n" + "\n", + fmt::arg("name", clock_class.name), + fmt::arg("uuid", uuid_str), + fmt::arg("description", clock_class.description), + fmt::arg("frequency", clock_class.frequency), + fmt::arg("offset", clock_class.offset)); append_metadata_fragment(clock_class_str); } @@ -911,9 +896,9 @@ void tsdl::trace_class_visitor::visit(const lttng::sessiond::trace::stream_class const auto clear_stream_class_on_exit = lttng::make_scope_exit([this]() noexcept { _current_stream_class = nullptr; }); - auto stream_class_str = fmt::format("stream {{\n" - " id = {};\n", - stream_class.id); + auto stream_class_str = lttng::format("stream {{\n" + " id = {};\n", + stream_class.id); variant_tsdl_keyword_sanitizer variant_sanitizer( _sanitized_types_overrides, [this](const lttng::sessiond::trace::field_location& location) -> const lst::type& { @@ -929,8 +914,8 @@ void tsdl::trace_class_visitor::visit(const lttng::sessiond::trace::stream_class event_header->accept(variant_sanitizer); event_header->accept(event_header_visitor); - stream_class_str += fmt::format(" event.header := {};\n", - event_header_visitor.move_description()); + stream_class_str += lttng::format(" event.header := {};\n", + event_header_visitor.move_description()); } const auto *packet_context = stream_class.packet_context(); @@ -942,8 +927,8 @@ void tsdl::trace_class_visitor::visit(const lttng::sessiond::trace::stream_class packet_context->accept(variant_sanitizer); packet_context->accept(packet_context_visitor); - stream_class_str += fmt::format(" packet.context := {};\n", - packet_context_visitor.move_description()); + stream_class_str += lttng::format(" packet.context := {};\n", + packet_context_visitor.move_description()); } const auto *event_context = stream_class.event_context(); @@ -954,8 +939,8 @@ void tsdl::trace_class_visitor::visit(const lttng::sessiond::trace::stream_class event_context->accept(variant_sanitizer); event_context->accept(event_context_visitor); - stream_class_str += fmt::format(" event.context := {};\n", - event_context_visitor.move_description()); + stream_class_str += lttng::format(" event.context := {};\n", + event_context_visitor.move_description()); } stream_class_str += "};\n\n"; @@ -969,19 +954,20 @@ void tsdl::trace_class_visitor::visit(const lttng::sessiond::trace::event_class& const auto clear_event_class_on_exit = lttng::make_scope_exit([this]() noexcept { _current_event_class = nullptr; }); - auto event_class_str = fmt::format("event {{\n" - " name = \"{name}\";\n" - " id = {id};\n" - " stream_id = {stream_class_id};\n" - " loglevel = {log_level};\n", - fmt::arg("name", event_class.name), - fmt::arg("id", event_class.id), - fmt::arg("stream_class_id", event_class.stream_class_id), - fmt::arg("log_level", event_class.log_level)); + auto event_class_str = + lttng::format("event {{\n" + " name = \"{name}\";\n" + " id = {id};\n" + " stream_id = {stream_class_id};\n" + " loglevel = {log_level};\n", + fmt::arg("name", event_class.name), + fmt::arg("id", event_class.id), + fmt::arg("stream_class_id", event_class.stream_class_id), + fmt::arg("log_level", event_class.log_level)); if (event_class.model_emf_uri) { event_class_str += - fmt::format(" model.emf.uri = \"{}\";\n", *event_class.model_emf_uri); + lttng::format(" model.emf.uri = \"{}\";\n", *event_class.model_emf_uri); } tsdl_field_visitor payload_visitor{ _trace_abi, 1, _sanitized_types_overrides }; @@ -995,7 +981,7 @@ void tsdl::trace_class_visitor::visit(const lttng::sessiond::trace::event_class& event_class.payload->accept(payload_visitor); event_class_str += - fmt::format(" fields := {};\n}};\n\n", payload_visitor.move_description()); + lttng::format(" fields := {};\n}};\n\n", payload_visitor.move_description()); append_metadata_fragment(event_class_str); } @@ -1047,7 +1033,7 @@ lookup_type_from_root_type(const lttng::sessiond::trace::type& root_type, * safely. */ if (!struct_type) { - LTTNG_THROW_ERROR(fmt::format( + LTTNG_THROW_ERROR(lttng::format( "Encountered a type that is not a structure while traversing field location: field-location=`{}`", field_location)); } @@ -1060,7 +1046,7 @@ lookup_type_from_root_type(const lttng::sessiond::trace::type& root_type, }); if (field_found_it == struct_type->fields_.cend()) { - LTTNG_THROW_ERROR(fmt::format( + LTTNG_THROW_ERROR(lttng::format( "Failed to find field using field location: field-name:=`{field_name}`, field-location=`{field_location}`", fmt::arg("field_location", field_location), fmt::arg("field_name", location_element)));