4 /*! \defgroup rate_ctr Rate counters
8 /*! \file rate_ctr.h */
12 #include <osmocom/core/linuxlist.h>
14 /*! \brief Number of rate counter intervals */
15 #define RATE_CTR_INTV_NUM 4
17 /*! \brief Rate counter interval */
19 RATE_CTR_INTV_SEC
, /*!< \brief last second */
20 RATE_CTR_INTV_MIN
, /*!< \brief last minute */
21 RATE_CTR_INTV_HOUR
, /*!< \brief last hour */
22 RATE_CTR_INTV_DAY
, /*!< \brief last day */
25 /*! \brief data we keep for each of the intervals */
26 struct rate_ctr_per_intv
{
27 uint64_t last
; /*!< \brief counter value in last interval */
28 uint64_t rate
; /*!< \brief counter rate */
31 /*! \brief data we keep for each actual value */
33 uint64_t current
; /*!< \brief current value */
34 /*! \brief per-interval data */
35 struct rate_ctr_per_intv intv
[RATE_CTR_INTV_NUM
];
38 /*! \brief rate counter description */
39 struct rate_ctr_desc
{
40 const char *name
; /*!< \brief name of the counter */
41 const char *description
;/*!< \brief description of the counter */
44 /*! \brief description of a rate counter group */
45 struct rate_ctr_group_desc
{
46 /*! \brief The prefix to the name of all counters in this group */
47 const char *group_name_prefix
;
48 /*! \brief The human-readable description of the group */
49 const char *group_description
;
50 /*! \brief The number of counters in this group */
51 const unsigned int num_ctr
;
52 /*! \brief Pointer to array of counter names */
53 const struct rate_ctr_desc
*ctr_desc
;
56 /*! \brief One instance of a counter group class */
57 struct rate_ctr_group
{
58 /*! \brief Linked list of all counter groups in the system */
59 struct llist_head list
;
60 /*! \brief Pointer to the counter group class */
61 const struct rate_ctr_group_desc
*desc
;
62 /*! \brief The index of this ctr_group within its class */
64 /*! \brief Actual counter structures below */
65 struct rate_ctr ctr
[0];
68 struct rate_ctr_group
*rate_ctr_group_alloc(void *ctx
,
69 const struct rate_ctr_group_desc
*desc
,
72 void rate_ctr_group_free(struct rate_ctr_group
*grp
);
74 void rate_ctr_add(struct rate_ctr
*ctr
, int inc
);
76 /*! \brief Increment the counter by 1 */
77 static inline void rate_ctr_inc(struct rate_ctr
*ctr
)
82 int rate_ctr_init(void *tall_ctx
);
84 struct rate_ctr_group
*rate_ctr_get_group_by_name_idx(const char *name
, const unsigned int idx
);
85 const struct rate_ctr
*rate_ctr_get_by_name(const struct rate_ctr_group
*ctrg
, const char *name
);
88 #endif /* RATE_CTR_H */