Line data Source code
1 : #include <ios> 2 : #include <sstream> 3 : 4 : #include "Module/Stateful/Probe/Throughput/Probe_throughput.hpp" 5 : #include "Tools/Exception/exception.hpp" 6 : 7 : using namespace spu; 8 : using namespace spu::module; 9 : 10 14 : Probe_throughput::Probe_throughput(const size_t data_size, 11 : const std::string& col_name, 12 : const double factor, 13 14 : tools::Reporter_probe* reporter) 14 : : Probe<uint8_t>(0, col_name) 15 14 : , t_start(std::chrono::steady_clock::now()) 16 14 : , data_size(data_size) 17 14 : , thr(0.) 18 14 : , factor(factor) 19 : { 20 14 : const std::string name = "Probe_throughput<" + col_name + ">"; 21 14 : this->set_name(name); 22 14 : this->set_single_wave(true); 23 : 24 14 : if (reporter != nullptr) this->register_reporter(reporter); 25 14 : } 26 : 27 14 : Probe_throughput::Probe_throughput(const size_t data_size, const std::string& col_name, tools::Reporter_probe* reporter) 28 14 : : Probe_throughput(data_size, col_name, 1024. * 1024., reporter) 29 : { 30 14 : } 31 : 32 14 : Probe_throughput::Probe_throughput(const std::string& col_name, tools::Reporter_probe* reporter) 33 14 : : Probe_throughput(1, col_name, reporter) 34 : { 35 14 : } 36 : 37 : void 38 14 : Probe_throughput::register_reporter(tools::Reporter_probe* reporter) 39 : { 40 14 : if (this->reporter != nullptr) 41 : { 42 0 : std::stringstream message; 43 : message << "It is not possible to register this probe to a new 'tools::Reporter_probe' because it is already " 44 0 : << "registered to an other 'tools::Reporter_probe'."; 45 0 : throw tools::runtime_error(__FILE__, __LINE__, __func__, message.str()); 46 0 : } 47 14 : this->reporter = reporter; 48 14 : this->proxy_register_probe(1, typeid(double), "", 100, std::ios_base::dec | std::ios_base::fixed, 3); 49 14 : } 50 : 51 : void 52 103 : Probe_throughput::_probe(const uint8_t* in, const size_t frame_id) 53 : { 54 103 : auto t_stop = std::chrono::steady_clock::now(); 55 103 : auto time_duration = (double)std::chrono::duration_cast<std::chrono::microseconds>(t_stop - this->t_start).count(); 56 103 : this->thr = ((double)(this->data_size * this->get_n_frames()) / (this->factor)) / (time_duration * 1e-6); 57 103 : this->t_start = t_stop; 58 : 59 236 : for (size_t f = 0; f < this->get_n_frames(); f++) 60 133 : this->proxy_probe((void*)&thr, frame_id); 61 103 : } 62 : 63 : void 64 14 : Probe_throughput::reset() 65 : { 66 14 : this->t_start = std::chrono::steady_clock::now(); 67 14 : this->thr = 0.; 68 14 : }