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

          Line data    Source code
       1             : #include <cassert>
       2             : #include <cstdint>
       3             : #include <format>
       4             : 
       5             : #include "tohost_monitor.hpp"
       6             : 
       7   775713416 : void ToHostElinkStats::update_processed_chunk(uint8_t status, uint32_t size) {
       8   775713416 :     ++processed_chunks;
       9   775713416 :     if ( size > largest_chunk_size){
      10          35 :         largest_chunk_size = size;
      11             :     }
      12   775713416 :     processed_bytes += size;
      13   775713416 :     if (status & SW_TRUNC){++sw_trunc_chunks;}
      14   775713416 :     if (status & FW_TRUNC){++fw_trunc_chunks;}
      15   775713416 :     if (status & SW_MALF) {++sw_error_chunks;}
      16   775713416 :     if (status & FW_MALF) {++fw_error_chunks;}
      17   775713416 :     if (status & FW_CRC)  {++fw_crc_chunks;}
      18   775713416 : }
      19             : 
      20             : 
      21         301 : ToHostElinkStats ToHostElinkStats::get_increment(ToHostElinkStats & previous)
      22             : {
      23         301 :     assert(this->fid == previous.fid);
      24         301 :     struct timespec now;
      25         301 :     ToHostElinkStats output(previous.fid);
      26             : 
      27             :     //Counters
      28         301 :     output.dropped_blocks     = this->dropped_blocks;
      29         301 :     output.processed_blocks   = this->processed_blocks;
      30         301 :     output.processed_chunks   = this->processed_chunks;
      31         301 :     output.processed_bytes    = this->processed_bytes;
      32         301 :     output.largest_chunk_size = this->largest_chunk_size;
      33         301 :     output.sw_trunc_chunks    = this->sw_trunc_chunks;
      34         301 :     output.fw_trunc_chunks    = this->fw_trunc_chunks;
      35         301 :     output.sw_error_chunks    = this->sw_error_chunks;
      36         301 :     output.fw_error_chunks    = this->fw_error_chunks;
      37         301 :     output.fw_crc_chunks      = this->fw_crc_chunks;
      38         301 :     output.oosequence_l0id    = this->oosequence_l0id;
      39             : 
      40             :     //Rates
      41         301 :     clock_gettime(CLOCK_MONOTONIC_RAW , &now);
      42         301 :     float seconds = now.tv_sec - previous.ts.tv_sec + 1e-9*(now.tv_nsec - previous.ts.tv_nsec);
      43         301 :     float chunk_increment = static_cast<float>(output.processed_chunks - previous.processed_chunks);
      44         301 :     float bytes_increment = static_cast<float>(output.processed_bytes - previous.processed_bytes);
      45         301 :     output.rate_chunks_kHz    = (chunk_increment / seconds) / 1000.;
      46         301 :     output.average_chunk_bytes = chunk_increment > 0 ? static_cast<uint32_t>(bytes_increment / chunk_increment) : 0;
      47             : 
      48             :     //Update old version of quantities for which a rate is printed
      49         301 :     previous.processed_chunks   = this->processed_chunks  ;
      50         301 :     previous.processed_bytes    = this->processed_bytes  ;
      51         301 :     previous.ts                 = now;
      52             : 
      53         301 :     return output;
      54             : }
      55             : 
      56             : 
      57         178 : void ToHostMonitor::append_device_stats(const std::string& ts, const std::string& hostname, const ToHostDeviceStats & s)
      58             : {
      59         178 : };
      60             : 
      61             : 
      62         178 : void ToHostMonitor::append_dma_stats(const std::string& ts, const std::string& hostname, int device, const ToHostDmaStats & ds)
      63             : {
      64         178 :     nlohmann::json j;
      65         178 :     j["dma_free_MB"] = ds.dma_free_MB;
      66         178 :     j["irqs"] = ds.irq_count;
      67             : 
      68         178 :     m_message = nlohmann::json();
      69         356 :     m_message["ts"] = ts;
      70         178 :     m_message["host"][hostname]
      71         178 :              ["app"]["tohost"]
      72         356 :              ["device"][std::to_string(device)]
      73         356 :              ["dma"][std::to_string(ds.dmaid)] = j;
      74             : 
      75         178 :     write_message();
      76         178 : }
      77             : 
      78             : 
      79         189 : void ToHostMonitor::append_reader_stats(const std::string& ts, const std::string& hostname, int device, int dma_id, const ToHostReaderStats & rs)
      80             : {
      81         189 :     nlohmann::json j;
      82         189 :     j["type"] = rs.type;
      83         189 :     j["subscriptions"] = rs.number_of_subscriptions;
      84         189 :     j["net_resources"] = rs.number_of_network_resources;
      85         189 :     j["net_calls"] = rs.number_of_network_resource_calls;
      86             : 
      87         189 :     m_message = nlohmann::json();
      88         378 :     m_message["ts"] = ts;
      89         189 :     m_message["host"][hostname]
      90         189 :              ["app"]["tohost"]
      91         378 :              ["device"][std::to_string(device)]
      92         378 :              ["dma"][std::to_string(dma_id)]
      93         378 :              ["thread"][std::to_string(rs.reader_id)] = j;
      94             : 
      95         189 :     write_message();
      96         189 : }
      97             : 
      98             : 
      99         302 : void ToHostMonitor::append_elink_stats(const std::string& ts, const std::string& hostname, int device, int dma_id, int reader_id, const ToHostElinkStats & es)
     100             : {
     101         302 :     nlohmann::json j;
     102         302 :     j["blocks"]          = es.processed_blocks   ;
     103         302 :     j["dropped_blocks"]  = es.dropped_blocks     ;
     104         302 :     j["chunks"]          = es.processed_chunks   ;
     105         302 :     j["chunk_kHz"]       = es.rate_chunks_kHz    ;
     106         302 :     j["avg_chunk_size"]  = es.average_chunk_bytes;
     107         302 :     j["max_chunk_size"]  = es.largest_chunk_size ;
     108         302 :     j["sw_trunc_chunks"] = es.sw_trunc_chunks    ;
     109         302 :     j["fw_trunc_chunks"] = es.fw_trunc_chunks    ;
     110         302 :     j["sw_error_chunks"] = es.sw_error_chunks    ;
     111         302 :     j["fw_error_chunks"] = es.fw_error_chunks    ;
     112         302 :     j["fw_crc_chunks"]   = es.fw_crc_chunks      ;
     113         302 :     j["oosequence_l0id"] = es.oosequence_l0id    ;
     114             : 
     115         302 :     m_message = nlohmann::json();
     116         604 :     m_message["ts"] = ts;
     117         302 :     m_message["host"][hostname]
     118         302 :              ["app"]["tohost"]
     119         604 :              ["device"][std::to_string(device)]
     120         604 :              ["dma"][std::to_string(dma_id)]
     121         604 :              ["thread"][std::to_string(reader_id)]
     122         604 :              ["fid"][std::format("{:#0x}", es.fid)] = j;
     123             : 
     124         302 :     write_message();
     125         302 : }

Generated by: LCOV version 1.0