38#define SET_TRANSMIT_TIMEOUT GNUNET_TIME_relative_multiply ( \
39 GNUNET_TIME_UNIT_SECONDS, 2)
41#define LOG(kind, ...) GNUNET_log_from (kind, "statistics-api", __VA_ARGS__)
267#if ENABLE_HEAP_STATISTICS
268 uint64_t current_heap_size = 0;
269 uint64_t current_rss = 0;
278 current_heap_size = mi.uordblks + mi.fordblks;
285 if (0 == getrusage (RUSAGE_SELF, &ru))
287 current_rss = 1024LL * ru.ru_maxrss;
291 if (current_heap_size >
h->peak_heap_size)
293 h->peak_heap_size = current_heap_size;
299 if (current_rss >
h->peak_rss)
301 h->peak_rss = current_rss;
303 "# peak resident set size",
345 slen = strlen (
watch->subsystem) + 1;
346 nlen = strlen (
watch->name) + 1;
394 if (NULL != (c =
h->current))
397 if ((NULL != c->
cont) &&
461 if (
h->current->aborted)
473 "Received valid statistic on `%s:%s': %llu\n",
477 h->current->proc (
h->current->cls,
485 "Processing of remaining statistics aborted by client.\n");
507 wid = ntohl (wvm->
wid);
508 if (wid >=
h->watches_size)
542 if (NULL !=
h->destroy_task)
545 h->destroy_task = NULL;
566 h->destroy_task = NULL;
569 "Running final destruction\n");
598 "Received DISCONNNECT_CONFIRM message from statistics, can complete disconnect\n");
599 if (NULL !=
h->destroy_task)
622 "Received end of statistics marker\n");
623 if (NULL == (c =
h->current))
674 if (NULL !=
h->backoff_task)
686 "Failed to connect to statistics service!\n");
690 while (NULL != (gh = gn))
701 for (
unsigned int i = 0; i <
h->watches_size; i++)
702 if (NULL !=
h->watches[i])
719 h->backoff_task = NULL;
743 for (gh =
h->action_head; NULL != gh; gh = gh->
next)
749 _ (
"Could not save some persistent statistics\n"));
750 if (NULL !=
h->destroy_task)
781 slen2 = strlen (c->
name) + 1;
814 "Transmitting watch request for `%s'\n",
816 slen1 = strlen (
handle->current->subsystem) + 1;
817 slen2 = strlen (
handle->current->name) + 1;
825 handle->current->subsystem,
852 slen = strlen (
handle->current->subsystem) + 1;
853 nlen = strlen (
handle->current->name) + 1;
859 if (
handle->current->make_persistent)
867 handle->current->subsystem,
929 if ((NULL !=
h->current) &&
932 next =
h->action_head;
933 while (NULL != (pos =
next))
954 "Deferring destruction\n");
959 "Cleaning all up\n");
960 while (NULL != (pos =
h->action_head))
968 if (NULL !=
h->backoff_task)
971 h->backoff_task = NULL;
973 if (NULL !=
h->destroy_task)
977 h->destroy_task = NULL;
979 for (
unsigned int i = 0; i <
h->watches_size; i++)
981 if (NULL ==
h->watches[i])
1005 if (NULL !=
h->backoff_task)
1015 while (NULL ==
h->current)
1017 h->current =
h->action_head;
1018 if (NULL ==
h->current)
1027 "Notifying service that we are done\n");
1041 switch (
h->current->type)
1085 slen2 = strlen (
name) + 1;
1181 for (
unsigned int i = 0; i <
handle->watches_size; i++)
1188 (0 == strcmp (w->
name,
1196 handle->watches[i] = NULL;
1216 int make_persistent,
1226 slen = strlen (
h->subsystem) + 1;
1227 nlen = strlen (
name) + 1;
1236 if (! ((0 == strcmp (
ai->subsystem,
1238 (0 == strcmp (
ai->name,
1295 ai->make_persistent = make_persistent;
1310 int make_persistent)
1327 int make_persistent)
struct GNUNET_MQ_MessageHandlers handlers[]
struct GNUNET_MessageHeader * msg
struct GNUNET_MQ_Envelope * env
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
static char * name
Name (label) of the records to list.
static char * value
Value of the record to add/remove.
static uint32_t type
Type string converted to DNS type value.
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
static int watch
Watch value continuously.
static char * subsystem
Set to subsystem that we're going to get stats for (or NULL for all).
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Constants for network protocols.
API to create, modify and access statistics.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_log(kind,...)
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
#define GNUNET_free(ptr)
Wrapper around free.
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
#define GNUNET_MESSAGE_TYPE_STATISTICS_END
Response to a STATISTICS_GET message (end of value stream).
#define GNUNET_MESSAGE_TYPE_STATISTICS_GET
Get a statistical value(s).
#define GNUNET_MESSAGE_TYPE_STATISTICS_VALUE
Response to a STATISTICS_GET message (with value).
#define GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE
Changes to a watched value.
#define GNUNET_MESSAGE_TYPE_STATISTICS_SET
Set a statistical value.
#define GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM
Service confirms disconnect and that it is done processing all requests from the client.
#define GNUNET_MESSAGE_TYPE_STATISTICS_WATCH
Watch changes to a statistical value.
#define GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT
Client is done sending service requests and will now disconnect.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
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.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
int(* GNUNET_STATISTICS_Iterator)(void *cls, const char *subsystem, const char *name, uint64_t value, int is_persistent)
Callback function to process statistic values.
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
int GNUNET_STATISTICS_watch_cancel(struct GNUNET_STATISTICS_Handle *handle, const char *subsystem, const char *name, GNUNET_STATISTICS_Iterator proc, void *proc_cls)
Stop watching statistics from the peer.
void GNUNET_STATISTICS_get_cancel(struct GNUNET_STATISTICS_GetHandle *gh)
Cancel a GNUNET_STATISTICS_get request.
void(* GNUNET_STATISTICS_Callback)(void *cls, int success)
Continuation called by GNUNET_STATISTICS_get() functions.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the 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.
int GNUNET_STATISTICS_watch(struct GNUNET_STATISTICS_Handle *handle, const char *subsystem, const char *name, GNUNET_STATISTICS_Iterator proc, void *proc_cls)
Watch statistics from the peer (be notified whenever they change).
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
unsigned int GNUNET_STRINGS_buffer_tokenize(const char *buffer, size_t size, unsigned int count,...)
Given a buffer of a given size, find "count" 0-terminated strings in the buffer and assign the count ...
size_t GNUNET_STRINGS_buffer_fill(char *buffer, size_t size, unsigned int count,...)
Fill a buffer of the given size with count 0-terminated strings (given as varargs).
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
static unsigned int size
Size of the "table".
static struct GNUNET_TIME_Relative delta
#define GNUNET_STATISTICS_PERSIST_BIT
Flag for the struct GNUNET_STATISTICS_ReplyMessage UID only.
#define GNUNET_STATISTICS_SETFLAG_PERSISTENT
The value being set is to be persistent (note that this bit can be combined with GNUNET_STATISTICS_SE...
#define GNUNET_STATISTICS_SETFLAG_RELATIVE
The value being set is a relative change.
static int check_statistics_value(void *cls, const struct GNUNET_STATISTICS_ReplyMessage *smsg)
Process a GNUNET_MESSAGE_TYPE_STATISTICS_VALUE message.
ActionType
Types of actions.
@ ACTION_WATCH
Watch a value.
@ ACTION_UPDATE
Update a value.
static void reconnect_later(struct GNUNET_STATISTICS_Handle *h)
Reconnect at a later time, respecting back-off.
#define SET_TRANSMIT_TIMEOUT
How long do we wait until a statistics request for setting a value times out? (The update will be los...
static void transmit_watch(struct GNUNET_STATISTICS_Handle *handle)
Transmit a WATCH request (and if successful, start to receive the response).
static void handle_disconnect_confirm(void *cls, const struct GNUNET_MessageHeader *msg)
Handle a GNUNET_MESSAGE_TYPE_STATISTICS_DISCONNECT_CONFIRM message.
static void handle_statistics_value(void *cls, const struct GNUNET_STATISTICS_ReplyMessage *smsg)
Process a GNUNET_MESSAGE_TYPE_STATISTICS_VALUE message.
static void schedule_watch_request(struct GNUNET_STATISTICS_Handle *h, struct GNUNET_STATISTICS_WatchEntry *watch)
Transmit request to service that we want to watch the development of a particular value.
static void free_action_item(struct GNUNET_STATISTICS_GetHandle *gh)
Free memory associated with the given action item.
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
static void schedule_action(void *cls)
Schedule the next action to be performed.
static void handle_statistics_watch_value(void *cls, const struct GNUNET_STATISTICS_WatchValueMessage *wvm)
We have received a watch value from the service.
static int try_connect(struct GNUNET_STATISTICS_Handle *h)
Try to (re)connect to the statistics service.
static void transmit_get(struct GNUNET_STATISTICS_Handle *handle)
Transmit a GET request (and if successful, start to receive the response).
static void update_memory_statistics(struct GNUNET_STATISTICS_Handle *h)
Obtain statistics about this process's memory consumption and report those as well (if they changed).
static void do_destroy(void *cls)
Task used to destroy the statistics handle.
static void transmit_set(struct GNUNET_STATISTICS_Handle *handle)
Transmit a SET/UPDATE request.
static void do_disconnect(struct GNUNET_STATISTICS_Handle *h)
Disconnect from the statistics service.
static void add_setter_action(struct GNUNET_STATISTICS_Handle *h, const char *name, int make_persistent, uint64_t value, enum ActionType type)
Queue a request to change a statistic.
static void handle_statistics_end(void *cls, const struct GNUNET_MessageHeader *msg)
Handle a GNUNET_MESSAGE_TYPE_STATISTICS_END message.
static void reconnect_task(void *cls)
We've waited long enough, reconnect now.
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Handle to a message queue.
Message handler for a specific message type.
Entry in list of pending tasks.
Linked list of things we still need to do.
char * name
What value is this action about? (can be NULL)
uint64_t value
Associated value.
GNUNET_STATISTICS_Callback cont
Continuation to call once action is complete.
int make_persistent
Flag for SET/UPDATE actions.
struct GNUNET_STATISTICS_GetHandle * prev
This is a doubly linked list.
GNUNET_STATISTICS_Iterator proc
Function to call (for GET actions only).
uint16_t msize
Size of the message that we will be transmitting.
enum ActionType type
Is this a ACTION_GET, ACTION_SET, ACTION_UPDATE or ACTION_WATCH?
struct GNUNET_TIME_Absolute timeout
Timeout for this action.
struct GNUNET_STATISTICS_GetHandle * next
This is a doubly linked list.
int aborted
Has the current iteration been aborted; for GET actions.
struct GNUNET_STATISTICS_Handle * sh
Main statistics handle.
char * subsystem
What subsystem is this action about? (can be NULL)
void * cls
Closure for proc and cont.
struct GNUNET_MQ_Handle * mq
Message queue to the service.
char * subsystem
Name of our subsystem.
struct GNUNET_STATISTICS_WatchEntry ** watches
Array of watch entries.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
struct GNUNET_STATISTICS_GetHandle * current
Action we are currently busy with (action request has been transmitted, we're now receiving the respo...
int do_destroy
Should this handle auto-destruct once all actions have been processed?
struct GNUNET_TIME_Relative backoff
Time for next connect retry.
unsigned int watches_size
Size of the watches array.
int receiving
Are we currently receiving from the service?
struct GNUNET_SCHEDULER_Task * destroy_task
Task for running do_destroy().
uint64_t peak_heap_size
Maximum heap size observed so far (if available).
struct GNUNET_STATISTICS_GetHandle * action_head
Head of the linked list of pending actions (first action to be performed).
struct GNUNET_SCHEDULER_Task * backoff_task
Task doing exponential back-off trying to reconnect.
struct GNUNET_STATISTICS_GetHandle * action_tail
Tail of the linked list of actions (for fast append).
uint64_t peak_rss
Maximum resident set side observed so far (if available).
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_STATISTICS_VALUE.
uint32_t uid
Unique numerical identifier for the value (will not change during the same client-session).
Message to set a statistic.
uint32_t flags
0 for absolute value, 1 for relative value; 2 to make persistent (see GNUNET_STATISTICS_SETFLAG_*).
Entry kept for each value we are watching.
void * proc_cls
Closure for proc.
char * name
What value is this action about? (never NULL)
GNUNET_STATISTICS_Iterator proc
Function to call.
char * subsystem
What subsystem is this action about? (never NULL)
Message transmitted if a watched value changes.
uint32_t reserved
Reserved (always 0).
uint32_t flags
0 for absolute value, 1 for relative value; 2 to make persistent (see GNUNET_STATISTICS_SETFLAG_*).
uint32_t wid
Unique watch identification number (watch requests are enumerated in the order they are received,...
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_TRANSPORT_AddressIdentifier * next
Kept in a DLL.
struct GNUNET_MQ_Handle * mq
Connection to VPN service.