GNUnet  0.11.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__)

Debug logging shorthand.

Definition at line 43 of file testbed_api_statistics.c.

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 calls GNUNET_TESTBED_operation_done() on the get_statistics operation.

Parameters
clsthe GetStatsContext

Definition at line 154 of file testbed_api_statistics.c.

155 {
156  struct GetStatsContext *sc = cls;
157 
158  GNUNET_assert (sc->call_completion_task_id != NULL);
159  sc->call_completion_task_id = NULL;
160  LOG_DEBUG ("Calling get_statistics() continuation callback\n");
161  sc->cont (sc->cb_cls, sc->main_op, NULL);
162 }
static struct GNUNET_FS_SearchContext * sc
Definition: gnunet-search.c:37
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Context information for use in GNUNET_TESTBED_get_statistics()
#define LOG_DEBUG(...)
Debug logging shorthand.

References GNUNET_assert, LOG_DEBUG, and sc.

Referenced by iteration_completion_cb().

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 172 of file testbed_api_statistics.c.

173 {
174  struct PeerGetStatsContext *peer_sc = cls;
175  struct GetStatsContext *sc;
176  struct GNUNET_TESTBED_Operation **op;
177 
178  sc = peer_sc->sc;
179  peer_sc->op_done_task_id = NULL;
180  op = &sc->ops[peer_sc->peer_index];
181  GNUNET_assert (NULL != *op);
183  *op = NULL;
184 }
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
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:2045
Opaque handle to an abstract operation to be executed by the testing framework.
Context information with respect to a particular peer.
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 peer_index
The index of this peer in the peers array of GetStatsContext.

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

Referenced by iteration_completion_cb().

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 195 of file testbed_api_statistics.c.

196 {
197  struct PeerGetStatsContext *peer_sc = cls;
198  struct GetStatsContext *sc;
199 
200  GNUNET_break (GNUNET_OK == success);
201  sc = peer_sc->sc;
202  peer_sc->get_handle = NULL;
203  sc->num_completed++;
205  if (sc->num_completed == sc->num_peers)
206  {
207  LOG_DEBUG ("Scheduling to call iteration completion callback\n");
208  sc->call_completion_task_id =
210  }
211 }
@ GNUNET_OK
Definition: gnunet_common.h:95
#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:1296
struct GNUNET_STATISTICS_GetHandle * get_handle
The handle from GNUNET_STATISTICS_get()
static void call_completion_task(void *cls)
Call statistics operation completion.
static void op_done_task(void *cls)
Task to mark statistics service connect operation as done.

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

Referenced by service_connect_comp().

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 225 of file testbed_api_statistics.c.

228 {
229  struct PeerGetStatsContext *peer_sc = cls;
230  struct GetStatsContext *sc;
231  struct GNUNET_TESTBED_Peer *peer;
232  int ret;
233 
234  sc = peer_sc->sc;
235  peer = sc->peers[peer_sc->peer_index];
236  LOG_DEBUG ("Peer %u: [%s,%s] -> %lu\n", peer_sc->peer_index,
237  subsystem, name, (unsigned long) value);
238  ret = sc->proc (sc->cb_cls, peer,
239  subsystem, name, value, is_persistent);
240  if (GNUNET_SYSERR == ret)
241  LOG_DEBUG ("Aborting iteration for peer %u\n", peer_sc->peer_index);
242  return ret;
243 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static char * value
Value of the record to add/remove.
static char * subsystem
Set to subsystem that we're going to get stats for (or NULL for all).
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
const char * name
A peer controlled by the testing framework.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.

References GNUNET_SYSERR, LOG_DEBUG, name, peer, PeerGetStatsContext::peer_index, ret, sc, PeerGetStatsContext::sc, subsystem, and value.

Referenced by service_connect_comp().

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 256 of file testbed_api_statistics.c.

260 {
261  struct PeerGetStatsContext *peer_sc = cls;
262  struct GNUNET_STATISTICS_Handle *h = ca_result;
263 
264  LOG_DEBUG ("Retrieving statistics of peer %u\n",
265  peer_sc->peer_index);
266  peer_sc->get_handle =
267  GNUNET_STATISTICS_get (h, peer_sc->sc->subsystem,
268  peer_sc->sc->name,
270  iterator_cb, peer_sc);
271 }
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
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.
Handle for the service.
char * name
The particular statistics value of interest.
char * subsystem
The subsystem of peers for which statistics are requested.
static void iteration_completion_cb(void *cls, int success)
Continuation called by the "get_all" and "get" functions.
static int iterator_cb(void *cls, const char *subsystem, const char *name, uint64_t value, int is_persistent)
Callback function to process statistic values.

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().

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 285 of file testbed_api_statistics.c.

286 {
287  struct PeerGetStatsContext *peer_sc = cls;
288 
289  LOG_DEBUG ("Connecting to statistics service of peer %u\n",
290  peer_sc->peer_index);
291  return GNUNET_STATISTICS_create ("<testbed-api>", cfg);
292 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.

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

Referenced by opstart_get_stats().

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 302 of file testbed_api_statistics.c.

303 {
304  struct PeerGetStatsContext *peer_sc = cls;
306 
307  if (NULL != peer_sc->get_handle)
308  {
310  peer_sc->get_handle = NULL;
311  }
313  if (NULL != peer_sc->op_done_task_id)
315  GNUNET_free (peer_sc);
316 }
static struct SolverHandle * sh
@ GNUNET_NO
Definition: gnunet_common.h:94
#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:972
void GNUNET_STATISTICS_get_cancel(struct GNUNET_STATISTICS_GetHandle *gh)
Cancel a GNUNET_STATISTICS_get request.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
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:245

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().

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 325 of file testbed_api_statistics.c.

326 {
327  struct GetStatsContext *sc = cls;
328  struct PeerGetStatsContext *peer_sc;
329  unsigned int peer;
330 
331  LOG_DEBUG ("Starting get_statistics operation\n");
332  sc->ops = GNUNET_malloc (sc->num_peers
333  * sizeof(struct GNUNET_TESTBED_Operation *));
334  for (peer = 0; peer < sc->num_peers; peer++)
335  {
336  if (NULL == sc->peers[peer])
337  {
338  GNUNET_break (0);
339  continue;
340  }
341  peer_sc = GNUNET_new (struct PeerGetStatsContext);
342  peer_sc->sc = sc;
343  peer_sc->peer_index = peer;
344  sc->ops[peer] =
345  GNUNET_TESTBED_service_connect (sc, sc->peers[peer], "statistics",
347  peer_sc,
348  &statistics_ca,
349  &statistics_da,
350  peer_sc);
351  }
352 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
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.
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.
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.
static void statistics_da(void *cls, void *op_result)
Adapter function called to destroy statistics connection.

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

Referenced by GNUNET_TESTBED_get_statistics().

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 361 of file testbed_api_statistics.c.

362 {
363  struct GetStatsContext *sc = cls;
364  unsigned int peer;
365 
366  LOG_DEBUG ("Cleaning up get_statistics operation\n");
367  if (NULL != sc->call_completion_task_id)
368  GNUNET_SCHEDULER_cancel (sc->call_completion_task_id);
369  if (NULL != sc->ops)
370  {
371  for (peer = 0; peer < sc->num_peers; peer++)
372  {
373  if (NULL != sc->ops[peer])
374  {
376  sc->ops[peer] = NULL;
377  }
378  }
379  GNUNET_free (sc->ops);
380  }
381  GNUNET_free (sc->subsystem);
382  GNUNET_free (sc->name);
383  GNUNET_free (sc);
384  if (GNUNET_YES ==
386  no_wait_queue = NULL;
387 }
@ GNUNET_YES
Definition: gnunet_common.h:97
int GNUNET_TESTBED_operation_queue_destroy_empty_(struct OperationQueue *queue)
Destroys the operation queue if it is empty.
static struct OperationQueue * no_wait_queue
A no-wait operation queue.

References GNUNET_free, GNUNET_SCHEDULER_cancel(), GNUNET_TESTBED_operation_done(), GNUNET_TESTBED_operation_queue_destroy_empty_(), GNUNET_YES, LOG_DEBUG, no_wait_queue, peer, and sc.

Referenced by GNUNET_TESTBED_get_statistics().

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 142 of file testbed_api_statistics.c.

Referenced by GNUNET_TESTBED_get_statistics(), and oprelease_get_stats().