Line data Source code
1 : #ifndef ARTDAQ_TEST_DAQRATE_TRANSFERTEST_HH
2 : #define ARTDAQ_TEST_DAQRATE_TRANSFERTEST_HH
3 :
4 : #include <chrono>
5 : #include <cmath>
6 : #include <string>
7 : #include <utility> // std::pair<>
8 : #include <vector>
9 :
10 : #include "fhiclcpp/ParameterSet.h"
11 :
12 : namespace artdaq {
13 : /**
14 : * \brief Test a set of TransferInterface plugins
15 : */
16 : class TransferTest
17 : {
18 : public:
19 : /**
20 : * \brief TransferTest Constructor
21 : * \param psi ParameterSet used to configure TransferTest
22 : *
23 : * \verbatim
24 : * TransferTest accepts the following Parameters:
25 : * "num_senders" (REQUIRED): Number of sending TransferTest instances
26 : * "num_receivers" (REQUIRED): Number of receiving TransferTest instances
27 : * "sends_per_sender" (REQUIRED): Number of sends each sender will perform
28 : * "sending_threads" (Default: 1): Number of TransferInterface instances to send fragments from for each source rank
29 : * "buffer_count" (Default: 10): Buffer count for TransferInterfaces
30 : * "fragment_size" (Default: 0x100000): Size of Fragments to transfer
31 : * "metrics": FHiCL table used to configure MetricManager (see documentation)
32 : * "transfer_plugin_type" (Default: TCPSocket): TransferInterface plugin to load
33 : * "hostmap" (OPTIONAL): Host map to use for "host_map" parameter of TransferInterface plugins (i.e. TCPSocketTransfer)
34 : * \endverbatim
35 : */
36 : explicit TransferTest(fhicl::ParameterSet psi);
37 :
38 : /**
39 : * \brief Run the test as configured
40 : * \return 0 upon success
41 : */
42 : int runTest();
43 :
44 : /**
45 : * @brief Get the result of the test
46 : * @return Test result (Unix-style, 0 is success)
47 : */
48 : int returnCode() { return return_code_; }
49 :
50 : private:
51 : std::pair<size_t, double> do_sending(int thread_index);
52 :
53 : std::pair<size_t, double> do_receiving();
54 :
55 : // Helper functions
56 : const std::vector<std::string> suffixes{" ", " K", " M", " G", " T"};
57 :
58 : std::string formatBytes(double bytes, size_t suffixIndex = 0);
59 : std::string formatHertz(double hertz, size_t suffixIndex = 0);
60 :
61 : int senders_;
62 : int receivers_;
63 : int sending_threads_;
64 : int sends_each_sender_;
65 : int receives_each_receiver_; // Should be sends_each_sender * sending_threads * sending_ranks / receiving_ranks
66 : int buffer_count_;
67 : int error_count_max_;
68 : size_t fragment_size_;
69 : std::chrono::steady_clock::time_point start_time_;
70 : fhicl::ParameterSet ps_;
71 : bool validate_mode_;
72 : int partition_number_;
73 :
74 : int return_code_{0};
75 : };
76 :
77 0 : inline std::string TransferTest::formatBytes(double bytes, size_t suffixIndex)
78 : {
79 0 : auto b = fabs(bytes);
80 :
81 0 : if (b > 1024.0 && suffixIndex < suffixes.size())
82 : {
83 0 : return formatBytes(bytes / 1024.0, suffixIndex + 1);
84 : }
85 :
86 0 : return std::to_string(bytes) + suffixes[suffixIndex] + "B";
87 : }
88 :
89 0 : inline std::string TransferTest::formatHertz(double hertz, size_t suffixIndex)
90 : {
91 0 : auto b = fabs(hertz);
92 :
93 0 : if (b > 1000.0 && suffixIndex < suffixes.size())
94 : {
95 0 : return formatHertz(hertz / 1000.0, suffixIndex + 1);
96 : }
97 :
98 0 : return std::to_string(hertz) + suffixes[suffixIndex] + "Hz";
99 : }
100 :
101 : } // namespace artdaq
102 : #endif // ARTDAQ_TEST_DAQRATE_TRANSFERTEST_HH
|