From a94bcd89e2a7980dd9de9b17d3395002951240e5 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Wed, 18 Sep 2013 13:27:45 +0000 Subject: [PATCH] collecting log functionality mv structs to perf_ats header --- src/ats-tests/perf_ats.c | 169 +---------------------- src/ats-tests/perf_ats.h | 224 +++++++++++++++++++++++++++++++ src/ats-tests/perf_ats_logging.c | 65 ++++++++- src/ats-tests/perf_ats_logging.h | 35 ----- 4 files changed, 291 insertions(+), 202 deletions(-) create mode 100644 src/ats-tests/perf_ats.h delete mode 100644 src/ats-tests/perf_ats_logging.h diff --git a/src/ats-tests/perf_ats.c b/src/ats-tests/perf_ats.c index 9f4c48f8b..bdd306ec4 100644 --- a/src/ats-tests/perf_ats.c +++ b/src/ats-tests/perf_ats.c @@ -28,7 +28,7 @@ #include "gnunet_testbed_service.h" #include "gnunet_ats_service.h" #include "gnunet_core_service.h" -#include "perf_ats_logging.h" +#include "perf_ats.h" #define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) #define BENCHMARK_DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) @@ -45,52 +45,6 @@ #define TEST_MESSAGE_SIZE 1000 #define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) -/** - * Information about a benchmarking partner - */ -struct BenchmarkPartner -{ - /** - * The peer itself this partner belongs to - */ - struct BenchmarkPeer *me; - - /** - * The partner peer - */ - struct BenchmarkPeer *dest; - - /** - * Core transmit handles - */ - struct GNUNET_CORE_TransmitHandle *cth; - - /** - * Transport transmit handles - */ - struct GNUNET_TRANSPORT_TransmitHandle *tth; - - /** - * Number of messages sent to this partner - */ - unsigned int messages_sent; - - /** - * Number of bytes sent to this partner - */ - unsigned int bytes_sent; - - /** - * Number of messages received from this partner - */ - unsigned int messages_received; - - /** - * Number of bytes received from this partner - */ - unsigned int bytes_received; -}; - /** * Connect peers with testbed */ @@ -112,123 +66,6 @@ struct TestbedConnectOperation struct GNUNET_TESTBED_Operation *connect_op; }; -/** - * Information we track for a peer in the testbed. - */ -struct BenchmarkPeer -{ - /** - * Handle with testbed. - */ - struct GNUNET_TESTBED_Peer *peer; - - /** - * Unique identifier - */ - int no; - - /** - * Is this peer a measter: GNUNET_YES/GNUNET_NO - */ - int master; - - /** - * Peer ID - */ - struct GNUNET_PeerIdentity id; - - /** - * Testbed operation to get peer information - */ - struct GNUNET_TESTBED_Operation *peer_id_op; - - /** - * Testbed operation to connect to ATS performance service - */ - struct GNUNET_TESTBED_Operation *ats_perf_op; - - /** - * Testbed operation to connect to core - */ - struct GNUNET_TESTBED_Operation *comm_op; - - /** - * ATS performance handle - */ - struct GNUNET_ATS_PerformanceHandle *ats_perf_handle; - - /** - * Masters only: - * Testbed connect operations to connect masters to slaves - */ - struct TestbedConnectOperation *core_connect_ops; - - /** - * Core handle - */ - struct GNUNET_CORE_Handle *ch; - - /** - * Core handle - */ - struct GNUNET_TRANSPORT_Handle *th; - - /** - * Masters only: - * Peer to set ATS preferences for - */ - struct BenchmarkPeer *pref_partner; - - /** - * Masters only - * Progress task - */ - GNUNET_SCHEDULER_TaskIdentifier ats_task; - - /** - * Masters only - * Progress task - */ - double pref_value; - - /** - * Array of partners with num_slaves entries (if master) or - * num_master entries (if slave) - */ - struct BenchmarkPartner *partners; - - /** - * Number of core connections - */ - int core_connections; - - /** - * Masters only: - * Number of connections to slave peers - */ - int core_slave_connections; - - /** - * Total number of messages this peer has sent - */ - unsigned int total_messages_sent; - - /** - * Total number of bytes this peer has sent - */ - unsigned int total_bytes_sent; - - /** - * Total number of messages this peer has received - */ - unsigned int total_messages_received; - - /** - * Total number of bytes this peer has received - */ - unsigned int total_bytes_received; -}; - /** * Overall state of the performance benchmark */ @@ -614,7 +451,7 @@ do_benchmark () mps[c_m].ats_task = GNUNET_SCHEDULER_add_now (&ats_pref_task, &mps[c_m]); } if (GNUNET_YES == logging) - perf_logging_start(); + perf_logging_start (mps, num_masters); } static void @@ -1209,6 +1046,7 @@ main_run (void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers, mps[c_m].pref_value = TEST_ATS_PREFRENCE_START; mps[c_m].partners = GNUNET_malloc (num_slaves * sizeof (struct BenchmarkPeer)); + mps[c_m].num_partners = num_slaves; /* Initialize partners */ for (c_s = 0; c_s < num_slaves; c_s++) { @@ -1228,6 +1066,7 @@ main_run (void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers, sps[c_s].master = GNUNET_NO; sps[c_s].partners = GNUNET_malloc (num_masters * sizeof (struct BenchmarkPeer)); + sps[c_s].num_partners = num_masters; /* Initialize partners */ for (c_m = 0; c_m < num_masters; c_m++) { diff --git a/src/ats-tests/perf_ats.h b/src/ats-tests/perf_ats.h new file mode 100644 index 000000000..b8e0f1eb7 --- /dev/null +++ b/src/ats-tests/perf_ats.h @@ -0,0 +1,224 @@ +/* + This file is part of GNUnet. + (C) 2010-2013 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/perf_ats.c + * @brief ats benchmark: start peers and modify preferences, monitor change over time + * @author Christian Grothoff + * @author Matthias Wachs + */ +#include "platform.h" +#include "gnunet_util_lib.h" +#include "gnunet_testbed_service.h" +#include "gnunet_ats_service.h" +#include "gnunet_core_service.h" + +#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) +#define BENCHMARK_DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) +#define TESTNAME_PREFIX "perf_ats_" +#define DEFAULT_SLAVES_NUM 3 +#define DEFAULT_MASTERS_NUM 1 + +#define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) +#define TEST_ATS_PREFRENCE_START 1.0 +#define TEST_ATS_PREFRENCE_DELTA 1.0 + +#define TEST_MESSAGE_TYPE_PING 12345 +#define TEST_MESSAGE_TYPE_PONG 12346 +#define TEST_MESSAGE_SIZE 1000 +#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) + +/** + * Information about a benchmarking partner + */ +struct BenchmarkPartner +{ + /** + * The peer itself this partner belongs to + */ + struct BenchmarkPeer *me; + + /** + * The partner peer + */ + struct BenchmarkPeer *dest; + + /** + * Core transmit handles + */ + struct GNUNET_CORE_TransmitHandle *cth; + + /** + * Transport transmit handles + */ + struct GNUNET_TRANSPORT_TransmitHandle *tth; + + /** + * Number of messages sent to this partner + */ + unsigned int messages_sent; + + /** + * Number of bytes sent to this partner + */ + unsigned int bytes_sent; + + /** + * Number of messages received from this partner + */ + unsigned int messages_received; + + /** + * Number of bytes received from this partner + */ + unsigned int bytes_received; +}; + + +/** + * Information we track for a peer in the testbed. + */ +struct BenchmarkPeer +{ + /** + * Handle with testbed. + */ + struct GNUNET_TESTBED_Peer *peer; + + /** + * Unique identifier + */ + int no; + + /** + * Is this peer a measter: GNUNET_YES/GNUNET_NO + */ + int master; + + /** + * Peer ID + */ + struct GNUNET_PeerIdentity id; + + /** + * Testbed operation to get peer information + */ + struct GNUNET_TESTBED_Operation *peer_id_op; + + /** + * Testbed operation to connect to ATS performance service + */ + struct GNUNET_TESTBED_Operation *ats_perf_op; + + /** + * Testbed operation to connect to core + */ + struct GNUNET_TESTBED_Operation *comm_op; + + /** + * ATS performance handle + */ + struct GNUNET_ATS_PerformanceHandle *ats_perf_handle; + + /** + * Masters only: + * Testbed connect operations to connect masters to slaves + */ + struct TestbedConnectOperation *core_connect_ops; + + /** + * Core handle + */ + struct GNUNET_CORE_Handle *ch; + + /** + * Core handle + */ + struct GNUNET_TRANSPORT_Handle *th; + + /** + * Masters only: + * Peer to set ATS preferences for + */ + struct BenchmarkPeer *pref_partner; + + /** + * Masters only + * Progress task + */ + GNUNET_SCHEDULER_TaskIdentifier ats_task; + + /** + * Masters only + * Progress task + */ + double pref_value; + + /** + * Array of partners with num_slaves entries (if master) or + * num_master entries (if slave) + */ + struct BenchmarkPartner *partners; + + /** + * Number of partners + */ + int num_partners; + + /** + * Number of core connections + */ + int core_connections; + + /** + * Masters only: + * Number of connections to slave peers + */ + int core_slave_connections; + + /** + * Total number of messages this peer has sent + */ + unsigned int total_messages_sent; + + /** + * Total number of bytes this peer has sent + */ + unsigned int total_bytes_sent; + + /** + * Total number of messages this peer has received + */ + unsigned int total_messages_received; + + /** + * Total number of bytes this peer has received + */ + unsigned int total_bytes_received; +}; + + +void +perf_logging_stop (); + +void +perf_logging_start (struct BenchmarkPeer *masters, int num_masters); + + +/* end of file perf_ats.h */ diff --git a/src/ats-tests/perf_ats_logging.c b/src/ats-tests/perf_ats_logging.c index 9cdccf54b..1864e0180 100644 --- a/src/ats-tests/perf_ats_logging.c +++ b/src/ats-tests/perf_ats_logging.c @@ -25,18 +25,79 @@ */ #include "platform.h" #include "gnunet_util_lib.h" +#include "perf_ats.h" + +#define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500) + +static GNUNET_SCHEDULER_TaskIdentifier log_task; + +static struct BenchmarkPeer *peers; +static int num_peers; + +static void +write_to_file () +{ + +} + +static void +collect_log_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + int c_m; + int c_s; + log_task = GNUNET_SCHEDULER_NO_TASK; + + struct BenchmarkPeer *m; + struct BenchmarkPartner *p; + + for (c_m = 0; c_m < num_peers; c_m++) + { + m = &peers[c_m]; + for (c_s = 0; c_s < m->num_partners; c_s++) + { + p = &peers[c_m].partners[c_s]; + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, + "Master [%u]: slave [%u]\n", + m->no, p->dest->no); + } + } + + if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) + return; + + log_task = GNUNET_SCHEDULER_add_delayed (LOGGING_FREQUENCY, + &collect_log_task, NULL); +} + void perf_logging_stop () { + struct GNUNET_SCHEDULER_TaskContext tc; + + if (GNUNET_SCHEDULER_NO_TASK != log_task) + GNUNET_SCHEDULER_cancel (log_task); + log_task = GNUNET_SCHEDULER_NO_TASK; + tc.reason = GNUNET_SCHEDULER_REASON_SHUTDOWN; + collect_log_task (NULL, &tc); + GNUNET_log(GNUNET_ERROR_TYPE_INFO, - _("Start logging\n")); + _("Stop logging\n")); + + write_to_file (); } void -perf_logging_start () +perf_logging_start (struct BenchmarkPeer *masters, int num_masters) { GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Start logging\n")); + + peers = masters; + num_peers = num_masters; + + /* Schedule logging task */ + log_task = GNUNET_SCHEDULER_add_now (&collect_log_task, NULL); } /* end of file perf_ats_logging.c */ + diff --git a/src/ats-tests/perf_ats_logging.h b/src/ats-tests/perf_ats_logging.h deleted file mode 100644 index 94a9a6590..000000000 --- a/src/ats-tests/perf_ats_logging.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2010-2013 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/perf_ats_logging.c - * @brief ats benchmark: logging for performance tests - * @author Christian Grothoff - * @author Matthias Wachs - */ -#include "platform.h" -#include "gnunet_util_lib.h" - -void -perf_logging_stop (); - -void -perf_logging_start (); - -/* end of file perf_ats_logging.c */ -- 2.25.1