stats fixes
authorChristian Grothoff <christian@grothoff.org>
Thu, 1 Jul 2010 09:03:30 +0000 (09:03 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 1 Jul 2010 09:03:30 +0000 (09:03 +0000)
src/statistics/statistics_api.c
src/statistics/test_statistics_api_loop.c

index 3289745b15300cc09348c33b56e4604433404aea..ed3d0bdb758a1ee3396853de05f3d5091e381c44 100644 (file)
@@ -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);
index b70e92bdc98dc016f40e891fff897a4fd3446c6f..5ba6132bfc3b11160035213e51509b26a98f5f63 100644 (file)
@@ -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));
 }