From c2c2321102d8b2ce8cd3cba888138a6be86e2b87 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 1 Jul 2010 09:03:30 +0000 Subject: stats fixes --- src/statistics/statistics_api.c | 51 ++++++++++++++++++++++++++++++- src/statistics/test_statistics_api_loop.c | 2 +- 2 files changed, 51 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c index 3289745b1..ed3d0bdb7 100644 --- a/src/statistics/statistics_api.c +++ b/src/statistics/statistics_api.c @@ -752,7 +752,8 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, size_t slen; size_t nlen; size_t nsize; - + int64_t delta; + GNUNET_assert (h != NULL); GNUNET_assert (name != NULL); if (GNUNET_YES != try_connect (h)) @@ -765,6 +766,54 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, GNUNET_break (0); return; } + ai = h->action_head; + while (ai != NULL) + { + if ( (0 == strcmp (ai->subsystem, h->subsystem)) && + (0 == strcmp (ai->name, name)) && + ( (ai->type == ACTION_UPDATE) || + (ai->type == ACTION_SET) ) ) + { + if (ai->type == ACTION_SET) + { + if (type == ACTION_UPDATE) + { + delta = (int64_t) value; + if (delta > 0) + { + ai->value += delta; + } + else + { + if (ai->value < -delta) + ai->value = 0; + else + ai->value += delta; + } + } + else + { + ai->value = value; + } + } + else + { + if (type == ACTION_UPDATE) + { + delta = (int64_t) value; + ai->value += delta; + } + else + { + ai->value = value; + ai->type = type; + } + } + ai->timeout = GNUNET_TIME_relative_to_absolute (SET_TRANSMIT_TIMEOUT); + return; + } + ai = ai->next; + } ai = GNUNET_malloc (sizeof (struct GNUNET_STATISTICS_GetHandle)); ai->sh = h; ai->subsystem = GNUNET_strdup (h->subsystem); diff --git a/src/statistics/test_statistics_api_loop.c b/src/statistics/test_statistics_api_loop.c index b70e92bdc..5ba6132bf 100644 --- a/src/statistics/test_statistics_api_loop.c +++ b/src/statistics/test_statistics_api_loop.c @@ -79,7 +79,7 @@ run (void *cls, i = 0; GNUNET_break (NULL != GNUNET_STATISTICS_get (h, NULL, "test-0", - GNUNET_TIME_UNIT_SECONDS, &next, &check_1, cls)); + GNUNET_TIME_UNIT_MINUTES, &next, &check_1, cls)); } -- cgit v1.2.3