Skip to content

Commit 791e055

Browse files
committed
Corrections after review
Signed-off-by: Javier Gil Aviles <[email protected]>
1 parent 5f239f1 commit 791e055

37 files changed

+214
-212
lines changed

examples/cpp/benchmark/CLIParser.hpp

+70-68
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
#include <iostream>
1818
#include <string>
1919

20+
#include <fastdds/dds/core/policy/QosPolicies.hpp>
2021
#include <fastdds/dds/log/Log.hpp>
2122
#include <fastdds/rtps/attributes/BuiltinTransports.hpp>
22-
#include <fastdds/dds/core/policy/QosPolicies.hpp>
2323

2424
#ifndef FASTDDS_EXAMPLES_CPP_BENCHMARK__CLIPARSER_HPP
2525
#define FASTDDS_EXAMPLES_CPP_BENCHMARK__CLIPARSER_HPP
@@ -34,16 +34,6 @@ using dds::Log;
3434

3535
class CLIParser
3636
{
37-
//! Entity benchmark structure (shared for both publisher and subscriber applications)
38-
struct entity_config
39-
{
40-
uint8_t ttl = 1;
41-
uint32_t domain = 0;
42-
std::string topic_name = "benchmark_topic";
43-
eprosima::fastdds::rtps::BuiltinTransports transport = eprosima::fastdds::rtps::BuiltinTransports::DEFAULT;
44-
ReliabilityQosPolicyKind reliability = ReliabilityQosPolicyKind::BEST_EFFORT_RELIABILITY_QOS;
45-
DurabilityQosPolicyKind durability = DurabilityQosPolicyKind::VOLATILE_DURABILITY_QOS;
46-
};
4737

4838
public:
4939

@@ -66,20 +56,29 @@ class CLIParser
6656
BIG
6757
};
6858

59+
//! Entity benchmark structure (shared for both publisher and subscriber applications)
60+
struct entity_config
61+
{
62+
uint8_t ttl = 1;
63+
uint32_t domain = 0;
64+
std::string topic_name = "benchmark_topic";
65+
uint16_t samples = 0;
66+
eprosima::fastdds::rtps::BuiltinTransports transport = eprosima::fastdds::rtps::BuiltinTransports::DEFAULT;
67+
ReliabilityQosPolicyKind reliability = ReliabilityQosPolicyKind::BEST_EFFORT_RELIABILITY_QOS;
68+
DurabilityQosPolicyKind durability = DurabilityQosPolicyKind::VOLATILE_DURABILITY_QOS;
69+
CLIParser::MsgSizeKind msg_size = CLIParser::MsgSizeKind::NONE;
70+
};
6971

7072
//! Publisher application benchmark structure
7173
struct publisher_config : public entity_config
7274
{
73-
uint16_t wait = 1000;
7475
uint16_t interval = 100;
75-
uint16_t end = 10000;
76-
CLIParser::MsgSizeKind msg_size = CLIParser::MsgSizeKind::NONE;
76+
uint16_t timeout = 10000;
7777
};
7878

7979
//! Subscriber application benchmark structure
8080
struct subscriber_config : public entity_config
8181
{
82-
CLIParser::MsgSizeKind msg_size = CLIParser::MsgSizeKind::NONE;
8382
};
8483

8584
//! Benchmark structure for the application
@@ -100,7 +99,7 @@ class CLIParser
10099
static void print_help(
101100
uint8_t return_code)
102101
{
103-
std::cout << "Usage: benchmark <entity> [options]" << std::endl;
102+
std::cout << "Usage: benchmark <entity> [options]" << std::endl;
104103
std::cout << "" << std::endl;
105104
std::cout << "Entities:" << std::endl;
106105
std::cout << " publisher Run a publisher entity" << std::endl;
@@ -122,6 +121,10 @@ class CLIParser
122121
std::cout << " · MEDIUM: int value + array of 512Kb" << std::endl;
123122
std::cout << " · BIG: int value + array of 8Mb" << std::endl;
124123
std::cout << " (Default: NONE)" << std::endl;
124+
std::cout << " -s <num>, --samples <num> Number of samples to send/receive" << std::endl;
125+
std::cout << " If a value is given timeout is ignore" << std::endl;
126+
std::cout << " [0 <= <num> <= 65535]" << std::endl;
127+
std::cout << " (Default: 0 [unlimited])" << std::endl;
125128
std::cout << " -t <transp>, --transport <transp> Select builtin transport <transp>:" << std::endl;
126129
std::cout << " · DEFAULT: SHM & UDPv4 (SHM prior UDP)" << std::endl;
127130
std::cout << " · SHM: Shared Memory Transport only" << std::endl;
@@ -137,10 +140,7 @@ class CLIParser
137140
std::cout << " -i <num>, --interval <num> Time between samples in milliseconds" << std::endl;
138141
std::cout << " [1 <= <num> <= 4294967]" << std::endl;
139142
std::cout << " (Default: 100 [0.1s])" << std::endl;
140-
std::cout << " -w <num>, --wait <num> Time before starting the sampling" << std::endl;
141-
std::cout << " [0 <= <num> <= 4294967]" << std::endl;
142-
std::cout << " (Default: 1000 [1s])" << std::endl;
143-
std::cout << " -e <num>, --end <num> Time running the test in milliseconds" << std::endl;
143+
std::cout << " -to <num>, --timeout <num> Time running the example in milliseconds" << std::endl;
144144
std::cout << " [1 <= <num> <= 4294967]" << std::endl;
145145
std::cout << " (Default: 10000 [10s])" << std::endl;
146146
std::cout << "" << std::endl;
@@ -291,6 +291,52 @@ class CLIParser
291291
print_help(EXIT_FAILURE);
292292
}
293293
}
294+
else if (arg == "-s" || arg == "--samples")
295+
{
296+
if (i + 1 < argc)
297+
{
298+
try
299+
{
300+
int input = std::stoi(argv[++i]);
301+
if (input < std::numeric_limits<std::uint16_t>::min() ||
302+
input > std::numeric_limits<std::uint16_t>::max())
303+
{
304+
throw std::out_of_range("sample argument out of range");
305+
}
306+
else
307+
{
308+
if (config.entity == CLIParser::EntityKind::PUBLISHER)
309+
{
310+
config.pub_config.samples = static_cast<uint16_t>(input);
311+
}
312+
else if (config.entity == CLIParser::EntityKind::SUBSCRIBER)
313+
{
314+
config.sub_config.samples = static_cast<uint16_t>(input);
315+
}
316+
else
317+
{
318+
EPROSIMA_LOG_ERROR(CLI_PARSER, "entity not specified for --sample argument");
319+
print_help(EXIT_FAILURE);
320+
}
321+
}
322+
}
323+
catch (const std::invalid_argument& e)
324+
{
325+
EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid sample argument for " + arg + ": " + e.what());
326+
print_help(EXIT_FAILURE);
327+
}
328+
catch (const std::out_of_range& e)
329+
{
330+
EPROSIMA_LOG_ERROR(CLI_PARSER, "sample argument out of range for " + arg + ": " + e.what());
331+
print_help(EXIT_FAILURE);
332+
}
333+
}
334+
else
335+
{
336+
EPROSIMA_LOG_ERROR(CLI_PARSER, "missing argument for " + arg);
337+
print_help(EXIT_FAILURE);
338+
}
339+
}
294340
else if (arg == "-t" || arg == "--transport")
295341
{
296342
if (++i < argc)
@@ -337,7 +383,7 @@ class CLIParser
337383
int input = std::stoi(argv[i]);
338384
if (input < 0 || input > 255)
339385
{
340-
throw std::out_of_range("domain argument " + std::string(
386+
throw std::out_of_range("ttl argument " + std::string(
341387
argv[i]) + " out of range [0, 255].");
342388
}
343389
else
@@ -348,7 +394,7 @@ class CLIParser
348394
}
349395
catch (const std::invalid_argument& e)
350396
{
351-
EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid domain argument " + std::string(
397+
EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid ttl argument " + std::string(
352398
argv[i]) + ": " + std::string(e.what()));
353399
print_help(EXIT_FAILURE);
354400
}
@@ -408,51 +454,7 @@ class CLIParser
408454
print_help(EXIT_FAILURE);
409455
}
410456
}
411-
else if (arg == "-w" || arg == "--wait")
412-
{
413-
if (config.entity == CLIParser::EntityKind::PUBLISHER)
414-
{
415-
if (++i < argc)
416-
{
417-
try
418-
{
419-
int input = std::stoi(argv[i]);
420-
if (input < 0 || static_cast<long>(input) > static_cast<long>(max_duration))
421-
{
422-
throw std::out_of_range("wait argument " + std::string(
423-
argv[i]) + " out of range [0, " + std::to_string(
424-
max_duration) + "].");
425-
}
426-
else
427-
{
428-
config.pub_config.wait = static_cast<uint16_t>(input);
429-
}
430-
}
431-
catch (const std::invalid_argument& e)
432-
{
433-
EPROSIMA_LOG_ERROR(CLI_PARSER, "invalid wait argument " + std::string(
434-
argv[i]) + ": " + std::string(e.what()));
435-
print_help(EXIT_FAILURE);
436-
}
437-
catch (const std::out_of_range& e)
438-
{
439-
EPROSIMA_LOG_ERROR(CLI_PARSER, std::string(e.what()));
440-
print_help(EXIT_FAILURE);
441-
}
442-
}
443-
else
444-
{
445-
EPROSIMA_LOG_ERROR(CLI_PARSER, "parsing wait argument");
446-
print_help(EXIT_FAILURE);
447-
}
448-
}
449-
else
450-
{
451-
EPROSIMA_LOG_ERROR(CLI_PARSER, "wait argument is only valid for publisher entity");
452-
print_help(EXIT_FAILURE);
453-
}
454-
}
455-
else if (arg == "-e" || arg == "--end")
457+
else if (arg == "-to" || arg == "--timeout")
456458
{
457459
if (config.entity == CLIParser::EntityKind::PUBLISHER)
458460
{
@@ -469,7 +471,7 @@ class CLIParser
469471
}
470472
else
471473
{
472-
config.pub_config.end = static_cast<uint16_t>(input);
474+
config.pub_config.timeout = static_cast<uint16_t>(input);
473475
}
474476
}
475477
catch (const std::invalid_argument& e)

examples/cpp/benchmark/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
4444
endif()
4545

4646
message(STATUS "Configuring benchmark example...")
47-
file(GLOB BENCHMARK_SOURCES_CXX "*.cxx")
47+
file(GLOB BENCHMARK_SOURCES_CXX "types/*.cxx")
4848
file(GLOB BENCHMARK_SOURCES_CPP "*.cpp")
4949

5050
add_executable(benchmark ${BENCHMARK_SOURCES_CXX} ${BENCHMARK_SOURCES_CPP})

0 commit comments

Comments
 (0)