X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fats-tests%2Fperf_ats.c;h=6198d1464c9f3784261a83a5d803afa7967f4c73;hb=f6ff4c48d5d41875e03b59df33117cb4ba943877;hp=bdd306ec4abb00a4f07c4bbaf743a7e15de60442;hpb=a94bcd89e2a7980dd9de9b17d3395002951240e5;p=oweals%2Fgnunet.git diff --git a/src/ats-tests/perf_ats.c b/src/ats-tests/perf_ats.c index bdd306ec4..6198d1464 100644 --- a/src/ats-tests/perf_ats.c +++ b/src/ats-tests/perf_ats.c @@ -30,11 +30,6 @@ #include "gnunet_core_service.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) -#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 @@ -116,6 +111,11 @@ static int test_core; */ static char *solver; +/** + * Preference string + */ +static char *testname; + /** * Preference string */ @@ -134,7 +134,7 @@ static int num_masters; /** * Array of master peers */ -struct BenchmarkPeer *mps; +static struct BenchmarkPeer *mps; /** * Number slave peers @@ -143,7 +143,17 @@ static int num_slaves; /** * Array of slave peers */ -struct BenchmarkPeer *sps; +static struct BenchmarkPeer *sps; + +/** + * Benchmark duration + */ +static struct GNUNET_TIME_Relative perf_duration; + +/** + * Logging frequency + */ +static struct GNUNET_TIME_Relative log_frequency; /** * Benchmark state @@ -158,7 +168,7 @@ evaluate () unsigned int duration; struct BenchmarkPeer *mp; - duration = (BENCHMARK_DURATION.rel_value_us / (1000 * 1000)); + duration = (perf_duration.rel_value_us / (1000 * 1000)); for (c_m = 0; c_m < num_masters; c_m++) { mp = &mps[c_m]; @@ -354,21 +364,32 @@ static size_t comm_send_ready (void *cls, size_t size, void *buf) { static char msgbuf[TEST_MESSAGE_SIZE]; - struct BenchmarkPartner *partner = cls; + struct BenchmarkPartner *p = cls; struct GNUNET_MessageHeader *msg; if (GNUNET_YES == test_core) - partner->cth = NULL; + p->cth = NULL; else - partner->tth = NULL; + p->tth = NULL; + + if (NULL == buf) + { + GNUNET_break (0); + return 0; + } + if (size < TEST_MESSAGE_SIZE) + { + GNUNET_break (0); + return 0; + } GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Master [%u]: Sending PING to [%u]\n", - partner->me->no, partner->dest->no); + p->me->no, p->dest->no); - partner->messages_sent++; - partner->bytes_sent += TEST_MESSAGE_SIZE; - partner->me->total_messages_sent++; - partner->me->total_bytes_sent += TEST_MESSAGE_SIZE; + p->messages_sent++; + p->bytes_sent += TEST_MESSAGE_SIZE; + p->me->total_messages_sent++; + p->me->total_bytes_sent += TEST_MESSAGE_SIZE; msg = (struct GNUNET_MessageHeader *) &msgbuf; memset (&msgbuf, 'a', TEST_MESSAGE_SIZE); @@ -378,6 +399,24 @@ comm_send_ready (void *cls, size_t size, void *buf) return TEST_MESSAGE_SIZE; } +static void +comm_schedule_send (struct BenchmarkPartner *p) +{ + if (GNUNET_YES == test_core) + { + p->cth = GNUNET_CORE_notify_transmit_ready ( + p->me->ch, GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES, &p->dest->id, + TEST_MESSAGE_SIZE, &comm_send_ready, p); + } + else + { + p->tth = GNUNET_TRANSPORT_notify_transmit_ready ( + p->me->th, &p->dest->id, TEST_MESSAGE_SIZE, 0,GNUNET_TIME_UNIT_MINUTES, + &comm_send_ready, p); + } + +} + static void print_progress () { @@ -385,7 +424,7 @@ print_progress () progress_task = GNUNET_SCHEDULER_NO_TASK; fprintf (stderr, "%llu..", - (long long unsigned) BENCHMARK_DURATION.rel_value_us / (1000 * 1000) - calls); + (long long unsigned) perf_duration.rel_value_us / (1000 * 1000) - calls); calls++; progress_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, @@ -426,7 +465,7 @@ do_benchmark () if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) GNUNET_SCHEDULER_cancel (shutdown_task); - shutdown_task = GNUNET_SCHEDULER_add_delayed (BENCHMARK_DURATION, + shutdown_task = GNUNET_SCHEDULER_add_delayed (perf_duration, &do_shutdown, NULL ); progress_task = GNUNET_SCHEDULER_add_now (&print_progress, NULL ); @@ -435,23 +474,13 @@ do_benchmark () for (c_m = 0; c_m < num_masters; c_m++) { for (c_s = 0; c_s < num_slaves; c_s++) - { - if (GNUNET_YES == test_core) - mps[c_m].partners[c_s].cth = GNUNET_CORE_notify_transmit_ready ( - mps[c_m].ch, GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES, &sps[c_s].id, - TEST_MESSAGE_SIZE, &comm_send_ready, &mps[c_m].partners[c_s]); - else - { - mps[c_m].partners[c_s].tth = GNUNET_TRANSPORT_notify_transmit_ready ( - mps[c_m].th, &sps[c_s].id, TEST_MESSAGE_SIZE, 0,GNUNET_TIME_UNIT_MINUTES, - &comm_send_ready, &mps[c_m].partners[c_s]); - } - } + comm_schedule_send (&mps[c_m].partners[c_s]); if (pref_val != GNUNET_ATS_PREFERENCE_END) mps[c_m].ats_task = GNUNET_SCHEDULER_add_now (&ats_pref_task, &mps[c_m]); } if (GNUNET_YES == logging) - perf_logging_start (mps, num_masters); + perf_logging_start (log_frequency, testname, mps, num_masters); + } static void @@ -655,8 +684,8 @@ comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other, struct BenchmarkPartner *p = NULL; for (c_m = 0; c_m < num_masters; c_m++) { - if (0 - == memcmp (other, &me->partners[c_m].dest->id, + /* Find a partner with other as destination */ + if (0 == memcmp (other, &me->partners[c_m].dest->id, sizeof(struct GNUNET_PeerIdentity))) { p = &me->partners[c_m]; @@ -728,21 +757,7 @@ comm_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other, p->me->total_messages_received++; p->me->total_bytes_received += TEST_MESSAGE_SIZE; - if (GNUNET_YES == test_core) - { - GNUNET_assert (NULL == p->cth); - p->cth = GNUNET_CORE_notify_transmit_ready (me->ch, GNUNET_NO, 0, - GNUNET_TIME_UNIT_MINUTES, &p->dest->id, TEST_MESSAGE_SIZE, - &comm_send_ready, p); - } - else - { - GNUNET_assert (NULL == p->tth); - p->tth = GNUNET_TRANSPORT_notify_transmit_ready ( - me->th, &p->dest->id, TEST_MESSAGE_SIZE, 0,GNUNET_TIME_UNIT_MINUTES, - &comm_send_ready, p); - } - + comm_schedule_send (p); return GNUNET_OK; } @@ -1168,6 +1183,22 @@ main (int argc, char *argv[]) return -1; } + for (c = 0; c < (argc - 1); c++) + { + if (0 == strcmp (argv[c], "-d")) + break; + } + if (c < argc - 1) + { + if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1], &perf_duration)) + fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]); + } + else + { + perf_duration = BENCHMARK_DURATION; + } + fprintf (stderr, "Running benchmark for %llu secs\n", (unsigned long long) (perf_duration.rel_value_us) / (1000 * 1000)); + for (c = 0; c < (argc - 1); c++) { if (0 == strcmp (argv[c], "-s")) @@ -1207,6 +1238,27 @@ main (int argc, char *argv[]) logging = GNUNET_YES; } + if (GNUNET_YES == logging) + { + for (c = 0; c < (argc - 1); c++) + { + if (0 == strcmp (argv[c], "-f")) + break; + } + if (c < argc - 1) + { + if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1], &log_frequency)) + fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]); + } + else + { + log_frequency = LOGGING_FREQUENCY; + } + fprintf (stderr, "Using log frequency %llu ms\n", + (unsigned long long) (log_frequency.rel_value_us) / (1000)); + } + + GNUNET_asprintf (&testname, "%s_%s_%s",solver, comm_name, pref_str); if (num_slaves < num_masters) { @@ -1240,6 +1292,7 @@ main (int argc, char *argv[]) GNUNET_free(pref_str); GNUNET_free(conf_name); GNUNET_free(test_name); + GNUNET_free(testname); GNUNET_free (comm_name); GNUNET_free(mps); GNUNET_free(sps);