LCOV - code coverage report
Current view: top level - src - PerfStats.h (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 16 16
Test Date: 2026-03-01 21:30:38 Functions: 100.0 % 3 3
Branches: 100.0 % 8 8

             Branch data     Line data    Source code
       1                 :             : #ifndef PERF_STATS_H
       2                 :             : #define PERF_STATS_H
       3                 :             : 
       4                 :             : #include <cmath>
       5                 :             : #include <limits>
       6                 :             : 
       7                 :             : // Stats helper
       8                 :             : struct ChannelStats {
       9                 :             :     // Session-wide stats (Persistent)
      10                 :             :     double session_min = 1e9;
      11                 :             :     double session_max = -1e9;
      12                 :             :     
      13                 :             :     // Interval stats (Reset every second)
      14                 :             :     double interval_sum = 0.0;
      15                 :             :     long interval_count = 0;
      16                 :             :     
      17                 :             :     // Latched values for display/consumption by other threads (Interval)
      18                 :             :     double l_avg = 0.0;
      19                 :             :     // Latched values for display/consumption by other threads (Session)
      20                 :             :     double l_min = 0.0;
      21                 :             :     double l_max = 0.0;
      22                 :             :     
      23                 :       49408 :     void Update(double val) {
      24                 :             :         // Update Session Min/Max
      25         [ +  + ]:       49408 :         if (val < session_min) session_min = val;
      26         [ +  + ]:       49408 :         if (val > session_max) session_max = val;
      27                 :             :         
      28                 :             :         // Update Interval Accumulator
      29                 :       49408 :         interval_sum += val;
      30                 :       49408 :         interval_count++;
      31                 :       49408 :     }
      32                 :             :     
      33                 :             :     // Called every interval (e.g. 1s) to latch data and reset interval counters
      34                 :           7 :     void ResetInterval() {
      35         [ +  + ]:           7 :         if (interval_count > 0) {
      36                 :           6 :             l_avg = interval_sum / interval_count;
      37                 :             :         } else {
      38                 :           1 :             l_avg = 0.0;
      39                 :             :         }
      40                 :             :         // Latch current session min/max for display
      41                 :           7 :         l_min = session_min;
      42                 :           7 :         l_max = session_max;
      43                 :             :         
      44                 :             :         // Reset interval data
      45                 :           7 :         interval_sum = 0.0; 
      46                 :           7 :         interval_count = 0;
      47                 :           7 :     }
      48                 :             :     
      49                 :             :     // Compatibility helper
      50         [ +  + ]:           3 :     double Avg() { return interval_count > 0 ? interval_sum / interval_count : 0.0; }
      51                 :             :     void Reset() { ResetInterval(); }
      52                 :             : };
      53                 :             : 
      54                 :             : #endif // PERF_STATS_H
        

Generated by: LCOV version 2.0-1