Skip to content

Commit

Permalink
IOX-eclipse-iceoryx#21 More refactoring and removing of obsolete header
Browse files Browse the repository at this point in the history
Signed-off-by: Hoinkis Simon (CC-AD/ESW1) <simon.hoinkis2@de.bosch.com>
  • Loading branch information
mossmaurice committed Dec 13, 2019
1 parent 3f9f4d7 commit 789c5bb
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 39 deletions.
1 change: 0 additions & 1 deletion tools/introspection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ set(${PROJECT_NAME}_DIR ${CMAKE_CURRENT_LIST_DIR}/cmake
add_library(iceoryx_introspection
source/iceoryx_introspection_app.cpp
source/introspection_app.cpp
source/introspection_app.cpp
)

add_library(${PROJECT_NAMESPACE}::iceoryx_introspection ALIAS iceoryx_introspection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@

#include "iceoryx_introspection/introspection_types.hpp"
#include "iceoryx_posh/popo/subscriber.hpp"
#include "iceoryx_posh/roudi/introspection_types.hpp"

#include <getopt.h>
#include <map>
#include <ncurses.h>
#include <unistd.h>
#include <vector>

namespace iox
Expand Down Expand Up @@ -67,11 +65,6 @@ class IntrospectionApp
public:
using SubscriberType = iox::popo::Subscriber;

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
Expand All @@ -82,30 +75,27 @@ class IntrospectionApp
/// @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
};

IntrospectionSelection introspectionSelection;

bool doIntrospection = false;

/// @brief this is needed for the child classes to extend the parseCmdLineArguments function
IntrospectionApp() noexcept;

void runIntrospection(const int updatePeriodMs, const IntrospectionSelection introspectionSelection);
void
parseCmdLineArguments(int argc,
char** argv,
CmdLineArgumentParsingMode cmdLineParsingMode = CmdLineArgumentParsingMode::ALL) noexcept;

void runIntrospection(const iox::units::Duration updatePeriodMs,
const IntrospectionSelection introspectionSelection);

private:
/// @brief initializes ncurses terminal
Expand All @@ -127,6 +117,9 @@ class IntrospectionApp
/// @param[in] timeoutMs timeout in milliseconds (-1 to wait forever)
void waitForUserInput(int32_t timeoutMs);

/// @brief Prints hint in case of wrong cmd line args
void printShortInfo(const std::string& binaryName) noexcept;

/// @brief prints to the terminal
/// @param[in] str string to print
/// @param[in] pr formatting options
Expand All @@ -138,23 +131,40 @@ class IntrospectionApp
/// @brief prints table showing current mempool usage
void printMemPoolInfo(const MemPoolIntrospectionTopic& topic);

void printPortIntrospectionData(const std::vector<ComposedSenderPortData>& senderPortData,
const std::vector<ComposedReceiverPortData>& receiverPortData);

/// @brief Waits till port is subscribed
bool waitForSubscription(SubscriberType& port);

/// @brief Prepares the sender port data before printing
std::vector<ComposedSenderPortData>
composeSenderPortData(const PortIntrospectionFieldTopic* portData,
const PortThroughputIntrospectionFieldTopic* throughputData);

/// @brief Prepares the receiver port data before printing
std::vector<ComposedReceiverPortData>
composeReceiverPortData(const PortIntrospectionFieldTopic* portData,
const ReceiverPortChangingIntrospectionFieldTopic* receiverPortChangingData);

/// @brief Print the prepared sender and receiver port data
void printPortIntrospectionData(const std::vector<ComposedSenderPortData>& senderPortData,
const std::vector<ComposedReceiverPortData>& receiverPortData);

/// @brief Prints help to the command line
void printHelp() noexcept;

template <typename T>
T bounded(T input, T min, T max) noexcept
{
return ((input >= min) ? ((input <= max) ? input : max) : min);
};
/// @brief Update rate of the terminal
iox::units::Duration updatePeriodMs = DEFAULT_UPDATE_PERIOD;

/// @brief ncurses pad
WINDOW* pad;

/// @brief first pad row to show on the ncurses window
int32_t yPad{0};

/// @brief first pad column to show on the ncurses window
int32_t xPad{0};
};
Expand Down
3 changes: 1 addition & 2 deletions tools/introspection/source/iceoryx_introspection_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

#include "iceoryx_introspection/iceoryx_introspection_app.hpp"
#include "iceoryx_introspection/introspection_run.hpp"

namespace iox
{
Expand All @@ -30,7 +29,7 @@ void IceOryxIntrospectionApp::run() noexcept
{
if (doIntrospection)
{
runIntrospection(updatePeriodMs, introspectionSelection);
runIntrospection(DEFAULT_UPDATE_PERIOD, introspectionSelection);
}
}

Expand Down
24 changes: 12 additions & 12 deletions tools/introspection/source/introspection_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
#include "iceoryx_introspection/introspection_app.hpp"
#include "iceoryx_introspection/introspection_types.hpp"
#include "iceoryx_posh/runtime/posh_runtime.hpp"
#include "iceoryx_utils/cxx/optional.hpp"
#include "iceoryx_utils/internal/units/duration.hpp"
#include "iceoryx_versions.hpp"

#include <chrono>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <poll.h>
#include <thread>

Expand All @@ -44,7 +41,7 @@ IntrospectionApp::IntrospectionApp(int argc, char* argv[]) noexcept
exit(EXIT_FAILURE);
}

processArgs(argc, argv);
parseCmdLineArguments(argc, argv);
}

void IntrospectionApp::printHelp() noexcept
Expand Down Expand Up @@ -75,7 +72,9 @@ 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
void IntrospectionApp::parseCmdLineArguments(int argc,
char** argv,
CmdLineArgumentParsingMode cmdLineParsingMode) noexcept
{
int opt;
int index;
Expand All @@ -97,9 +96,9 @@ void IntrospectionApp::processArgs(int argc, char** argv) noexcept

case 't':
{
int l_rate = std::atoi(optarg);
updatePeriodMs =
bounded(l_rate, MIN_UPDATE_PERIOD.milliSeconds<int>(), MAX_UPDATE_PERIOD.milliSeconds<int>());
/// @todo Calling milliseconds() should not be ambiguous, extend units::Duration?
iox::units::Duration l_rate = iox::units::Duration::milliseconds(static_cast<long double>(std::atoi(optarg)));
updatePeriodMs = bounded(l_rate, MIN_UPDATE_PERIOD, MAX_UPDATE_PERIOD);
break;
}

Expand Down Expand Up @@ -180,7 +179,6 @@ void IntrospectionApp::refreshTerminal()
wmove(pad, titleLines, 0);
}

/// @brief updates the first pad coordinates to display
void IntrospectionApp::updateDisplayYX()
{
constexpr int32_t yIncrement = 1;
Expand Down Expand Up @@ -218,6 +216,7 @@ void IntrospectionApp::waitForUserInput(int32_t timeoutMs)
fileDesc.fd = STDIN_FILENO;
fileDesc.events = POLLIN;
constexpr size_t nFileDesc = 1;
/// @todo Wrap kernel calls with SmartC
int32_t eventCount = poll(&fileDesc, nFileDesc, timeoutMs);

// Event detected
Expand Down Expand Up @@ -592,7 +591,8 @@ IntrospectionApp::composeReceiverPortData(const PortIntrospectionFieldTopic* por
return receiverPortData;
}

void IntrospectionApp::runIntrospection(const int updatePeriodMs, const IntrospectionSelection introspectionSelection)
void IntrospectionApp::runIntrospection(const iox::units::Duration updatePeriodMs,
const IntrospectionSelection introspectionSelection)
{
iox::runtime::PoshRuntime::getInstance(iox::roudi::INTROSPECTION_MQ_APP_NAME);

Expand Down Expand Up @@ -814,13 +814,13 @@ void IntrospectionApp::runIntrospection(const int updatePeriodMs, const Introspe
refreshTerminal();

// Watch user input for updatePeriodMs
auto tWaitRemaining = std::chrono::milliseconds(updatePeriodMs);
auto tWaitRemaining = std::chrono::milliseconds(updatePeriodMs.milliSeconds<uint64_t>());
auto tWaitBegin = std::chrono::system_clock::now();
while (tWaitRemaining.count() >= 0)
{
waitForUserInput(static_cast<int32_t>(tWaitRemaining.count()));
auto tWaitElapsed = std::chrono::system_clock::now() - tWaitBegin;
tWaitRemaining = std::chrono::milliseconds(updatePeriodMs)
tWaitRemaining = std::chrono::milliseconds(updatePeriodMs.milliSeconds<uint64_t>())
- std::chrono::duration_cast<std::chrono::milliseconds>(tWaitElapsed);
}
}
Expand Down

0 comments on commit 789c5bb

Please sign in to comment.