forked from eclipse-iceoryx/iceoryx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IOX-eclipse-iceoryx#21 Mirror way of extending RouDi for introspection
Signed-off-by: Hoinkis Simon (CC-AD/ESW1) <simon.hoinkis2@de.bosch.com>
- Loading branch information
1 parent
21a86e4
commit 9b9b917
Showing
6 changed files
with
319 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
tools/introspection/include/iceoryx_introspection/iceoryx_introspection_app.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "iceoryx_introspection/introspection_app.hpp" | ||
|
||
namespace iox | ||
{ | ||
namespace client | ||
{ | ||
namespace introspection | ||
{ | ||
|
||
class IceOryxIntrospectionApp : public IntrospectionApp | ||
{ | ||
public: | ||
/// @brief contructor to create the introspection | ||
/// @param[in] argc forwarding of command line arguments | ||
/// @param[in] argv forwarding of command line arguments | ||
/// @param[in] config the configuration to use | ||
IceOryxIntrospectionApp(int argc, char* argv[]) noexcept; | ||
|
||
/// @brief starts the execution of introspection | ||
void run() noexcept override; | ||
}; | ||
|
||
} // namespace client | ||
} // namespace iox | ||
} |
88 changes: 88 additions & 0 deletions
88
tools/introspection/include/iceoryx_introspection/introspection_app.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include "iceoryx_introspection/introspection_types.hpp" | ||
|
||
#include <getopt.h> | ||
|
||
namespace iox | ||
{ | ||
namespace client | ||
{ | ||
namespace introspection | ||
{ | ||
static constexpr option longOptions[] = {{"help", no_argument, nullptr, 'h'}, | ||
{"version", no_argument, nullptr, 'v'}, | ||
{"time", required_argument, nullptr, 't'}, | ||
{"mempool", no_argument, nullptr, 0}, | ||
{"port", no_argument, nullptr, 0}, | ||
{"process", no_argument, nullptr, 0}, | ||
{"all", no_argument, nullptr, 0}, | ||
{nullptr, 0, nullptr, 0}}; | ||
|
||
static constexpr const char* shortOptions = "hvt:"; | ||
|
||
static constexpr iox::units::Duration MIN_UPDATE_PERIOD = 500_ms; | ||
static constexpr iox::units::Duration DEFAULT_UPDATE_PERIOD = 1000_ms; | ||
static constexpr iox::units::Duration MAX_UPDATE_PERIOD = 10000_ms; | ||
|
||
/// @brief base class for introspection | ||
class IntrospectionApp | ||
{ | ||
public: | ||
int updatePeriodMs = DEFAULT_UPDATE_PERIOD.milliSeconds<int>(); | ||
bool doIntrospection = false; | ||
|
||
IntrospectionSelection introspectionSelection; | ||
|
||
/// @brief contructor to create a introspection | ||
/// @param[in] argc forwarding of command line arguments | ||
/// @param[in] argv forwarding of command line arguments | ||
/// @param[in] config the configuration to use | ||
IntrospectionApp(int argc, char* argv[]) noexcept; | ||
|
||
virtual ~IntrospectionApp() noexcept {}; | ||
|
||
/// @brief interface to start the execution of the introspection | ||
virtual void run() noexcept = 0; | ||
|
||
template <typename T> | ||
T bounded(T input, T min, T max) noexcept | ||
{ | ||
return ((input >= min) ? ((input <= max) ? input : max) : min); | ||
}; | ||
|
||
/// @brief Prints help to the command line | ||
void printHelp() noexcept; | ||
|
||
void printShortInfo(const std::string& binaryName) noexcept; | ||
|
||
void processArgs(int argc, char** argv) noexcept; | ||
|
||
protected: | ||
enum class CmdLineArgumentParsingMode | ||
{ | ||
ALL, | ||
ONE | ||
}; | ||
|
||
/// @brief this is needed for the child classes to extend the parseCmdLineArguments function | ||
IntrospectionApp() noexcept; | ||
}; | ||
|
||
} // namespace introspection | ||
} // namespace client | ||
} // namespace iox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "iceoryx_introspection/iceoryx_introspection_app.hpp" | ||
#include "iceoryx_introspection/introspection_run.hpp" | ||
|
||
namespace iox | ||
{ | ||
namespace client | ||
{ | ||
namespace introspection | ||
{ | ||
IceOryxIntrospectionApp::IceOryxIntrospectionApp(int argc, char* argv[]) noexcept | ||
: IntrospectionApp(argc, argv) | ||
{ | ||
} | ||
|
||
void IceOryxIntrospectionApp::run() noexcept | ||
{ | ||
if (doIntrospection) | ||
{ | ||
runIntrospection(updatePeriodMs, introspectionSelection); | ||
} | ||
} | ||
|
||
} // namespace introspection | ||
} // namespace client | ||
} // namespace iox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "iceoryx_introspection/introspection_app.hpp" | ||
#include "iceoryx_introspection/introspection_run.hpp" | ||
#include "iceoryx_introspection/introspection_types.hpp" | ||
#include "iceoryx_utils/internal/units/duration.hpp" | ||
#include "iceoryx_versions.hpp" | ||
|
||
#include <iostream> | ||
|
||
using namespace iox::client::introspection; | ||
using namespace iox::units::duration_literals; | ||
|
||
namespace iox | ||
{ | ||
namespace client | ||
{ | ||
namespace introspection | ||
{ | ||
IntrospectionApp::IntrospectionApp(int argc, char* argv[]) noexcept | ||
{ | ||
if (argc < 2) | ||
{ | ||
printShortInfo(argv[0]); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
processArgs(argc, argv); | ||
} | ||
|
||
void IntrospectionApp::printHelp() noexcept | ||
{ | ||
std::cout << "Usage:\n" | ||
" introspection [OPTIONS] [SUBSCRIPTION]\n" | ||
" introspection --help\n" | ||
" introspection --version\n" | ||
"\nOptions:\n" | ||
" -h, --help Display help and exit.\n" | ||
" -t, --time <ms> Update period (in milliseconds) for the display of introspection data\n" | ||
" [min: " | ||
<< MIN_UPDATE_PERIOD.milliSeconds<int>() | ||
<< ", max: " << MAX_UPDATE_PERIOD.milliSeconds<int>() | ||
<< ", default: " << DEFAULT_UPDATE_PERIOD.milliSeconds<int>() | ||
<< "]\n" | ||
" -v, --version Display latest official iceoryx release version and exit.\n" | ||
"\nSubscription:\n" | ||
" Select which introspection data you would like to receive.\n" | ||
" --all Subscribe to all available introspection data.\n" | ||
" --mempool Subscribe to mempool introspection data.\n" | ||
" --port Subscribe to port introspection data.\n" | ||
" --process Subscribe to process introspection data.\n" | ||
<< std::endl; | ||
} | ||
|
||
void IntrospectionApp::printShortInfo(const std::string& binaryName) noexcept | ||
{ | ||
std::cout << "Run '" << binaryName << " --help' for more information." << std::endl; | ||
} | ||
|
||
void IntrospectionApp::processArgs(int argc, char** argv) noexcept | ||
{ | ||
int opt; | ||
int index; | ||
|
||
while ( | ||
(opt = getopt_long(argc, argv, shortOptions, longOptions, &index)) | ||
!= -1) | ||
{ | ||
switch (opt) | ||
{ | ||
case 'h': | ||
printHelp(); | ||
exit(EXIT_SUCCESS); | ||
break; | ||
|
||
case 'v': | ||
std::cout << "Latest official IceOryx release version: " << ICEORYX_LATEST_RELEASE_VERSION << "\n" | ||
<< std::endl; | ||
exit(EXIT_SUCCESS); | ||
break; | ||
|
||
case 't': | ||
{ | ||
int l_rate = std::atoi(optarg); | ||
updatePeriodMs = bounded(l_rate, | ||
MIN_UPDATE_PERIOD.milliSeconds<int>(), | ||
MAX_UPDATE_PERIOD.milliSeconds<int>()); | ||
break; | ||
} | ||
|
||
case 0: | ||
if (longOptions[index].flag != 0) | ||
break; | ||
|
||
if (strcmp(longOptions[index].name, "all") == 0) | ||
{ | ||
introspectionSelection.mempool = introspectionSelection.port = introspectionSelection.process = true; | ||
doIntrospection = true; | ||
} | ||
else if (strcmp(longOptions[index].name, "port") == 0) | ||
{ | ||
introspectionSelection.port = true; | ||
doIntrospection = true; | ||
} | ||
else if (strcmp(longOptions[index].name, "process") == 0) | ||
{ | ||
introspectionSelection.process = true; | ||
doIntrospection = true; | ||
} | ||
else if (strcmp(longOptions[index].name, "mempool") == 0) | ||
{ | ||
introspectionSelection.mempool = true; | ||
doIntrospection = true; | ||
} | ||
|
||
break; | ||
|
||
case '?': | ||
default: | ||
printShortInfo(argv[0]); | ||
exit(EXIT_FAILURE); | ||
} | ||
} | ||
if (!doIntrospection) | ||
{ | ||
std::cout << "Wrong usage. "; | ||
printShortInfo(argv[0]); | ||
exit(EXIT_FAILURE); | ||
} | ||
} | ||
|
||
} // namespace introspection | ||
} // namespace client | ||
} // namespace iox |
Oops, something went wrong.