Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Argument Parser #3638

Closed
wants to merge 11 commits into from
751 changes: 751 additions & 0 deletions dds/DCPS/ArgParsing.cpp

Large diffs are not rendered by default.

916 changes: 916 additions & 0 deletions dds/DCPS/ArgParsing.h

Large diffs are not rendered by default.

34 changes: 0 additions & 34 deletions performance-tests/bench/common/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,6 @@

namespace Bench {

std::string get_option_argument(int& i, int argc, ACE_TCHAR* argv[])
{
if (i == argc - 1) {
std::cerr << "Option " << ACE_TEXT_ALWAYS_CHAR(argv[i])<< " requires an argument" << std::endl;
throw int{1};
}
return ACE_TEXT_ALWAYS_CHAR(argv[++i]);
}

int get_option_argument_int(int& i, int argc, ACE_TCHAR* argv[])
{
int value;
try {
value = static_cast<int>(std::stoll(get_option_argument(i, argc, argv)));
} catch (const std::exception&) {
std::cerr << "Option " << ACE_TEXT_ALWAYS_CHAR(argv[i]) << " requires an argument that's a valid number" << std::endl;
throw 1;
}
return value;
}

unsigned get_option_argument_uint(int& i, int argc, ACE_TCHAR* argv[])
{
unsigned value;
try {
value = static_cast<unsigned>(std::stoull(get_option_argument(i, argc, argv)));
} catch (const std::exception&) {
std::cerr << "Option " << ACE_TEXT_ALWAYS_CHAR(argv[i])
<< " requires an argument that's a valid positive number" << std::endl;
throw 1;
}
return value;
}

std::string& string_replace(std::string& input, const std::string& oldstr, const std::string& newstr)
{
size_t pos = input.find(oldstr);
Expand Down
21 changes: 8 additions & 13 deletions performance-tests/bench/common/util.h
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
#ifndef BENCH_UTIL_HEADER
#define BENCH_UTIL_HEADER

#include <chrono>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include "PropertyStatBlock.h"
#include "Bench_Common_Export.h"

#include <ace/ace_wchar.h> // For ACE_TCHAR
#include <ace/Default_Constants.h> // For ACE_DIRECTORY_SEPARATOR_*
#include <ace/SString.h>
#include "ace/Time_Value.h"
#include <ace/Time_Value.h>

#include "PropertyStatBlock.h"
#include "Bench_Common_Export.h"
#include <chrono>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>

const ACE_Time_Value ZERO_TIME(0, 0);

namespace Bench {

// Argument Parsing
Bench_Common_Export std::string get_option_argument(int& i, int argc, ACE_TCHAR* argv[]);
Bench_Common_Export int get_option_argument_int(int& i, int argc, ACE_TCHAR* argv[]);
Bench_Common_Export unsigned get_option_argument_uint(int& i, int argc, ACE_TCHAR* argv[]);

Bench_Common_Export std::string& string_replace(std::string& input, const std::string& oldstr, const std::string& newstr);

// Filesytem
Expand Down
104 changes: 47 additions & 57 deletions performance-tests/bench/node_controller/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,47 @@
* The Node Controller takes directives from a Test Controller, spawns Spawned Processes,
* and report the results back.
*/
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <memory>
#include <sstream>
#include <cstdint>
#include <mutex>
#include <thread>
#include <atomic>
#include <condition_variable>

#include <ace/Process_Manager.h>
#include <ace/OS_NS_stdlib.h>
#include <ace/OS_NS_fcntl.h>
#ifdef ACE_WIN32
#include <ace/WFMO_Reactor.h>
#endif
#include "ProcessStatsCollector.h"
#include "PropertyStatBlock.h"

#include <util.h>
#include <BenchTypeSupportImpl.h>
#include <tests/Utils/StatusMatching.h>
#include <Common.h>

#include <dds/DdsDcpsInfrastructureC.h>
#include <dds/DdsDcpsPublicationC.h>
#include <dds/DCPS/Service_Participant.h>
#include <dds/DCPS/DomainParticipantImpl.h>
#include <dds/DCPS/Marked_Default_Qos.h>
#include <dds/DCPS/WaitSet.h>

#include <dds/DCPS/ArgParsing.h>
#ifdef ACE_AS_STATIC_LIBS
#include <dds/DCPS/RTPS/RtpsDiscovery.h>
#include <dds/DCPS/transport/rtps_udp/RtpsUdp.h>
# include <dds/DCPS/RTPS/RtpsDiscovery.h>
# include <dds/DCPS/transport/rtps_udp/RtpsUdp.h>
#endif

#include <util.h>
#include <BenchTypeSupportImpl.h>
#include <tests/Utils/StatusMatching.h>
#include <Common.h>
#include "ProcessStatsCollector.h"
#include "PropertyStatBlock.h"
#include <ace/Process_Manager.h>
#include <ace/OS_NS_stdlib.h>
#include <ace/OS_NS_fcntl.h>
#ifdef ACE_WIN32
# include <ace/WFMO_Reactor.h>
#endif

#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <memory>
#include <sstream>
#include <cstdint>
#include <mutex>
#include <thread>
#include <atomic>
#include <condition_variable>

using namespace Bench::NodeController;
using Bench::get_option_argument_int;
using Bench::get_option_argument;
using Bench::join_path;
using Bench::string_replace;
using Bench::create_temp_dir;
Expand Down Expand Up @@ -589,37 +589,27 @@ int ACE_TMAIN(int argc, ACE_TCHAR* argv[])
int domain = default_control_domain;
std::string name;

try {
if (argc == 1) {
std::cerr << "A valid run type is required" << std::endl;
throw 1;
}
{
using namespace OpenDDS::DCPS::ArgParsing;

const ACE_TCHAR* run_mode_arg = argv[1];
if (!ACE_OS::strcmp(run_mode_arg, ACE_TEXT("one-shot"))) {
run_mode = RunMode::one_shot;
} else if (!ACE_OS::strcmp(run_mode_arg, ACE_TEXT("daemon"))) {
run_mode = RunMode::daemon;
} else if (!ACE_OS::strcmp(run_mode_arg, ACE_TEXT("daemon-exit-on-error"))) {
run_mode = RunMode::daemon_exit_on_error;
} else {
std::cerr << "Invalid run mode: " << ACE_TEXT_ALWAYS_CHAR(run_mode_arg) << std::endl;
throw 1;
}
ArgParser arg_parser("Communicates with test_controller to start and report results of workers "
"for a scenario. See bench documentation for details.");

for (int i = 2; i < argc; i++) {
if (!ACE_OS::strcmp(argv[i], ACE_TEXT("--domain"))) {
domain = get_option_argument_int(i, argc, argv);
} else if (!ACE_OS::strcmp(argv[i], ACE_TEXT("--name"))) {
name = get_option_argument(i, argc, argv);
} else {
std::cerr << "Invalid option: " << ACE_TEXT_ALWAYS_CHAR(argv[i]) << std::endl;
return 1;
}
}
} catch(const int value) {
std::cerr << "See DDS_ROOT/performance-tests/bench/README.md for usage" << std::endl;
return value;
PositionalAs<ChoiceValue<RunMode> > run_mode_arg(arg_parser, "RUN_MODE",
"Controls how the program loops.", run_mode);
run_mode_arg.handler.add_choice("one-shot", RunMode::one_shot, "Run one scenario and exit.");
run_mode_arg.handler.add_choice("daemon", RunMode::daemon, "Run scenarios until killed.");
run_mode_arg.handler.add_choice("daemon-exit-on-error", RunMode::daemon_exit_on_error,
"Run scenarios until killed or an error occurs.");

OptionAs<IntValue<int> > domain_opt(arg_parser, "domain",
"The DDS Domain to use. The default is 89.",
domain, "DOMAIN_INT");

OptionAs<StringValue> name_opt(arg_parser, "name", "Human friendly name for the node.",
name, "NAME_STR");

arg_parser.parse(argc, argv);
}

// Try to get a temp_dir
Expand Down