iceoryx_doc  1.0.1
mempool_introspection.hpp
1 // Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // SPDX-License-Identifier: Apache-2.0
16 #ifndef IOX_POSH_ROUDI_INTROSPECTION_MEMPOOL_INTROSPECTION_HPP
17 #define IOX_POSH_ROUDI_INTROSPECTION_MEMPOOL_INTROSPECTION_HPP
18 
19 #include "iceoryx_posh/internal/log/posh_logging.hpp"
20 #include "iceoryx_posh/internal/mepoo/memory_manager.hpp"
21 #include "iceoryx_posh/internal/roudi/port_manager.hpp"
22 #include "iceoryx_posh/mepoo/mepoo_config.hpp"
23 #include "iceoryx_posh/roudi/introspection_types.hpp"
24 #include "iceoryx_utils/cxx/method_callback.hpp"
25 #include "iceoryx_utils/internal/concurrent/periodic_task.hpp"
26 
27 #include <cstdint>
28 
29 namespace iox
30 {
31 namespace roudi
32 {
38 template <typename MemoryManager, typename SegmentManager, typename PublisherPort>
40 {
41  public:
47  MemPoolIntrospection(MemoryManager& rouDiInternalMemoryManager,
48  SegmentManager& segmentManager,
49  PublisherPort&& publisherPort);
50 
52 
53  // delete copy constructor and assignment operator
55  MemPoolIntrospection& operator=(MemPoolIntrospection const&) = delete;
56  // delete move constructor and assignment operator
58  MemPoolIntrospection& operator=(MemPoolIntrospection&&) = delete;
59 
62  void run() noexcept;
63 
66  void stop() noexcept;
67 
71  void setSendInterval(const units::Duration interval) noexcept;
72 
73  protected:
74  MemoryManager* m_rouDiInternalMemoryManager{nullptr}; // mempool handler needs to outlive this class (!)
75  SegmentManager* m_segmentManager{nullptr};
76  PublisherPort m_publisherPort{nullptr};
77  void send() noexcept;
78 
79  private:
80  static void prepareIntrospectionSample(MemPoolIntrospectionInfo& sample,
81  const posix::PosixGroup& readerGroup,
82  const posix::PosixGroup& writerGroup,
83  uint32_t id) noexcept;
84 
86  void copyMemPoolInfo(const MemoryManager& memoryManager, MemPoolInfoContainer& dest) noexcept;
87 
88  private:
89  units::Duration m_sendInterval{units::Duration::fromSeconds(1U)};
90  concurrent::PeriodicTask<cxx::MethodCallback<void>> m_publishingTask{
91  concurrent::PeriodicTaskManualStart, "MemPoolIntr", *this, &MemPoolIntrospection::send};
92 };
93 
98 
99 } // namespace roudi
100 } // namespace iox
101 #include "mempool_introspection.inl"
102 
103 #endif // IOX_POSH_ROUDI_INTROSPECTION_MEMPOOL_INTROSPECTION_HPP
The PublisherPortUser provides the API for accessing a publisher port from the user side....
Definition: publisher_port_user.hpp:39
This class handles the mempool intropection for RouDi. It is recommended to use the MemPoolIntrospect...
Definition: mempool_introspection.hpp:40
void stop() noexcept
This function stops the thread which sends the introspection data. It is not possible to start the th...
Definition: mempool_introspection.inl:51
void setSendInterval(const units::Duration interval) noexcept
This function configures the interval for the transmission of the mempool introspection data.
Definition: mempool_introspection.inl:57
MemPoolIntrospection(MemoryManager &rouDiInternalMemoryManager, SegmentManager &segmentManager, PublisherPort &&publisherPort)
The constructor for the MemPoolIntrospection. It starts a thread and set it into a wait condition.
Definition: mempool_introspection.inl:28
void run() noexcept
This function starts the periodic transmission of snapshots of the mempool introspecton data....
Definition: mempool_introspection.inl:45
cxx::vector< MemPoolInfo, MAX_NUMBER_OF_MEMPOOLS > MemPoolInfoContainer
container for MemPoolInfo structs of all available mempools.
Definition: introspection_types.hpp:48
Definition: service_description.hpp:29
the topic for the mempool introspection that a user can subscribe to
Definition: introspection_types.hpp:52