adding stats
authorChristian Grothoff <christian@grothoff.org>
Wed, 19 Oct 2011 12:26:57 +0000 (12:26 +0000)
committerChristian Grothoff <christian@grothoff.org>
Wed, 19 Oct 2011 12:26:57 +0000 (12:26 +0000)
src/ats/Makefile.am
src/ats/ats_api_scheduling.c
src/ats/gnunet-service-ats.c
src/ats/gnunet-service-ats.h [new file with mode: 0644]
src/ats/gnunet-service-ats_addresses.c
src/ats/gnunet-service-ats_performance.c
src/ats/gnunet-service-ats_scheduling.c

index 6d945dd5125742a899c393090664fb5f9c863fee..5cba4fccb105f9ad5d81b5761673b6af0175b4c1 100644 (file)
@@ -22,12 +22,13 @@ bin_PROGRAMS = \
  gnunet-service-ats
 
 gnunet_service_ats_SOURCES = \
- gnunet-service-ats.c \
+ gnunet-service-ats.c gnunet-service-ats.h\
  gnunet-service-ats_addresses.c gnunet-service-ats_addresses.h \
  gnunet-service-ats_performance.c gnunet-service-ats_performance.h \
  gnunet-service-ats_scheduling.c gnunet-service-ats_scheduling.h \
  gnunet-service-ats_reservations.c gnunet-service-ats_reservations.h
 gnunet_service_ats_LDADD = \
+  $(top_builddir)/src/statistics/libgnunetstatistics.la \
   $(top_builddir)/src/util/libgnunetutil.la \
   $(GN_LIBINTL)
 
@@ -35,7 +36,7 @@ gnunet_service_ats_LDADD = \
 check_PROGRAMS = \
  test_ats_api_scheduling
 # test_ats_api_bandwidth_consumption
+
 if ENABLE_TEST_RUN
 TESTS = $(check_PROGRAMS)
 endif
index e625749187f789514efaef69b09489a2cb08dee2..955b21286f435f9227903fc6e435290252d231cc 100644 (file)
@@ -345,6 +345,7 @@ remove_session (struct GNUNET_ATS_SchedulingHandle *sh,
                const struct GNUNET_PeerIdentity *peer)
 {
   GNUNET_assert (session_id < sh->session_array_size);
+  GNUNET_assert (GNUNET_YES == sh->session_array[session_id].slot_used);
   GNUNET_assert (0 == memcmp (peer,
                              &sh->session_array[session_id].peer,
                              sizeof (struct GNUNET_PeerIdentity)));
index 768bef1b7c2a4aa42d959b5d5e4634c09a71c52d..e497a7aaf33a5ef026f71ff9b4fda1e437853094 100644 (file)
 #include "platform.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_ats_service.h"
+#include "gnunet-service-ats.h"
 #include "gnunet-service-ats_addresses.h"
 #include "gnunet-service-ats_performance.h"
 #include "gnunet-service-ats_scheduling.h"
 #include "gnunet-service-ats_reservations.h"
 #include "ats.h"
 
+/**
+ * Handle for statistics.
+ */
+struct GNUNET_STATISTICS_Handle *GSA_stats;
 
 /**
  * We have received a 'ClientStartMessage' from a client.  Find out which
@@ -106,6 +111,11 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   GAS_scheduling_done ();
   GAS_performance_done ();
   GAS_reservations_done ();
+  if (NULL != GSA_stats)
+  {
+    GNUNET_STATISTICS_destroy (GSA_stats, GNUNET_NO);
+    GSA_stats = 0;
+  }
 }
 
 
@@ -135,6 +145,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
       GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0},
     {NULL, NULL, 0, 0}
   };
+  GSA_stats = GNUNET_STATISTICS_create ("ats", cfg);
   GAS_reservations_init ();
   GAS_performance_init (server);
   GAS_scheduling_init (server);
diff --git a/src/ats/gnunet-service-ats.h b/src/ats/gnunet-service-ats.h
new file mode 100644 (file)
index 0000000..b60332d
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+     This file is part of GNUnet.
+     (C) 2011 Christian Grothoff (and other contributing authors)
+
+     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 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file ats/gnunet-service-ats.h
+ * @brief ats service
+ * @author Matthias Wachs
+ * @author Christian Grothoff
+ */
+#ifndef GNUNET_SERVICE_ATS_H
+#define GNUNET_SERVICE_ATS_H
+
+#include "gnunet_statistics_service.h"
+
+/**
+ * Handle for statistics.
+ */
+extern struct GNUNET_STATISTICS_Handle *GSA_stats;
+
+
+#endif
index b3e838f3946c6b438366b27819b57780a397cb9b..99dc0e17a966207f9c76c7a4fb17a7d38dbcf199 100644 (file)
@@ -26,6 +26,7 @@
  */
 #include "platform.h"
 #include "gnunet_ats_service.h"
+#include "gnunet-service-ats.h"
 #include "gnunet-service-ats_addresses.h"
 #include "gnunet-service-ats_performance.h"
 #include "gnunet-service-ats_scheduling.h"
@@ -134,6 +135,14 @@ recalculate_assigned_bw ()
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Recalculating bandwidth for all active connections\n");
+  GNUNET_STATISTICS_update (GSA_stats,
+                           "# bandwidth recalculations performed",
+                           1,
+                           GNUNET_NO);
+  GNUNET_STATISTICS_set (GSA_stats,
+                        "# active addresses",
+                        active_addr_count,
+                        GNUNET_NO);
   GNUNET_CONTAINER_multihashmap_iterate (addresses, 
                                         &update_bw_it,
                                         NULL);
index e0e5e4c1823ddb99e3887345bf1ce1a4af5a27dc..24450031fdb74f6f8a376e0f52eeb6ab6be39ec1 100644 (file)
@@ -25,6 +25,7 @@
  * @author Christian Grothoff
  */
 #include "platform.h"
+#include "gnunet-service-ats.h"
 #include "gnunet-service-ats_addresses.h"
 #include "gnunet-service-ats_performance.h"
 #include "gnunet-service-ats_reservations.h"
@@ -183,10 +184,16 @@ GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer,
   strcpy (&addrp[plugin_addr_len], plugin_name);
   for (pc = pc_head; pc != NULL; pc = pc->next)
     if (pc->flag == START_FLAG_PERFORMANCE_WITH_PIC)
+    {
       GNUNET_SERVER_notification_context_unicast (nc,
                                                  pc->client,
                                                  &msg->header,
                                                  GNUNET_YES);
+      GNUNET_STATISTICS_update (GSA_stats,
+                               "# performance updates given to clients",
+                               1,
+                               GNUNET_NO);
+    }
 }
 
 
@@ -225,6 +232,10 @@ GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
   result.header.type = htons (GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT);
   result.amount = htonl (amount);
   result.res_delay = GNUNET_TIME_relative_hton (res_delay);
+  GNUNET_STATISTICS_update (GSA_stats,
+                           "# reservatin requests processed",
+                           1,
+                           GNUNET_NO);
   GNUNET_SERVER_notification_context_unicast (nc,
                                              client,
                                              &result.header,
@@ -266,6 +277,10 @@ GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client,
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
+  GNUNET_STATISTICS_update (GSA_stats,
+                           "# preference change requests processed",
+                           1,
+                           GNUNET_NO);
   pi = (const struct PreferenceInformation *) &msg[1];
   for (i=0;i<nump;i++)
     GAS_addresses_change_preference (&msg->peer,
index 242076568f3c3359701eaf76e28765c0bbecc628..3ed5eb1dd0f624a000f60a0671881b38b7571921 100644 (file)
@@ -25,6 +25,7 @@
  * @author Christian Grothoff
  */
 #include "platform.h"
+#include "gnunet-service-ats.h"
 #include "gnunet-service-ats_addresses.h"
 #include "gnunet-service-ats_scheduling.h"
 #include "ats.h"
@@ -114,6 +115,10 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe
 
   if (my_client == NULL)
     return;
+  GNUNET_STATISTICS_update (GSA_stats,
+                           "# address suggestions made",
+                           1,
+                           GNUNET_NO);
   GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
   GNUNET_assert (atsi_count < GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information));
   msg = (struct AddressSuggestionMessage*) buf;
@@ -153,6 +158,10 @@ GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client,
   const struct RequestAddressMessage * msg = (const struct RequestAddressMessage *) message;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "REQUEST_ADDRESS");
+  GNUNET_STATISTICS_update (GSA_stats,
+                           "# address requests received",
+                           1,
+                           GNUNET_NO);
   GNUNET_break (0 == ntohl (msg->reserved));
   GAS_addresses_request_address (&msg->peer);
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -210,6 +219,10 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
+  GNUNET_STATISTICS_update (GSA_stats,
+                           "# address updates received",
+                           1,
+                           GNUNET_NO);
   GAS_addresses_update (&m->peer,
                        plugin_name,
                        address,
@@ -276,6 +289,10 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
+  GNUNET_STATISTICS_update (GSA_stats,
+                           "# addresses destroyed",
+                           1,
+                           GNUNET_NO);
   GAS_addresses_destroy (&m->peer,
                         plugin_name,
                         address,