iceoryx_introspection 2.0.5
Loading...
Searching...
No Matches
introspection_app.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_TOOLS_ICEORYX_INTROSPECTION_INTROSPECTION_APP_HPP
17#define IOX_TOOLS_ICEORYX_INTROSPECTION_INTROSPECTION_APP_HPP
18
19#include "iceoryx_hoofs/platform/getopt.hpp"
20#include "iceoryx_introspection/introspection_types.hpp"
21#include "iceoryx_posh/popo/subscriber.hpp"
22
23#include <map>
24#include <ncurses.h>
25#include <vector>
26
27namespace iox
28{
29namespace client
30{
31namespace introspection
32{
33static constexpr option longOptions[] = {{"help", no_argument, nullptr, 'h'},
34 {"version", no_argument, nullptr, 'v'},
35 {"time", required_argument, nullptr, 't'},
36 {"mempool", no_argument, nullptr, 0},
37 {"port", no_argument, nullptr, 0},
38 {"process", no_argument, nullptr, 0},
39 {"all", no_argument, nullptr, 0},
40 {nullptr, 0, nullptr, 0}};
41
42static constexpr const char* shortOptions = "hvt:";
43
44static constexpr iox::units::Duration MIN_UPDATE_PERIOD = 500_ms;
45static constexpr iox::units::Duration DEFAULT_UPDATE_PERIOD = 1000_ms;
46static constexpr iox::units::Duration MAX_UPDATE_PERIOD = 10000_ms;
47
49enum class ColorPairs : uint8_t
50{
51 redOnBlack = 1,
52 whiteOnRed
53};
54
56static const std::map<PrettyOptions, uint32_t> prettyMap = {
57 {PrettyOptions::title, A_BOLD | COLOR_PAIR(static_cast<uint8_t>(ColorPairs::redOnBlack))},
58 {PrettyOptions::highlight, A_BOLD | A_UNDERLINE},
59 {PrettyOptions::error, A_BOLD | COLOR_PAIR(static_cast<uint8_t>(ColorPairs::whiteOnRed))},
60 {PrettyOptions::bold, A_BOLD},
61 {PrettyOptions::normal, A_NORMAL}};
62
63
67{
68 public:
72 IntrospectionApp(int argc, char* argv[]) noexcept;
73
74 virtual ~IntrospectionApp() noexcept {};
75
77 virtual void run() noexcept = 0;
78
79 protected:
80 enum class CmdLineArgumentParsingMode
81 {
82 ALL,
83 ONE
84 };
85
86 IntrospectionSelection introspectionSelection;
87
88 bool doIntrospection = false;
89
91 IntrospectionApp() noexcept;
92
93 void
94 parseCmdLineArguments(int argc,
95 char** argv,
96 CmdLineArgumentParsingMode cmdLineParsingMode = CmdLineArgumentParsingMode::ALL) noexcept;
97
98 void runIntrospection(const iox::units::Duration updatePeriodMs,
99 const IntrospectionSelection introspectionSelection);
100
101 private:
103 void initTerminal();
104
106 void clearToBottom();
107
109 void closeTerminal();
110
112 void refreshTerminal();
113
115 void updateDisplayYX();
116
119 void waitForUserInput(int32_t timeoutMs);
120
122 void printShortInfo(const std::string& binaryName) noexcept;
123
127 void prettyPrint(const std::string& str, const PrettyOptions pr = PrettyOptions::normal);
128
130 void printProcessIntrospectionData(const ProcessIntrospectionFieldTopic* processIntrospectionField);
131
133 void printMemPoolInfo(const MemPoolIntrospectionInfo& introspectionInfo);
134
136 template <typename Subscriber>
137 bool waitForSubscription(Subscriber& port);
138
140 std::vector<ComposedPublisherPortData>
141 composePublisherPortData(const PortIntrospectionFieldTopic* portData,
142 const PortThroughputIntrospectionFieldTopic* throughputData);
143
145 std::vector<ComposedSubscriberPortData>
146 composeSubscriberPortData(const PortIntrospectionFieldTopic* portData,
147 const SubscriberPortChangingIntrospectionFieldTopic* subscriberPortChangingData);
148
150 void printPortIntrospectionData(const std::vector<ComposedPublisherPortData>& publisherPortData,
151 const std::vector<ComposedSubscriberPortData>& subscriberPortData);
152
154 void printHelp() noexcept;
155
156 template <typename T>
157 T bounded(T input, T min, T max) noexcept
158 {
159 return ((input >= min) ? ((input <= max) ? input : max) : min);
160 }
161
163 iox::units::Duration updatePeriodMs = DEFAULT_UPDATE_PERIOD;
164
166 WINDOW* pad;
167
169 int32_t yPad{0};
170
172 int32_t xPad{0};
173};
174
175} // namespace introspection
176} // namespace client
177} // namespace iox
178
179#endif // IOX_TOOLS_ICEORYX_INTROSPECTION_INTROSPECTION_APP_HPP
base class for introspection
Definition introspection_app.hpp:67
virtual void run() noexcept=0
interface to start the execution of the introspection
IntrospectionApp() noexcept
this is needed for the child classes to extend the parseCmdLineArguments function
IntrospectionApp(int argc, char *argv[]) noexcept
constructor to create a introspection
Definition introspection_types.hpp:50
Definition introspection_types.hpp:61
Definition introspection_types.hpp:42