LCOV - code coverage report
Current view: top level - src - tohost_monitor.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 22 24 91.7 %
Date: 2025-09-09 12:09:29 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         178 :     explicit ToHostDeviceStats(int d)
      18         178 :         : 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         178 :     explicit ToHostDmaStats(int dm, int mb, uint64_t irq)
      32         178 :         : 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         189 :     explicit ToHostReaderStats(int ri, int t, uint32_t s, uint32_t r, uint64_t c) :
      48         189 :         reader_id(ri),
      49         189 :         type(t),
      50         189 :         number_of_subscriptions(s),
      51         189 :         number_of_network_resources(r),
      52         189 :         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 processed_bytes     = 0;
      65             :     float rate_chunks_kHz        = 0;
      66             :     uint64_t dropped_blocks      = 0;
      67             :     uint32_t largest_chunk_size  = 0;
      68             :     uint32_t average_chunk_bytes = 0;
      69             :     uint64_t sw_trunc_chunks     = 0;
      70             :     uint64_t fw_trunc_chunks     = 0;
      71             :     uint64_t sw_error_chunks     = 0;
      72             :     uint64_t fw_error_chunks     = 0;
      73             :     uint64_t fw_crc_chunks       = 0;
      74             :     uint64_t oosequence_l0id     = 0;
      75             :     struct timespec ts;
      76             : 
      77   605395874 :     void increment_processed_blocks(){++processed_blocks;}
      78           0 :     void increment_dropped_blocks(){++dropped_blocks;}
      79           0 :     void increment_oosequence_l0id(){++oosequence_l0id;}
      80             :     void update_processed_chunk(uint8_t e, uint32_t s);
      81             :     ToHostElinkStats get_increment(ToHostElinkStats & stats);
      82         301 :     ToHostElinkStats() = default;
      83             : 
      84         378 :     explicit ToHostElinkStats(uint64_t f) : fid(f), processed_blocks(0),  processed_chunks(0),
      85         378 :         processed_bytes(0), rate_chunks_kHz(0),
      86         378 :         dropped_blocks(0),largest_chunk_size(0), sw_trunc_chunks(0), fw_trunc_chunks(0),
      87         378 :         sw_error_chunks(0), fw_error_chunks(0), fw_crc_chunks(0), oosequence_l0id(0)
      88             :         {
      89         378 :             clock_gettime(CLOCK_MONOTONIC_RAW , &ts);
      90         378 :         };
      91             : };
      92             : 
      93             : 
      94             : /**
      95             :  * Monitoring information for the felix-tohost application.
      96             :  * ToHostMonitor gathers the hierarchical monitoring data (buffers > readers > decoders)
      97             :  * and returns a json string.
      98             :  */
      99           1 : class ToHostMonitor : public Monitor
     100             : {
     101             :     public:
     102          23 :         explicit ToHostMonitor(std::string& fifoname) : Monitor(fifoname) {
     103          23 :             m_message = nlohmann::json::array();
     104          23 :         }
     105             :         //These functions are called in a nested loop with hierarchy
     106             :         //devices > dmas > readers > elinks.
     107             :         /**
     108             :          * @brief append to the JSON message device-level information.
     109             :          * @param ts the timestamp
     110             :          * @param hostname the hostname
     111             :          * @param s data structure containing device statistics
     112             :          */
     113             :         void append_device_stats(const std::string& ts, const std::string& hostname, const ToHostDeviceStats & s);
     114             : 
     115             :         /**
     116             :          * @brief append to the JSON message buffer-level information.
     117             :          * @param ts the timestamp
     118             :          * @param hostname the hostname
     119             :          * @param deviceid the device identifier.
     120             :          * @param s data structure containing DMA buffer statistics
     121             :          */
     122             :         void append_dma_stats(const std::string& ts, const std::string& hostname, int deviceid, const ToHostDmaStats & s);
     123             : 
     124             :         /**
     125             :          * @brief append to the JSON message reader-level information.
     126             :          * @param ts the timestamp
     127             :          * @param hostname the hostname
     128             :          * @param deviceid the device identifier.
     129             :          * @param dma_id the dma identifier
     130             :          * @param s data structure containing reader statistics
     131             :          */
     132             :         void append_reader_stats(const std::string& ts, const std::string& hostname, int deviceid, int dma_id, const ToHostReaderStats & s);
     133             : 
     134             :         /**
     135             :          * @brief append to the JSON message decoder-level information.
     136             :          * @param ts the timestamp
     137             :          * @param hostname the hostname
     138             :          * @param deviceid the device identifier.
     139             :          * @param dma_id the dma identifier
     140             :          * @param reader_id the reader id
     141             :          * @param s data structure containing e-link statistics
     142             :          */
     143             :         void append_elink_stats(const std::string& ts, const std::string& hostname, int device, int dma_id, int reader_id, const ToHostElinkStats & s);
     144             : };
     145             : 
     146             : #endif /* FELIX_TOHOST_MONITOR_H_ */

Generated by: LCOV version 1.0