Add a cmd option to control state change mechanism

This commit is contained in:
Alexey Rybalchenko
2016-04-27 15:04:29 +02:00
parent b9883d3b13
commit 5421922668
9 changed files with 94 additions and 197 deletions

View File

@@ -17,69 +17,42 @@
#include "boost/program_options.hpp"
#include "FairMQLogger.h"
#include "FairMQTools.h"
#include "FairMQParser.h"
#include "FairMQProgOptions.h"
#include "FairMQBenchmarkSampler.h"
#include "runSimpleMQStateMachine.h"
using namespace std;
using namespace FairMQParser;
using namespace boost::program_options;
int main(int argc, char** argv)
{
FairMQBenchmarkSampler sampler;
sampler.CatchSignals();
FairMQProgOptions config;
try
{
int msgSize;
int numMsgs;
options_description sampler_options("Sampler options");
sampler_options.add_options()
options_description samplerOptions("Sampler options");
samplerOptions.add_options()
("msg-size", value<int>(&msgSize)->default_value(1000), "Message size in bytes")
("num-msgs", value<int>(&numMsgs)->default_value(0), "Number of messages to send");
config.AddToCmdLineOptions(sampler_options);
FairMQProgOptions config;
config.AddToCmdLineOptions(samplerOptions);
if (config.ParseAll(argc, argv))
{
return 0;
}
string filename = config.GetValue<string>("config-json-file");
string id = config.GetValue<string>("id");
config.UserParser<JSON>(filename, id);
sampler.fChannels = config.GetFairMQMap();
LOG(INFO) << "PID: " << getpid();
sampler.SetTransport(config.GetValue<std::string>("transport"));
sampler.SetProperty(FairMQBenchmarkSampler::Id, id);
FairMQBenchmarkSampler sampler;
sampler.SetProperty(FairMQBenchmarkSampler::MsgSize, msgSize);
sampler.SetProperty(FairMQBenchmarkSampler::NumMsgs, numMsgs);
sampler.SetProperty(FairMQBenchmarkSampler::NumIoThreads, config.GetValue<int>("io-threads"));
sampler.ChangeState("INIT_DEVICE");
sampler.WaitForEndOfState("INIT_DEVICE");
sampler.ChangeState("INIT_TASK");
sampler.WaitForEndOfState("INIT_TASK");
sampler.ChangeState("RUN");
sampler.InteractiveStateLoop();
runStateMachine(sampler, config);
}
catch (exception& e)
catch (std::exception& e)
{
LOG(ERROR) << e.what();
LOG(INFO) << "Command line options are the following : ";
config.PrintHelp();
LOG(ERROR) << "Unhandled Exception reached the top of main: "
<< e.what() << ", application will now exit";
return 1;
}

View File

@@ -15,40 +15,28 @@
#include <iostream>
#include "FairMQLogger.h"
#include "FairMQParser.h"
#include "FairMQProgOptions.h"
#include "FairMQMerger.h"
#include "runSimpleMQStateMachine.h"
int main(int argc, char** argv)
{
FairMQMerger merger;
merger.CatchSignals();
FairMQProgOptions config;
try
{
FairMQProgOptions config;
if (config.ParseAll(argc, argv))
{
return 0;
}
merger.SetConfig(config);
merger.ChangeState("INIT_DEVICE");
merger.WaitForEndOfState("INIT_DEVICE");
merger.ChangeState("INIT_TASK");
merger.WaitForEndOfState("INIT_TASK");
merger.ChangeState("RUN");
merger.InteractiveStateLoop();
FairMQMerger merger;
runStateMachine(merger, config);
}
catch (std::exception& e)
{
LOG(ERROR) << e.what();
LOG(INFO) << "Command line options are the following: ";
config.PrintHelp();
LOG(ERROR) << "Unhandled Exception reached the top of main: "
<< e.what() << ", application will now exit";
return 1;
}

View File

@@ -15,42 +15,28 @@
#include <iostream>
#include "FairMQLogger.h"
#include "FairMQParser.h"
#include "FairMQProgOptions.h"
#include "FairMQProxy.h"
using namespace std;
#include "runSimpleMQStateMachine.h"
int main(int argc, char** argv)
{
FairMQProxy proxy;
proxy.CatchSignals();
FairMQProgOptions config;
try
{
FairMQProgOptions config;
if (config.ParseAll(argc, argv))
{
return 0;
}
proxy.SetConfig(config);
proxy.ChangeState("INIT_DEVICE");
proxy.WaitForEndOfState("INIT_DEVICE");
proxy.ChangeState("INIT_TASK");
proxy.WaitForEndOfState("INIT_TASK");
proxy.ChangeState("RUN");
proxy.InteractiveStateLoop();
FairMQProxy proxy;
runStateMachine(proxy, config);
}
catch (std::exception& e)
{
LOG(ERROR) << e.what();
LOG(INFO) << "Command line options are the following: ";
config.PrintHelp();
LOG(ERROR) << "Unhandled Exception reached the top of main: "
<< e.what() << ", application will now exit";
return 1;
}

View File

@@ -17,66 +17,39 @@
#include "boost/program_options.hpp"
#include "FairMQLogger.h"
#include "FairMQParser.h"
#include "FairMQProgOptions.h"
#include "FairMQSink.h"
#include "runSimpleMQStateMachine.h"
using namespace std;
using namespace FairMQParser;
using namespace boost::program_options;
int main(int argc, char** argv)
{
FairMQSink sink;
sink.CatchSignals();
FairMQProgOptions config;
try
{
int numMsgs;
options_description sink_options("Sink options");
sink_options.add_options()
options_description sinkOptions("Sink options");
sinkOptions.add_options()
("num-msgs", value<int>(&numMsgs)->default_value(0), "Number of messages to receive");
config.AddToCmdLineOptions(sink_options);
FairMQProgOptions config;
config.AddToCmdLineOptions(sinkOptions);
if (config.ParseAll(argc, argv))
{
return 0;
}
string filename = config.GetValue<string>("config-json-file");
string id = config.GetValue<string>("id");
// int ioThreads = config.GetValue<int>("io-threads");
config.UserParser<JSON>(filename, id);
sink.fChannels = config.GetFairMQMap();
LOG(INFO) << "PID: " << getpid();
sink.SetTransport(config.GetValue<std::string>("transport"));
sink.SetProperty(FairMQSink::Id, id);
FairMQSink sink;
sink.SetProperty(FairMQSink::NumMsgs, numMsgs);
sink.SetProperty(FairMQSink::NumIoThreads, config.GetValue<int>("io-threads"));
sink.ChangeState("INIT_DEVICE");
sink.WaitForEndOfState("INIT_DEVICE");
sink.ChangeState("INIT_TASK");
sink.WaitForEndOfState("INIT_TASK");
sink.ChangeState("RUN");
sink.InteractiveStateLoop();
runStateMachine(sink, config);
}
catch (exception& e)
catch (std::exception& e)
{
LOG(ERROR) << e.what();
LOG(INFO) << "Started with: ";
config.PrintHelp();
LOG(ERROR) << "Unhandled Exception reached the top of main: "
<< e.what() << ", application will now exit";
return 1;
}

View File

@@ -15,40 +15,28 @@
#include <iostream>
#include "FairMQLogger.h"
#include "FairMQParser.h"
#include "FairMQProgOptions.h"
#include "FairMQSplitter.h"
#include "runSimpleMQStateMachine.h"
int main(int argc, char** argv)
{
FairMQSplitter splitter;
splitter.CatchSignals();
FairMQProgOptions config;
try
{
FairMQProgOptions config;
if (config.ParseAll(argc, argv))
{
return 0;
}
splitter.SetConfig(config);
splitter.ChangeState("INIT_DEVICE");
splitter.WaitForEndOfState("INIT_DEVICE");
splitter.ChangeState("INIT_TASK");
splitter.WaitForEndOfState("INIT_TASK");
splitter.ChangeState("RUN");
splitter.InteractiveStateLoop();
FairMQSplitter splitter;
runStateMachine(splitter, config);
}
catch (std::exception& e)
{
LOG(ERROR) << e.what();
LOG(INFO) << "Command line options are the following: ";
config.PrintHelp();
LOG(ERROR) << "Unhandled Exception reached the top of main: "
<< e.what() << ", application will now exit";
return 1;
}

View File

@@ -25,16 +25,18 @@ echo "Usage: startBenchmark [message size=1000000] [number of messages=0]"
SAMPLER="bsampler"
SAMPLER+=" --id bsampler1"
#SAMPLER+=" --io-threads 2"
#SAMPLER+=" --control static"
#SAMPLER+=" --transport nanomsg"
SAMPLER+=" --msg-size $msgSize"
SAMPLER+=" --num-msgs $numMsgs"
SAMPLER+=" --config-json-file @CMAKE_BINARY_DIR@/bin/config/benchmark.json"
xterm -geometry 80x23+0+0 -hold -e taskset 0x1 @CMAKE_BINARY_DIR@/bin/$SAMPLER &
SAMPLER+=" --mq-config @CMAKE_BINARY_DIR@/bin/config/benchmark.json"
xterm -geometry 80x23+0+0 -hold -e @CMAKE_BINARY_DIR@/bin/$SAMPLER &
SINK="sink"
SINK+=" --id sink1"
#SINK+=" --io-threads 2"
#SINK+=" --control static"
#SINK+=" --transport nanomsg"
SINK+=" --num-msgs $numMsgs"
SINK+=" --config-json-file @CMAKE_BINARY_DIR@/bin/config/benchmark.json"
xterm -geometry 80x23+500+0 -hold -e taskset 0x2 @CMAKE_BINARY_DIR@/bin/$SINK &
SINK+=" --mq-config @CMAKE_BINARY_DIR@/bin/config/benchmark.json"
xterm -geometry 80x23+500+0 -hold -e @CMAKE_BINARY_DIR@/bin/$SINK &