LCOV - code coverage report
Current view: top level - disco/metrics - fd_metrics_base.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 11 14 78.6 %
Date: 2025-01-08 12:08:44 Functions: 1 83 1.2 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_disco_metrics_fd_metrics_base_h
       2             : #define HEADER_fd_src_disco_metrics_fd_metrics_base_h
       3             : 
       4             : #include "../../util/fd_util.h"
       5             : 
       6           6 : #define FD_METRICS_TYPE_GAUGE     (0UL)
       7         102 : #define FD_METRICS_TYPE_COUNTER   (1UL)
       8           6 : #define FD_METRICS_TYPE_HISTOGRAM (2UL)
       9             : 
      10           0 : #define FD_METRICS_CONVERTER_NONE        (0UL)
      11             : #define FD_METRICS_CONVERTER_SECONDS     (1UL)
      12           0 : #define FD_METRICS_CONVERTER_NANOSECONDS (2UL)
      13             : 
      14     6291750 : #define MIDX( type, group, measurement ) (FD_METRICS_##type##_##group##_##measurement##_OFF)
      15             : 
      16             : #define DECLARE_METRIC( MEASUREMENT, TYPE ) {              \
      17             :     .name      = FD_METRICS_##TYPE##_##MEASUREMENT##_NAME, \
      18             :     .type      = FD_METRICS_TYPE_##TYPE,                   \
      19             :     .desc      = FD_METRICS_##TYPE##_##MEASUREMENT##_DESC, \
      20             :     .offset    = FD_METRICS_##TYPE##_##MEASUREMENT##_OFF,  \
      21             :     .converter = FD_METRICS_##TYPE##_##MEASUREMENT##_CVT   \
      22             :   }
      23             : 
      24             : #define DECLARE_METRIC_ENUM( MEASUREMENT, TYPE, ENUM_NAME, ENUM_VARIANT ) { \
      25             :     .name         = FD_METRICS_##TYPE##_##MEASUREMENT##_NAME,               \
      26             :     .enum_name    = FD_METRICS_ENUM_##ENUM_NAME##_NAME,                     \
      27             :     .enum_variant = FD_METRICS_ENUM_##ENUM_NAME##_V_##ENUM_VARIANT##_NAME,  \
      28             :     .type         = FD_METRICS_TYPE_##TYPE,                                 \
      29             :     .desc         = FD_METRICS_##TYPE##_##MEASUREMENT##_DESC,               \
      30             :     .offset       = FD_METRICS_##TYPE##_##MEASUREMENT##_OFF +               \
      31             :                     FD_METRICS_ENUM_##ENUM_NAME##_V_##ENUM_VARIANT##_IDX,   \
      32             :     .converter    = FD_METRICS_##TYPE##_##MEASUREMENT##_CVT                 \
      33             :   }
      34             : 
      35             : #define DECLARE_METRIC_HISTOGRAM_NONE( MEASUREMENT ) {     \
      36             :     .name = FD_METRICS_HISTOGRAM_##MEASUREMENT##_NAME,     \
      37             :     .type = FD_METRICS_TYPE_HISTOGRAM,                     \
      38             :     .desc = FD_METRICS_HISTOGRAM_##MEASUREMENT##_DESC,     \
      39             :     .offset = FD_METRICS_HISTOGRAM_##MEASUREMENT##_OFF,    \
      40             :     .converter = FD_METRICS_HISTOGRAM_##MEASUREMENT##_CVT, \
      41             :     .histogram = {                                         \
      42             :       .none = {                                            \
      43             :         .min = FD_METRICS_HISTOGRAM_##MEASUREMENT##_MIN,   \
      44             :         .max = FD_METRICS_HISTOGRAM_##MEASUREMENT##_MAX,   \
      45             :       },                                                   \
      46             :     },                                                     \
      47             :   }
      48             : 
      49             : #define DECLARE_METRIC_HISTOGRAM_SECONDS( MEASUREMENT ) {  \
      50             :     .name = FD_METRICS_HISTOGRAM_##MEASUREMENT##_NAME,     \
      51             :     .type = FD_METRICS_TYPE_HISTOGRAM,                     \
      52             :     .desc = FD_METRICS_HISTOGRAM_##MEASUREMENT##_DESC,     \
      53             :     .offset = FD_METRICS_HISTOGRAM_##MEASUREMENT##_OFF,    \
      54             :     .converter = FD_METRICS_HISTOGRAM_##MEASUREMENT##_CVT, \
      55             :     .histogram = {                                         \
      56             :       .seconds = {                                         \
      57             :         .min = FD_METRICS_HISTOGRAM_##MEASUREMENT##_MIN,   \
      58             :         .max = FD_METRICS_HISTOGRAM_##MEASUREMENT##_MAX,   \
      59             :       },                                                   \
      60             :     },                                                     \
      61             :   }
      62             : 
      63             : typedef struct {
      64             :   char const * name;
      65             :   char const * enum_name;
      66             :   char const * enum_variant;
      67             :   int          type;
      68             :   char const * desc;
      69             :   ulong        offset;
      70             : 
      71             :   int converter;
      72             : 
      73             :   union {
      74             :     struct {
      75             : 
      76             :       union {
      77             :         struct {
      78             :           ulong min;
      79             :           ulong max;
      80             :         } none;
      81             :         
      82             :         struct {
      83             :           double min;
      84             :           double max;
      85             :         } seconds;
      86             :       };
      87             :     } histogram;
      88             :   };
      89             : } fd_metrics_meta_t;
      90             : 
      91             : FD_PROTOTYPES_BEGIN
      92             : 
      93             : FD_FN_PURE static inline char *
      94         114 : fd_metrics_meta_type_str( fd_metrics_meta_t const * metric ) {
      95         114 :   switch( metric->type ) {
      96           6 :     case FD_METRICS_TYPE_GAUGE:     return "gauge";
      97         102 :     case FD_METRICS_TYPE_COUNTER:   return "counter";
      98           6 :     case FD_METRICS_TYPE_HISTOGRAM: return "histogram";
      99           0 :     default:                        return "unknown";
     100         114 :   }
     101         114 : }
     102             : 
     103             : FD_PROTOTYPES_END
     104             : 
     105             : #endif /* HEADER_fd_src_disco_metrics_fd_metrics_base_h */

Generated by: LCOV version 1.14