void parse_data_source(po::variables_map vm, size_t i) { if (vm.count("l" + std::to_string(i) + "_source")) { // set given parameters std::string source = vm["l" + std::to_string(i) + "_source"].as<std::string>(); if (source == "flim") { _links.at(i).source = flim; L_(info) << " data source: flim"; } else if (source == "pgen_far") { _links.at(i).source = pgen_far; L_(info) << " data source: far-end pgen"; parse_eq_id(vm, i); } else if (source == "pgen_near") { _links.at(i).source = pgen_near; L_(info) << " data source: near-end pgen"; parse_eq_id(vm, i); } else if (source == "disable") { _links.at(i).source = disable; L_(info) << " data source: disable"; } else { throw ParametersException("No valid arg for data source."); } } else { // set default parameters _links.at(i).source = disable; L_(info) << " data source: disable (default)"; } }
void parse_eq_id(po::variables_map vm, size_t i) { if (vm.count("l" + std::to_string(i) + "_eq_id")) { _links.at(i).eq_id = boost::numeric_cast<uint16_t>( std::stoul(vm["l" + std::to_string(i) + "_eq_id"].as<std::string>(), nullptr, 0)); } else { throw ParametersException("If reading from pgen eq_id is required."); } }
void Parameters::parse_options(int argc, char* argv[]) { unsigned log_level = 2; std::string log_file; po::options_description desc("Allowed options"); auto desc_add = desc.add_options(); desc_add("version,V", "print version string"); desc_add("help,h", "produce help message"); desc_add("log-level,l", po::value<unsigned>(&log_level), "set the log level (default:2, all:0)"); desc_add("log-file,L", po::value<std::string>(&log_file), "name of target log file"); desc_add("client-index,c", po::value<int32_t>(&client_index_), "index of this executable in the list of processor tasks"); desc_add("analyze-pattern,a", po::value<bool>(&analyze_)->implicit_value(true), "enable/disable pattern check"); desc_add("benchmark,b", po::value<bool>(&benchmark_)->implicit_value(true), "run benchmark test only"); desc_add("verbose,v", po::value<size_t>(&verbosity_), "set output verbosity"); desc_add("shm-identifier,s", po::value<std::string>(&shm_identifier_), "shared memory identifier used for receiving timeslices"); desc_add("input-archive,i", po::value<std::string>(&input_archive_), "name of an input file archive to read"); desc_add("output-archive,o", po::value<std::string>(&output_archive_), "name of an output file archive to write"); desc_add("publish,P", po::value<std::string>(&publish_address_) ->implicit_value("tcp://*:5556"), "enable timeslice publisher on given address"); desc_add("subscribe,S", po::value<std::string>(&subscribe_address_) ->implicit_value("tcp://localhost:5556"), "subscribe to timeslice publisher on given address"); desc_add("maximum-number,n", po::value<uint64_t>(&maximum_number_), "set the maximum number of microslices to process (default: " "unlimited)"); po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); if (vm.count("help") != 0u) { std::cout << desc << std::endl; exit(EXIT_SUCCESS); } if (vm.count("version") != 0u) { std::cout << "tsclient, version 0.0" << std::endl; exit(EXIT_SUCCESS); } logging::add_console(static_cast<severity_level>(log_level)); if (vm.count("log-file")) { L_(info) << "Logging output to " << log_file; logging::add_file(log_file, static_cast<severity_level>(log_level)); } size_t input_sources = vm.count("shm-identifier") + vm.count("input-archive") + vm.count("subscribe"); if (input_sources == 0 && !benchmark_) { throw ParametersException("no input source specified"); } if (input_sources > 1) { throw ParametersException("more than one input source specified"); } }
void parse_options(int argc, char* argv[]) { std::string config_file; unsigned log_level; std::string log_file; po::options_description generic("Generic options"); auto generic_add = generic.add_options(); generic_add("help,h", "produce help message"); generic_add("config-file,c", po::value<std::string>(&config_file)->default_value("flib.cfg"), "name of a configuration file"); generic_add("log-level,l", po::value<unsigned>(&log_level)->default_value(2), "set the log level (all:0)"); generic_add("log-file,L", po::value<std::string>(&log_file), "name of target log file"); po::options_description config("Configuration (flib.cfg or cmd line)"); auto config_add = config.add_options(); config_add("flib-addr,i", po::value<pci_addr>(), "PCI BDF address of target FLIB in BB:DD.F format"); config_add("identify", po::value<bool>(&_identify)->default_value(false), "toggle FLIB ID led"); config_add("mc-size,t", po::value<uint32_t>(), "size of pattern generator microslices in units of " "1024 ns (31 bit wide)"); config_add("pgen-rate,r", po::value<float>(), "MS fill level of pattern generator in [0,1]"); config_add("mc-size-limit", po::value<uint32_t>(&_mc_size_limit), "Threshold of microslice size limiter in bytes."); config_add("l0_source", po::value<std::string>(), "Link 0 data source <disable|flim|pgen_far|pgen_near>"); config_add("l0_eq_id", po::value<std::string>(), "Equipment identifier of link 0 pgen data source (16 Bit)"); config_add("l1_source", po::value<std::string>(), "Link 1 data source <disable|flim|pgen_far|pgen_near>"); config_add("l1_eq_id", po::value<std::string>(), "Equipment identifier of link 1 pgen data source (16 Bit)"); config_add("l2_source", po::value<std::string>(), "Link 2 data source <disable|flim|pgen_far|pgen_near>"); config_add("l2_eq_id", po::value<std::string>(), "Equipment identifier of link 2 pgen data source (16 Bit)"); config_add("l3_source", po::value<std::string>(), "Link 3 data source <disable|flim|pgen_far|pgen_near>"); config_add("l3_eq_id", po::value<std::string>(), "Equipment identifier of link 3 pgen data source (16 Bit)"); config_add("l4_source", po::value<std::string>(), "Link 4 data source <disable|flim|pgen_far|pgen_near>"); config_add("l4_eq_id", po::value<std::string>(), "Equipment identifier of link 4 pgen data source (16 Bit)"); config_add("l5_source", po::value<std::string>(), "Link 5 data source <disable|flim|pgen_far|pgen_near>"); config_add("l5_eq_id", po::value<std::string>(), "Equipment identifier of link 5 pgen data source (16 Bit)"); config_add("l6_source", po::value<std::string>(), "Link 6 data source <disable|flim|pgen_far|pgen_near>"); config_add("l6_eq_id", po::value<std::string>(), "Equipment identifier of link 6 pgen data source (16 Bit)"); config_add("l7_source", po::value<std::string>(), "Link 7 data source <disable|flim|pgen_far|pgen_near>"); config_add("l7_eq_id", po::value<std::string>(), "Equipment identifier of link 7 pgen data source (16 Bit)"); po::options_description cmdline_options("Allowed options"); cmdline_options.add(generic).add(config); po::options_description config_file_options; config_file_options.add(config); po::variables_map vm; po::store(po::parse_command_line(argc, argv, cmdline_options), vm); po::notify(vm); std::ifstream ifs(config_file.c_str()); if (!ifs) { throw ParametersException("cannot open config file: " + config_file); } else { po::store(po::parse_config_file(ifs, config_file_options), vm); notify(vm); } if (vm.count("help")) { std::cout << cmdline_options << "\n"; exit(EXIT_SUCCESS); } logging::add_console(static_cast<severity_level>(log_level)); if (vm.count("log-file")) { L_(info) << "Logging output to " << log_file; logging::add_file(log_file, static_cast<severity_level>(log_level)); } L_(info) << "Device config:"; if (vm.count("flib-addr")) { _flib_addr = vm["flib-addr"].as<pci_addr>(); _flib_autodetect = false; L_(info) << " FLIB address: " << std::hex << std::setw(2) << std::setfill('0') << static_cast<unsigned>(_flib_addr.bus) << ":" << std::setw(2) << std::setfill('0') << static_cast<unsigned>(_flib_addr.dev) << "." << static_cast<unsigned>(_flib_addr.func) << std::dec; } else { _flib_autodetect = true; L_(info) << " FLIB address: autodetect"; } if (vm.count("mc-size")) { _mc_size = vm["mc-size"].as<uint32_t>(); if (_mc_size > 2147483647) { // 31 bit check throw ParametersException("Pgen microslice size out of range"); } else { L_(info) << " Pgen microslice size: " << human_readable_mc_size(_mc_size); } } else { L_(info) << " Pgen microslice size: " << human_readable_mc_size(_mc_size) << " (default)"; } if (vm.count("pgen-rate")) { _pgen_rate = vm["pgen-rate"].as<float>(); if (_pgen_rate < 0 || _pgen_rate > 1) { // range check throw ParametersException("Pgen rate out of range"); } else { L_(info) << " Pgen rate: " << _pgen_rate; } } L_(info) << " FLIB microslice size limit: " << _mc_size_limit << " bytes"; for (size_t i = 0; i < _num_flib_links; ++i) { L_(info) << "Link " << i << " config:"; parse_data_source(vm, i); } // end loop over links }
void Parameters::parse_options(int argc, char* argv[]) { unsigned log_level = 2; std::string log_file; po::options_description general("General options"); auto general_add = general.add_options(); general_add("version,V", "print version string"); general_add("help,h", "produce help message"); general_add("log-level,l", po::value<unsigned>(&log_level), "set the log level (default:2, all:0)"); general_add("log-file,L", po::value<std::string>(&log_file), "name of target log file"); general_add("maximum-number,n", po::value<uint64_t>(&maximum_number), "set the maximum number of microslices to process (default: " "unlimited)"); po::options_description source("Source options"); auto source_add = source.add_options(); source_add("shm-channel,c", po::value<size_t>(&shm_channel), "use given shared memory channel as data source"); source_add("input-shm,I", po::value<std::string>(&input_shm), "name of a shared memory to use as data source"); source_add("input-archive,i", po::value<std::string>(&input_archive), "name of an input file archive to read"); po::options_description opmode("Operation mode options"); auto opmode_add = opmode.add_options(); opmode_add("debugger,d", po::value<bool>(&debugger)->implicit_value(true), "enable/disable debugger (raw message unpacking and printout)"); opmode_add("sorter,s", po::value<bool>(&sorter)->implicit_value(true), "enable/disable sorting by epoch in epoch buffer for sink(s) (build output ms from epochs)"); opmode_add("ep_in_ms,N", po::value<uint32_t>(&epoch_per_ms), "Number of epochs stored in each output MS in case sorter is used (default:1)"); opmode_add("sortmesg", po::value<bool>(&sortmesg)->implicit_value(true), "enable/disable message sorting inside epoch buffer before creation of new ms"); po::options_description sink("Sink options"); auto sink_add = sink.add_options(); sink_add("dump_verbosity,v", po::value<size_t>(&dump_verbosity), "set output debug dump verbosity"); sink_add("output-shm,O", po::value<std::string>(&output_shm), "name of a shared memory to write to"); sink_add("output-archive,o", po::value<std::string>(&output_archive), "name of an output file archive to write"); po::options_description desc; desc.add(general).add(source).add(opmode).add(sink); po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); if (vm.count("help") != 0u) { std::cout << "ngdpbtool, git revision " << g_GIT_REVISION << std::endl; std::cout << desc << std::endl; exit(EXIT_SUCCESS); } if (vm.count("version") != 0u) { std::cout << "ngdpbtool, git revision " << g_GIT_REVISION << std::endl; exit(EXIT_SUCCESS); } logging::add_console(static_cast<severity_level>(log_level)); if (vm.count("log-file")) { L_(info) << "Logging output to " << log_file; logging::add_file(log_file, static_cast<severity_level>(log_level)); } size_t input_sources = vm.count("input-archive") + vm.count("input-shm"); if (input_sources == 0) { throw ParametersException("no input source specified"); } if (input_sources > 1) { throw ParametersException("more than one input source specified"); } }
Parameters::Parameters(int argc, char **argv) throw(ParametersException) : _sourceLanguage("") { //variables const option longOptions[] = {{"help", no_argument, nullptr, 'h'}, {"version", no_argument, nullptr, 'v'}, {"source-directory", required_argument, nullptr, 'S'}, {"source-language", required_argument, nullptr, 'l'}, {"language-directory", required_argument, nullptr, 'L'}, {nullptr, 0, nullptr, 0}}; const char *longOptionsStr = "hvS: l: L: "; int longOptionsIndex = 0, opt = 0; //aucune option if (argc <= 1) { _showHelp(); exit(0); } //analyse des options while (true) { opt = getopt_long(argc, argv, longOptionsStr, longOptions, &longOptionsIndex); if (opt == (-1)) { break; } switch (opt) { case 'h': //--help ou -h _showHelp(); exit(0); break; case 'v': //--version ou -v _showVersion(); exit(0); break; case 'S': //--source-directory=<directory> ou -S<directory> _sourceDirectories.push_back(optarg); break; case 'l': //--source-language=<language> ou -l<language> if (!_sourceLanguage.empty()) { throw ParametersException(tr("L'option \"--source-language=<language> ou -l<language>\" est définie plusieurs fois.")); } _sourceLanguage = optarg; break; case 'L': //--language-directory=<directory> ou -L<directory> _languageDirectories.push_back(optarg); break; case 0: break; default: exit(1); break; } } //analyse des sources while (optind < argc) { _sources.push_back(argv[optind]); optind++; } }
void parse_options(int argc, char* argv[]) { std::string config_file; unsigned log_level; std::string log_file; po::options_description generic("Generic options"); auto generic_add = generic.add_options(); generic_add("help,h", "produce help message"); generic_add( "config-file,c", po::value<std::string>(&config_file)->default_value("flib_server.cfg"), "name of a configuration file"); po::options_description config( "Configuration (flib_server.cfg or cmd line)"); auto config_add = config.add_options(); config_add("flib-addr,i", po::value<pci_addr>(), "PCI BDF address of target FLIB in BB:DD.F format"); config_add( "shm,o", po::value<std::string>(&_shm)->default_value("flib_shared_memory"), "name of the shared memory to be used"); config_add("data-buffer-size-exp", po::value<size_t>(&_data_buffer_size_exp)->default_value(27), "exp. size of the data buffer in bytes"); config_add("desc-buffer-size-exp", po::value<size_t>(&_desc_buffer_size_exp)->default_value(19), "exp. size of the descriptor buffer (number of entries)"); config_add("log-level,l", po::value<unsigned>(&log_level)->default_value(2), "set the log level (all:0)"); config_add("log-file,L", po::value<std::string>(&log_file), "name of target log file"); config_add("etcd-authority", po::value<std::string>(&_etcd.authority) ->default_value("127.0.0.1:2379"), "where to find the etcd server"); config_add("etcd-path", po::value<std::string>(&_etcd.path), "base path for this instance, leave empty to not use etcd"); config_add("exec,e", po::value<std::string>(&_exec)->value_name("<string>"), "name of an executable to run after startup"); po::options_description cmdline_options("Allowed options"); cmdline_options.add(generic).add(config); po::options_description config_file_options; config_file_options.add(config); po::variables_map vm; po::store(po::parse_command_line(argc, argv, cmdline_options), vm); po::notify(vm); std::ifstream ifs(config_file.c_str()); if (!ifs) { if (config_file != "flib_server.cfg") { throw ParametersException("Cannot open config file: " + config_file); } } else { std::cout << "Using config file: " << config_file << "\n"; po::store(po::parse_config_file(ifs, config_file_options), vm); notify(vm); } if (vm.count("help")) { std::cout << cmdline_options << "\n"; exit(EXIT_SUCCESS); } logging::add_console(static_cast<severity_level>(log_level)); if (vm.count("log-file")) { L_(info) << "Logging output to " << log_file; logging::add_file(log_file, static_cast<severity_level>(log_level)); } if (vm.count("flib-addr")) { _flib_addr = vm["flib-addr"].as<pci_addr>(); _flib_autodetect = false; L_(debug) << "FLIB address: " << std::hex << std::setw(2) << std::setfill('0') << static_cast<unsigned>(_flib_addr.bus) << ":" << std::setw(2) << std::setfill('0') << static_cast<unsigned>(_flib_addr.dev) << "." << static_cast<unsigned>(_flib_addr.func); } else { _flib_autodetect = true; L_(debug) << "FLIB address: autodetect"; } if (vm.count("etcd-path")) { _etcd.use_etcd = true; } L_(info) << "Shared memory file: " << _shm; L_(info) << print_buffer_info(); }
void Parameters::parse_options(int argc, char* argv[]) { unsigned log_level = 2; po::options_description general("General options"); auto general_add = general.add_options(); general_add("version,V", "print version string"); general_add("help,h", "produce help message"); general_add("log-level,l", po::value<unsigned>(&log_level), "set the log level (default:2, all:0)"); general_add("maximum-number,n", po::value<uint64_t>(&maximum_number), "set the maximum number of microslices to process (default: " "unlimited)"); po::options_description source("Source options"); auto source_add = source.add_options(); source_add("pattern-generator,p", po::value<uint32_t>(&pattern_generator), "use pattern generator to produce timeslices"); source_add("shm-channel,c", po::value<size_t>(&shm_channel), "use given shared memory channel as data source"); source_add("input-shm,I", po::value<std::string>(&input_shm), "name of a shared memory to use as data source"); source_add("input-archive,i", po::value<std::string>(&input_archive), "name of an input file archive to read"); po::options_description sink("Sink options"); auto sink_add = sink.add_options(); sink_add("analyze,a", po::value<bool>(&analyze)->implicit_value(true), "enable/disable pattern check"); sink_add("dump_verbosity,v", po::value<size_t>(&dump_verbosity), "set output debug dump verbosity"); sink_add("output-shm,O", po::value<std::string>(&output_shm), "name of a shared memory to write to"); sink_add("output-archive,o", po::value<std::string>(&output_archive), "name of an output file archive to write"); po::options_description desc; desc.add(general).add(source).add(sink); po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); if (vm.count("help") != 0u) { std::cout << "mstool, git revision " << g_GIT_REVISION << std::endl; std::cout << desc << std::endl; exit(EXIT_SUCCESS); } if (vm.count("version") != 0u) { std::cout << "mstool, git revision " << g_GIT_REVISION << std::endl; exit(EXIT_SUCCESS); } logging::add_console(static_cast<severity_level>(log_level)); use_pattern_generator = vm.count("pattern-generator") != 0; size_t input_sources = vm.count("pattern-generator") + vm.count("input-archive") + vm.count("input-shm"); if (input_sources == 0) { throw ParametersException("no input source specified"); } if (input_sources > 1) { throw ParametersException("more than one input source specified"); } }