kstats_wrapper.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2010 iptelorg GmbH
  5. *
  6. * Permission to use, copy, modify, and distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. /** k compatible statistics implemented in terms of sr counters.
  19. * New functions:
  20. * stats_support() - partially replaces get_stats_collector().
  21. * Returns 1 if statistics support is compiled, 0 otherwise.
  22. * get_stat_name() - returns the name of a stat_var.
  23. * get_stat_module() - returns the module of a stat_var.
  24. * Removed functions:
  25. * get_stats_collector()
  26. * destroy_stats_collector()
  27. * Removed variables/structures:
  28. * stats_collector
  29. * module_stats
  30. *
  31. * @file kstats_wrapper.h
  32. * @ingroup: libkcore
  33. */
  34. /*
  35. * History:
  36. * --------
  37. * 2010-08-08 initial version (andrei)
  38. * 2010-08-18 type declaration needed by sr_module.c moved to
  39. * ../../kstats_types.h (andrei)
  40. */
  41. #ifndef __kstats_wrapper_h
  42. #define __kstats_wrapper_h
  43. #include "../../counters.h"
  44. #include "../../kstats_types.h"
  45. /* k stat flags */
  46. #define STAT_NO_RESET 1 /* used in dialog(k), nat_traversal(k),
  47. registrar(k), statistics(k), usrloc(k) */
  48. /* #define STAT_NO_SYN 2 -- not used */
  49. #define STAT_SHM_NAME 4 /* used only from usrloc(k) */
  50. #define STAT_IS_FUNC 8
  51. #ifdef STATISTICS
  52. /* statistics support check */
  53. #define stats_support() 1
  54. int register_stat( char *module, char *name, stat_var **pvar, int flags);
  55. int register_module_stats(char *module, stat_export_t *stats);
  56. inline static stat_var* get_stat(str *name)
  57. {
  58. counter_handle_t h;
  59. str grp;
  60. grp.s = 0;
  61. grp.len = 0;
  62. if (counter_lookup_str(&h, &grp, name) < 0)
  63. return 0;
  64. return (void*)(unsigned long)h.id;
  65. }
  66. inline static unsigned long get_stat_val(stat_var *v)
  67. {
  68. counter_handle_t h;
  69. h.id = (unsigned short)(unsigned long)v;
  70. return (unsigned long)counter_get_val(h);
  71. }
  72. inline static char* get_stat_name(stat_var *v)
  73. {
  74. counter_handle_t h;
  75. h.id = (unsigned short)(unsigned long)v;
  76. return counter_get_name(h);
  77. }
  78. inline static char* get_stat_module(stat_var *v)
  79. {
  80. counter_handle_t h;
  81. h.id = (unsigned short)(unsigned long)v;
  82. return counter_get_group(h);
  83. }
  84. inline static void update_stat(stat_var* v, int n)
  85. {
  86. counter_handle_t h;
  87. h.id = (unsigned short)(unsigned long)v;
  88. counter_add(h, n);
  89. }
  90. inline static void reset_stat(stat_var* v)
  91. {
  92. counter_handle_t h;
  93. h.id = (unsigned short)(unsigned long)v;
  94. counter_reset(h);
  95. }
  96. #define if_update_stat(c, var, n) \
  97. do{ \
  98. if ((c)) update_stat((var), (n)); \
  99. }while(0)
  100. #define if_reset_stat(c, var) \
  101. do{ \
  102. if ((c)) reset_stat((var)); \
  103. }while(0)
  104. #else /* STATISTICS */
  105. /* statistics support check */
  106. #define stats_support() 0
  107. #define register_module_stats(mod, stats) 0
  108. #define register_stat(mod, name, var, flags) 0
  109. #define get_stat(name) 0
  110. #define get_stat_val(var) 0
  111. #define update_stat(v, n)
  112. #define reset_stat(v)
  113. #define if_update_stat(c, v, n)
  114. #define if_reset_stat(c, v)
  115. #endif /* STATISTICS */
  116. #endif /*__kstats_wrapper_h*/
  117. /* vi: set ts=4 sw=4 tw=79:ai:cindent: */