LCOV - code coverage report
Current view: top level - felix-star/src - tohost_monitor.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 89 89 100.0 %
Date: 2025-08-12 04:15:35 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   778192126 : void ToHostElinkStats::update_processed_chunk(uint8_t status, uint32_t size) {
       8   778192126 :     ++processed_chunks;
       9   778192126 :     if ( size > largest_chunk_size){
      10          36 :         largest_chunk_size = size;
      11             :     }
      12   778192126 :     processed_bytes += size;
      13   778192126 :     if (status & SW_TRUNC){++sw_trunc_chunks;}
      14   778192126 :     if (status & FW_TRUNC){++fw_trunc_chunks;}
      15   778192126 :     if (status & SW_MALF) {++sw_error_chunks;}
      16   778192126 :     if (status & FW_MALF) {++fw_error_chunks;}
      17   778192126 :     if (status & FW_CRC)  {++fw_crc_chunks;}
      18   778192126 : }
      19             : 
      20             : 
      21         297 : ToHostElinkStats ToHostElinkStats::get_increment(ToHostElinkStats & previous)
      22             : {
      23         297 :     assert(this->fid == previous.fid);
      24         297 :     struct timespec now;
      25         297 :     ToHostElinkStats output(previous.fid);
      26             : 
      27             :     //Counters
      28         297 :     output.dropped_blocks     = this->dropped_blocks;
      29         297 :     output.processed_blocks   = this->processed_blocks;
      30         297 :     output.processed_chunks   = this->processed_chunks;
      31         297 :     output.processed_bytes    = this->processed_bytes;
      32         297 :     output.largest_chunk_size = this->largest_chunk_size;
      33         297 :     output.sw_trunc_chunks    = this->sw_trunc_chunks;
      34         297 :     output.fw_trunc_chunks    = this->fw_trunc_chunks;
      35         297 :     output.sw_error_chunks    = this->sw_error_chunks;
      36         297 :     output.fw_error_chunks    = this->fw_error_chunks;
      37         297 :     output.fw_crc_chunks      = this->fw_crc_chunks;
      38         297 :     output.oosequence_l0id    = this->oosequence_l0id;
      39             : 
      40             :     //Rates
      41         297 :     clock_gettime(CLOCK_MONOTONIC_RAW , &now);
      42         297 :     float seconds = now.tv_sec - previous.ts.tv_sec + 1e-9*(now.tv_nsec - previous.ts.tv_nsec);
      43         297 :     float chunk_increment = static_cast<float>(output.processed_chunks - previous.processed_chunks);
      44         297 :     float bytes_increment = static_cast<float>(output.processed_bytes - previous.processed_bytes);
      45         297 :     output.rate_chunks_kHz    = (chunk_increment / seconds) / 1000.;
      46         297 :     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         297 :     previous.processed_chunks   = this->processed_chunks  ;
      50         297 :     previous.processed_bytes    = this->processed_bytes  ;
      51         297 :     previous.ts                 = now;
      52             : 
      53         297 :     return output;
      54             : }
      55             : 
      56             : 
      57         176 : void ToHostMonitor::append_device_stats(const std::string& ts, const std::string& hostname, const ToHostDeviceStats & s)
      58             : {
      59         176 : };
      60             : 
      61             : 
      62         176 : void ToHostMonitor::append_dma_stats(const std::string& ts, const std::string& hostname, int device, const ToHostDmaStats & ds)
      63             : {
      64         176 :     nlohmann::json j;
      65         176 :     j["dma_free_MB"] = ds.dma_free_MB;
      66         176 :     j["irqs"] = ds.irq_count;
      67             : 
      68         352 :     m_message = nlohmann::json();
      69         176 :     m_message["ts"] = ts;
      70         176 :     m_message["host"][hostname]
      71         176 :              ["app"]["tohost"]
      72         176 :              ["device"][std::to_string(device)]
      73         352 :              ["dma"][std::to_string(ds.dmaid)] = j;
      74             : 
      75         176 :     write_message();
      76         176 : }
      77             : 
      78             : 
      79         188 : void ToHostMonitor::append_reader_stats(const std::string& ts, const std::string& hostname, int device, int dma_id, const ToHostReaderStats & rs)
      80             : {
      81         188 :     nlohmann::json j;
      82         188 :     j["type"] = rs.type;
      83         188 :     j["subscriptions"] = rs.number_of_subscriptions;
      84         188 :     j["net_resources"] = rs.number_of_network_resources;
      85         188 :     j["net_calls"] = rs.number_of_network_resource_calls;
      86             : 
      87         376 :     m_message = nlohmann::json();
      88         188 :     m_message["ts"] = ts;
      89         188 :     m_message["host"][hostname]
      90         188 :              ["app"]["tohost"]
      91         188 :              ["device"][std::to_string(device)]
      92         376 :              ["dma"][std::to_string(dma_id)]
      93         564 :              ["thread"][std::to_string(rs.reader_id)] = j;
      94             : 
      95         188 :     write_message();
      96         188 : }
      97             : 
      98             : 
      99         298 : 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         298 :     nlohmann::json j;
     102         298 :     j["blocks"]          = es.processed_blocks   ;
     103         298 :     j["dropped_blocks"]  = es.dropped_blocks     ;
     104         298 :     j["chunks"]          = es.processed_chunks   ;
     105         298 :     j["chunk_kHz"]       = es.rate_chunks_kHz    ;
     106         298 :     j["avg_chunk_size"]  = es.average_chunk_bytes;
     107         298 :     j["max_chunk_size"]  = es.largest_chunk_size ;
     108         298 :     j["sw_trunc_chunks"] = es.sw_trunc_chunks    ;
     109         298 :     j["fw_trunc_chunks"] = es.fw_trunc_chunks    ;
     110         298 :     j["sw_error_chunks"] = es.sw_error_chunks    ;
     111         298 :     j["fw_error_chunks"] = es.fw_error_chunks    ;
     112         298 :     j["fw_crc_chunks"]   = es.fw_crc_chunks      ;
     113         298 :     j["oosequence_l0id"] = es.oosequence_l0id    ;
     114             : 
     115         596 :     m_message = nlohmann::json();
     116         298 :     m_message["ts"] = ts;
     117         298 :     m_message["host"][hostname]
     118         298 :              ["app"]["tohost"]
     119         298 :              ["device"][std::to_string(device)]
     120         596 :              ["dma"][std::to_string(dma_id)]
     121         596 :              ["thread"][std::to_string(reader_id)]
     122         894 :              ["fid"][std::format("{:#0x}", es.fid)] = j;
     123             : 
     124         298 :     write_message();
     125         298 : }

Generated by: LCOV version 1.0