00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00022
00023
00024
00025
00026
00027
00028 #include "kstats_wrapper.h"
00029
00030 #ifdef STATISTICS
00031
00032
00041 static counter_val_t cnt_cbk_wrapper(counter_handle_t h, void* param)
00042 {
00043 stat_function k_stat_f;
00044
00045 k_stat_f = param;
00046 return k_stat_f();
00047 }
00048
00049
00050
00051 int register_stat( char *module, char *name, stat_var **pvar, int flags)
00052 {
00053 int cnt_flags;
00054 counter_handle_t h;
00055 int ret;
00056
00057 if (module == 0 || name == 0 || pvar == 0) {
00058 BUG("invalid parameters (%p, %p, %p)\n", module, name, pvar);
00059 return -1;
00060 }
00061
00062 cnt_flags = (flags & STAT_NO_RESET) ? CNT_F_NO_RESET : 0;
00063 if (flags & STAT_IS_FUNC)
00064 ret = counter_register(&h, module, name, cnt_flags,
00065 cnt_cbk_wrapper,(stat_function)pvar,
00066 "kamailio statistic (no description)",
00067 0);
00068 else
00069 ret = counter_register(&h, module, name, cnt_flags, 0, 0,
00070 "kamailio statistic (no description)", 0);
00071 if (ret < 0) {
00072 if (ret == -2)
00073 ERR("counter %s.%s already registered\n", module, name);
00074 goto error;
00075 }
00076 if (!(flags & STAT_IS_FUNC))
00077 *pvar = (void*)(unsigned long)h.id;
00078 return 0;
00079 error:
00080 if (!(flags & STAT_IS_FUNC))
00081 *pvar = 0;
00082 return -1;
00083 }
00084
00085
00086
00087 int register_module_stats(char *module, stat_export_t *stats)
00088 {
00089 if (module == 0 || *module == 0) {
00090 BUG("null or empty module name\n");
00091 goto error;
00092 }
00093 if (stats == 0 || stats[0].name == 0)
00094
00095 return 0;
00096 for (; stats->name; stats++)
00097 if (register_stat(module, stats->name, stats->stat_pointer,
00098 stats->flags) < 0 ){
00099 ERR("failed to add statistic %s.%s\n", module, stats->name);
00100 goto error;
00101 }
00102 return 0;
00103 error:
00104 return -1;
00105 }
00106
00107 #endif
00108