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 16 : Probe_throughput::Probe_throughput(const size_t data_size, 11 : const std::string& col_name, 12 : const double factor, 13 16 : tools::Reporter_probe* reporter) 14 : : Probe<uint8_t>(0, col_name) 15 16 : , t_start(std::chrono::steady_clock::now()) 16 16 : , data_size(data_size) 17 16 : , thr(0.) 18 16 : , factor(factor) 19 : { 20 16 : const std::string name = "Probe_throughput<" + col_name + ">"; 21 16 : this->set_name(name); 22 16 : this->set_single_wave(true); 23 : 24 16 : if (reporter != nullptr) this->register_reporter(reporter); 25 16 : } 26 : 27 16 : Probe_throughput::Probe_throughput(const size_t data_size, const std::string& col_name, tools::Reporter_probe* reporter) 28 16 : : Probe_throughput(data_size, col_name, 1024. * 1024., reporter) 29 : { 30 16 : } 31 : 32 16 : Probe_throughput::Probe_throughput(const std::string& col_name, tools::Reporter_probe* reporter) 33 16 : : Probe_throughput(1, col_name, reporter) 34 : { 35 16 : } 36 : 37 : void 38 16 : Probe_throughput::register_reporter(tools::Reporter_probe* reporter) 39 : { 40 16 : 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 16 : this->reporter = reporter; 48 16 : this->proxy_register_probe(1, typeid(double), "", 100, std::ios_base::dec | std::ios_base::fixed, 3); 49 16 : } 50 : 51 : void 52 106 : Probe_throughput::_probe(const uint8_t* /*in*/, const size_t frame_id) 53 : { 54 106 : auto t_stop = std::chrono::steady_clock::now(); 55 106 : auto time_duration = (double)std::chrono::duration_cast<std::chrono::microseconds>(t_stop - this->t_start).count(); 56 106 : this->thr = ((double)(this->data_size * this->get_n_frames()) / (this->factor)) / (time_duration * 1e-6); 57 106 : this->t_start = t_stop; 58 : 59 262 : for (size_t f = 0; f < this->get_n_frames(); f++) 60 156 : this->proxy_probe((void*)&thr, frame_id); 61 106 : } 62 : 63 : void 64 16 : Probe_throughput::reset() 65 : { 66 16 : this->t_start = std::chrono::steady_clock::now(); 67 16 : this->thr = 0.; 68 16 : }