Line data Source code
1 : #include <format> 2 : #include "fromhost_monitor.hpp" 3 : 4 22 : FromHostDmaStats FromHostDmaStats::get_increment(FromHostDmaStats & previous) 5 : { 6 22 : struct timespec now; 7 22 : FromHostDmaStats output(*this); 8 22 : clock_gettime(CLOCK_MONOTONIC_RAW , &now); 9 22 : float seconds = now.tv_sec - previous.ts.tv_sec + 1e-9*(now.tv_nsec - previous.ts.tv_nsec); 10 22 : float msg_increment = static_cast<float>(output.msg_counter - previous.msg_counter); 11 22 : float bytes_increment = static_cast<float>(output.bytes_counter - previous.bytes_counter); 12 : //rates 13 22 : output.msg_rate_Hz = msg_increment/seconds; 14 22 : output.msg_rate_Mbps = ((8*bytes_increment) / seconds) / 1024. / 1024.; 15 22 : previous = output; 16 22 : previous.ts = now; 17 22 : return output; 18 : } 19 : 20 : 21 10004 : void FromHostElinkStats::on_processed_msg(uint32_t size) 22 : { 23 10004 : ++processed_msg; 24 10004 : if ( size > largest_msg_size){ 25 5 : largest_msg_size = size; 26 : } 27 10004 : processed_bytes += size; 28 10004 : } 29 : 30 : 31 22 : FromHostElinkStats FromHostElinkStats::get_increment(FromHostElinkStats & previous) 32 : { 33 22 : assert(this->fid == previous.fid); 34 22 : struct timespec now; 35 22 : FromHostElinkStats output(previous.fid); 36 : 37 : //Counters 38 22 : output.processed_msg = this->processed_msg; 39 22 : output.processed_bytes = this->processed_bytes; 40 22 : output.dropped_msg = this->dropped_msg; 41 22 : output.largest_msg_size = this->largest_msg_size; 42 : 43 : //Rates 44 22 : clock_gettime(CLOCK_MONOTONIC_RAW , &now); 45 22 : float seconds = now.tv_sec - previous.ts.tv_sec + 1e-9*(now.tv_nsec - previous.ts.tv_nsec); 46 22 : float msg_increment = static_cast<float>(output.processed_msg - previous.processed_msg); 47 22 : float bytes_increment = static_cast<float>(output.processed_bytes - previous.processed_bytes); 48 22 : output.rate_msg_Hz = msg_increment / seconds; 49 22 : output.rate_msg_Mbps = ((8*bytes_increment) / seconds) / 1024. / 1024.; 50 : 51 : //update old version 52 22 : previous.processed_msg = this->processed_msg; 53 22 : previous.processed_bytes = this->processed_bytes; 54 22 : previous.ts = now; 55 : 56 22 : return output; 57 : } 58 : 59 : 60 23 : void FromHostMonitor::append_device_stats(const std::string& ts, const std::string& hostname, const FromHostDeviceStats & ds) 61 : { 62 23 : }; 63 : 64 : 65 23 : void FromHostMonitor::append_dma_stats(const std::string& ts, const std::string& hostname, int device, const FromHostDmaStats & ds) 66 : { 67 23 : nlohmann::json j; 68 23 : j["dma_free_MB"] = ds.dma_free_MB; 69 23 : j["msg_rate_Hz"] = ds.msg_rate_Hz; 70 23 : j["msg_rate_Mbps"] = ds.msg_rate_Mbps; 71 : 72 46 : m_message = nlohmann::json(); 73 23 : m_message["ts"] = ts; 74 23 : m_message["host"][hostname] 75 23 : ["app"]["fromhost"] 76 23 : ["device"][std::to_string(device)] 77 46 : ["dma"][std::to_string(ds.dmaid)] = j; 78 : 79 23 : write_message(); 80 23 : } 81 : 82 23 : void FromHostMonitor::append_writer_stats(const std::string& ts, const std::string& hostname, int device, int dma_id, const FromHostWriterStats & ws) 83 : { 84 23 : nlohmann::json j; 85 23 : j["type"] = ws.type; 86 23 : j["number_of_connections"] = ws.number_of_connections; 87 : 88 46 : m_message = nlohmann::json(); 89 23 : m_message["ts"] = ts; 90 23 : m_message["host"][hostname] 91 23 : ["app"]["fromhost"] 92 23 : ["device"][std::to_string(device)] 93 46 : ["dma"][std::to_string(dma_id)] 94 69 : ["thread"][std::to_string(ws.writer_id)] = j; 95 : 96 23 : write_message(); 97 23 : } 98 : 99 23 : void FromHostMonitor::append_elink_stats(const std::string& ts, const std::string& hostname, int device, int dma_id, int reader_id, const FromHostElinkStats & es) 100 : { 101 23 : nlohmann::json j; 102 23 : j["msgs"] = es.processed_msg; 103 23 : j["bytes"] = es.processed_bytes; 104 23 : j["max_msg_size"] = es.largest_msg_size; 105 23 : j["dropped_msgs"] = es.dropped_msg; 106 23 : j["rate_msg_Hz"] = es.rate_msg_Hz; 107 23 : j["rate_msg_Mbps"] = es.rate_msg_Mbps; 108 : 109 46 : m_message = nlohmann::json(); 110 23 : m_message["ts"] = ts; 111 23 : m_message["host"][hostname] 112 23 : ["app"]["fromhost"] 113 23 : ["device"][std::to_string(device)] 114 46 : ["dma"][std::to_string(dma_id)] 115 46 : ["thread"][std::to_string(reader_id)] 116 69 : ["fid"][std::format("{:#0x}", es.fid)] = j; 117 : 118 23 : write_message(); 119 23 : }