diff --git a/examples/cpp/benchmark/CLIParser.hpp b/examples/cpp/benchmark/CLIParser.hpp index 2d6d4bc28c6..b99742065fe 100644 --- a/examples/cpp/benchmark/CLIParser.hpp +++ b/examples/cpp/benchmark/CLIParser.hpp @@ -17,9 +17,9 @@ #include #include +#include #include #include -#include #ifndef FASTDDS_EXAMPLES_CPP_BENCHMARK__CLIPARSER_HPP #define FASTDDS_EXAMPLES_CPP_BENCHMARK__CLIPARSER_HPP @@ -34,16 +34,6 @@ using dds::Log; class CLIParser { - //! Entity benchmark structure (shared for both publisher and subscriber applications) - struct entity_config - { - uint8_t ttl = 1; - uint32_t domain = 0; - std::string topic_name = "benchmark_topic"; - eprosima::fastdds::rtps::BuiltinTransports transport = eprosima::fastdds::rtps::BuiltinTransports::DEFAULT; - ReliabilityQosPolicyKind reliability = ReliabilityQosPolicyKind::BEST_EFFORT_RELIABILITY_QOS; - DurabilityQosPolicyKind durability = DurabilityQosPolicyKind::VOLATILE_DURABILITY_QOS; - }; public: @@ -66,20 +56,29 @@ class CLIParser BIG }; + //! Entity benchmark structure (shared for both publisher and subscriber applications) + struct entity_config + { + uint8_t ttl = 1; + uint32_t domain = 0; + std::string topic_name = "benchmark_topic"; + uint16_t samples = 0; + eprosima::fastdds::rtps::BuiltinTransports transport = eprosima::fastdds::rtps::BuiltinTransports::DEFAULT; + ReliabilityQosPolicyKind reliability = ReliabilityQosPolicyKind::BEST_EFFORT_RELIABILITY_QOS; + DurabilityQosPolicyKind durability = DurabilityQosPolicyKind::VOLATILE_DURABILITY_QOS; + CLIParser::MsgSizeKind msg_size = CLIParser::MsgSizeKind::NONE; + }; //! Publisher application benchmark structure struct publisher_config : public entity_config { - uint16_t wait = 1000; uint16_t interval = 100; - uint16_t end = 10000; - CLIParser::MsgSizeKind msg_size = CLIParser::MsgSizeKind::NONE; + uint16_t timeout = 10000; }; //! Subscriber application benchmark structure struct subscriber_config : public entity_config { - CLIParser::MsgSizeKind msg_size = CLIParser::MsgSizeKind::NONE; }; //! Benchmark structure for the application @@ -100,7 +99,7 @@ class CLIParser static void print_help( uint8_t return_code) { - std::cout << "Usage: benchmark [options]" << std::endl; + std::cout << "Usage: benchmark [options]" << std::endl; std::cout << "" << std::endl; std::cout << "Entities:" << std::endl; std::cout << " publisher Run a publisher entity" << std::endl; @@ -122,6 +121,10 @@ class CLIParser std::cout << " · MEDIUM: int value + array of 512Kb" << std::endl; std::cout << " · BIG: int value + array of 8Mb" << std::endl; std::cout << " (Default: NONE)" << std::endl; + std::cout << " -s , --samples Number of samples to send/receive" << std::endl; + std::cout << " If a value is given timeout is ignore" << std::endl; + std::cout << " [0 <= <= 65535]" << std::endl; + std::cout << " (Default: 0 [unlimited])" << std::endl; std::cout << " -t , --transport Select builtin transport :" << std::endl; std::cout << " · DEFAULT: SHM & UDPv4 (SHM prior UDP)" << std::endl; std::cout << " · SHM: Shared Memory Transport only" << std::endl; @@ -137,10 +140,7 @@ class CLIParser std::cout << " -i , --interval Time between samples in milliseconds" << std::endl; std::cout << " [1 <= <= 4294967]" << std::endl; std::cout << " (Default: 100 [0.1s])" << std::endl; - std::cout << " -w , --wait Time before starting the sampling" << std::endl; - std::cout << " [0 <= <= 4294967]" << std::endl; - std::cout << " (Default: 1000 [1s])" << std::endl; - std::cout << " -e , --end Time running the test in milliseconds" << std::endl; + std::cout << " -to , --timeout Time running the example in milliseconds" << std::endl; std::cout << " [1 <= <= 4294967]" << std::endl; std::cout << " (Default: 10000 [10s])" << std::endl; std::cout << "" << std::endl; @@ -291,6 +291,52 @@ class CLIParser print_help(EXIT_FAILURE); } } + else if (arg == "-s" || arg == "--samples") + { + if (i + 1 < argc) + { + try + { + int input = std::stoi(argv[++i]); + if (input < std::numeric_limits::min() || + input > std::numeric_limits::max()) + { + throw std::out_of_range("sample argument out of range"); + } + else + { + if (config.entity == CLIParser::EntityKind::PUBLISHER) + { + config.pub_config.samples = static_cast(input); + } + else if (config.entity == CLIParser::EntityKind::SUBSCRIBER) + { + config.sub_config.samples = static_cast(input); + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "entity not specified for --sample argument"); + print_help(EXIT_FAILURE); + } + } + } + catch (const std::invalid_argument& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid sample argument for " + arg + ": " + e.what()); + print_help(EXIT_FAILURE); + } + catch (const std::out_of_range& e) + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "sample argument out of range for " + arg + ": " + e.what()); + print_help(EXIT_FAILURE); + } + } + else + { + EPROSIMA_LOG_ERROR(CLI_PARSER, "missing argument for " + arg); + print_help(EXIT_FAILURE); + } + } else if (arg == "-t" || arg == "--transport") { if (++i < argc) @@ -337,7 +383,7 @@ class CLIParser int input = std::stoi(argv[i]); if (input < 0 || input > 255) { - throw std::out_of_range("domain argument " + std::string( + throw std::out_of_range("ttl argument " + std::string( argv[i]) + " out of range [0, 255]."); } else @@ -348,7 +394,7 @@ class CLIParser } catch (const std::invalid_argument& e) { - EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid domain argument " + std::string( + EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid ttl argument " + std::string( argv[i]) + ": " + std::string(e.what())); print_help(EXIT_FAILURE); } @@ -408,51 +454,7 @@ class CLIParser print_help(EXIT_FAILURE); } } - else if (arg == "-w" || arg == "--wait") - { - if (config.entity == CLIParser::EntityKind::PUBLISHER) - { - if (++i < argc) - { - try - { - int input = std::stoi(argv[i]); - if (input < 0 || static_cast(input) > static_cast(max_duration)) - { - throw std::out_of_range("wait argument " + std::string( - argv[i]) + " out of range [0, " + std::to_string( - max_duration) + "]."); - } - else - { - config.pub_config.wait = static_cast(input); - } - } - catch (const std::invalid_argument& e) - { - EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid wait argument " + std::string( - argv[i]) + ": " + std::string(e.what())); - print_help(EXIT_FAILURE); - } - catch (const std::out_of_range& e) - { - EPROSIMA_LOG_ERROR(CLI_PARSER, std::string(e.what())); - print_help(EXIT_FAILURE); - } - } - else - { - EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing wait argument"); - print_help(EXIT_FAILURE); - } - } - else - { - EPROSIMA_LOG_ERROR(CLI_PARSER, "wait argument is only valid for publisher entity"); - print_help(EXIT_FAILURE); - } - } - else if (arg == "-e" || arg == "--end") + else if (arg == "-to" || arg == "--timeout") { if (config.entity == CLIParser::EntityKind::PUBLISHER) { @@ -469,7 +471,7 @@ class CLIParser } else { - config.pub_config.end = static_cast(input); + config.pub_config.timeout = static_cast(input); } } catch (const std::invalid_argument& e) diff --git a/examples/cpp/benchmark/CMakeLists.txt b/examples/cpp/benchmark/CMakeLists.txt index 9a064df5ea3..912e2dcfcae 100644 --- a/examples/cpp/benchmark/CMakeLists.txt +++ b/examples/cpp/benchmark/CMakeLists.txt @@ -44,7 +44,7 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) endif() message(STATUS "Configuring benchmark example...") -file(GLOB BENCHMARK_SOURCES_CXX "*.cxx") +file(GLOB BENCHMARK_SOURCES_CXX "types/*.cxx") file(GLOB BENCHMARK_SOURCES_CPP "*.cpp") add_executable(benchmark ${BENCHMARK_SOURCES_CXX} ${BENCHMARK_SOURCES_CPP}) diff --git a/examples/cpp/benchmark/PublisherApp.cpp b/examples/cpp/benchmark/PublisherApp.cpp index 64860dc1ea4..11eea84a147 100644 --- a/examples/cpp/benchmark/PublisherApp.cpp +++ b/examples/cpp/benchmark/PublisherApp.cpp @@ -35,10 +35,10 @@ #include #include -#include "BenchmarkPubSubTypes.hpp" -#include "Benchmark_smallPubSubTypes.hpp" -#include "Benchmark_mediumPubSubTypes.hpp" -#include "Benchmark_bigPubSubTypes.hpp" +#include "types/BenchmarkPubSubTypes.hpp" +#include "types/Benchmark_smallPubSubTypes.hpp" +#include "types/Benchmark_mediumPubSubTypes.hpp" +#include "types/Benchmark_bigPubSubTypes.hpp" using namespace eprosima::fastdds::dds; using namespace eprosima::fastdds::rtps; @@ -59,9 +59,9 @@ PublisherApp::PublisherApp( , reader_(nullptr) , type_(nullptr) , matched_(0) + , samples_(config.samples) , period_ms_(config.interval) - , wait_(config.wait) - , end_(config.end) + , timeout_(config.timeout) , stop_(false) , msg_size_(config.msg_size) , count(0) @@ -70,6 +70,10 @@ PublisherApp::PublisherApp( , sent(0) { + if (samples_ > 0) + { + timeout_ = 0; + } // Create the participant DomainParticipantQos pqos = PARTICIPANT_QOS_DEFAULT; pqos.name("Benchmark_pub_participant"); @@ -240,28 +244,20 @@ void PublisherApp::on_data_available( if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data) { std::cout << "Sample with index: '" << - benchmark_.index() << "' (0 Bytes) RECEIVED" << std::endl; - sent = 0; - if (elapsed.count() >= end_) + benchmark_.index() << "' (Array 0 Bytes) RECEIVED" << std::endl; + if ((elapsed.count() >= timeout_ && timeout_ != 0) || (count >= samples_ && samples_ != 0)) { cv_.notify_one(); return; } - if (benchmark_.index() > count) - { - benchmark_.index(count); - } - else - { - benchmark_.index(benchmark_.index() + 1); - } + benchmark_.index(benchmark_.index() + 1); count = benchmark_.index() + 1; + if ((RETCODE_OK == writer_->write(&benchmark_)) == true) { - sent = 1; std::cout << "Sample with index: '" << - benchmark_.index() << "' (0 Bytes) SENT" << std::endl; + benchmark_.index() << "' (Array 0 Bytes) SENT" << std::endl; } } } @@ -273,29 +269,21 @@ void PublisherApp::on_data_available( if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data) { std::cout << "Sample with index: '" << - benchmark_small_.index() << "' (" << static_cast(benchmark_small_.array().size()) << + benchmark_small_.index() << "' (Array " << static_cast(benchmark_small_.array().size()) << " Bytes) RECEIVED" << std::endl; - sent = 0; - if (elapsed.count() >= end_) + if ((elapsed.count() >= timeout_ && timeout_ != 0) || (count >= samples_ && samples_ != 0)) { cv_.notify_one(); return; } - if (benchmark_small_.index() > count) - { - benchmark_small_.index(count); - } - else - { - benchmark_small_.index(benchmark_small_.index() + 1); - } + benchmark_small_.index(benchmark_small_.index() + 1); count = benchmark_small_.index() + 1; + if ((RETCODE_OK == writer_->write(&benchmark_small_)) == true) { - sent = 1; std::cout << "Sample with index: '" << - benchmark_small_.index() << "' (" << static_cast(benchmark_small_.array().size()) << + benchmark_small_.index() << "' (Array " << static_cast(benchmark_small_.array().size()) << " Bytes) SENT" << std::endl; } } @@ -308,29 +296,21 @@ void PublisherApp::on_data_available( if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data) { std::cout << "Sample with index: '" << - benchmark_medium_.index() << "' (" << static_cast(benchmark_medium_.data().size()) << + benchmark_medium_.index() << "' (Array " << static_cast(benchmark_medium_.data().size()) << " Bytes) RECEIVED" << std::endl; - sent = 0; - if (elapsed.count() >= end_) + if ((elapsed.count() >= timeout_ && timeout_ != 0) || (count >= samples_ && samples_ != 0)) { cv_.notify_one(); return; } - if (benchmark_medium_.index() > count) - { - benchmark_medium_.index(count); - } - else - { - benchmark_medium_.index(benchmark_medium_.index() + 1); - } + benchmark_medium_.index(benchmark_medium_.index() + 1); count = benchmark_medium_.index() + 1; + if ((RETCODE_OK == writer_->write(&benchmark_medium_)) == true) { - sent = 1; std::cout << "Sample with index: '" << - benchmark_medium_.index() << "' (" << static_cast(benchmark_medium_.data().size()) << + benchmark_medium_.index() << "' (Array " << static_cast(benchmark_medium_.data().size()) << " Bytes) SENT" << std::endl; } } @@ -343,29 +323,21 @@ void PublisherApp::on_data_available( if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data) { std::cout << "Sample with index: '" << - benchmark_big_.index() << "' (" << static_cast(benchmark_big_.data().size()) << + benchmark_big_.index() << "' (Array " << static_cast(benchmark_big_.data().size()) << " Bytes) RECEIVED" << std::endl; - sent = 0; - if (elapsed.count() >= end_) + if ((elapsed.count() >= timeout_ && timeout_ != 0) || (count >= samples_ && samples_ != 0)) { cv_.notify_one(); return; } - if (benchmark_big_.index() > count) - { - benchmark_big_.index(count); - } - else - { - benchmark_big_.index(benchmark_big_.index() + 1); - } + benchmark_big_.index(benchmark_big_.index() + 1); count = benchmark_big_.index() + 1; + if ((RETCODE_OK == writer_->write(&benchmark_big_)) == true) { - sent = 1; std::cout << "Sample with index: '" << - benchmark_big_.index() << "' (" << static_cast(benchmark_big_.data().size()) << + benchmark_big_.index() << "' (Array " << static_cast(benchmark_big_.data().size()) << " Bytes) SENT" << std::endl; } } @@ -379,48 +351,29 @@ void PublisherApp::on_data_available( void PublisherApp::run() { - uint16_t prevCount = 0; - while (!is_stopped() && !publish()) { - // Wait for period - std::unique_lock initial_lock(mutex_); - auto check = cv_.wait_for(initial_lock, std::chrono::milliseconds(1), [&]() - { - return is_stopped(); - }); - if (check) - { - return; - } - } - { - // Wait for period - std::unique_lock wait_lock(mutex_); - auto check = cv_.wait_for(wait_lock, std::chrono::milliseconds(wait_), [&]() - { - return is_stopped(); - }); - if (check) - { - return; - } - count = 0; + // Wait for the data endpoints discovery + std::unique_lock matched_lock(mutex_); + cv_.wait(matched_lock, [&]() + { + // at least one has been discovered + return ((matched_ >= 2) || is_stopped()); + }); } + publish(); + + uint16_t prevCount = 0; auto actualTime = std::chrono::steady_clock::now(); auto elapsed = std::chrono::duration_cast(actualTime - startTime); - while (!is_stopped() && elapsed.count() < end_) + while (!is_stopped() && (elapsed.count() < timeout_ || timeout_ == 0) && (samples_ == 0 || count < samples_)) { // Wait for period or stop event std::unique_lock periodic_lock(mutex_); - auto check = cv_.wait_for(periodic_lock, std::chrono::milliseconds(period_ms_), [&]() - { - return is_stopped(); - }); - if (check) - { - return; - } + cv_.wait_for(periodic_lock, std::chrono::milliseconds(period_ms_), [&]() + { + return is_stopped(); + }); vSamples.push_back(static_cast(count) - prevCount); prevCount = static_cast(count); actualTime = std::chrono::steady_clock::now(); @@ -449,31 +402,55 @@ void PublisherApp::run() throw std::runtime_error("Type invalid"); } std::cout << "SAMPLES: "; - for (uint16_t i = 0; i < vSamples.size(); ++i) { std::cout << vSamples[i] << ","; } std::cout << std::endl; + std::cout << "THROUGHTPUT BPS(Bytes per Second): "; + double mean_bps = static_cast(count) / (elapsed.count() / 1000.0); + switch (msg_size_) + { + case CLIParser::MsgSizeKind::NONE: + mean_bps= mean_bps * 4; + break; - // Wait in case a response is still nedded - std::unique_lock final_lock(mutex_); - cv_.wait(final_lock, [&]() - { - return is_stopped() || (sent == 0); - }); + case CLIParser::MsgSizeKind::SMALL: + mean_bps= mean_bps * (4 + benchmark_small_.array().size()); + break; + + case CLIParser::MsgSizeKind::MEDIUM: + mean_bps= mean_bps * (4 + benchmark_medium_.data().size()); + break; + + case CLIParser::MsgSizeKind::BIG: + mean_bps= mean_bps * (4 + benchmark_big_.data().size()); + break; + + default: + throw std::runtime_error("Type invalid"); + } + if (mean_bps >= 1e9) + { + std::cout << mean_bps / 1e9 << " Gbps" << std::endl; + } + else if (mean_bps >= 1e6) + { + std::cout << mean_bps / 1e6 << " Mbps" << std::endl; + } + else if (mean_bps >= 1e3) + { + std::cout << mean_bps / 1e3 << " Kbps" << std::endl; + } + else + { + std::cout << mean_bps << " bps" << std::endl; + } } bool PublisherApp::publish() { bool ret = false; - // Wait for the data endpoints discovery - std::unique_lock matched_lock(mutex_); - cv_.wait(matched_lock, [&]() - { - // at least one has been discovered - return ((matched_ == 2) || is_stopped()); - }); if (!is_stopped()) { switch (msg_size_) @@ -484,7 +461,7 @@ bool PublisherApp::publish() if (ret == true) { std::cout << "First Sample with index: '" - << benchmark_.index() << "'(0 Bytes) SENT" << std::endl; + << benchmark_.index() << "'(Array 0 Bytes) SENT" << std::endl; } break; @@ -494,7 +471,7 @@ bool PublisherApp::publish() if (ret == true) { std::cout << "First Sample with index: '" - << benchmark_small_.index() << "' (" << static_cast(benchmark_small_.array().size()) + << benchmark_small_.index() << "' (Array " << static_cast(benchmark_small_.array().size()) << " Bytes) SENT" << std::endl; } break; @@ -505,7 +482,7 @@ bool PublisherApp::publish() if (ret == true) { std::cout << "First Sample with index: '" - << benchmark_medium_.index() << "' (" << static_cast(benchmark_medium_.data().size()) + << benchmark_medium_.index() << "' (Array " << static_cast(benchmark_medium_.data().size()) << " Bytes) SENT" << std::endl; } break; @@ -516,7 +493,7 @@ bool PublisherApp::publish() if (ret == true) { std::cout << "First Sample with index: '" - << benchmark_big_.index() << "' (" << static_cast(benchmark_big_.data().size()) + << benchmark_big_.index() << "' (Array " << static_cast(benchmark_big_.data().size()) << " Bytes) SENT" << std::endl; } break; diff --git a/examples/cpp/benchmark/PublisherApp.hpp b/examples/cpp/benchmark/PublisherApp.hpp index ffc05dfef2b..7c8082e81e8 100644 --- a/examples/cpp/benchmark/PublisherApp.hpp +++ b/examples/cpp/benchmark/PublisherApp.hpp @@ -31,10 +31,10 @@ #include "Application.hpp" #include "CLIParser.hpp" -#include "Benchmark.hpp" -#include "Benchmark_small.hpp" -#include "Benchmark_medium.hpp" -#include "Benchmark_big.hpp" +#include "types/Benchmark.hpp" +#include "types/Benchmark_small.hpp" +#include "types/Benchmark_medium.hpp" +#include "types/Benchmark_big.hpp" using namespace eprosima::fastdds::dds; @@ -106,13 +106,13 @@ class PublisherApp : public Application, public DataWriterListener, public DataR int16_t matched_; + uint16_t samples_; + std::mutex mutex_; uint16_t period_ms_; - uint16_t wait_; - - uint16_t end_; + uint16_t timeout_; std::condition_variable cv_; diff --git a/examples/cpp/benchmark/README.md b/examples/cpp/benchmark/README.md index 3842a96307d..53628d20bbf 100644 --- a/examples/cpp/benchmark/README.md +++ b/examples/cpp/benchmark/README.md @@ -268,13 +268,13 @@ This is accomplished by setting the environment variable ``FASTDDS_DEFAULT_PROFI * Ubuntu ( / MacOS ) ```shell - user@machine:example_path$ export FASTDDS_DEFAULT_PROFILES_FILE=hello_world_profile.xml + user@machine:example_path$ export FASTDDS_DEFAULT_PROFILES_FILE=benchmark_profile.xml ``` * Windows ```powershell - example_path> set FASTDDS_DEFAULT_PROFILES_FILE=hello_world_profile.xml + example_path> set FASTDDS_DEFAULT_PROFILES_FILE=benchmark_profile.xml ``` The example provides with an XML profiles files with certain QoS: diff --git a/examples/cpp/benchmark/SubscriberApp.cpp b/examples/cpp/benchmark/SubscriberApp.cpp index 2d45bbdaedb..ed25268229e 100644 --- a/examples/cpp/benchmark/SubscriberApp.cpp +++ b/examples/cpp/benchmark/SubscriberApp.cpp @@ -35,10 +35,10 @@ #include #include -#include "BenchmarkPubSubTypes.hpp" -#include "Benchmark_smallPubSubTypes.hpp" -#include "Benchmark_mediumPubSubTypes.hpp" -#include "Benchmark_bigPubSubTypes.hpp" +#include "types/BenchmarkPubSubTypes.hpp" +#include "types/Benchmark_smallPubSubTypes.hpp" +#include "types/Benchmark_mediumPubSubTypes.hpp" +#include "types/Benchmark_bigPubSubTypes.hpp" using namespace eprosima::fastdds::dds; using namespace eprosima::fastdds::rtps; @@ -58,6 +58,7 @@ SubscriberApp::SubscriberApp( , topic_sub_(nullptr) , reader_(nullptr) , type_(nullptr) + , samples_(config.samples) , matched_(0) , stop_(false) , msg_size_(config.msg_size) @@ -228,7 +229,7 @@ void SubscriberApp::on_data_available( if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data) { std::cout << "Sample with index: '" << - benchmark_.index() << "' (0 Bytes) RECEIVED" << std::endl; + benchmark_.index() << "' (Array 0 Bytes) RECEIVED" << std::endl; benchmark_.index(benchmark_.index() + 1); while (matched_ == 0) { @@ -242,10 +243,15 @@ void SubscriberApp::on_data_available( return; } } + if(benchmark_.index() >= samples_) + { + stop(); + return; + } if ((RETCODE_OK == writer_->write(&benchmark_)) == true) { std::cout << "Sample with index: '" << - benchmark_.index() << "' (0 Bytes) SENT" << std::endl; + benchmark_.index() << "' (Array 0 Bytes) SENT" << std::endl; } } } @@ -257,7 +263,7 @@ void SubscriberApp::on_data_available( if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data) { std::cout << "Sample with index: '" << - benchmark_small_.index() << "' (" << static_cast(benchmark_small_.array().size()) << + benchmark_small_.index() << "' (Array " << static_cast(benchmark_small_.array().size()) << " Bytes) RECEIVED" << std::endl; benchmark_small_.index(benchmark_small_.index() + 1); while (matched_ == 0) @@ -272,10 +278,15 @@ void SubscriberApp::on_data_available( return; } } + if(benchmark_small_.index() >= samples_) + { + stop(); + return; + } if ((RETCODE_OK == writer_->write(&benchmark_small_)) == true) { std::cout << "Sample with index: '" << - benchmark_small_.index() << "' (" << static_cast(benchmark_small_.array().size()) << + benchmark_small_.index() << "' (Array " << static_cast(benchmark_small_.array().size()) << " Bytes) SENT" << std::endl; } } @@ -288,7 +299,7 @@ void SubscriberApp::on_data_available( if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data) { std::cout << "Sample with index: '" << - benchmark_medium_.index() << "' (" << static_cast(benchmark_medium_.data().size()) << + benchmark_medium_.index() << "' (Array " << static_cast(benchmark_medium_.data().size()) << " Bytes) RECEIVED" << std::endl; benchmark_medium_.index(benchmark_medium_.index() + 1); while (matched_ == 0) @@ -303,10 +314,15 @@ void SubscriberApp::on_data_available( return; } } + if(benchmark_medium_.index() >= samples_) + { + stop(); + return; + } if ((RETCODE_OK == writer_->write(&benchmark_medium_)) == true) { std::cout << "Sample with index: '" << - benchmark_medium_.index() << "' (" << static_cast(benchmark_medium_.data().size()) << + benchmark_medium_.index() << "' (Array " << static_cast(benchmark_medium_.data().size()) << " Bytes) SENT" << std::endl; } } @@ -319,7 +335,7 @@ void SubscriberApp::on_data_available( if ((info.instance_state == ALIVE_INSTANCE_STATE) && info.valid_data) { std::cout << "Sample with index: '" << - benchmark_big_.index() << "' (" << static_cast(benchmark_big_.data().size()) << + benchmark_big_.index() << "' (Array " << static_cast(benchmark_big_.data().size()) << " Bytes) RECEIVED" << std::endl; benchmark_big_.index(benchmark_big_.index() + 1); while (matched_ == 0) @@ -334,10 +350,15 @@ void SubscriberApp::on_data_available( return; } } + if(benchmark_big_.index() >= samples_) + { + stop(); + return; + } if ((RETCODE_OK == writer_->write(&benchmark_big_)) == true) { std::cout << "Sample with index: '" << - benchmark_big_.index() << "' (" << static_cast(benchmark_big_.data().size()) << + benchmark_big_.index() << "' (Array " << static_cast(benchmark_big_.data().size()) << " Bytes) SENT" << std::endl; } } diff --git a/examples/cpp/benchmark/SubscriberApp.hpp b/examples/cpp/benchmark/SubscriberApp.hpp index 70d3c8f4c81..0e7872b4a63 100644 --- a/examples/cpp/benchmark/SubscriberApp.hpp +++ b/examples/cpp/benchmark/SubscriberApp.hpp @@ -30,10 +30,10 @@ #include "Application.hpp" #include "CLIParser.hpp" -#include "Benchmark.hpp" -#include "Benchmark_small.hpp" -#include "Benchmark_medium.hpp" -#include "Benchmark_big.hpp" +#include "types/Benchmark.hpp" +#include "types/Benchmark_small.hpp" +#include "types/Benchmark_medium.hpp" +#include "types/Benchmark_big.hpp" using namespace eprosima::fastdds::dds; @@ -100,6 +100,8 @@ class SubscriberApp : public Application, public DataWriterListener, public Data TypeSupport type_; + uint16_t samples_; + int16_t matched_; std::mutex mutex_; diff --git a/examples/cpp/benchmark/main.cpp b/examples/cpp/benchmark/main.cpp index 284e78c0c6b..2116b311c92 100644 --- a/examples/cpp/benchmark/main.cpp +++ b/examples/cpp/benchmark/main.cpp @@ -44,14 +44,14 @@ int main( { auto ret = EXIT_SUCCESS; CLIParser::benchmark_config config = CLIParser::parse_cli_options(argc, argv); - uint32_t end = 1; + uint32_t timeout = 1; switch (config.entity) { case CLIParser::EntityKind::PUBLISHER: - end = config.pub_config.end; + timeout = config.pub_config.timeout; break; case CLIParser::EntityKind::SUBSCRIBER: - end = 0; + timeout = 0; break; default: break; @@ -74,14 +74,14 @@ int main( { std::thread thread(&Application::run, app); - if (end == 0) + if (timeout == 0) { std::cout << app_name << " running. Please press Ctrl+C to stop the " << app_name << " at any time." << std::endl; } else { - std::cout << app_name << " running for " << end << " milliseconds. Please press Ctrl+C to stop the " + std::cout << app_name << " running for " << timeout << " milliseconds. Please press Ctrl+C to stop the " << app_name << " at any time." << std::endl; } diff --git a/examples/cpp/benchmark/Benchmark.hpp b/examples/cpp/benchmark/types/Benchmark.hpp similarity index 100% rename from examples/cpp/benchmark/Benchmark.hpp rename to examples/cpp/benchmark/types/Benchmark.hpp diff --git a/examples/cpp/benchmark/BenchmarkCdrAux.hpp b/examples/cpp/benchmark/types/BenchmarkCdrAux.hpp similarity index 100% rename from examples/cpp/benchmark/BenchmarkCdrAux.hpp rename to examples/cpp/benchmark/types/BenchmarkCdrAux.hpp diff --git a/examples/cpp/benchmark/BenchmarkCdrAux.ipp b/examples/cpp/benchmark/types/BenchmarkCdrAux.ipp similarity index 100% rename from examples/cpp/benchmark/BenchmarkCdrAux.ipp rename to examples/cpp/benchmark/types/BenchmarkCdrAux.ipp diff --git a/examples/cpp/benchmark/BenchmarkPubSubTypes.cxx b/examples/cpp/benchmark/types/BenchmarkPubSubTypes.cxx similarity index 100% rename from examples/cpp/benchmark/BenchmarkPubSubTypes.cxx rename to examples/cpp/benchmark/types/BenchmarkPubSubTypes.cxx diff --git a/examples/cpp/benchmark/BenchmarkPubSubTypes.hpp b/examples/cpp/benchmark/types/BenchmarkPubSubTypes.hpp similarity index 100% rename from examples/cpp/benchmark/BenchmarkPubSubTypes.hpp rename to examples/cpp/benchmark/types/BenchmarkPubSubTypes.hpp diff --git a/examples/cpp/benchmark/BenchmarkTypeObjectSupport.cxx b/examples/cpp/benchmark/types/BenchmarkTypeObjectSupport.cxx similarity index 100% rename from examples/cpp/benchmark/BenchmarkTypeObjectSupport.cxx rename to examples/cpp/benchmark/types/BenchmarkTypeObjectSupport.cxx diff --git a/examples/cpp/benchmark/BenchmarkTypeObjectSupport.hpp b/examples/cpp/benchmark/types/BenchmarkTypeObjectSupport.hpp similarity index 100% rename from examples/cpp/benchmark/BenchmarkTypeObjectSupport.hpp rename to examples/cpp/benchmark/types/BenchmarkTypeObjectSupport.hpp diff --git a/examples/cpp/benchmark/Benchmark_big.hpp b/examples/cpp/benchmark/types/Benchmark_big.hpp similarity index 100% rename from examples/cpp/benchmark/Benchmark_big.hpp rename to examples/cpp/benchmark/types/Benchmark_big.hpp diff --git a/examples/cpp/benchmark/Benchmark_bigCdrAux.hpp b/examples/cpp/benchmark/types/Benchmark_bigCdrAux.hpp similarity index 100% rename from examples/cpp/benchmark/Benchmark_bigCdrAux.hpp rename to examples/cpp/benchmark/types/Benchmark_bigCdrAux.hpp diff --git a/examples/cpp/benchmark/Benchmark_bigCdrAux.ipp b/examples/cpp/benchmark/types/Benchmark_bigCdrAux.ipp similarity index 100% rename from examples/cpp/benchmark/Benchmark_bigCdrAux.ipp rename to examples/cpp/benchmark/types/Benchmark_bigCdrAux.ipp diff --git a/examples/cpp/benchmark/Benchmark_bigPubSubTypes.cxx b/examples/cpp/benchmark/types/Benchmark_bigPubSubTypes.cxx similarity index 100% rename from examples/cpp/benchmark/Benchmark_bigPubSubTypes.cxx rename to examples/cpp/benchmark/types/Benchmark_bigPubSubTypes.cxx diff --git a/examples/cpp/benchmark/Benchmark_bigPubSubTypes.hpp b/examples/cpp/benchmark/types/Benchmark_bigPubSubTypes.hpp similarity index 100% rename from examples/cpp/benchmark/Benchmark_bigPubSubTypes.hpp rename to examples/cpp/benchmark/types/Benchmark_bigPubSubTypes.hpp diff --git a/examples/cpp/benchmark/Benchmark_bigTypeObjectSupport.cxx b/examples/cpp/benchmark/types/Benchmark_bigTypeObjectSupport.cxx similarity index 100% rename from examples/cpp/benchmark/Benchmark_bigTypeObjectSupport.cxx rename to examples/cpp/benchmark/types/Benchmark_bigTypeObjectSupport.cxx diff --git a/examples/cpp/benchmark/Benchmark_bigTypeObjectSupport.hpp b/examples/cpp/benchmark/types/Benchmark_bigTypeObjectSupport.hpp similarity index 100% rename from examples/cpp/benchmark/Benchmark_bigTypeObjectSupport.hpp rename to examples/cpp/benchmark/types/Benchmark_bigTypeObjectSupport.hpp diff --git a/examples/cpp/benchmark/Benchmark_medium.hpp b/examples/cpp/benchmark/types/Benchmark_medium.hpp similarity index 100% rename from examples/cpp/benchmark/Benchmark_medium.hpp rename to examples/cpp/benchmark/types/Benchmark_medium.hpp diff --git a/examples/cpp/benchmark/Benchmark_mediumCdrAux.hpp b/examples/cpp/benchmark/types/Benchmark_mediumCdrAux.hpp similarity index 100% rename from examples/cpp/benchmark/Benchmark_mediumCdrAux.hpp rename to examples/cpp/benchmark/types/Benchmark_mediumCdrAux.hpp diff --git a/examples/cpp/benchmark/Benchmark_mediumCdrAux.ipp b/examples/cpp/benchmark/types/Benchmark_mediumCdrAux.ipp similarity index 100% rename from examples/cpp/benchmark/Benchmark_mediumCdrAux.ipp rename to examples/cpp/benchmark/types/Benchmark_mediumCdrAux.ipp diff --git a/examples/cpp/benchmark/Benchmark_mediumPubSubTypes.cxx b/examples/cpp/benchmark/types/Benchmark_mediumPubSubTypes.cxx similarity index 100% rename from examples/cpp/benchmark/Benchmark_mediumPubSubTypes.cxx rename to examples/cpp/benchmark/types/Benchmark_mediumPubSubTypes.cxx diff --git a/examples/cpp/benchmark/Benchmark_mediumPubSubTypes.hpp b/examples/cpp/benchmark/types/Benchmark_mediumPubSubTypes.hpp similarity index 100% rename from examples/cpp/benchmark/Benchmark_mediumPubSubTypes.hpp rename to examples/cpp/benchmark/types/Benchmark_mediumPubSubTypes.hpp diff --git a/examples/cpp/benchmark/Benchmark_mediumTypeObjectSupport.cxx b/examples/cpp/benchmark/types/Benchmark_mediumTypeObjectSupport.cxx similarity index 100% rename from examples/cpp/benchmark/Benchmark_mediumTypeObjectSupport.cxx rename to examples/cpp/benchmark/types/Benchmark_mediumTypeObjectSupport.cxx diff --git a/examples/cpp/benchmark/Benchmark_mediumTypeObjectSupport.hpp b/examples/cpp/benchmark/types/Benchmark_mediumTypeObjectSupport.hpp similarity index 100% rename from examples/cpp/benchmark/Benchmark_mediumTypeObjectSupport.hpp rename to examples/cpp/benchmark/types/Benchmark_mediumTypeObjectSupport.hpp diff --git a/examples/cpp/benchmark/Benchmark_small.hpp b/examples/cpp/benchmark/types/Benchmark_small.hpp similarity index 100% rename from examples/cpp/benchmark/Benchmark_small.hpp rename to examples/cpp/benchmark/types/Benchmark_small.hpp diff --git a/examples/cpp/benchmark/Benchmark_smallCdrAux.hpp b/examples/cpp/benchmark/types/Benchmark_smallCdrAux.hpp similarity index 100% rename from examples/cpp/benchmark/Benchmark_smallCdrAux.hpp rename to examples/cpp/benchmark/types/Benchmark_smallCdrAux.hpp diff --git a/examples/cpp/benchmark/Benchmark_smallCdrAux.ipp b/examples/cpp/benchmark/types/Benchmark_smallCdrAux.ipp similarity index 100% rename from examples/cpp/benchmark/Benchmark_smallCdrAux.ipp rename to examples/cpp/benchmark/types/Benchmark_smallCdrAux.ipp diff --git a/examples/cpp/benchmark/Benchmark_smallPubSubTypes.cxx b/examples/cpp/benchmark/types/Benchmark_smallPubSubTypes.cxx similarity index 100% rename from examples/cpp/benchmark/Benchmark_smallPubSubTypes.cxx rename to examples/cpp/benchmark/types/Benchmark_smallPubSubTypes.cxx diff --git a/examples/cpp/benchmark/Benchmark_smallPubSubTypes.hpp b/examples/cpp/benchmark/types/Benchmark_smallPubSubTypes.hpp similarity index 100% rename from examples/cpp/benchmark/Benchmark_smallPubSubTypes.hpp rename to examples/cpp/benchmark/types/Benchmark_smallPubSubTypes.hpp diff --git a/examples/cpp/benchmark/Benchmark_smallTypeObjectSupport.cxx b/examples/cpp/benchmark/types/Benchmark_smallTypeObjectSupport.cxx similarity index 100% rename from examples/cpp/benchmark/Benchmark_smallTypeObjectSupport.cxx rename to examples/cpp/benchmark/types/Benchmark_smallTypeObjectSupport.cxx diff --git a/examples/cpp/benchmark/Benchmark_smallTypeObjectSupport.hpp b/examples/cpp/benchmark/types/Benchmark_smallTypeObjectSupport.hpp similarity index 100% rename from examples/cpp/benchmark/Benchmark_smallTypeObjectSupport.hpp rename to examples/cpp/benchmark/types/Benchmark_smallTypeObjectSupport.hpp diff --git a/test/examples/test_benchmark.py b/test/examples/test_benchmark.py index b6704d06ba6..d50ba9e5953 100644 --- a/test/examples/test_benchmark.py +++ b/test/examples/test_benchmark.py @@ -17,7 +17,7 @@ import re config_test_cases = [ - ('--transport DEFAULT --msg-size NONE', '--transport DEFAULT --msg-size NONE'), # Builtin transports + ('--transport DEFAULT --msg-size NONE', '--transport DEFAULT --msg-size NONE'), ('--transport DEFAULT --msg-size SMALL', '--transport DEFAULT --msg-size SMALL'), ('--transport DEFAULT --msg-size MEDIUM', '--transport DEFAULT --msg-size MEDIUM'), ('--transport DEFAULT --msg-size BIG', '--transport DEFAULT --msg-size BIG'), @@ -44,8 +44,8 @@ def test_benchmark(pub_args, sub_args): """.""" ret = False out = '' - pub_requirements = '--reliable --transient-local -w 0 -e 1000' - sub_requirements = '--reliable --transient-local' + pub_requirements = '--reliable --transient-local -s 1000' + sub_requirements = '--reliable --transient-local -s 1000' command_prerequisites = 'PUB_ARGS="' + pub_requirements + ' ' + pub_args + '" SUB_ARGS="' + sub_requirements + ' ' + sub_args + '" '