GNUnet  0.10.x
Data Structures | Macros | Functions | Variables
testbed_api_statistics.c File Reference

high-level statistics function More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testbed_service.h"
#include "testbed_api_operations.h"
Include dependency graph for testbed_api_statistics.c:

Go to the source code of this file.

Data Structures

struct  GetStatsContext
 Context information for use in GNUNET_TESTBED_get_statistics() More...
 
struct  PeerGetStatsContext
 Context information with respect to a particular peer. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "testbed-api-statistics", __VA_ARGS__)
 Generic logging shorthand. More...
 
#define LOG_DEBUG(...)   LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
 Debug logging shorthand. More...
 

Functions

static void call_completion_task (void *cls)
 Call statistics operation completion. More...
 
static void op_done_task (void *cls)
 Task to mark statistics service connect operation as done. More...
 
static void iteration_completion_cb (void *cls, int success)
 Continuation called by the "get_all" and "get" functions. More...
 
static int iterator_cb (void *cls, const char *subsystem, const char *name, uint64_t value, int is_persistent)
 Callback function to process statistic values. More...
 
static void service_connect_comp (void *cls, struct GNUNET_TESTBED_Operation *op, void *ca_result, const char *emsg)
 Called after opening a connection to the statistics service of a peer. More...
 
static void * statistics_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Adapter function called to establish a connection to the statistics service of a peer. More...
 
static void statistics_da (void *cls, void *op_result)
 Adapter function called to destroy statistics connection. More...
 
static void opstart_get_stats (void *cls)
 Function called when get_statistics operation is ready. More...
 
static void oprelease_get_stats (void *cls)
 Function called when get_statistics operation is cancelled or marked as done. More...
 
struct GNUNET_TESTBED_OperationGNUNET_TESTBED_get_statistics (unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, const char *subsystem, const char *name, GNUNET_TESTBED_StatisticsIterator proc, GNUNET_TESTBED_OperationCompletionCallback cont, void *cls)
 Convenience method that iterates over all (running) peers and retrieves all statistics from each peer. More...
 

Variables

static struct OperationQueueno_wait_queue
 A no-wait operation queue. More...
 

Detailed Description

high-level statistics function

Author
Christian Grothoff
Sree Harsha Totakura

Definition in file testbed_api_statistics.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "testbed-api-statistics", __VA_ARGS__)

Generic logging shorthand.

Definition at line 37 of file testbed_api_statistics.c.

◆ LOG_DEBUG

#define LOG_DEBUG (   ...)    LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)

Function Documentation

◆ call_completion_task()

static void call_completion_task ( void *  cls)
static

Call statistics operation completion.

We call it in a separate task because the iteration_completion_cb() cannot destroy statistics handle which will be the case if the user calles GNUNET_TESTBED_operation_done() on the get_statistics operation.

Parameters
clsthe GetStatsContext

Definition at line 155 of file testbed_api_statistics.c.

References GetStatsContext::call_completion_task_id, GetStatsContext::cb_cls, GetStatsContext::cont, GNUNET_assert, LOG_DEBUG, GetStatsContext::main_op, and sc.

Referenced by iteration_completion_cb().

156 {
157  struct GetStatsContext *sc = cls;
158 
160  sc->call_completion_task_id = NULL;
161  LOG_DEBUG ("Calling get_statistics() continuation callback\n");
162  sc->cont (sc->cb_cls, sc->main_op, NULL);
163 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
GNUNET_TESTBED_OperationCompletionCallback cont
The callback to call when we are done iterating through all peers' statistics services.
#define LOG_DEBUG(...)
Debug logging shorthand.
struct GNUNET_SCHEDULER_Task * call_completion_task_id
The task for calling the continuation callback.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
Context information for use in GNUNET_TESTBED_get_statistics()
void * cb_cls
The closure for the above callbacks.
struct GNUNET_TESTBED_Operation * main_op
The main operation we generate while creating this context.
Here is the caller graph for this function:

◆ op_done_task()

static void op_done_task ( void *  cls)
static

Task to mark statistics service connect operation as done.

We call it here as we cannot destroy the statistics handle in iteration_completion_cb()

Parameters
clsthe PeerGetStatsContext

Definition at line 173 of file testbed_api_statistics.c.

References GNUNET_assert, GNUNET_TESTBED_operation_done(), op, PeerGetStatsContext::op_done_task_id, GetStatsContext::ops, PeerGetStatsContext::peer_index, sc, and PeerGetStatsContext::sc.

Referenced by iteration_completion_cb().

174 {
175  struct PeerGetStatsContext *peer_sc = cls;
176  struct GetStatsContext *sc;
177  struct GNUNET_TESTBED_Operation **op;
178 
179  sc = peer_sc->sc;
180  peer_sc->op_done_task_id = NULL;
181  op = &sc->ops[peer_sc->peer_index];
182  GNUNET_assert (NULL != *op);
184  *op = NULL;
185 }
unsigned int peer_index
The index of this peer in the peers array of GetStatsContext.
struct GNUNET_SCHEDULER_Task * op_done_task_id
Task to mark the statistics service connect operation as done.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GetStatsContext * sc
The GetStatsContext which is associated with this context.
Opaque handle to an abstract operation to be executed by the testing framework.
void GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation)
This function is used to signal that the event information (struct GNUNET_TESTBED_EventInformation) f...
Definition: testbed_api.c:2046
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
Context information for use in GNUNET_TESTBED_get_statistics()
Context information with respect to a particular peer.
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:139
struct GNUNET_TESTBED_Operation ** ops
The service connect operations we create to open connection to the statistics service of each given p...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ iteration_completion_cb()

static void iteration_completion_cb ( void *  cls,
int  success 
)
static

Continuation called by the "get_all" and "get" functions.

Parameters
clsthe PeerGetStatsContext
successGNUNET_OK if statistics were successfully obtained, GNUNET_SYSERR if not.

Definition at line 196 of file testbed_api_statistics.c.

References call_completion_task(), GetStatsContext::call_completion_task_id, PeerGetStatsContext::get_handle, GNUNET_break, GNUNET_OK, GNUNET_SCHEDULER_add_now(), LOG_DEBUG, GetStatsContext::num_completed, GetStatsContext::num_peers, op_done_task(), PeerGetStatsContext::op_done_task_id, sc, and PeerGetStatsContext::sc.

Referenced by service_connect_comp().

197 {
198  struct PeerGetStatsContext *peer_sc = cls;
199  struct GetStatsContext *sc;
200 
201  GNUNET_break (GNUNET_OK == success);
202  sc = peer_sc->sc;
203  peer_sc->get_handle = NULL;
204  sc->num_completed++;
206  if (sc->num_completed == sc->num_peers)
207  {
208  LOG_DEBUG ("Scheduling to call iteration completion callback\n");
211  }
212 }
struct GNUNET_SCHEDULER_Task * op_done_task_id
Task to mark the statistics service connect operation as done.
struct GetStatsContext * sc
The GetStatsContext which is associated with this context.
unsigned int num_completed
How many peers' statistics have we iterated through.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_STATISTICS_GetHandle * get_handle
The handle from GNUNET_STATISTICS_get()
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1273
#define LOG_DEBUG(...)
Debug logging shorthand.
static void call_completion_task(void *cls)
Call statistics operation completion.
struct GNUNET_SCHEDULER_Task * call_completion_task_id
The task for calling the continuation callback.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
Context information for use in GNUNET_TESTBED_get_statistics()
Context information with respect to a particular peer.
unsigned int num_peers
The number of peers present in the peers array.
static void op_done_task(void *cls)
Task to mark statistics service connect operation as done.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterator_cb()

static int iterator_cb ( void *  cls,
const char *  subsystem,
const char *  name,
uint64_t  value,
int  is_persistent 
)
static

Callback function to process statistic values.

Parameters
clsthe PeerGetStatsContext
subsystemname of subsystem that created the statistic
namethe name of the datum
valuethe current value
is_persistentGNUNET_YES if the value is persistent, GNUNET_NO if not
Returns
GNUNET_OK to continue, GNUNET_SYSERR to abort iteration

Definition at line 226 of file testbed_api_statistics.c.

References GetStatsContext::cb_cls, GNUNET_SYSERR, LOG_DEBUG, peer, PeerGetStatsContext::peer_index, GetStatsContext::peers, GetStatsContext::proc, ret, sc, and PeerGetStatsContext::sc.

Referenced by service_connect_comp().

229 {
230  struct PeerGetStatsContext *peer_sc = cls;
231  struct GetStatsContext *sc;
232  struct GNUNET_TESTBED_Peer *peer;
233  int ret;
234 
235  sc = peer_sc->sc;
236  peer = sc->peers[peer_sc->peer_index];
237  LOG_DEBUG ("Peer %u: [%s,%s] -> %lu\n", peer_sc->peer_index,
238  subsystem, name, (unsigned long) value);
239  ret = sc->proc (sc->cb_cls, peer,
240  subsystem, name, value, is_persistent);
241  if (GNUNET_SYSERR == ret)
242  LOG_DEBUG ("Aborting iteration for peer %u\n", peer_sc->peer_index);
243  return ret;
244 }
unsigned int peer_index
The index of this peer in the peers array of GetStatsContext.
static char * subsystem
Set to subsystem that we're going to get stats for (or NULL for all).
GNUNET_TESTBED_StatisticsIterator proc
The iterator to call with statistics information.
struct GetStatsContext * sc
The GetStatsContext which is associated with this context.
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct GNUNET_TESTBED_Peer ** peers
The array of peers whose statistics services are to be accessed.
static char * value
Value of the record to add/remove.
#define LOG_DEBUG(...)
Debug logging shorthand.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
const char * name
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
Context information for use in GNUNET_TESTBED_get_statistics()
Context information with respect to a particular peer.
void * cb_cls
The closure for the above callbacks.
A peer controlled by the testing framework.
Here is the caller graph for this function:

◆ service_connect_comp()

static void service_connect_comp ( void *  cls,
struct GNUNET_TESTBED_Operation op,
void *  ca_result,
const char *  emsg 
)
static

Called after opening a connection to the statistics service of a peer.

Parameters
clsthe PeerGetStatsContext
opthe operation that has been finished
ca_resultthe service handle returned from GNUNET_TESTBED_ConnectAdapter()
emsgerror message in case the operation has failed; will be NULL if operation has executed successfully.

Definition at line 257 of file testbed_api_statistics.c.

References PeerGetStatsContext::get_handle, GNUNET_STATISTICS_get(), h, iteration_completion_cb(), iterator_cb(), LOG_DEBUG, GetStatsContext::name, PeerGetStatsContext::peer_index, PeerGetStatsContext::sc, and GetStatsContext::subsystem.

Referenced by opstart_get_stats().

261 {
262  struct PeerGetStatsContext *peer_sc = cls;
263  struct GNUNET_STATISTICS_Handle *h = ca_result;
264 
265  LOG_DEBUG ("Retrieving statistics of peer %u\n",
266  peer_sc->peer_index);
267  peer_sc->get_handle =
268  GNUNET_STATISTICS_get (h, peer_sc->sc->subsystem,
269  peer_sc->sc->name,
271  iterator_cb, peer_sc);
272 }
unsigned int peer_index
The index of this peer in the peers array of GetStatsContext.
struct GetStatsContext * sc
The GetStatsContext which is associated with this context.
char * subsystem
The subsystem of peers for which statistics are requested.
Handle for the service.
struct GNUNET_STATISTICS_GetHandle * get_handle
The handle from GNUNET_STATISTICS_get()
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
static void iteration_completion_cb(void *cls, int success)
Continuation called by the "get_all" and "get" functions.
#define LOG_DEBUG(...)
Debug logging shorthand.
Context information with respect to a particular peer.
struct GNUNET_STATISTICS_GetHandle * GNUNET_STATISTICS_get(struct GNUNET_STATISTICS_Handle *handle, const char *subsystem, const char *name, GNUNET_STATISTICS_Callback cont, GNUNET_STATISTICS_Iterator proc, void *cls)
Get statistic from the peer.
char * name
The particular statistics value of interest.
static int iterator_cb(void *cls, const char *subsystem, const char *name, uint64_t value, int is_persistent)
Callback function to process statistic values.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ statistics_ca()

static void* statistics_ca ( void *  cls,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Adapter function called to establish a connection to the statistics service of a peer.

Parameters
clsthe PeerGetStatsContext
cfgconfiguration of the peer to connect to; will be available until GNUNET_TESTBED_operation_done() is called on the operation returned from GNUNET_TESTBED_service_connect()
Returns
service handle to return in 'op_result', NULL on error

Definition at line 286 of file testbed_api_statistics.c.

References GNUNET_STATISTICS_create(), LOG_DEBUG, and PeerGetStatsContext::peer_index.

Referenced by opstart_get_stats().

287 {
288  struct PeerGetStatsContext *peer_sc = cls;
289 
290  LOG_DEBUG ("Connecting to statistics service of peer %u\n",
291  peer_sc->peer_index);
292  return GNUNET_STATISTICS_create ("<testbed-api>", cfg);
293 }
unsigned int peer_index
The index of this peer in the peers array of GetStatsContext.
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
#define LOG_DEBUG(...)
Debug logging shorthand.
Context information with respect to a particular peer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ statistics_da()

static void statistics_da ( void *  cls,
void *  op_result 
)
static

Adapter function called to destroy statistics connection.

Parameters
clsthe PeerGetStatsContext
op_resultservice handle returned from the connect adapter

Definition at line 303 of file testbed_api_statistics.c.

References PeerGetStatsContext::get_handle, GNUNET_free, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_destroy(), GNUNET_STATISTICS_get_cancel(), PeerGetStatsContext::op_done_task_id, op_result(), and sh.

Referenced by opstart_get_stats().

304 {
305  struct PeerGetStatsContext *peer_sc = cls;
307 
308  if (NULL != peer_sc->get_handle)
309  {
311  peer_sc->get_handle = NULL;
312  }
314  if (NULL != peer_sc->op_done_task_id)
316  GNUNET_free (peer_sc);
317 }
struct GNUNET_SCHEDULER_Task * op_done_task_id
Task to mark the statistics service connect operation as done.
static int op_result(struct GNUNET_OP_Handle *h, uint64_t op_id, int64_t result_code, const void *data, uint16_t data_size, void **ctx, uint8_t cancel)
Remove an operation, and call its result callback (unless it was cancelled).
Definition: op.c:244
void GNUNET_STATISTICS_get_cancel(struct GNUNET_STATISTICS_GetHandle *gh)
Cancel a GNUNET_STATISTICS_get request.
#define GNUNET_NO
Definition: gnunet_common.h:81
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
Handle for the service.
struct GNUNET_STATISTICS_GetHandle * get_handle
The handle from GNUNET_STATISTICS_get()
static struct SolverHandle * sh
Context information with respect to a particular peer.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ opstart_get_stats()

static void opstart_get_stats ( void *  cls)
static

Function called when get_statistics operation is ready.

Parameters
clsthe GetStatsContext

Definition at line 326 of file testbed_api_statistics.c.

References GNUNET_break, GNUNET_malloc, GNUNET_new, GNUNET_TESTBED_service_connect(), LOG_DEBUG, GetStatsContext::num_peers, GetStatsContext::ops, peer, PeerGetStatsContext::peer_index, GetStatsContext::peers, sc, PeerGetStatsContext::sc, service_connect_comp(), statistics_ca(), and statistics_da().

Referenced by GNUNET_TESTBED_get_statistics().

327 {
328  struct GetStatsContext *sc = cls;
329  struct PeerGetStatsContext *peer_sc;
330  unsigned int peer;
331 
332  LOG_DEBUG ("Starting get_statistics operation\n");
333  sc->ops = GNUNET_malloc (sc->num_peers *
334  sizeof (struct GNUNET_TESTBED_Operation *));
335  for (peer = 0; peer < sc->num_peers; peer++)
336  {
337  if (NULL == sc->peers[peer])
338  {
339  GNUNET_break (0);
340  continue;
341  }
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",
348  peer_sc,
349  &statistics_ca,
350  &statistics_da,
351  peer_sc);
352  }
353 }
unsigned int peer_index
The index of this peer in the peers array of GetStatsContext.
struct GetStatsContext * sc
The GetStatsContext which is associated with this context.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void statistics_da(void *cls, void *op_result)
Adapter function called to destroy statistics connection.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Opaque handle to an abstract operation to be executed by the testing framework.
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_service_connect(void *op_cls, struct GNUNET_TESTBED_Peer *peer, const char *service_name, GNUNET_TESTBED_ServiceConnectCompletionCallback cb, void *cb_cls, GNUNET_TESTBED_ConnectAdapter ca, GNUNET_TESTBED_DisconnectAdapter da, void *cada_cls)
Connect to a service offered by the given peer.
struct GNUNET_TESTBED_Peer ** peers
The array of peers whose statistics services are to be accessed.
static void * statistics_ca(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Adapter function called to establish a connection to the statistics service of a peer.
#define LOG_DEBUG(...)
Debug logging shorthand.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
Context information for use in GNUNET_TESTBED_get_statistics()
Context information with respect to a particular peer.
unsigned int num_peers
The number of peers present in the peers array.
static void service_connect_comp(void *cls, struct GNUNET_TESTBED_Operation *op, void *ca_result, const char *emsg)
Called after opening a connection to the statistics service of a peer.
#define GNUNET_malloc(size)
Wrapper around malloc.
struct GNUNET_TESTBED_Operation ** ops
The service connect operations we create to open connection to the statistics service of each given p...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ oprelease_get_stats()

static void oprelease_get_stats ( void *  cls)
static

Function called when get_statistics operation is cancelled or marked as done.

Parameters
clsthe GetStatsContext

Definition at line 362 of file testbed_api_statistics.c.

References GetStatsContext::call_completion_task_id, GNUNET_free, GNUNET_free_non_null, GNUNET_SCHEDULER_cancel(), GNUNET_TESTBED_operation_done(), GNUNET_TESTBED_operation_queue_destroy_empty_(), GNUNET_YES, LOG_DEBUG, GetStatsContext::name, GetStatsContext::num_peers, GetStatsContext::ops, peer, sc, and GetStatsContext::subsystem.

Referenced by GNUNET_TESTBED_get_statistics().

363 {
364  struct GetStatsContext *sc = cls;
365  unsigned int peer;
366 
367  LOG_DEBUG ("Cleaning up get_statistics operation\n");
368  if (NULL != sc->call_completion_task_id)
370  if (NULL != sc->ops)
371  {
372  for (peer = 0; peer < sc->num_peers; peer++)
373  {
374  if (NULL != sc->ops[peer])
375  {
377  sc->ops[peer] = NULL;
378  }
379  }
380  GNUNET_free (sc->ops);
381  }
384  GNUNET_free (sc);
385  if (GNUNET_YES ==
387  no_wait_queue = NULL;
388 }
static struct OperationQueue * no_wait_queue
A no-wait operation queue.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
char * subsystem
The subsystem of peers for which statistics are requested.
void GNUNET_TESTBED_operation_done(struct GNUNET_TESTBED_Operation *operation)
This function is used to signal that the event information (struct GNUNET_TESTBED_EventInformation) f...
Definition: testbed_api.c:2046
int GNUNET_TESTBED_operation_queue_destroy_empty_(struct OperationQueue *queue)
Destroys the operation queue if it is empty.
#define LOG_DEBUG(...)
Debug logging shorthand.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_SCHEDULER_Task * call_completion_task_id
The task for calling the continuation callback.
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
Context information for use in GNUNET_TESTBED_get_statistics()
unsigned int num_peers
The number of peers present in the peers array.
char * name
The particular statistics value of interest.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_TESTBED_Operation ** ops
The service connect operations we create to open connection to the statistics service of each given p...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ no_wait_queue

struct OperationQueue* no_wait_queue
static

A no-wait operation queue.

Definition at line 143 of file testbed_api_statistics.c.