gnunet_statistics_service.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2009-2013, 2016 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @author Christian Grothoff
  18. *
  19. * @file
  20. * API to create, modify and access statistics.
  21. *
  22. * @defgroup statistics Statistics service
  23. * Track statistics or provide access to statistics.
  24. *
  25. * Create, modify and access statistics about the operation of GNUnet.
  26. *
  27. * All statistical values must be of type `unsigned long long`.
  28. *
  29. * @see [Documentation](https://gnunet.org/gnunet-statistics-subsystem)
  30. *
  31. * @{
  32. */
  33. #ifndef GNUNET_STATISTICS_SERVICE_H
  34. #define GNUNET_STATISTICS_SERVICE_H
  35. #ifdef __cplusplus
  36. extern "C"
  37. {
  38. #if 0 /* keep Emacsens' auto-indent happy */
  39. }
  40. #endif
  41. #endif
  42. #include "gnunet_util_lib.h"
  43. /**
  44. * Version of the statistics API.
  45. */
  46. #define GNUNET_STATISTICS_VERSION 0x00000000
  47. /**
  48. * Opaque handle for the statistics service.
  49. */
  50. struct GNUNET_STATISTICS_Handle;
  51. /**
  52. * Callback function to process statistic values.
  53. *
  54. * @param cls closure
  55. * @param subsystem name of subsystem that created the statistic
  56. * @param name the name of the datum
  57. * @param value the current value
  58. * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
  59. * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
  60. */
  61. typedef int
  62. (*GNUNET_STATISTICS_Iterator) (void *cls,
  63. const char *subsystem,
  64. const char *name,
  65. uint64_t value,
  66. int is_persistent);
  67. /**
  68. * Get handle for the statistics service.
  69. *
  70. * @param subsystem name of subsystem using the service
  71. * @param cfg services configuration in use
  72. * @return handle to use
  73. */
  74. struct GNUNET_STATISTICS_Handle *
  75. GNUNET_STATISTICS_create (const char *subsystem,
  76. const struct GNUNET_CONFIGURATION_Handle *cfg);
  77. /**
  78. * Destroy a handle (free all state associated with it).
  79. *
  80. * @param h statistics handle to destroy
  81. * @param sync_first set to #GNUNET_YES if pending SET requests should
  82. * be completed
  83. */
  84. void
  85. GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h,
  86. int sync_first);
  87. /**
  88. * Watch statistics from the peer (be notified whenever they change).
  89. *
  90. * @param handle identification of the statistics service
  91. * @param subsystem limit to the specified subsystem, never NULL
  92. * @param name name of the statistic value, never NULL
  93. * @param proc function to call on each value
  94. * @param proc_cls closure for @a proc
  95. * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  96. */
  97. int
  98. GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle,
  99. const char *subsystem,
  100. const char *name,
  101. GNUNET_STATISTICS_Iterator proc,
  102. void *proc_cls);
  103. /**
  104. * Stop watching statistics from the peer.
  105. *
  106. * @param handle identification of the statistics service
  107. * @param subsystem limit to the specified subsystem, never NULL
  108. * @param name name of the statistic value, never NULL
  109. * @param proc function to call on each value
  110. * @param proc_cls closure for @a proc
  111. * @return #GNUNET_OK on success, #GNUNET_SYSERR on error (no such watch)
  112. */
  113. int
  114. GNUNET_STATISTICS_watch_cancel (struct GNUNET_STATISTICS_Handle *handle,
  115. const char *subsystem,
  116. const char *name,
  117. GNUNET_STATISTICS_Iterator proc,
  118. void *proc_cls);
  119. /**
  120. * Continuation called by #GNUNET_STATISTICS_get() functions.
  121. *
  122. * @param cls closure
  123. * @param success #GNUNET_OK if statistics were
  124. * successfully obtained, #GNUNET_SYSERR if not.
  125. */
  126. typedef void
  127. (*GNUNET_STATISTICS_Callback) (void *cls,
  128. int success);
  129. /**
  130. * Handle that can be used to cancel a statistics 'get' operation.
  131. */
  132. struct GNUNET_STATISTICS_GetHandle;
  133. /**
  134. * Get statistic from the peer.
  135. *
  136. * @param handle identification of the statistics service
  137. * @param subsystem limit to the specified subsystem, NULL for all subsystems
  138. * @param name name of the statistic value, NULL for all values
  139. * @param cont continuation to call when done (can be NULL)
  140. * This callback CANNOT destroy the statistics handle in the same call.
  141. * @param proc function to call on each value
  142. * @param cls closure for @a proc and @a cont
  143. * @return NULL on error
  144. */
  145. struct GNUNET_STATISTICS_GetHandle *
  146. GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
  147. const char *subsystem,
  148. const char *name,
  149. GNUNET_STATISTICS_Callback cont,
  150. GNUNET_STATISTICS_Iterator proc,
  151. void *cls);
  152. /**
  153. * Cancel a #GNUNET_STATISTICS_get request. Must be called before the 'cont'
  154. * function is called.
  155. *
  156. * @param gh handle of the request to cancel
  157. */
  158. void
  159. GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh);
  160. /**
  161. * Set statistic value for the peer. Will always use our
  162. * subsystem (the argument used when @a handle was created).
  163. *
  164. * @param handle identification of the statistics service
  165. * @param name name of the statistic value
  166. * @param value new value to set
  167. * @param make_persistent should the value be kept across restarts?
  168. */
  169. void
  170. GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle,
  171. const char *name,
  172. uint64_t value,
  173. int make_persistent);
  174. /**
  175. * Set statistic value for the peer. Will always use our
  176. * subsystem (the argument used when @a handle was created).
  177. *
  178. * @param handle identification of the statistics service
  179. * @param name name of the statistic value
  180. * @param delta change in value (added to existing value)
  181. * @param make_persistent should the value be kept across restarts?
  182. */
  183. void
  184. GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle,
  185. const char *name,
  186. int64_t delta,
  187. int make_persistent);
  188. #if 0 /* keep Emacsens' auto-indent happy */
  189. {
  190. #endif
  191. #ifdef __cplusplus
  192. }
  193. #endif
  194. /** @} */ /* end of group statistics */
  195. #endif