GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 2, or (at your
+ by the Free Software Foundation; either version 3, or (at your
option) any later version.
GNUnet is distributed in the hope that it will be useful, but
* @author Christian Grothoff
*/
#include "platform.h"
-#include "gnunet_client_lib.h"
+#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
-#include "gnunet_container_lib.h"
#include "gnunet_protocols.h"
-#include "gnunet_server_lib.h"
#include "gnunet_statistics_service.h"
-#include "gnunet_strings_lib.h"
#include "statistics.h"
/**
*/
struct GNUNET_TIME_Relative backoff;
+ /**
+ * Maximum heap size observed so far (if available).
+ */
+ uint64_t peak_heap_size;
+
+ /**
+ * Maximum resident set side observed so far (if available).
+ */
+ uint64_t peak_rss;
+
/**
* Size of the 'watches' array.
*/
};
+/**
+ * Obtain statistics about this process's memory consumption and
+ * report those as well (if they changed).
+ */
+static void
+update_memory_statistics (struct GNUNET_STATISTICS_Handle *h)
+{
+#if ENABLE_HEAP_STATISTICS
+ uint64_t current_heap_size = 0;
+ uint64_t current_rss = 0;
+
+ if (GNUNET_NO != h->do_destroy)
+ return;
+#if HAVE_MALLINFO
+ {
+ struct mallinfo mi;
+
+ mi = mallinfo();
+ current_heap_size = mi.uordblks + mi.fordblks;
+ }
+#endif
+#if HAVE_GETRUSAGE
+ {
+ struct rusage ru;
+
+ if (0 == getrusage (RUSAGE_SELF, &ru))
+ {
+ current_rss = 1024LL * ru.ru_maxrss;
+ }
+ }
+#endif
+ if (current_heap_size > h->peak_heap_size)
+ {
+ h->peak_heap_size = current_heap_size;
+ GNUNET_STATISTICS_set (h, "# peak heap size", current_heap_size, GNUNET_NO);
+ }
+ if (current_rss > h->peak_rss)
+ {
+ h->peak_rss = current_rss;
+ GNUNET_STATISTICS_set (h, "# peak resident set size", current_rss, GNUNET_NO);
+ }
+#endif
+}
+
+
/**
* Schedule the next action to be performed.
*
do_disconnect (struct GNUNET_STATISTICS_Handle *h)
{
struct GNUNET_STATISTICS_GetHandle *c;
-
+
if (NULL != h->th)
{
GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
h->th = NULL;
- }
+ }
if (NULL != h->client)
{
GNUNET_CLIENT_disconnect (h->client);
if (NULL != (c = h->current))
{
h->current = NULL;
- if (NULL != c->cont)
+ if ( (NULL != c->cont) &&
+ (GNUNET_YES != c->aborted) )
c->cont (c->cls, GNUNET_SYSERR);
free_action_item (c);
}
return GNUNET_NO;
if (NULL != h->client)
return GNUNET_YES;
- h->client = GNUNET_CLIENT_connect ("statistics", h->cfg);
+ h->client = GNUNET_CLIENT_connect ("statistics", h->cfg);
if (NULL != h->client)
{
- gn = h->action_head;
+ gn = h->action_head;
while (NULL != (gh = gn))
{
gn = gh->next;
}
h->backoff_task =
GNUNET_SCHEDULER_add_delayed (h->backoff, &reconnect_task, h);
- h->backoff = GNUNET_TIME_relative_multiply (h->backoff, 2);
- h->backoff =
- GNUNET_TIME_relative_min (h->backoff, GNUNET_CONSTANTS_SERVICE_TIMEOUT);
+ h->backoff = GNUNET_TIME_STD_BACKOFF (h->backoff);
}
return GNUNET_SYSERR;
}
w = h->watches[wid];
- if (NULL == w)
- return GNUNET_NO;
+ if (NULL == w)
+ return GNUNET_NO;
(void) w->proc (w->proc_cls, w->subsystem, w->name,
GNUNET_ntohll (wvm->value),
0 != (ntohl (wvm->flags) & GNUNET_STATISTICS_PERSIST_BIT));
else
{
h->receiving = GNUNET_NO;
- }
+ }
h->current = NULL;
schedule_action (h);
if (NULL != c->cont)
{
do_disconnect (h);
reconnect_later (h);
- return;
+ return;
}
/* finally, look for more! */
LOG (GNUNET_ERROR_TYPE_DEBUG,
h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
return;
case GNUNET_MESSAGE_TYPE_STATISTICS_WATCH_VALUE:
- if (GNUNET_OK !=
+ if (GNUNET_OK !=
(ret = process_watch_value (h, msg)))
{
do_disconnect (h);
if (GNUNET_NO == ret)
- h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
+ h->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
reconnect_later (h);
return;
}
GNUNET_assert (h->watches_size > 0);
GNUNET_CLIENT_receive (h->client, &receive_stats, h,
GNUNET_TIME_UNIT_FOREVER_REL);
- return;
+ return;
default:
GNUNET_break (0);
do_disconnect (h);
GNUNET_assert (NULL == handle->current->cont);
free_action_item (handle->current);
handle->current = NULL;
+ update_memory_statistics (handle);
return nsize;
}
{
struct GNUNET_STATISTICS_Handle *ret;
+ if (GNUNET_YES ==
+ GNUNET_CONFIGURATION_get_value_yesno (cfg, "statistics", "DISABLE"))
+ return NULL;
GNUNET_assert (NULL != subsystem);
GNUNET_assert (NULL != cfg);
ret = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_Handle));
h->current = NULL;
}
}
- next = h->action_head;
+ next = h->action_head;
while (NULL != (pos = next))
{
next = pos->next;
for (i = 0; i < h->watches_size; i++)
{
if (NULL == h->watches[i])
- continue;
+ continue;
GNUNET_free (h->watches[i]->subsystem);
GNUNET_free (h->watches[i]->name);
GNUNET_free (h->watches[i]);
* @param timeout after how long should we give up (and call
* cont with an error code)?
* @param cont continuation to call when done (can be NULL)
+ * This callback CANNOT destroy the statistics handle in the same call.
* @param proc function to call on each value
* @param cls closure for cont and proc
* @return NULL on error
{
if (NULL == gh)
return;
+ gh->cont = NULL;
if (gh->sh->current == gh)
{
gh->aborted = GNUNET_YES;
/**
- * Stop watching statistics from the peer.
+ * Stop watching statistics from the peer.
*
* @param handle identification of the statistics service
* @param subsystem limit to the specified subsystem, never NULL
GNUNET_free (w->name);
GNUNET_free (w->subsystem);
GNUNET_free (w);
- handle->watches[i] = NULL;
+ handle->watches[i] = NULL;
return GNUNET_OK;
- }
+ }
}
return GNUNET_SYSERR;
}
for (ai = h->action_head; NULL != ai; ai = ai->next)
{
if (! ( (0 == strcmp (ai->subsystem, h->subsystem)) &&
- (0 == strcmp (ai->name, name)) &&
+ (0 == strcmp (ai->name, name)) &&
( (ACTION_UPDATE == ai->type) ||
(ACTION_SET == ai->type) ) ) )
continue;
}
ai->timeout = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT);
ai->make_persistent = make_persistent;
- return;
+ return;
}
/* no existing entry matches, create a fresh one */
ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle));