X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fctf2-trace-class-visitor.cpp;h=71a2e48d2190c29e0401c4876dda9322e815a456;hb=20c4b46aee1a984bc558b483826c1078f24d35e9;hp=6a6248504d8a86152ab3c14973ebe0ded438959c;hpb=4f2da8b8c0f8fad2ae35dbdb9f29769da52a3dc1;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/ctf2-trace-class-visitor.cpp b/src/bin/lttng-sessiond/ctf2-trace-class-visitor.cpp index 6a6248504..71a2e48d2 100644 --- a/src/bin/lttng-sessiond/ctf2-trace-class-visitor.cpp +++ b/src/bin/lttng-sessiond/ctf2-trace-class-visitor.cpp @@ -6,8 +6,8 @@ * */ -#include "ctf2-trace-class-visitor.hpp" #include "clock-class.hpp" +#include "ctf2-trace-class-visitor.hpp" #include #include @@ -15,6 +15,7 @@ #include #include +#include namespace lsc = lttng::sessiond::ctf2; namespace lst = lttng::sessiond::trace; @@ -27,10 +28,10 @@ const std::string record_separator = "\x1e"; json::json make_json_fragment(const char *type) { - return {{"type", type}}; + return { { "type", type } }; } -json::json to_json(const lst::field_location &location) +json::json to_json(const lst::field_location& location) { json::json location_array; @@ -55,8 +56,9 @@ json::json to_json(const lst::field_location &location) break; } - std::copy(location.elements_.begin(), location.elements_.end(), - std::back_inserter(location_array)); + std::copy(location.elements_.begin(), + location.elements_.end(), + std::back_inserter(location_array)); return location_array; } @@ -101,16 +103,15 @@ const char *get_role_name(lst::static_length_blob_type::role role) namespace ctf2 { class trace_environment_visitor : public lst::trace_class_environment_visitor { public: - trace_environment_visitor() - { - } + trace_environment_visitor() = default; /* NOLINT clang-tidy 14 identifies this as a move + constructor. */ - virtual void visit(const lst::environment_field& field) override + void visit(const lst::environment_field& field) override { _visit(field); } - virtual void visit(const lst::environment_field& field) override + void visit(const lst::environment_field& field) override { _visit(field); } @@ -134,9 +135,7 @@ private: class field_visitor : public lttng::sessiond::trace::field_visitor, public lttng::sessiond::trace::type_visitor { public: - field_visitor() - { - } + field_visitor() = default; /* NOLINT clang-tidy 14 identifies this as a move constructor. */ /* Only call once. */ json::json move_fragment() @@ -145,7 +144,7 @@ public: } private: - virtual void visit(const lst::field& field) override final + void visit(const lst::field& field) final { field_visitor field_type_visitor; field.get_type().accept(field_type_visitor); @@ -154,19 +153,19 @@ private: _fragment["field-class"] = field_type_visitor.move_fragment(); } - virtual void visit(const lst::integer_type& type) override final + void visit(const lst::integer_type& type) final { _fragment["type"] = type.signedness_ == lst::integer_type::signedness::SIGNED ? - "fixed-length-signed-integer" : - "fixed-length-unsigned-integer"; + "fixed-length-signed-integer" : + "fixed-length-unsigned-integer"; _fragment["length"] = type.size; _fragment["byte-order"] = type.byte_order == lst::byte_order::BIG_ENDIAN_ ? - "big-endian" : - "little-endian"; + "big-endian" : + "little-endian"; _fragment["alignment"] = type.alignment; _fragment["preferred-display-base"] = (unsigned int) type.base_; - if (type.roles_.size() > 0) { + if (!type.roles_.empty()) { json::json role_array = json::json::array(); for (const auto role : type.roles_) { @@ -177,35 +176,37 @@ private: } } - virtual void visit(const lst::floating_point_type& type) override final + void visit(const lst::floating_point_type& type) final { _fragment["type"] = "fixed-length-floating-point-number"; _fragment["length"] = type.exponent_digits + type.mantissa_digits; _fragment["byte-order"] = type.byte_order == lst::byte_order::BIG_ENDIAN_ ? - "big-endian" : - "little-endian"; + "big-endian" : + "little-endian"; _fragment["alignment"] = type.alignment; } template void visit_enumeration(const EnumerationType& type) { - _fragment["type"] = std::is_signed::value ? - "fixed-length-signed-enumeration" : - "fixed-length-unsigned-enumeration"; + _fragment["type"] = + std::is_signed< + typename EnumerationType::mapping::range_t::range_integer_t>::value ? + "fixed-length-signed-enumeration" : + "fixed-length-unsigned-enumeration"; _fragment["length"] = type.size; _fragment["byte-order"] = type.byte_order == lst::byte_order::BIG_ENDIAN_ ? - "big-endian" : - "little-endian"; + "big-endian" : + "little-endian"; _fragment["alignment"] = type.alignment; _fragment["preferred-display-base"] = (unsigned int) type.base_; - if (type.roles_.size() > 0) { + if (!type.roles_.empty()) { if (std::is_signed::value) { - LTTNG_THROW_ERROR(fmt::format( - "Failed to serialize {}: unexpected role", - _fragment["type"])); + range_integer_t>::value) { + LTTNG_THROW_ERROR( + lttng::format("Failed to serialize {}: unexpected role", + _fragment["type"])); } auto role_array = json::json::array(); @@ -218,30 +219,31 @@ private: } if (type.mappings_->size() < 1) { - LTTNG_THROW_ERROR(fmt::format( - "Failed to serialize {}: enumeration must have at least one mapping", - _fragment["type"])); + LTTNG_THROW_ERROR(lttng::format( + "Failed to serialize {}: enumeration must have at least one mapping", + _fragment["type"])); } json::json mappings_value; - for (const auto &mapping : *type.mappings_) { - mappings_value[mapping.name] = {{mapping.range.begin, mapping.range.end}}; + for (const auto& mapping : *type.mappings_) { + mappings_value[mapping.name] = { { mapping.range.begin, + mapping.range.end } }; } _fragment["mappings"] = std::move(mappings_value); } - 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 { _fragment["type"] = "static-length-array"; @@ -256,7 +258,7 @@ private: _fragment["length"] = type.length; } - virtual void visit(const lst::dynamic_length_array_type& type) override final + void visit(const lst::dynamic_length_array_type& type) final { _fragment["type"] = "dynamic-length-array"; @@ -271,12 +273,12 @@ private: _fragment["length-field-location"] = to_json(type.length_field_location); } - virtual void visit(const lst::static_length_blob_type& type) override final + void visit(const lst::static_length_blob_type& type) final { _fragment["type"] = "static-length-blob"; _fragment["length"] = type.length_bytes; - if (type.roles_.size() > 0) { + if (!type.roles_.empty()) { auto role_array = json::json::array(); for (const auto role : type.roles_) { @@ -287,19 +289,18 @@ private: } } - virtual void visit(const lst::dynamic_length_blob_type& type) override final + void visit(const lst::dynamic_length_blob_type& type) final { _fragment["type"] = "dynamic-length-blob"; _fragment["length-field-location"] = to_json(type.length_field_location); } - 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 { _fragment["type"] = "null-terminated-string"; } - virtual void visit(const lst::structure_type& type) override final + void visit(const lst::structure_type& type) final { _fragment["type"] = "structure"; @@ -308,7 +309,7 @@ private: } auto member_classes_value = json::json::array(); - for (const auto &field : type.fields_) { + for (const auto& field : type.fields_) { ::ctf2::field_visitor member_visitor; json::json member_class; @@ -331,7 +332,8 @@ private: json::json member_class; /* TODO missing selector-field-range. */ - member_class["selector-field-ranges"] = {{option.first.range.begin, option.first.range.end}}; + member_class["selector-field-ranges"] = { { option.first.range.begin, + option.first.range.end } }; option.second->accept(option_visitor); member_class["field-class"] = option_visitor.move_fragment(); options_value.emplace_back(std::move(member_class)); @@ -340,23 +342,23 @@ private: _fragment["options"] = std::move(options_value); } - virtual void visit(const lst::variant_type& type) override final + void visit(const lst::variant_type& type) final { visit_variant(type); } - virtual void visit(const lst::variant_type& type) override final + void visit(const lst::variant_type& type) final { visit_variant(type); } - virtual void visit(const lst::static_length_string_type& type) override final + void visit(const lst::static_length_string_type& type) final { _fragment["type"] = "static-length-string"; _fragment["length"] = type.length; } - virtual void visit(const lst::dynamic_length_string_type& type) override final + void visit(const lst::dynamic_length_string_type& type) final { _fragment["type"] = "dynamic-length-string"; _fragment["length-field-location"] = to_json(type.length_field_location); @@ -369,8 +371,8 @@ private: }; /* namespace */ lsc::trace_class_visitor::trace_class_visitor( - lsc::append_metadata_fragment_function append_metadata_fragment) : - _append_metadata_fragment(append_metadata_fragment) + lsc::append_metadata_fragment_function append_metadata_fragment) : + _append_metadata_fragment(std::move(append_metadata_fragment)) { } @@ -403,17 +405,16 @@ void lsc::trace_class_visitor::visit(const lst::trace_class& trace_class) void lsc::trace_class_visitor::visit(const lst::clock_class& clock_class) { - auto clock_class_fragment = make_json_fragment("clock-class"); + auto clock_class_fragment = make_json_fragment("clock-class"); json::json offset; - offset.update({{"seconds", clock_class.offset / clock_class.frequency}, - {"cycles", clock_class.offset % clock_class.frequency}}); + offset.update({ { "seconds", clock_class.offset / clock_class.frequency }, + { "cycles", clock_class.offset % clock_class.frequency } }); - clock_class_fragment.update({ - {"name", clock_class.name}, - {"description", clock_class.description}, - {"frequency", clock_class.frequency}, - {"offset", std::move(offset)}}); + clock_class_fragment.update({ { "name", clock_class.name }, + { "description", clock_class.description }, + { "frequency", clock_class.frequency }, + { "offset", std::move(offset) } }); if (clock_class.uuid) { clock_class_fragment["uuid"] = *clock_class.uuid; @@ -429,7 +430,7 @@ void lsc::trace_class_visitor::visit(const lst::stream_class& stream_class) stream_class_fragment["id"] = stream_class.id; if (stream_class.default_clock_class_name) { stream_class_fragment["default-clock-class-name"] = - *stream_class.default_clock_class_name; + *stream_class.default_clock_class_name; } const auto packet_context = stream_class.packet_context(); @@ -445,8 +446,7 @@ void lsc::trace_class_visitor::visit(const lst::stream_class& stream_class) ::ctf2::field_visitor visitor; event_header->accept(visitor); - stream_class_fragment["event-record-header-field-class"] = - visitor.move_fragment(); + stream_class_fragment["event-record-header-field-class"] = visitor.move_fragment(); } const auto event_context = stream_class.event_context(); @@ -455,7 +455,7 @@ void lsc::trace_class_visitor::visit(const lst::stream_class& stream_class) event_context->accept(visitor); stream_class_fragment["event-record-common-context-field-class"] = - visitor.move_fragment(); + visitor.move_fragment(); } append_metadata_fragment(stream_class_fragment);