diff options
author | Julius Bünger <buenger@mytum.de> | 2018-01-15 18:13:39 +0100 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2018-01-16 13:18:02 +0100 |
commit | 5441f24ab5327f576b941e8e1e14a00270690759 (patch) | |
tree | 19d0bc74f3ec43be5e8ea7683b47549143533826 /src/rps/test_rps.c | |
parent | 7141b7243358344e865c4ce2c9692872fc9006cb (diff) | |
download | gnunet-5441f24ab5327f576b941e8e1e14a00270690759.tar.gz gnunet-5441f24ab5327f576b941e8e1e14a00270690759.zip |
rps: start using statistics service
Diffstat (limited to 'src/rps/test_rps.c')
-rw-r--r-- | src/rps/test_rps.c | 204 |
1 files changed, 202 insertions, 2 deletions
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c index 7d61ae6a1..c958194a8 100644 --- a/src/rps/test_rps.c +++ b/src/rps/test_rps.c | |||
@@ -41,6 +41,11 @@ | |||
41 | static uint32_t num_peers; | 41 | static uint32_t num_peers; |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * How many peers are ready to shutdown? | ||
45 | */ | ||
46 | static uint32_t num_shutdown_ready; | ||
47 | |||
48 | /** | ||
44 | * How long do we run the test? | 49 | * How long do we run the test? |
45 | */ | 50 | */ |
46 | //#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 51 | //#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
@@ -236,6 +241,16 @@ struct RPSPeer | |||
236 | * Pending operation on that peer | 241 | * Pending operation on that peer |
237 | */ | 242 | */ |
238 | const struct OpListEntry *entry_op_manage; | 243 | const struct OpListEntry *entry_op_manage; |
244 | |||
245 | /** | ||
246 | * Testbed operation to connect to statistics service | ||
247 | */ | ||
248 | struct GNUNET_TESTBED_Operation *stat_op; | ||
249 | |||
250 | /** | ||
251 | * Handle to the statistics service | ||
252 | */ | ||
253 | struct GNUNET_STATISTICS_Handle *stats_h; | ||
239 | }; | 254 | }; |
240 | 255 | ||
241 | 256 | ||
@@ -318,7 +333,7 @@ typedef void (*ReplyHandle) (void *cls, | |||
318 | /** | 333 | /** |
319 | * Called directly before disconnecting from the service | 334 | * Called directly before disconnecting from the service |
320 | */ | 335 | */ |
321 | typedef void (*PostTest) (void *cls, struct GNUNET_RPS_Handle *h); | 336 | typedef void (*PostTest) (const struct RPSPeer *peer); |
322 | 337 | ||
323 | /** | 338 | /** |
324 | * Function called after disconnect to evaluate test success | 339 | * Function called after disconnect to evaluate test success |
@@ -355,6 +370,21 @@ enum OPTION_QUICK_QUIT { | |||
355 | }; | 370 | }; |
356 | 371 | ||
357 | /** | 372 | /** |
373 | * @brief Do we collect statistics at the end? | ||
374 | */ | ||
375 | enum OPTION_COLLECT_STATISTICS { | ||
376 | /** | ||
377 | * @brief We collect statistics at the end | ||
378 | */ | ||
379 | COLLECT_STATISTICS, | ||
380 | |||
381 | /** | ||
382 | * @brief We do not collect statistics at the end | ||
383 | */ | ||
384 | NO_COLLECT_STATISTICS, | ||
385 | }; | ||
386 | |||
387 | /** | ||
358 | * Structure to define a single test | 388 | * Structure to define a single test |
359 | */ | 389 | */ |
360 | struct SingleTestRun | 390 | struct SingleTestRun |
@@ -413,6 +443,11 @@ struct SingleTestRun | |||
413 | * Quit test before timeout? | 443 | * Quit test before timeout? |
414 | */ | 444 | */ |
415 | enum OPTION_QUICK_QUIT have_quick_quit; | 445 | enum OPTION_QUICK_QUIT have_quick_quit; |
446 | |||
447 | /** | ||
448 | * Collect statistics at the end? | ||
449 | */ | ||
450 | enum OPTION_COLLECT_STATISTICS have_collect_statistics; | ||
416 | } cur_test_run; | 451 | } cur_test_run; |
417 | 452 | ||
418 | /** | 453 | /** |
@@ -575,9 +610,21 @@ shutdown_op (void *cls) | |||
575 | churn_task = NULL; | 610 | churn_task = NULL; |
576 | } | 611 | } |
577 | for (i = 0; i < num_peers; i++) | 612 | for (i = 0; i < num_peers; i++) |
613 | { | ||
578 | if (NULL != rps_peers[i].op) | 614 | if (NULL != rps_peers[i].op) |
579 | GNUNET_TESTBED_operation_done (rps_peers[i].op); | 615 | GNUNET_TESTBED_operation_done (rps_peers[i].op); |
580 | GNUNET_SCHEDULER_shutdown (); | 616 | if (NULL != cur_test_run.post_test) |
617 | { | ||
618 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i); | ||
619 | cur_test_run.post_test (&rps_peers[i]); | ||
620 | } | ||
621 | } | ||
622 | /* If we do not collect statistics, shut down directly */ | ||
623 | if (NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics || | ||
624 | num_peers <= num_shutdown_ready) | ||
625 | { | ||
626 | GNUNET_SCHEDULER_shutdown (); | ||
627 | } | ||
581 | } | 628 | } |
582 | 629 | ||
583 | 630 | ||
@@ -753,6 +800,76 @@ rps_connect_adapter (void *cls, | |||
753 | return h; | 800 | return h; |
754 | } | 801 | } |
755 | 802 | ||
803 | /** | ||
804 | * Called to open a connection to the peer's statistics | ||
805 | * | ||
806 | * @param cls peer context | ||
807 | * @param cfg configuration of the peer to connect to; will be available until | ||
808 | * GNUNET_TESTBED_operation_done() is called on the operation returned | ||
809 | * from GNUNET_TESTBED_service_connect() | ||
810 | * @return service handle to return in 'op_result', NULL on error | ||
811 | */ | ||
812 | static void * | ||
813 | stat_connect_adapter (void *cls, | ||
814 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
815 | { | ||
816 | struct RPSPeer *peer = cls; | ||
817 | |||
818 | peer->stats_h = GNUNET_STATISTICS_create ("rps-profiler", cfg); | ||
819 | return peer->stats_h; | ||
820 | } | ||
821 | |||
822 | /** | ||
823 | * Called to disconnect from peer's statistics service | ||
824 | * | ||
825 | * @param cls peer context | ||
826 | * @param op_result service handle returned from the connect adapter | ||
827 | */ | ||
828 | static void | ||
829 | stat_disconnect_adapter (void *cls, void *op_result) | ||
830 | { | ||
831 | struct RPSPeer *peer = cls; | ||
832 | |||
833 | //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel | ||
834 | // (peer->stats_h, "core", "# peers connected", | ||
835 | // stat_iterator, peer)); | ||
836 | //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel | ||
837 | // (peer->stats_h, "nse", "# peers connected", | ||
838 | // stat_iterator, peer)); | ||
839 | GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); | ||
840 | peer->stats_h = NULL; | ||
841 | } | ||
842 | |||
843 | /** | ||
844 | * Called after successfully opening a connection to a peer's statistics | ||
845 | * service; we register statistics monitoring for CORE and NSE here. | ||
846 | * | ||
847 | * @param cls the callback closure from functions generating an operation | ||
848 | * @param op the operation that has been finished | ||
849 | * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter() | ||
850 | * @param emsg error message in case the operation has failed; will be NULL if | ||
851 | * operation has executed successfully. | ||
852 | */ | ||
853 | static void | ||
854 | stat_complete_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | ||
855 | void *ca_result, const char *emsg ) | ||
856 | { | ||
857 | //struct GNUNET_STATISTICS_Handle *sh = ca_result; | ||
858 | //struct RPSPeer *peer = (struct RPSPeer *) cls; | ||
859 | |||
860 | if (NULL != emsg) | ||
861 | { | ||
862 | GNUNET_break (0); | ||
863 | return; | ||
864 | } | ||
865 | //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch | ||
866 | // (sh, "core", "# peers connected", | ||
867 | // stat_iterator, peer)); | ||
868 | //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch | ||
869 | // (sh, "nse", "# peers connected", | ||
870 | // stat_iterator, peer)); | ||
871 | } | ||
872 | |||
756 | 873 | ||
757 | /** | 874 | /** |
758 | * Adapter function called to destroy connection to | 875 | * Adapter function called to destroy connection to |
@@ -1541,6 +1658,71 @@ profiler_eval (void) | |||
1541 | return evaluate (); | 1658 | return evaluate (); |
1542 | } | 1659 | } |
1543 | 1660 | ||
1661 | /** | ||
1662 | * Continuation called by #GNUNET_STATISTICS_get() functions. | ||
1663 | * | ||
1664 | * Checks whether all peers received their statistics yet. | ||
1665 | * Issues the shutdown. | ||
1666 | * | ||
1667 | * @param cls closure | ||
1668 | * @param success #GNUNET_OK if statistics were | ||
1669 | * successfully obtained, #GNUNET_SYSERR if not. | ||
1670 | */ | ||
1671 | void | ||
1672 | post_test_shutdown_ready_cb (void *cls, | ||
1673 | int success) | ||
1674 | { | ||
1675 | const struct RPSPeer *rps_peer = (const struct RPSPeer *) cls; | ||
1676 | if (NULL != rps_peer->stat_op) | ||
1677 | { | ||
1678 | GNUNET_TESTBED_operation_done (rps_peer->stat_op); | ||
1679 | } | ||
1680 | num_shutdown_ready++; | ||
1681 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1682 | "%" PRIu32 " of %" PRIu32 " Peers are ready to shut down\n", | ||
1683 | num_shutdown_ready, | ||
1684 | num_peers); | ||
1685 | if (num_peers <= num_shutdown_ready) | ||
1686 | { | ||
1687 | GNUNET_SCHEDULER_shutdown (); | ||
1688 | } | ||
1689 | } | ||
1690 | |||
1691 | /** | ||
1692 | * Callback function to process statistic values. | ||
1693 | * | ||
1694 | * @param cls closure | ||
1695 | * @param subsystem name of subsystem that created the statistic | ||
1696 | * @param name the name of the datum | ||
1697 | * @param value the current value | ||
1698 | * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not | ||
1699 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | ||
1700 | */ | ||
1701 | int | ||
1702 | stat_iterator (void *cls, | ||
1703 | const char *subsystem, | ||
1704 | const char *name, | ||
1705 | uint64_t value, | ||
1706 | int is_persistent) | ||
1707 | { | ||
1708 | //const struct RPSPeer *rps_peer = (const struct RPSPeer *) cls; | ||
1709 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %" PRIu64 "\n", value); | ||
1710 | return GNUNET_OK; | ||
1711 | } | ||
1712 | |||
1713 | void post_profiler (const struct RPSPeer *rps_peer) | ||
1714 | { | ||
1715 | if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics) | ||
1716 | { | ||
1717 | GNUNET_STATISTICS_get (rps_peer->stats_h, | ||
1718 | "rps", | ||
1719 | "# rounds", | ||
1720 | post_test_shutdown_ready_cb, | ||
1721 | stat_iterator, | ||
1722 | (struct RPSPeer *) rps_peer); | ||
1723 | } | ||
1724 | } | ||
1725 | |||
1544 | 1726 | ||
1545 | /*********************************************************************** | 1727 | /*********************************************************************** |
1546 | * /Definition of tests | 1728 | * /Definition of tests |
@@ -1623,6 +1805,19 @@ run (void *cls, | |||
1623 | &rps_disconnect_adapter, | 1805 | &rps_disconnect_adapter, |
1624 | &rps_peers[i]); | 1806 | &rps_peers[i]); |
1625 | } | 1807 | } |
1808 | /* Connect all peers to statistics service */ | ||
1809 | if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics) | ||
1810 | { | ||
1811 | rps_peers[i].stat_op = | ||
1812 | GNUNET_TESTBED_service_connect (NULL, | ||
1813 | peers[i], | ||
1814 | "statistics", | ||
1815 | stat_complete_cb, | ||
1816 | &rps_peers[i], | ||
1817 | &stat_connect_adapter, | ||
1818 | &stat_disconnect_adapter, | ||
1819 | &rps_peers[i]); | ||
1820 | } | ||
1626 | } | 1821 | } |
1627 | 1822 | ||
1628 | if (NULL != churn_task) | 1823 | if (NULL != churn_task) |
@@ -1644,12 +1839,15 @@ main (int argc, char *argv[]) | |||
1644 | int ret_value; | 1839 | int ret_value; |
1645 | 1840 | ||
1646 | num_peers = 5; | 1841 | num_peers = 5; |
1842 | num_shutdown_ready = 0; | ||
1647 | cur_test_run.name = "test-rps-default"; | 1843 | cur_test_run.name = "test-rps-default"; |
1648 | cur_test_run.init_peer = default_init_peer; | 1844 | cur_test_run.init_peer = default_init_peer; |
1649 | cur_test_run.pre_test = NULL; | 1845 | cur_test_run.pre_test = NULL; |
1650 | cur_test_run.reply_handle = default_reply_handle; | 1846 | cur_test_run.reply_handle = default_reply_handle; |
1651 | cur_test_run.eval_cb = default_eval_cb; | 1847 | cur_test_run.eval_cb = default_eval_cb; |
1848 | cur_test_run.post_test = NULL; | ||
1652 | cur_test_run.have_churn = HAVE_CHURN; | 1849 | cur_test_run.have_churn = HAVE_CHURN; |
1850 | cur_test_run.have_collect_statistics = NO_COLLECT_STATISTICS; | ||
1653 | churn_task = NULL; | 1851 | churn_task = NULL; |
1654 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); | 1852 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); |
1655 | 1853 | ||
@@ -1767,10 +1965,12 @@ main (int argc, char *argv[]) | |||
1767 | cur_test_run.main_test = profiler_cb; | 1965 | cur_test_run.main_test = profiler_cb; |
1768 | cur_test_run.reply_handle = profiler_reply_handle; | 1966 | cur_test_run.reply_handle = profiler_reply_handle; |
1769 | cur_test_run.eval_cb = profiler_eval; | 1967 | cur_test_run.eval_cb = profiler_eval; |
1968 | cur_test_run.post_test = post_profiler; | ||
1770 | cur_test_run.request_interval = 2; | 1969 | cur_test_run.request_interval = 2; |
1771 | cur_test_run.num_requests = 5; | 1970 | cur_test_run.num_requests = 5; |
1772 | cur_test_run.have_churn = HAVE_CHURN; | 1971 | cur_test_run.have_churn = HAVE_CHURN; |
1773 | cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; | 1972 | cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; |
1973 | cur_test_run.have_collect_statistics = COLLECT_STATISTICS; | ||
1774 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300); | 1974 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300); |
1775 | 1975 | ||
1776 | /* 'Clean' directory */ | 1976 | /* 'Clean' directory */ |