aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_statistics.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/testbed_api_statistics.c')
-rw-r--r--src/testbed/testbed_api_statistics.c207
1 files changed, 102 insertions, 105 deletions
diff --git a/src/testbed/testbed_api_statistics.c b/src/testbed/testbed_api_statistics.c
index 6115f6e61..e7440dfa1 100644
--- a/src/testbed/testbed_api_statistics.c
+++ b/src/testbed/testbed_api_statistics.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -34,21 +34,20 @@
34/** 34/**
35 * Generic logging shorthand 35 * Generic logging shorthand
36 */ 36 */
37#define LOG(kind,...) \ 37#define LOG(kind, ...) \
38 GNUNET_log_from (kind, "testbed-api-statistics", __VA_ARGS__) 38 GNUNET_log_from(kind, "testbed-api-statistics", __VA_ARGS__)
39 39
40/** 40/**
41 * Debug logging shorthand 41 * Debug logging shorthand
42 */ 42 */
43#define LOG_DEBUG(...) \ 43#define LOG_DEBUG(...) \
44 LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) 44 LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
45 45
46 46
47/** 47/**
48 * Context information for use in GNUNET_TESTBED_get_statistics() 48 * Context information for use in GNUNET_TESTBED_get_statistics()
49 */ 49 */
50struct GetStatsContext 50struct GetStatsContext {
51{
52 /** 51 /**
53 * The main operation we generate while creating this context 52 * The main operation we generate while creating this context
54 */ 53 */
@@ -106,15 +105,13 @@ struct GetStatsContext
106 * How many peers' statistics have we iterated through 105 * How many peers' statistics have we iterated through
107 */ 106 */
108 unsigned int num_completed; 107 unsigned int num_completed;
109
110}; 108};
111 109
112 110
113/** 111/**
114 * Context information with respect to a particular peer 112 * Context information with respect to a particular peer
115 */ 113 */
116struct PeerGetStatsContext 114struct PeerGetStatsContext {
117{
118 /** 115 /**
119 * The GetStatsContext which is associated with this context 116 * The GetStatsContext which is associated with this context
120 */ 117 */
@@ -152,14 +149,14 @@ static struct OperationQueue *no_wait_queue;
152 * @param cls the GetStatsContext 149 * @param cls the GetStatsContext
153 */ 150 */
154static void 151static void
155call_completion_task (void *cls) 152call_completion_task(void *cls)
156{ 153{
157 struct GetStatsContext *sc = cls; 154 struct GetStatsContext *sc = cls;
158 155
159 GNUNET_assert (sc->call_completion_task_id != NULL); 156 GNUNET_assert(sc->call_completion_task_id != NULL);
160 sc->call_completion_task_id = NULL; 157 sc->call_completion_task_id = NULL;
161 LOG_DEBUG ("Calling get_statistics() continuation callback\n"); 158 LOG_DEBUG("Calling get_statistics() continuation callback\n");
162 sc->cont (sc->cb_cls, sc->main_op, NULL); 159 sc->cont(sc->cb_cls, sc->main_op, NULL);
163} 160}
164 161
165 162
@@ -170,7 +167,7 @@ call_completion_task (void *cls)
170 * @param cls the PeerGetStatsContext 167 * @param cls the PeerGetStatsContext
171 */ 168 */
172static void 169static void
173op_done_task (void *cls) 170op_done_task(void *cls)
174{ 171{
175 struct PeerGetStatsContext *peer_sc = cls; 172 struct PeerGetStatsContext *peer_sc = cls;
176 struct GetStatsContext *sc; 173 struct GetStatsContext *sc;
@@ -179,8 +176,8 @@ op_done_task (void *cls)
179 sc = peer_sc->sc; 176 sc = peer_sc->sc;
180 peer_sc->op_done_task_id = NULL; 177 peer_sc->op_done_task_id = NULL;
181 op = &sc->ops[peer_sc->peer_index]; 178 op = &sc->ops[peer_sc->peer_index];
182 GNUNET_assert (NULL != *op); 179 GNUNET_assert(NULL != *op);
183 GNUNET_TESTBED_operation_done (*op); 180 GNUNET_TESTBED_operation_done(*op);
184 *op = NULL; 181 *op = NULL;
185} 182}
186 183
@@ -193,22 +190,22 @@ op_done_task (void *cls)
193 * successfully obtained, GNUNET_SYSERR if not. 190 * successfully obtained, GNUNET_SYSERR if not.
194 */ 191 */
195static void 192static void
196iteration_completion_cb (void *cls, int success) 193iteration_completion_cb(void *cls, int success)
197{ 194{
198 struct PeerGetStatsContext *peer_sc = cls; 195 struct PeerGetStatsContext *peer_sc = cls;
199 struct GetStatsContext *sc; 196 struct GetStatsContext *sc;
200 197
201 GNUNET_break (GNUNET_OK == success); 198 GNUNET_break(GNUNET_OK == success);
202 sc = peer_sc->sc; 199 sc = peer_sc->sc;
203 peer_sc->get_handle = NULL; 200 peer_sc->get_handle = NULL;
204 sc->num_completed++; 201 sc->num_completed++;
205 peer_sc->op_done_task_id = GNUNET_SCHEDULER_add_now (&op_done_task, peer_sc); 202 peer_sc->op_done_task_id = GNUNET_SCHEDULER_add_now(&op_done_task, peer_sc);
206 if (sc->num_completed == sc->num_peers) 203 if (sc->num_completed == sc->num_peers)
207 { 204 {
208 LOG_DEBUG ("Scheduling to call iteration completion callback\n"); 205 LOG_DEBUG("Scheduling to call iteration completion callback\n");
209 sc->call_completion_task_id = 206 sc->call_completion_task_id =
210 GNUNET_SCHEDULER_add_now (&call_completion_task, sc); 207 GNUNET_SCHEDULER_add_now(&call_completion_task, sc);
211 } 208 }
212} 209}
213 210
214 211
@@ -223,9 +220,9 @@ iteration_completion_cb (void *cls, int success)
223 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 220 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
224 */ 221 */
225static int 222static int
226iterator_cb (void *cls, const char *subsystem, 223iterator_cb(void *cls, const char *subsystem,
227 const char *name, uint64_t value, 224 const char *name, uint64_t value,
228 int is_persistent) 225 int is_persistent)
229{ 226{
230 struct PeerGetStatsContext *peer_sc = cls; 227 struct PeerGetStatsContext *peer_sc = cls;
231 struct GetStatsContext *sc; 228 struct GetStatsContext *sc;
@@ -234,12 +231,12 @@ iterator_cb (void *cls, const char *subsystem,
234 231
235 sc = peer_sc->sc; 232 sc = peer_sc->sc;
236 peer = sc->peers[peer_sc->peer_index]; 233 peer = sc->peers[peer_sc->peer_index];
237 LOG_DEBUG ("Peer %u: [%s,%s] -> %lu\n", peer_sc->peer_index, 234 LOG_DEBUG("Peer %u: [%s,%s] -> %lu\n", peer_sc->peer_index,
238 subsystem, name, (unsigned long) value); 235 subsystem, name, (unsigned long)value);
239 ret = sc->proc (sc->cb_cls, peer, 236 ret = sc->proc(sc->cb_cls, peer,
240 subsystem, name, value, is_persistent); 237 subsystem, name, value, is_persistent);
241 if (GNUNET_SYSERR == ret) 238 if (GNUNET_SYSERR == ret)
242 LOG_DEBUG ("Aborting iteration for peer %u\n", peer_sc->peer_index); 239 LOG_DEBUG("Aborting iteration for peer %u\n", peer_sc->peer_index);
243 return ret; 240 return ret;
244} 241}
245 242
@@ -254,21 +251,21 @@ iterator_cb (void *cls, const char *subsystem,
254 * operation has executed successfully. 251 * operation has executed successfully.
255 */ 252 */
256static void 253static void
257service_connect_comp (void *cls, 254service_connect_comp(void *cls,
258 struct GNUNET_TESTBED_Operation *op, 255 struct GNUNET_TESTBED_Operation *op,
259 void *ca_result, 256 void *ca_result,
260 const char *emsg) 257 const char *emsg)
261{ 258{
262 struct PeerGetStatsContext *peer_sc = cls; 259 struct PeerGetStatsContext *peer_sc = cls;
263 struct GNUNET_STATISTICS_Handle *h = ca_result; 260 struct GNUNET_STATISTICS_Handle *h = ca_result;
264 261
265 LOG_DEBUG ("Retrieving statistics of peer %u\n", 262 LOG_DEBUG("Retrieving statistics of peer %u\n",
266 peer_sc->peer_index); 263 peer_sc->peer_index);
267 peer_sc->get_handle = 264 peer_sc->get_handle =
268 GNUNET_STATISTICS_get (h, peer_sc->sc->subsystem, 265 GNUNET_STATISTICS_get(h, peer_sc->sc->subsystem,
269 peer_sc->sc->name, 266 peer_sc->sc->name,
270 &iteration_completion_cb, 267 &iteration_completion_cb,
271 iterator_cb, peer_sc); 268 iterator_cb, peer_sc);
272} 269}
273 270
274 271
@@ -283,13 +280,13 @@ service_connect_comp (void *cls,
283 * @return service handle to return in 'op_result', NULL on error 280 * @return service handle to return in 'op_result', NULL on error
284 */ 281 */
285static void * 282static void *
286statistics_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) 283statistics_ca(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
287{ 284{
288 struct PeerGetStatsContext *peer_sc = cls; 285 struct PeerGetStatsContext *peer_sc = cls;
289 286
290 LOG_DEBUG ("Connecting to statistics service of peer %u\n", 287 LOG_DEBUG("Connecting to statistics service of peer %u\n",
291 peer_sc->peer_index); 288 peer_sc->peer_index);
292 return GNUNET_STATISTICS_create ("<testbed-api>", cfg); 289 return GNUNET_STATISTICS_create("<testbed-api>", cfg);
293} 290}
294 291
295 292
@@ -300,20 +297,20 @@ statistics_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
300 * @param op_result service handle returned from the connect adapter 297 * @param op_result service handle returned from the connect adapter
301 */ 298 */
302static void 299static void
303statistics_da (void *cls, void *op_result) 300statistics_da(void *cls, void *op_result)
304{ 301{
305 struct PeerGetStatsContext *peer_sc = cls; 302 struct PeerGetStatsContext *peer_sc = cls;
306 struct GNUNET_STATISTICS_Handle *sh = op_result; 303 struct GNUNET_STATISTICS_Handle *sh = op_result;
307 304
308 if (NULL != peer_sc->get_handle) 305 if (NULL != peer_sc->get_handle)
309 { 306 {
310 GNUNET_STATISTICS_get_cancel (peer_sc->get_handle); 307 GNUNET_STATISTICS_get_cancel(peer_sc->get_handle);
311 peer_sc->get_handle = NULL; 308 peer_sc->get_handle = NULL;
312 } 309 }
313 GNUNET_STATISTICS_destroy (sh, GNUNET_NO); 310 GNUNET_STATISTICS_destroy(sh, GNUNET_NO);
314 if (NULL != peer_sc->op_done_task_id) 311 if (NULL != peer_sc->op_done_task_id)
315 GNUNET_SCHEDULER_cancel (peer_sc->op_done_task_id); 312 GNUNET_SCHEDULER_cancel(peer_sc->op_done_task_id);
316 GNUNET_free (peer_sc); 313 GNUNET_free(peer_sc);
317} 314}
318 315
319 316
@@ -323,33 +320,33 @@ statistics_da (void *cls, void *op_result)
323 * @param cls the GetStatsContext 320 * @param cls the GetStatsContext
324 */ 321 */
325static void 322static void
326opstart_get_stats (void *cls) 323opstart_get_stats(void *cls)
327{ 324{
328 struct GetStatsContext *sc = cls; 325 struct GetStatsContext *sc = cls;
329 struct PeerGetStatsContext *peer_sc; 326 struct PeerGetStatsContext *peer_sc;
330 unsigned int peer; 327 unsigned int peer;
331 328
332 LOG_DEBUG ("Starting get_statistics operation\n"); 329 LOG_DEBUG("Starting get_statistics operation\n");
333 sc->ops = GNUNET_malloc (sc->num_peers * 330 sc->ops = GNUNET_malloc(sc->num_peers *
334 sizeof (struct GNUNET_TESTBED_Operation *)); 331 sizeof(struct GNUNET_TESTBED_Operation *));
335 for (peer = 0; peer < sc->num_peers; peer++) 332 for (peer = 0; peer < sc->num_peers; peer++)
336 {
337 if (NULL == sc->peers[peer])
338 { 333 {
339 GNUNET_break (0); 334 if (NULL == sc->peers[peer])
340 continue; 335 {
336 GNUNET_break(0);
337 continue;
338 }
339 peer_sc = GNUNET_new(struct PeerGetStatsContext);
340 peer_sc->sc = sc;
341 peer_sc->peer_index = peer;
342 sc->ops[peer] =
343 GNUNET_TESTBED_service_connect(sc, sc->peers[peer], "statistics",
344 &service_connect_comp,
345 peer_sc,
346 &statistics_ca,
347 &statistics_da,
348 peer_sc);
341 } 349 }
342 peer_sc = GNUNET_new (struct PeerGetStatsContext);
343 peer_sc->sc = sc;
344 peer_sc->peer_index = peer;
345 sc->ops[peer] =
346 GNUNET_TESTBED_service_connect (sc, sc->peers[peer], "statistics",
347 &service_connect_comp,
348 peer_sc,
349 &statistics_ca,
350 &statistics_da,
351 peer_sc);
352 }
353} 350}
354 351
355 352
@@ -359,31 +356,31 @@ opstart_get_stats (void *cls)
359 * @param cls the GetStatsContext 356 * @param cls the GetStatsContext
360 */ 357 */
361static void 358static void
362oprelease_get_stats (void *cls) 359oprelease_get_stats(void *cls)
363{ 360{
364 struct GetStatsContext *sc = cls; 361 struct GetStatsContext *sc = cls;
365 unsigned int peer; 362 unsigned int peer;
366 363
367 LOG_DEBUG ("Cleaning up get_statistics operation\n"); 364 LOG_DEBUG("Cleaning up get_statistics operation\n");
368 if (NULL != sc->call_completion_task_id) 365 if (NULL != sc->call_completion_task_id)
369 GNUNET_SCHEDULER_cancel (sc->call_completion_task_id); 366 GNUNET_SCHEDULER_cancel(sc->call_completion_task_id);
370 if (NULL != sc->ops) 367 if (NULL != sc->ops)
371 {
372 for (peer = 0; peer < sc->num_peers; peer++)
373 { 368 {
374 if (NULL != sc->ops[peer]) 369 for (peer = 0; peer < sc->num_peers; peer++)
375 { 370 {
376 GNUNET_TESTBED_operation_done (sc->ops[peer]); 371 if (NULL != sc->ops[peer])
377 sc->ops[peer] = NULL; 372 {
378 } 373 GNUNET_TESTBED_operation_done(sc->ops[peer]);
374 sc->ops[peer] = NULL;
375 }
376 }
377 GNUNET_free(sc->ops);
379 } 378 }
380 GNUNET_free (sc->ops); 379 GNUNET_free_non_null(sc->subsystem);
381 } 380 GNUNET_free_non_null(sc->name);
382 GNUNET_free_non_null (sc->subsystem); 381 GNUNET_free(sc);
383 GNUNET_free_non_null (sc->name);
384 GNUNET_free (sc);
385 if (GNUNET_YES == 382 if (GNUNET_YES ==
386 GNUNET_TESTBED_operation_queue_destroy_empty_ (no_wait_queue)) 383 GNUNET_TESTBED_operation_queue_destroy_empty_(no_wait_queue))
387 no_wait_queue = NULL; 384 no_wait_queue = NULL;
388} 385}
389 386
@@ -402,33 +399,33 @@ oprelease_get_stats (void *cls)
402 * @return operation handle to cancel the operation 399 * @return operation handle to cancel the operation
403 */ 400 */
404struct GNUNET_TESTBED_Operation * 401struct GNUNET_TESTBED_Operation *
405GNUNET_TESTBED_get_statistics (unsigned int num_peers, 402GNUNET_TESTBED_get_statistics(unsigned int num_peers,
406 struct GNUNET_TESTBED_Peer **peers, 403 struct GNUNET_TESTBED_Peer **peers,
407 const char *subsystem, const char *name, 404 const char *subsystem, const char *name,
408 GNUNET_TESTBED_StatisticsIterator proc, 405 GNUNET_TESTBED_StatisticsIterator proc,
409 GNUNET_TESTBED_OperationCompletionCallback cont, 406 GNUNET_TESTBED_OperationCompletionCallback cont,
410 void *cls) 407 void *cls)
411{ 408{
412 struct GetStatsContext *sc; 409 struct GetStatsContext *sc;
413 410
414 GNUNET_assert (NULL != proc); 411 GNUNET_assert(NULL != proc);
415 GNUNET_assert (NULL != cont); 412 GNUNET_assert(NULL != cont);
416 if (NULL == no_wait_queue) 413 if (NULL == no_wait_queue)
417 no_wait_queue = GNUNET_TESTBED_operation_queue_create_ 414 no_wait_queue = GNUNET_TESTBED_operation_queue_create_
418 (OPERATION_QUEUE_TYPE_FIXED, UINT_MAX); 415 (OPERATION_QUEUE_TYPE_FIXED, UINT_MAX);
419 sc = GNUNET_new (struct GetStatsContext); 416 sc = GNUNET_new(struct GetStatsContext);
420 sc->peers = peers; 417 sc->peers = peers;
421 sc->subsystem = (NULL == subsystem) ? NULL : GNUNET_strdup (subsystem); 418 sc->subsystem = (NULL == subsystem) ? NULL : GNUNET_strdup(subsystem);
422 sc->name = (NULL == name) ? NULL : GNUNET_strdup (name); 419 sc->name = (NULL == name) ? NULL : GNUNET_strdup(name);
423 sc->proc = proc; 420 sc->proc = proc;
424 sc->cont = cont; 421 sc->cont = cont;
425 sc->cb_cls = cls; 422 sc->cb_cls = cls;
426 sc->num_peers = num_peers; 423 sc->num_peers = num_peers;
427 sc->main_op = 424 sc->main_op =
428 GNUNET_TESTBED_operation_create_ (sc, &opstart_get_stats, 425 GNUNET_TESTBED_operation_create_(sc, &opstart_get_stats,
429 &oprelease_get_stats); 426 &oprelease_get_stats);
430 GNUNET_TESTBED_operation_queue_insert_ (no_wait_queue, sc->main_op); 427 GNUNET_TESTBED_operation_queue_insert_(no_wait_queue, sc->main_op);
431 GNUNET_TESTBED_operation_begin_wait_ (sc->main_op); 428 GNUNET_TESTBED_operation_begin_wait_(sc->main_op);
432 return sc->main_op; 429 return sc->main_op;
433} 430}
434 431