sessiond: return raw pointer to packet header
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 21 Jul 2022 19:41:43 +0000 (15:41 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 8 Dec 2022 14:05:33 +0000 (09:05 -0500)
There is no benefit to transfering the ownership of a new packet header
everytime it is serialized. Packet headers don't change after the
creation of a session; prefer allocating it once and provide a
raw (const) pointer to the session's instance.

While LTTng always produces one, a trace doesn't absolutely need a
packet header so a pointer is preferred over a reference.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I66b8f9ad74e332edcc8273c076137a7fff0d4d5e

src/bin/lttng-sessiond/trace-class.hpp
src/bin/lttng-sessiond/ust-registry-session.cpp
src/bin/lttng-sessiond/ust-registry-session.hpp

index 05ea5c23efbf4c8c6fc8df36e0df3c3728a3029f..52dcb76a94355315004638334d8672fa2f75ea57 100644 (file)
@@ -50,7 +50,7 @@ public:
         * to continue the traversal to the trace class' children.
         */
        virtual void accept(trace_class_visitor& trace_class_visitor) const;
-       virtual lttng::sessiond::trace::type::cuptr get_packet_header() const = 0;
+       virtual const lttng::sessiond::trace::type *get_packet_header() const noexcept = 0;
 
        virtual ~trace_class() = default;
 
index 48983f2b21d8d4f3347ae63d784c766c9597160f..03a87e2868f98d4f36848e0f2f45d9f3a88e41c4 100644 (file)
@@ -251,7 +251,8 @@ lsu::registry_session::registry_session(const struct lst::abi& in_abi,
        _metadata_generating_visitor{lttng::make_unique<ls::tsdl::trace_class_visitor>(
                        abi, [this](const std::string& fragment) {
                                _append_metadata_fragment(fragment);
-                       })}
+                       })},
+       _packet_header{_create_packet_header()}
 {
        pthread_mutex_init(&_lock, NULL);
        if (_shm_path.size() > 0) {
@@ -287,6 +288,44 @@ lsu::registry_session::registry_session(const struct lst::abi& in_abi,
        }
 }
 
+lst::type::cuptr lsu::registry_session::_create_packet_header() const
+{
+       lst::structure_type::fields packet_header_fields;
+
+       /* uint32_t magic */
+       packet_header_fields.emplace_back(lttng::make_unique<lst::field>("magic",
+                       lttng::make_unique<lst::integer_type>(abi.uint32_t_alignment,
+                                       abi.byte_order, 32, lst::integer_type::signedness::UNSIGNED,
+                                       lst::integer_type::base::HEXADECIMAL,
+                                       std::initializer_list<lst::integer_type::role>({lst::integer_type::role::PACKET_MAGIC_NUMBER}))));
+
+       /* uuid */
+       packet_header_fields.emplace_back(lttng::make_unique<lst::field>("uuid",
+                       lttng::make_unique<lst::static_length_blob_type>(0, 16,
+                                       std::initializer_list<lst::static_length_blob_type::role>({lst::static_length_blob_type::role::TRACE_CLASS_UUID}))));
+
+       /* uint32_t stream_id */
+       packet_header_fields.emplace_back(lttng::make_unique<lst::field>("stream_id",
+                       lttng::make_unique<lst::integer_type>(abi.uint32_t_alignment,
+                                       abi.byte_order, 32, lst::integer_type::signedness::UNSIGNED,
+                                       lst::integer_type::base::DECIMAL,
+                                       std::initializer_list<lst::integer_type::role>({lst::integer_type::role::DATA_STREAM_CLASS_ID}))));
+
+       /* uint64_t stream_instance_id */
+       packet_header_fields.emplace_back(lttng::make_unique<lst::field>("stream_instance_id",
+                       lttng::make_unique<lst::integer_type>(abi.uint64_t_alignment,
+                                       abi.byte_order, 64, lst::integer_type::signedness::UNSIGNED,
+                                       lst::integer_type::base::DECIMAL,
+                                       std::initializer_list<lst::integer_type::role>({lst::integer_type::role::DATA_STREAM_ID}))));
+
+       return lttng::make_unique<lst::structure_type>(0, std::move(packet_header_fields));
+}
+
+const lst::type *lsu::registry_session::get_packet_header() const noexcept
+{
+       return _packet_header.get();
+}
+
 /*
  * For a given enumeration in a registry, delete the entry and destroy
  * the enumeration.
@@ -665,39 +704,6 @@ lsu::registry_session::get_enumeration(const char *enum_name, uint64_t enum_id)
        return lsu::registry_enum::const_rcu_protected_reference{*reg_enum, std::move(rcu_lock)};
 }
 
-lst::type::cuptr lsu::registry_session::get_packet_header() const
-{
-       lst::structure_type::fields packet_header_fields;
-
-       /* uint32_t magic */
-       packet_header_fields.emplace_back(lttng::make_unique<lst::field>("magic",
-                       lttng::make_unique<lst::integer_type>(abi.uint32_t_alignment,
-                                       abi.byte_order, 32, lst::integer_type::signedness::UNSIGNED,
-                                       lst::integer_type::base::HEXADECIMAL,
-                                       std::initializer_list<lst::integer_type::role>({lst::integer_type::role::PACKET_MAGIC_NUMBER}))));
-
-       /* uuid */
-       packet_header_fields.emplace_back(lttng::make_unique<lst::field>("uuid",
-                       lttng::make_unique<lst::static_length_blob_type>(0, 16,
-                                       std::initializer_list<lst::static_length_blob_type::role>({lst::static_length_blob_type::role::TRACE_CLASS_UUID}))));
-
-       /* uint32_t stream_id */
-       packet_header_fields.emplace_back(lttng::make_unique<lst::field>("stream_id",
-                       lttng::make_unique<lst::integer_type>(abi.uint32_t_alignment,
-                                       abi.byte_order, 32, lst::integer_type::signedness::UNSIGNED,
-                                       lst::integer_type::base::DECIMAL,
-                                       std::initializer_list<lst::integer_type::role>({lst::integer_type::role::DATA_STREAM_CLASS_ID}))));
-
-       /* uint64_t stream_instance_id */
-       packet_header_fields.emplace_back(lttng::make_unique<lst::field>("stream_instance_id",
-                       lttng::make_unique<lst::integer_type>(abi.uint64_t_alignment,
-                                       abi.byte_order, 64, lst::integer_type::signedness::UNSIGNED,
-                                       lst::integer_type::base::DECIMAL,
-                                       std::initializer_list<lst::integer_type::role>({lst::integer_type::role::DATA_STREAM_ID}))));
-
-       return lttng::make_unique<lst::structure_type>(0, std::move(packet_header_fields));
-}
-
 /*
  * Lookup enumeration by name and comparing enumeration entries.
  * Needs to be called from RCU read-side critical section.
index 4bda57a0774a2deab35b963fc1d49196f752594b..fc425dca092d7b32c94ba0080f8ebf415b351b9b 100644 (file)
@@ -62,7 +62,7 @@ public:
        void regenerate_metadata();
        virtual ~registry_session();
 
-       virtual lttng::sessiond::trace::type::cuptr get_packet_header() const override;
+       virtual const lttng::sessiond::trace::type *get_packet_header() const noexcept override;
 
        /*
         * With multiple writers and readers, use this lock to access
@@ -116,6 +116,7 @@ private:
        void _reset_metadata();
        void _destroy_enum(registry_enum *reg_enum) noexcept;
        registry_enum *_lookup_enum(const registry_enum *target_enum) const;
+       lttng::sessiond::trace::type::cuptr _create_packet_header() const;
 
        virtual void _accept_on_clock_classes(
                        lttng::sessiond::trace::trace_class_visitor& trace_class_visitor)
@@ -195,6 +196,7 @@ private:
 
        lttng::sessiond::ust::clock_class::cuptr _clock;
        const lttng::sessiond::trace::trace_class_visitor::cuptr _metadata_generating_visitor;
+       lttng::sessiond::trace::type::cuptr _packet_header;
 };
 
 } /* namespace ust */
This page took 0.027045 seconds and 4 git commands to generate.