aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaximilian Szengel <gnunet@maxsz.de>2012-11-05 21:01:49 +0000
committerMaximilian Szengel <gnunet@maxsz.de>2012-11-05 21:01:49 +0000
commit34cc46c6a9cd0df400e1276538114b90991fa02c (patch)
tree5a5294cf3cb4856b6088df13970c001053c4bd16 /src
parent9b0414d6f98f33d7e1c33dafe105eb58da0bf79b (diff)
downloadgnunet-34cc46c6a9cd0df400e1276538114b90991fa02c.tar.gz
gnunet-34cc46c6a9cd0df400e1276538114b90991fa02c.zip
regex profiler fixes
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-regex-profiler.c227
-rw-r--r--src/mesh/gnunet-service-regexprofiler.c16
2 files changed, 145 insertions, 98 deletions
diff --git a/src/mesh/gnunet-regex-profiler.c b/src/mesh/gnunet-regex-profiler.c
index 49eb2b91c..1157149e3 100644
--- a/src/mesh/gnunet-regex-profiler.c
+++ b/src/mesh/gnunet-regex-profiler.c
@@ -237,6 +237,11 @@ static struct GNUNET_TESTBED_Operation *topology_op;
237static GNUNET_SCHEDULER_TaskIdentifier abort_task; 237static GNUNET_SCHEDULER_TaskIdentifier abort_task;
238 238
239/** 239/**
240 * Shutdown task identifier
241 */
242static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
243
244/**
240 * Host registration task identifier 245 * Host registration task identifier
241 */ 246 */
242static GNUNET_SCHEDULER_TaskIdentifier register_hosts_task; 247static GNUNET_SCHEDULER_TaskIdentifier register_hosts_task;
@@ -447,6 +452,7 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
447 char output_buffer[512]; 452 char output_buffer[512];
448 size_t size; 453 size_t size;
449 454
455 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
450 if (GNUNET_SCHEDULER_NO_TASK != abort_task) 456 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
451 GNUNET_SCHEDULER_cancel (abort_task); 457 GNUNET_SCHEDULER_cancel (abort_task);
452 if (GNUNET_SCHEDULER_NO_TASK != register_hosts_task) 458 if (GNUNET_SCHEDULER_NO_TASK != register_hosts_task)
@@ -525,10 +531,12 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
525static void 531static void
526do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 532do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
527{ 533{
528 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting\n"); 534 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting...\n");
529 abort_task = GNUNET_SCHEDULER_NO_TASK; 535 abort_task = GNUNET_SCHEDULER_NO_TASK;
530 result = GNUNET_SYSERR; 536 result = GNUNET_SYSERR;
531 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 537 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
538 GNUNET_SCHEDULER_cancel (shutdown_task);
539 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
532} 540}
533 541
534 542
@@ -639,14 +647,14 @@ stats_cb (void *cls,
639 if (++peer_cnt == num_search_strings) 647 if (++peer_cnt == num_search_strings)
640 { 648 {
641 struct GNUNET_TIME_Relative delay = { 100 }; 649 struct GNUNET_TIME_Relative delay = { 100 };
642 GNUNET_SCHEDULER_add_delayed (delay, &do_shutdown, NULL); 650 shutdown_task = GNUNET_SCHEDULER_add_delayed (delay, &do_shutdown, NULL);
643 } 651 }
644} 652}
645 653
646 654
647/** 655/**
648 * Function called by testbed once we are connected to stats service. Create a 656 * Function called by testbed once we are connected to stats
649 * mesh tunnel and try to match the peer's string. 657 * service. Get the statistics for the services of interest.
650 * 658 *
651 * @param cls the 'struct RegexPeer' for which we connected to stats 659 * @param cls the 'struct RegexPeer' for which we connected to stats
652 * @param op connect operation handle 660 * @param op connect operation handle
@@ -671,21 +679,40 @@ stats_connect_cb (void *cls,
671 return; 679 return;
672 } 680 }
673 681
674 GNUNET_assert (NULL != peer->mesh_handle);
675
676 peer->stats_handle = ca_result; 682 peer->stats_handle = ca_result;
677 683
678 peer->mesh_tunnel_handle = GNUNET_MESH_tunnel_create (peer->mesh_handle, 684 if (NULL == GNUNET_STATISTICS_get (peer->stats_handle, "mesh", NULL,
679 NULL, 685 GNUNET_TIME_UNIT_FOREVER_REL,
680 &mesh_peer_connect_handler, 686 NULL,
681 &mesh_peer_disconnect_handler, 687 &stats_iterator, peer))
682 peer); 688 {
683 689 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
684 peer->prof_start_time = GNUNET_TIME_absolute_get (); 690 "Could not get mesh statistics of peer %u!\n", peer->id);
685 691 }
686 peer->search_str_matched = GNUNET_NO; 692 if (NULL == GNUNET_STATISTICS_get (peer->stats_handle, "regexprofiler", NULL,
687 GNUNET_MESH_peer_request_connect_by_string (peer->mesh_tunnel_handle, 693 GNUNET_TIME_UNIT_FOREVER_REL,
688 peer->search_str); 694 NULL,
695 &stats_iterator, peer))
696 {
697 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
698 "Could not get regexprofiler statistics of peer %u!\n", peer->id);
699 }
700 if (NULL == GNUNET_STATISTICS_get (peer->stats_handle, "transport", NULL,
701 GNUNET_TIME_UNIT_FOREVER_REL,
702 NULL,
703 &stats_iterator, peer))
704 {
705 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
706 "Could not get transport statistics of peer %u!\n", peer->id);
707 }
708 if (NULL == GNUNET_STATISTICS_get (peer->stats_handle, "dht", NULL,
709 GNUNET_TIME_UNIT_FOREVER_REL,
710 &stats_cb,
711 &stats_iterator, peer))
712 {
713 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
714 "Could not get dht statistics of peer %u!\n", peer->id);
715 }
689} 716}
690 717
691 718
@@ -730,6 +757,14 @@ mesh_peer_connect_handler (void *cls,
730 char output_buffer[512]; 757 char output_buffer[512];
731 size_t size; 758 size_t size;
732 759
760 if (GNUNET_YES == peer->search_str_matched)
761 {
762 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
763 "String %s on peer %u already matched!\n",
764 peer->search_str, peer->id);
765 return;
766 }
767
733 peers_found++; 768 peers_found++;
734 769
735 if (NULL == peer_id) 770 if (NULL == peer_id)
@@ -763,58 +798,35 @@ mesh_peer_connect_handler (void *cls,
763 size = 798 size =
764 GNUNET_snprintf (output_buffer, 799 GNUNET_snprintf (output_buffer,
765 sizeof (output_buffer), 800 sizeof (output_buffer),
766 "Peer: %u (%p)\nHost: %s\nPolicy file: %s\nSearch string: %s\nSearch duration: %s\n\n", 801 "%p Peer: %u\n%p Host: %s\n%p Policy file: %s\n%p Search string: %s\n%p Search duration: %s\n\n",
802 peer,
767 peer->id, 803 peer->id,
768 peer, 804 peer,
769 GNUNET_TESTBED_host_get_hostname (peer->host_handle), 805 GNUNET_TESTBED_host_get_hostname (peer->host_handle),
806 peer,
770 peer->policy_file, 807 peer->policy_file,
808 peer,
771 peer->search_str, 809 peer->search_str,
810 peer,
772 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO)); 811 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
773 812
774 if (size != GNUNET_DISK_file_write (data_file, output_buffer, size)) 813 if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
775 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); 814 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
776 } 815 }
816 }
777 817
778 if (NULL == peer->stats_handle) 818 GNUNET_TESTBED_operation_done (peer->mesh_op_handle);
779 { 819 peer->mesh_op_handle = NULL;
780 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
781 "Cannot get statistics for peer %u, stats handle is NULL!\n");
782 return;
783 }
784 820
785 if (NULL == GNUNET_STATISTICS_get (peer->stats_handle, "mesh", NULL, 821 peer->stats_op_handle =
786 GNUNET_TIME_UNIT_FOREVER_REL, 822 GNUNET_TESTBED_service_connect (NULL,
787 NULL, 823 peer->peer_handle,
788 &stats_iterator, peer)) 824 "statistics",
789 { 825 &stats_connect_cb,
790 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 826 peer,
791 "Could not get mesh statistics of peer %u!\n", peer->id); 827 &stats_ca,
792 } 828 &stats_da,
793 if (NULL == GNUNET_STATISTICS_get (peer->stats_handle, "regexprofiler", NULL, 829 peer);
794 GNUNET_TIME_UNIT_FOREVER_REL,
795 NULL,
796 &stats_iterator, peer))
797 {
798 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
799 "Could not get regexprofiler statistics of peer %u!\n", peer->id);
800 }
801 if (NULL == GNUNET_STATISTICS_get (peer->stats_handle, "transport", NULL,
802 GNUNET_TIME_UNIT_FOREVER_REL,
803 NULL,
804 &stats_iterator, peer))
805 {
806 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
807 "Could not get transport statistics of peer %u!\n", peer->id);
808 }
809 if (NULL == GNUNET_STATISTICS_get (peer->stats_handle, "dht", NULL,
810 GNUNET_TIME_UNIT_FOREVER_REL,
811 &stats_cb,
812 &stats_iterator, peer))
813 {
814 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
815 "Could not get dht statistics of peer %u!\n", peer->id);
816 }
817 }
818 830
819 if (peers_found == num_search_strings) 831 if (peers_found == num_search_strings)
820 { 832 {
@@ -848,14 +860,14 @@ do_connect_by_string_timeout (void *cls,
848 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 860 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
849 "Found %i of %i strings\n", peers_found, num_search_strings); 861 "Found %i of %i strings\n", peers_found, num_search_strings);
850 862
851 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 863 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
852} 864}
853 865
854 866
855/** 867/**
856 * Connect by string task that is run to search for a string in the NFA. It 868 * Connect by string task that is run to search for a string in the
857 * first connects to the mesh service, then connects to the stats service of 869 * NFA. It first connects to the mesh service and when a connection is
858 * this peer and then it starts the string search. 870 * established it starts to search for the string.
859 * 871 *
860 * @param cls NULL 872 * @param cls NULL
861 * @param tc the task context 873 * @param tc the task context
@@ -864,34 +876,27 @@ static void
864do_connect_by_string (void *cls, 876do_connect_by_string (void *cls,
865 const struct GNUNET_SCHEDULER_TaskContext * tc) 877 const struct GNUNET_SCHEDULER_TaskContext * tc)
866{ 878{
867 unsigned int search_cnt;
868 struct RegexPeer *peer;
869
870 printf ("Starting string search.\n"); 879 printf ("Starting string search.\n");
871 fflush (stdout); 880 fflush (stdout);
872 881
873 for (search_cnt = 0; search_cnt < num_search_strings; search_cnt++) 882 peers[0].search_str = search_strings[0];
874 { 883 peers[0].search_str_matched = GNUNET_NO;
875 peer = &peers[search_cnt % num_peers];
876 peer->search_str = search_strings[search_cnt];
877 peer->search_str_matched = GNUNET_NO;
878 884
879 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 885 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
880 "Searching for string \"%s\" on peer %d with file %s\n", 886 "Searching for string \"%s\" on peer %d with file %s\n",
881 peer->search_str, (search_cnt % num_peers), peer->policy_file); 887 peers[0].search_str, 0, peers[0].policy_file);
882 888
883 /* First connect to mesh service, then connect to stats service 889 /* First connect to mesh service, then search for string. Next
884 and then try connecting by string in stats_connect_cb */ 890 connect will be in mesh_connect_cb */
885 peer->mesh_op_handle = 891 peers[0].mesh_op_handle =
886 GNUNET_TESTBED_service_connect (NULL, 892 GNUNET_TESTBED_service_connect (NULL,
887 peers->peer_handle, 893 peers[0].peer_handle,
888 "mesh", 894 "mesh",
889 &mesh_connect_cb, 895 &mesh_connect_cb,
890 peer, 896 &peers[0],
891 &mesh_ca, 897 &mesh_ca,
892 &mesh_da, 898 &mesh_da,
893 peer); 899 &peers[0]);
894 }
895 900
896 search_timeout_task = GNUNET_SCHEDULER_add_delayed (search_timeout, 901 search_timeout_task = GNUNET_SCHEDULER_add_delayed (search_timeout,
897 &do_connect_by_string_timeout, NULL); 902 &do_connect_by_string_timeout, NULL);
@@ -912,6 +917,8 @@ static void
912mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, 917mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
913 void *ca_result, const char *emsg) 918 void *ca_result, const char *emsg)
914{ 919{
920 static unsigned int peer_cnt;
921 unsigned int next_p;
915 struct RegexPeer *peer = (struct RegexPeer *) cls; 922 struct RegexPeer *peer = (struct RegexPeer *) cls;
916 923
917 if (NULL != emsg || NULL == op || NULL == ca_result) 924 if (NULL != emsg || NULL == op || NULL == ca_result)
@@ -920,20 +927,44 @@ mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
920 GNUNET_assert (0); 927 GNUNET_assert (0);
921 } 928 }
922 929
923 GNUNET_assert (peer->mesh_handle != NULL); 930 GNUNET_assert (NULL != peer->mesh_handle);
924 GNUNET_assert (peer->mesh_op_handle == op); 931 GNUNET_assert (peer->mesh_op_handle == op);
925 GNUNET_assert (peer->mesh_handle == ca_result); 932 GNUNET_assert (peer->mesh_handle == ca_result);
926 933
927 /* First connect to the stats service, then start to search */ 934 peer->mesh_tunnel_handle =
928 peer->stats_op_handle = 935 GNUNET_MESH_tunnel_create (peer->mesh_handle,
929 GNUNET_TESTBED_service_connect (NULL, 936 NULL,
930 peers->peer_handle, 937 &mesh_peer_connect_handler,
931 "statistics", 938 &mesh_peer_disconnect_handler,
932 &stats_connect_cb, 939 peer);
933 peer, 940
934 &stats_ca, 941 peer->prof_start_time = GNUNET_TIME_absolute_get ();
935 &stats_da, 942
936 peer); 943 peer->search_str_matched = GNUNET_NO;
944 GNUNET_MESH_peer_request_connect_by_string (peer->mesh_tunnel_handle,
945 peer->search_str);
946
947 if (peer_cnt < num_search_strings)
948 {
949 next_p = ((++peer_cnt) % num_peers);
950
951 peers[next_p].search_str = search_strings[next_p];
952 peers[next_p].search_str_matched = GNUNET_NO;
953
954 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
955 "Searching for string \"%s\" on peer %d with file %s\n",
956 peers[next_p].search_str, next_p, peers[next_p].policy_file);
957
958 peers[next_p].mesh_op_handle =
959 GNUNET_TESTBED_service_connect (NULL,
960 peers[next_p].peer_handle,
961 "mesh",
962 &mesh_connect_cb,
963 &peers[next_p],
964 &mesh_ca,
965 &mesh_da,
966 &peers[next_p]);
967 }
937} 968}
938 969
939 970
@@ -1627,13 +1658,13 @@ run (void *cls, char *const *args, const char *cfgfile,
1627 if (num_hosts != nhost) 1658 if (num_hosts != nhost)
1628 { 1659 {
1629 fprintf (stderr, _("Exiting\n")); 1660 fprintf (stderr, _("Exiting\n"));
1630 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 1661 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1631 return; 1662 return;
1632 } 1663 }
1633 if (NULL == config) 1664 if (NULL == config)
1634 { 1665 {
1635 fprintf (stderr, _("No configuration file given. Exiting\n")); 1666 fprintf (stderr, _("No configuration file given. Exiting\n"));
1636 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 1667 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1637 return; 1668 return;
1638 } 1669 }
1639 if ( (NULL != data_filename) && 1670 if ( (NULL != data_filename) &&
@@ -1650,14 +1681,14 @@ run (void *cls, char *const *args, const char *cfgfile,
1650 if (GNUNET_YES != GNUNET_DISK_directory_test (args[1])) 1681 if (GNUNET_YES != GNUNET_DISK_directory_test (args[1]))
1651 { 1682 {
1652 fprintf (stderr, _("Specified policies directory does not exist. Exiting.\n")); 1683 fprintf (stderr, _("Specified policies directory does not exist. Exiting.\n"));
1653 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 1684 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1654 return; 1685 return;
1655 } 1686 }
1656 policy_dir = args[1]; 1687 policy_dir = args[1];
1657 if (GNUNET_YES != GNUNET_DISK_file_test (args[2])) 1688 if (GNUNET_YES != GNUNET_DISK_file_test (args[2]))
1658 { 1689 {
1659 fprintf (stderr, _("No search strings file given. Exiting.\n")); 1690 fprintf (stderr, _("No search strings file given. Exiting.\n"));
1660 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 1691 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1661 return; 1692 return;
1662 } 1693 }
1663 nsearchstrs = load_search_strings (args[2], &search_strings, num_search_strings); 1694 nsearchstrs = load_search_strings (args[2], &search_strings, num_search_strings);
@@ -1665,13 +1696,13 @@ run (void *cls, char *const *args, const char *cfgfile,
1665 { 1696 {
1666 num_search_strings = nsearchstrs; 1697 num_search_strings = nsearchstrs;
1667 fprintf (stderr, _("Error loading search strings. Given file does not contain enough strings. Exiting.\n")); 1698 fprintf (stderr, _("Error loading search strings. Given file does not contain enough strings. Exiting.\n"));
1668 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 1699 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1669 return; 1700 return;
1670 } 1701 }
1671 if (0 >= num_search_strings || NULL == search_strings) 1702 if (0 >= num_search_strings || NULL == search_strings)
1672 { 1703 {
1673 fprintf (stderr, _("Error loading search strings. Exiting.\n")); 1704 fprintf (stderr, _("Error loading search strings. Exiting.\n"));
1674 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 1705 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1675 return; 1706 return;
1676 } 1707 }
1677 unsigned int i; 1708 unsigned int i;
@@ -1733,7 +1764,7 @@ main (int argc, char *const *argv)
1733 GNUNET_PROGRAM_run (argc, argv, "gnunet-regex-profiler [OPTIONS] hosts-file policy-dir search-strings-file", 1764 GNUNET_PROGRAM_run (argc, argv, "gnunet-regex-profiler [OPTIONS] hosts-file policy-dir search-strings-file",
1734 _("Profiler for regex/mesh"), 1765 _("Profiler for regex/mesh"),
1735 options, &run, NULL); 1766 options, &run, NULL);
1736 GNUNET_free ((void*) argv); 1767
1737 if (GNUNET_OK != ret) 1768 if (GNUNET_OK != ret)
1738 return ret; 1769 return ret;
1739 if (GNUNET_OK != result) 1770 if (GNUNET_OK != result)
diff --git a/src/mesh/gnunet-service-regexprofiler.c b/src/mesh/gnunet-service-regexprofiler.c
index fdbe3a923..b155cb783 100644
--- a/src/mesh/gnunet-service-regexprofiler.c
+++ b/src/mesh/gnunet-service-regexprofiler.c
@@ -244,4 +244,20 @@ main (int argc, char *const *argv)
244 &run, NULL)) ? global_ret : 1; 244 &run, NULL)) ? global_ret : 1;
245} 245}
246 246
247
248#ifdef LINUX
249#include <malloc.h>
250
251/**
252 * MINIMIZE heap size (way below 128k) since this process doesn't need much.
253 */
254void __attribute__ ((constructor)) GNUNET_ARM_memory_init ()
255{
256 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
257 mallopt (M_TOP_PAD, 1 * 1024);
258 malloc_trim (0);
259}
260#endif
261
262
247/* end of gnunet-service-regexprofiler.c */ 263/* end of gnunet-service-regexprofiler.c */