From 1b41ef00317b5f38a7860bfa4711a03552744241 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 19 Oct 2011 12:26:57 +0000 Subject: [PATCH] adding stats --- src/ats/Makefile.am | 5 ++-- src/ats/ats_api_scheduling.c | 1 + src/ats/gnunet-service-ats.c | 11 +++++++ src/ats/gnunet-service-ats.h | 38 ++++++++++++++++++++++++ src/ats/gnunet-service-ats_addresses.c | 9 ++++++ src/ats/gnunet-service-ats_performance.c | 15 ++++++++++ src/ats/gnunet-service-ats_scheduling.c | 17 +++++++++++ 7 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 src/ats/gnunet-service-ats.h diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index 6d945dd51..5cba4fccb 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am @@ -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 diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c index e62574918..955b21286 100644 --- a/src/ats/ats_api_scheduling.c +++ b/src/ats/ats_api_scheduling.c @@ -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))); diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c index 768bef1b7..e497a7aaf 100644 --- a/src/ats/gnunet-service-ats.c +++ b/src/ats/gnunet-service-ats.c @@ -27,12 +27,17 @@ #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 index 000000000..b60332d20 --- /dev/null +++ b/src/ats/gnunet-service-ats.h @@ -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 diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index b3e838f39..99dc0e17a 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -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); diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c index e0e5e4c18..24450031f 100644 --- a/src/ats/gnunet-service-ats_performance.c +++ b/src/ats/gnunet-service-ats_performance.c @@ -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;ipeer, diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c index 242076568..3ed5eb1dd 100644 --- a/src/ats/gnunet-service-ats_scheduling.c +++ b/src/ats/gnunet-service-ats_scheduling.c @@ -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, -- 2.25.1