17
17
#include < iostream>
18
18
#include < string>
19
19
20
+ #include < fastdds/dds/core/policy/QosPolicies.hpp>
20
21
#include < fastdds/dds/log/Log.hpp>
21
22
#include < fastdds/rtps/attributes/BuiltinTransports.hpp>
22
- #include < fastdds/dds/core/policy/QosPolicies.hpp>
23
23
24
24
#ifndef FASTDDS_EXAMPLES_CPP_BENCHMARK__CLIPARSER_HPP
25
25
#define FASTDDS_EXAMPLES_CPP_BENCHMARK__CLIPARSER_HPP
@@ -34,16 +34,6 @@ using dds::Log;
34
34
35
35
class CLIParser
36
36
{
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
- };
47
37
48
38
public:
49
39
@@ -66,20 +56,29 @@ class CLIParser
66
56
BIG
67
57
};
68
58
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
+ };
69
71
70
72
// ! Publisher application benchmark structure
71
73
struct publisher_config : public entity_config
72
74
{
73
- uint16_t wait = 1000 ;
74
75
uint16_t interval = 100 ;
75
- uint16_t end = 10000 ;
76
- CLIParser::MsgSizeKind msg_size = CLIParser::MsgSizeKind::NONE;
76
+ uint16_t timeout = 10000 ;
77
77
};
78
78
79
79
// ! Subscriber application benchmark structure
80
80
struct subscriber_config : public entity_config
81
81
{
82
- CLIParser::MsgSizeKind msg_size = CLIParser::MsgSizeKind::NONE;
83
82
};
84
83
85
84
// ! Benchmark structure for the application
@@ -100,7 +99,7 @@ class CLIParser
100
99
static void print_help (
101
100
uint8_t return_code)
102
101
{
103
- std::cout << " Usage: benchmark <entity> [options]" << std::endl;
102
+ std::cout << " Usage: benchmark <entity> [options]" << std::endl;
104
103
std::cout << " " << std::endl;
105
104
std::cout << " Entities:" << std::endl;
106
105
std::cout << " publisher Run a publisher entity" << std::endl;
@@ -122,6 +121,10 @@ class CLIParser
122
121
std::cout << " · MEDIUM: int value + array of 512Kb" << std::endl;
123
122
std::cout << " · BIG: int value + array of 8Mb" << std::endl;
124
123
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;
125
128
std::cout << " -t <transp>, --transport <transp> Select builtin transport <transp>:" << std::endl;
126
129
std::cout << " · DEFAULT: SHM & UDPv4 (SHM prior UDP)" << std::endl;
127
130
std::cout << " · SHM: Shared Memory Transport only" << std::endl;
@@ -137,10 +140,7 @@ class CLIParser
137
140
std::cout << " -i <num>, --interval <num> Time between samples in milliseconds" << std::endl;
138
141
std::cout << " [1 <= <num> <= 4294967]" << std::endl;
139
142
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;
144
144
std::cout << " [1 <= <num> <= 4294967]" << std::endl;
145
145
std::cout << " (Default: 10000 [10s])" << std::endl;
146
146
std::cout << " " << std::endl;
@@ -291,6 +291,52 @@ class CLIParser
291
291
print_help (EXIT_FAILURE);
292
292
}
293
293
}
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
+ }
294
340
else if (arg == " -t" || arg == " --transport" )
295
341
{
296
342
if (++i < argc)
@@ -337,7 +383,7 @@ class CLIParser
337
383
int input = std::stoi (argv[i]);
338
384
if (input < 0 || input > 255 )
339
385
{
340
- throw std::out_of_range (" domain argument " + std::string (
386
+ throw std::out_of_range (" ttl argument " + std::string (
341
387
argv[i]) + " out of range [0, 255]." );
342
388
}
343
389
else
@@ -348,7 +394,7 @@ class CLIParser
348
394
}
349
395
catch (const std::invalid_argument& e)
350
396
{
351
- EPROSIMA_LOG_ERROR (CLI_PARSER, " invalid domain argument " + std::string (
397
+ EPROSIMA_LOG_ERROR (CLI_PARSER, " invalid ttl argument " + std::string (
352
398
argv[i]) + " : " + std::string (e.what ()));
353
399
print_help (EXIT_FAILURE);
354
400
}
@@ -408,51 +454,7 @@ class CLIParser
408
454
print_help (EXIT_FAILURE);
409
455
}
410
456
}
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" )
456
458
{
457
459
if (config.entity == CLIParser::EntityKind::PUBLISHER)
458
460
{
@@ -469,7 +471,7 @@ class CLIParser
469
471
}
470
472
else
471
473
{
472
- config.pub_config .end = static_cast <uint16_t >(input);
474
+ config.pub_config .timeout = static_cast <uint16_t >(input);
473
475
}
474
476
}
475
477
catch (const std::invalid_argument& e)
0 commit comments