Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
rcpt_performance_main.cpp
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2016 The SKA organisation
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "cheetah/emulator/EmulatorAppConfig.h"
25 #include "cheetah/rcpt/PacketGenerator.h"
26 #include "cheetah/emulator/Factory.h"
27 #include "cheetah/emulator/Config.h"
28 #include "cheetah/rcpt/RcptTimerStats.h"
29 #include "cheetah/rcpt/UdpStream.h"
30 #include "panda/BasicAppConfig.h"
31 #include "panda/IpAddress.h"
32 #include "panda/TupleUtilities.h"
33 #include "panda/Log.h"
34 #include <memory>
35 #include <thread>
36 #include <chrono>
37 #include <type_traits>
38 
39 //class PerformanceTesterConfig : public ska::panda::BasicAppConfig
41 {
42  public:
44  : ska::cheetah::emulator::EmulatorAppConfig("rcpt_performance_test", "execute performance tests for the UDP rcpt data ingest of cheetah ")
45  , _iterations(10000)
46  {
47  add(_rcpt_config);
48  }
49 
50  ska::cheetah::rcpt::Config const& rcpt_config() const
51  {
52  return _rcpt_config;
53  }
54 
55  ska::cheetah::rcpt::Config& rcpt_config()
56  {
57  return _rcpt_config;
58  }
59 
60  unsigned iterations() const {
61  return _iterations;
62  }
63 
64  protected:
65  void add_options(OptionsDescriptionEasyInit& add_options) override
66  {
67  add_options
68  ("iter", boost::program_options::value<unsigned>(&_iterations)->default_value(_iterations), "number of chunks to process for each test");
69  EmulatorAppConfig::add_options(add_options);
70  }
71 
72 
73  private:
74  ska::cheetah::rcpt::Config _rcpt_config;
75  unsigned _iterations;
76 };
77 
78 typedef std::chrono::high_resolution_clock ClockType;
79 
80 int main(int argc, char** argv) {
81  PerformanceTesterConfig app_config;
82  int rv;
83  typedef uint8_t DataType;
84  try {
85  // ---------- configuration -----------------
86  ska::cheetah::emulator::Config& emulator_config = app_config.emulator_config();
87  // add dynamic items to config
89  app_config.set_generator_list(generator_factory.available());
90 
91  // parse command line options
92  if( (rv=app_config.parse(argc, argv)) ) return rv;
93 
94  // set the stream to listen on a random port
95  auto& rcpt_config = app_config.rcpt_config();
96  ska::panda::IpAddress address(0, "127.0.0.1");
97  boost::asio::ip::udp::endpoint local_endpoint = address.end_point<boost::asio::ip::udp::endpoint>();
98  rcpt_config.remote_end_point(local_endpoint);
99  ska::cheetah::rcpt::UdpStream stream(rcpt_config);
100  ska::panda::DataManager<ska::cheetah::rcpt::UdpStream> dm(stream);
101 
102  auto endpoint = stream.local_end_point();
103  emulator_config.fixed_address(ska::panda::IpAddress(endpoint));
104 
105  // setup the emulator
108  typedef typename FactoryType::EmulatorType EmulatorType;
109  FactoryType factory(emulator_config, generator_factory);
110  std::unique_ptr<EmulatorType> emulator(factory.create(emulator_config.generator()
111  , ska::cheetah::data::DimensionSize<ska::cheetah::data::Frequency>(rcpt_config.number_of_channels())
112  , ska::cheetah::data::DimensionSize<ska::cheetah::data::Time>(rcpt_config.samples_per_chunk())));
113  PANDA_LOG << "emulator using generator: '" << emulator_config.generator() << "'";
114 
115  std::thread th([&]() { emulator->run(); });
116 
117  // ---------- tests -----------------
119  unsigned iter_max = app_config.iterations();
120  for(unsigned iter=0; iter < iter_max; ++iter)
121  {
122  auto data=dm.next();
123  stats(*std::get<ska::panda::Index<std::shared_ptr<typename ska::cheetah::rcpt::BeamFormerDataTraits::DataType>, typename decltype(dm)::DataSetType>::value>(data), ClockType::now());
124  }
125  PANDA_LOG << "\n----\n\t" << stats << "\n----";
126  emulator->stop();
127  th.join();
128  }
129  catch(std::exception const& e) {
130  std::cerr << "Emulator: " << e.what() << std::endl;
131  }
132  catch(...) {
133  std::cerr << "Emulator: unknown exception caught" << std::endl;
134  }
135  return 1;
136 }
construct a suitable generatro object
Definition: GeneratorApp.h:38
Packs data into a UDP stream Packet Header format of the BeamFormer.
unsigned number_of_channels() const
return the number of channels in a chunk
Definition: Config.cpp:83
factory to construct emulators
Definition: Factory.h:45
unsigned samples_per_chunk() const
return the number of time samples in a chunk
Definition: Config.cpp:73
cheetah::generators::Config const & generators_config() const
the configuration block for generators
Definition: Config.cpp:69
Configuration options for the Emulator.
Definition: Config.h:50
boost::asio::ip::udp::endpoint remote_end_point() const
geters and setters for the UDP connection (IP address and port or remote peer)
Definition: Config.cpp:63
void fixed_address(panda::IpAddress const &)
set the address to stream UDP packets to
Definition: Config.cpp:64
Top level configuration for the emulator app.
std::string const & generator() const
the name of the data generator to use
Definition: Config.cpp:94
configurable parameters for the rcpt
Definition: Config.h:42
Calculate rcpt specific performance information.
void set_generator_list(std::vector< std::string > const &generator_names)
set the known generators