LCOV - code coverage report
Current view: top level - src - tohost_monitor.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 22 25 88.0 %
Date: 2025-11-14 15:45:10 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #ifndef FELIX_TOHOST_MONITOR_H_
       2             : #define FELIX_TOHOST_MONITOR_H_
       3             : 
       4             : #include "monitor.hpp"
       5             : 
       6             : enum ChunkStatus {
       7             :     FW_TRUNC = 1, SW_TRUNC = 2, FW_MALF = 4, FW_CRC = 8, SW_MALF = 16
       8             : };
       9             : 
      10             : /**
      11             :  * Monitoring info for one Device.
      12             :  */
      13             : struct ToHostDeviceStats
      14             : {
      15             :     int device_id;
      16             : 
      17         174 :     explicit ToHostDeviceStats(int d)
      18         174 :         : device_id(d) {};
      19             : };
      20             : 
      21             : 
      22             : /**
      23             :  * Monitoring info for one DMA buffer.
      24             :  */
      25             : struct ToHostDmaStats
      26             : {
      27             :     int dmaid;
      28             :     uint32_t dma_free_MB;
      29             :     uint64_t irq_count;
      30             : 
      31         174 :     explicit ToHostDmaStats(int dm, int mb, uint64_t irq)
      32         174 :         : dmaid(dm), dma_free_MB(mb), irq_count(irq) {};
      33             : };
      34             : 
      35             : 
      36             : /**
      37             :  * Monitoring info for each reader associated to a DMA buffer.
      38             :  */
      39             : struct ToHostReaderStats
      40             : {
      41             :     int reader_id;
      42             :     int type;
      43             :     uint32_t number_of_subscriptions;
      44             :     uint32_t number_of_network_resources;
      45             :     uint64_t number_of_network_resource_calls;
      46             : 
      47         185 :     explicit ToHostReaderStats(int ri, int t, uint32_t s, uint32_t r, uint64_t c) :
      48         185 :         reader_id(ri),
      49         185 :         type(t),
      50         185 :         number_of_subscriptions(s),
      51         185 :         number_of_network_resources(r),
      52         185 :         number_of_network_resource_calls(c) {};
      53             : };
      54             : 
      55             : 
      56             : /**
      57             :  * Monitoring info for each decoder (one per e-link) part of a reader.
      58             :  */
      59             : struct ToHostElinkStats
      60             : {
      61             :     uint64_t fid                  = 0;
      62             :     uint64_t processed_blocks     = 0;
      63             :     uint64_t processed_chunks     = 0;
      64             :     uint64_t dropped_empty_chunks = 0; ///< Number of dropped empty chunks
      65             :     uint64_t processed_bytes      = 0;
      66             :     float rate_chunks_kHz         = 0;
      67             :     uint64_t dropped_blocks       = 0;
      68             :     uint32_t largest_chunk_size   = 0;
      69             :     uint32_t average_chunk_bytes  = 0;
      70             :     uint64_t sw_trunc_chunks      = 0;
      71             :     uint64_t fw_trunc_chunks      = 0;
      72             :     uint64_t sw_error_chunks      = 0;
      73             :     uint64_t fw_error_chunks      = 0;
      74             :     uint64_t fw_crc_chunks        = 0;
      75             :     uint64_t oosequence_l0id      = 0;
      76             :     struct timespec ts ;
      77             : 
      78   579383487 :     void increment_processed_blocks(){++processed_blocks;}
      79           0 :     void increment_dropped_blocks(){++dropped_blocks;}
      80           0 :     void increment_oosequence_l0id(){++oosequence_l0id;}
      81             :     void update_processed_chunk(uint8_t e, uint32_t s);
      82             : 
      83             :     /**
      84             :      * @brief Increment the count of empty chunks.
      85             :      */
      86           0 :     void increment_empty_chunks() { ++dropped_empty_chunks; }
      87             : 
      88             :     ToHostElinkStats get_increment(ToHostElinkStats & stats);
      89         293 :     ToHostElinkStats() = default;
      90             : 
      91         370 :     explicit ToHostElinkStats(uint64_t f) : fid(f), processed_blocks(0),  processed_chunks(0),
      92         370 :         processed_bytes(0), rate_chunks_kHz(0),
      93         370 :         dropped_blocks(0),largest_chunk_size(0), sw_trunc_chunks(0), fw_trunc_chunks(0),
      94         370 :         sw_error_chunks(0), fw_error_chunks(0), fw_crc_chunks(0), oosequence_l0id(0)
      95             :         {
      96         370 :             clock_gettime(CLOCK_MONOTONIC_RAW , &ts);
      97         370 :         };
      98             : };
      99             : 
     100             : 
     101             : /**
     102             :  * Monitoring information for the felix-tohost application.
     103             :  * ToHostMonitor gathers the hierarchical monitoring data (buffers > readers > decoders)
     104             :  * and returns a json string.
     105             :  */
     106           1 : class ToHostMonitor : public Monitor
     107             : {
     108             :     public:
     109          23 :         explicit ToHostMonitor(std::string& fifoname) : Monitor(fifoname) {
     110          23 :             m_message = nlohmann::json::array();
     111          23 :         }
     112             :         //These functions are called in a nested loop with hierarchy
     113             :         //devices > dmas > readers > elinks.
     114             :         /**
     115             :          * @brief append to the JSON message device-level information.
     116             :          * @param ts the timestamp
     117             :          * @param hostname the hostname
     118             :          * @param s data structure containing device statistics
     119             :          */
     120             :         void append_device_stats(const std::string& ts, const std::string& hostname, const ToHostDeviceStats & s);
     121             : 
     122             :         /**
     123             :          * @brief append to the JSON message buffer-level information.
     124             :          * @param ts the timestamp
     125             :          * @param hostname the hostname
     126             :          * @param deviceid the device identifier.
     127             :          * @param s data structure containing DMA buffer statistics
     128             :          */
     129             :         void append_dma_stats(const std::string& ts, const std::string& hostname, int deviceid, const ToHostDmaStats & s);
     130             : 
     131             :         /**
     132             :          * @brief append to the JSON message reader-level information.
     133             :          * @param ts the timestamp
     134             :          * @param hostname the hostname
     135             :          * @param deviceid the device identifier.
     136             :          * @param dma_id the dma identifier
     137             :          * @param s data structure containing reader statistics
     138             :          */
     139             :         void append_reader_stats(const std::string& ts, const std::string& hostname, int deviceid, int dma_id, const ToHostReaderStats & s);
     140             : 
     141             :         /**
     142             :          * @brief append to the JSON message decoder-level information.
     143             :          * @param ts the timestamp
     144             :          * @param hostname the hostname
     145             :          * @param deviceid the device identifier.
     146             :          * @param dma_id the dma identifier
     147             :          * @param reader_id the reader id
     148             :          * @param s data structure containing e-link statistics
     149             :          */
     150             :         void append_elink_stats(const std::string& ts, const std::string& hostname, int device, int dma_id, int reader_id, const ToHostElinkStats & s);
     151             : };
     152             : 
     153             : #endif /* FELIX_TOHOST_MONITOR_H_ */

Generated by: LCOV version 1.0