libosmocore
0.9.3
Osmocom core library
|
00001 #pragma once 00002 00009 #include <stdint.h> 00010 00011 #include <osmocom/core/linuxlist.h> 00012 00014 #define RATE_CTR_INTV_NUM 4 00015 00017 enum rate_ctr_intv { 00018 RATE_CTR_INTV_SEC, 00019 RATE_CTR_INTV_MIN, 00020 RATE_CTR_INTV_HOUR, 00021 RATE_CTR_INTV_DAY, 00022 }; 00023 00025 struct rate_ctr_per_intv { 00026 uint64_t last; 00027 uint64_t rate; 00028 }; 00029 00031 struct rate_ctr { 00032 uint64_t current; 00033 uint64_t previous; 00035 struct rate_ctr_per_intv intv[RATE_CTR_INTV_NUM]; 00036 }; 00037 00039 struct rate_ctr_desc { 00040 const char *name; 00041 const char *description; 00042 }; 00043 00045 struct rate_ctr_group_desc { 00047 const char *group_name_prefix; 00049 const char *group_description; 00051 int class_id; 00053 const unsigned int num_ctr; 00055 const struct rate_ctr_desc *ctr_desc; 00056 }; 00057 00059 struct rate_ctr_group { 00061 struct llist_head list; 00063 const struct rate_ctr_group_desc *desc; 00065 unsigned int idx; 00067 struct rate_ctr ctr[0]; 00068 }; 00069 00070 struct rate_ctr_group *rate_ctr_group_alloc(void *ctx, 00071 const struct rate_ctr_group_desc *desc, 00072 unsigned int idx); 00073 00074 static inline void rate_ctr_group_upd_idx(struct rate_ctr_group *grp, unsigned int idx) 00075 { 00076 grp->idx = idx; 00077 } 00078 00079 void rate_ctr_group_free(struct rate_ctr_group *grp); 00080 00081 void rate_ctr_add(struct rate_ctr *ctr, int inc); 00082 00084 static inline void rate_ctr_inc(struct rate_ctr *ctr) 00085 { 00086 rate_ctr_add(ctr, 1); 00087 } 00088 00090 int64_t rate_ctr_difference(struct rate_ctr *ctr); 00091 00092 int rate_ctr_init(void *tall_ctx); 00093 00094 struct rate_ctr_group *rate_ctr_get_group_by_name_idx(const char *name, const unsigned int idx); 00095 const struct rate_ctr *rate_ctr_get_by_name(const struct rate_ctr_group *ctrg, const char *name); 00096 00097 typedef int (*rate_ctr_handler_t)( 00098 struct rate_ctr_group *, struct rate_ctr *, 00099 const struct rate_ctr_desc *, void *); 00100 typedef int (*rate_ctr_group_handler_t)(struct rate_ctr_group *, void *); 00101 00102 00107 int rate_ctr_for_each_counter(struct rate_ctr_group *ctrg, 00108 rate_ctr_handler_t handle_counter, void *data); 00109 00110 int rate_ctr_for_each_group(rate_ctr_group_handler_t handle_group, void *data); 00111