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

Generated by: LCOV version 1.0