LCOV - code coverage report
Current view: top level - src - fromhost_monitor.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 82 82 100.0 %
Date: 2025-09-09 12:09:29 Functions: 7 7 100.0 %

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

Generated by: LCOV version 1.0