2 This file is part of GNUnet
3 Copyright (C) 2009-2013, 2016 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @author Christian Grothoff
23 * API to create, modify and access statistics.
25 * @defgroup statistics Statistics service
26 * Track statistics or provide access to statistics.
28 * Create, modify and access statistics about the operation of GNUnet.
30 * All statistical values must be of type `unsigned long long`.
32 * @see [Documentation](https://gnunet.org/gnunet-statistics-subsystem)
37 #ifndef GNUNET_STATISTICS_SERVICE_H
38 #define GNUNET_STATISTICS_SERVICE_H
43 #if 0 /* keep Emacsens' auto-indent happy */
48 #include "gnunet_util_lib.h"
51 * Version of the statistics API.
53 #define GNUNET_STATISTICS_VERSION 0x00000000
56 * Opaque handle for the statistics service.
58 struct GNUNET_STATISTICS_Handle;
61 * Callback function to process statistic values.
64 * @param subsystem name of subsystem that created the statistic
65 * @param name the name of the datum
66 * @param value the current value
67 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
68 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
71 (*GNUNET_STATISTICS_Iterator) (void *cls,
72 const char *subsystem,
79 * Get handle for the statistics service.
81 * @param subsystem name of subsystem using the service
82 * @param cfg services configuration in use
83 * @return handle to use
85 struct GNUNET_STATISTICS_Handle *
86 GNUNET_STATISTICS_create (const char *subsystem,
87 const struct GNUNET_CONFIGURATION_Handle *cfg);
91 * Destroy a handle (free all state associated with it).
93 * @param h statistics handle to destroy
94 * @param sync_first set to #GNUNET_YES if pending SET requests should
98 GNUNET_STATISTICS_destroy (struct GNUNET_STATISTICS_Handle *h,
103 * Watch statistics from the peer (be notified whenever they change).
105 * @param handle identification of the statistics service
106 * @param subsystem limit to the specified subsystem, never NULL
107 * @param name name of the statistic value, never NULL
108 * @param proc function to call on each value
109 * @param proc_cls closure for @a proc
110 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
113 GNUNET_STATISTICS_watch (struct GNUNET_STATISTICS_Handle *handle,
114 const char *subsystem,
116 GNUNET_STATISTICS_Iterator proc,
121 * Stop watching statistics from the peer.
123 * @param handle identification of the statistics service
124 * @param subsystem limit to the specified subsystem, never NULL
125 * @param name name of the statistic value, never NULL
126 * @param proc function to call on each value
127 * @param proc_cls closure for @a proc
128 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error (no such watch)
131 GNUNET_STATISTICS_watch_cancel (struct GNUNET_STATISTICS_Handle *handle,
132 const char *subsystem,
134 GNUNET_STATISTICS_Iterator proc,
139 * Continuation called by #GNUNET_STATISTICS_get() functions.
142 * @param success #GNUNET_OK if statistics were
143 * successfully obtained, #GNUNET_SYSERR if not.
146 (*GNUNET_STATISTICS_Callback) (void *cls,
151 * Handle that can be used to cancel a statistics 'get' operation.
153 struct GNUNET_STATISTICS_GetHandle;
157 * Get statistic from the peer.
159 * @param handle identification of the statistics service
160 * @param subsystem limit to the specified subsystem, NULL for all subsystems
161 * @param name name of the statistic value, NULL for all values
162 * @param cont continuation to call when done (can be NULL)
163 * This callback CANNOT destroy the statistics handle in the same call.
164 * @param proc function to call on each value
165 * @param cls closure for @a proc and @a cont
166 * @return NULL on error
168 struct GNUNET_STATISTICS_GetHandle *
169 GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle,
170 const char *subsystem,
172 GNUNET_STATISTICS_Callback cont,
173 GNUNET_STATISTICS_Iterator proc,
178 * Cancel a #GNUNET_STATISTICS_get request. Must be called before the 'cont'
179 * function is called.
181 * @param gh handle of the request to cancel
184 GNUNET_STATISTICS_get_cancel (struct GNUNET_STATISTICS_GetHandle *gh);
188 * Set statistic value for the peer. Will always use our
189 * subsystem (the argument used when @a handle was created).
191 * @param handle identification of the statistics service
192 * @param name name of the statistic value
193 * @param value new value to set
194 * @param make_persistent should the value be kept across restarts?
197 GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle,
200 int make_persistent);
204 * Set statistic value for the peer. Will always use our
205 * subsystem (the argument used when @a handle was created).
207 * @param handle identification of the statistics service
208 * @param name name of the statistic value
209 * @param delta change in value (added to existing value)
210 * @param make_persistent should the value be kept across restarts?
213 GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle,
216 int make_persistent);
220 #if 0 /* keep Emacsens' auto-indent happy */
227 /** @} */ /* end of group statistics */