aboutsummaryrefslogtreecommitdiff
path: root/src/rps/gnunet-rps-profiler.c
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2018-07-10 11:02:42 +0200
committerJulius Bünger <buenger@mytum.de>2018-07-10 11:02:42 +0200
commit857f3bc73618d69cd1122a8a519c89a46aee037b (patch)
treef315660b9bfe53fdb88094a76e19ef857c6910f2 /src/rps/gnunet-rps-profiler.c
parent041218a66dff4e23ac0944a7c1bca7b0833fc2fe (diff)
downloadgnunet-857f3bc73618d69cd1122a8a519c89a46aee037b.tar.gz
gnunet-857f3bc73618d69cd1122a8a519c89a46aee037b.zip
fix rps profiler: keep track about scheduled tasks properly
Diffstat (limited to 'src/rps/gnunet-rps-profiler.c')
-rw-r--r--src/rps/gnunet-rps-profiler.c157
1 files changed, 105 insertions, 52 deletions
diff --git a/src/rps/gnunet-rps-profiler.c b/src/rps/gnunet-rps-profiler.c
index 26675d782..9ad6d3c3b 100644
--- a/src/rps/gnunet-rps-profiler.c
+++ b/src/rps/gnunet-rps-profiler.c
@@ -446,6 +446,10 @@ struct RPSPeer
446 * @brief statistics values 446 * @brief statistics values
447 */ 447 */
448 uint64_t stats[STAT_TYPE_MAX]; 448 uint64_t stats[STAT_TYPE_MAX];
449 /**
450 * @brief Handle for the statistics get request
451 */
452 struct GNUNET_STATISTICS_GetHandle *h_stat_get[STAT_TYPE_MAX];
449}; 453};
450 454
451/** 455/**
@@ -874,6 +878,81 @@ static int check_statistics_collect_completed ()
874 return GNUNET_YES; 878 return GNUNET_YES;
875} 879}
876 880
881
882static void
883cancel_pending_req (struct PendingRequest *pending_req)
884{
885 struct RPSPeer *rps_peer;
886
887 rps_peer = pending_req->rps_peer;
888 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head,
889 rps_peer->pending_req_tail,
890 pending_req);
891 rps_peer->num_pending_reqs--;
892 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
893 "Cancelling pending rps get request\n");
894 GNUNET_SCHEDULER_cancel (pending_req->request_task);
895 GNUNET_free (pending_req);
896}
897
898static void
899cancel_request (struct PendingReply *pending_rep)
900{
901 struct RPSPeer *rps_peer;
902
903 rps_peer = pending_rep->rps_peer;
904 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head,
905 rps_peer->pending_rep_tail,
906 pending_rep);
907 rps_peer->num_pending_reps--;
908 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
909 "Cancelling rps get reply\n");
910 GNUNET_RPS_request_cancel (pending_rep->req_handle);
911 GNUNET_free (pending_rep);
912}
913
914void
915clean_peer (unsigned peer_index)
916{
917 struct PendingReply *pending_rep;
918 struct PendingRequest *pending_req;
919
920 pending_rep = rps_peers[peer_index].pending_rep_head;
921 while (NULL != (pending_rep = rps_peers[peer_index].pending_rep_head))
922 {
923 cancel_request (pending_rep);
924 }
925 pending_req = rps_peers[peer_index].pending_req_head;
926 while (NULL != (pending_req = rps_peers[peer_index].pending_req_head))
927 {
928 cancel_pending_req (pending_req);
929 }
930 if (NULL != rps_peers[peer_index].rps_handle)
931 {
932 GNUNET_RPS_disconnect (rps_peers[peer_index].rps_handle);
933 rps_peers[peer_index].rps_handle = NULL;
934 }
935 for (unsigned stat_type = STAT_TYPE_ROUNDS;
936 stat_type < STAT_TYPE_MAX;
937 stat_type++)
938 {
939 if (NULL != rps_peers[peer_index].h_stat_get[stat_type])
940 {
941 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
942 "(%u) did not yet receive stat value for `%s'\n",
943 rps_peers[peer_index].index,
944 stat_type_2_str (stat_type));
945 GNUNET_STATISTICS_get_cancel (
946 rps_peers[peer_index].h_stat_get[stat_type]);
947 }
948 }
949 if (NULL != rps_peers[peer_index].op)
950 {
951 GNUNET_TESTBED_operation_done (rps_peers[peer_index].op);
952 rps_peers[peer_index].op = NULL;
953 }
954}
955
877/** 956/**
878 * Task run on timeout to shut everything down. 957 * Task run on timeout to shut everything down.
879 */ 958 */
@@ -881,10 +960,12 @@ static void
881shutdown_op (void *cls) 960shutdown_op (void *cls)
882{ 961{
883 unsigned int i; 962 unsigned int i;
963 struct OpListEntry *entry;
884 964
885 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 965 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
886 "Shutdown task scheduled, going down.\n"); 966 "Shutdown task scheduled, going down.\n");
887 in_shutdown = GNUNET_YES; 967 in_shutdown = GNUNET_YES;
968 shutdown_task = NULL;
888 if (NULL != post_test_task) 969 if (NULL != post_test_task)
889 { 970 {
890 GNUNET_SCHEDULER_cancel (post_test_task); 971 GNUNET_SCHEDULER_cancel (post_test_task);
@@ -895,19 +976,21 @@ shutdown_op (void *cls)
895 GNUNET_SCHEDULER_cancel (churn_task); 976 GNUNET_SCHEDULER_cancel (churn_task);
896 churn_task = NULL; 977 churn_task = NULL;
897 } 978 }
979 entry = oplist_head;
980 while (NULL != (entry = oplist_head))
981 {
982 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
983 "Operation still pending on shutdown (%u)\n",
984 entry->index);
985 GNUNET_TESTBED_operation_done (entry->op);
986 GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry);
987 GNUNET_free (entry);
988 }
898 for (i = 0; i < num_peers; i++) 989 for (i = 0; i < num_peers; i++)
899 { 990 {
900 if (NULL != rps_peers[i].rps_handle) 991 clean_peer (i);
901 {
902 GNUNET_RPS_disconnect (rps_peers[i].rps_handle);
903 rps_peers[i].rps_handle = NULL;
904 }
905 if (NULL != rps_peers[i].op)
906 {
907 GNUNET_TESTBED_operation_done (rps_peers[i].op);
908 rps_peers[i].op = NULL;
909 }
910 } 992 }
993 GNUNET_SCHEDULER_shutdown ();
911} 994}
912 995
913 996
@@ -947,7 +1030,6 @@ post_test_op (void *cls)
947 { 1030 {
948 GNUNET_SCHEDULER_cancel (shutdown_task); 1031 GNUNET_SCHEDULER_cancel (shutdown_task);
949 shutdown_task = GNUNET_SCHEDULER_add_now (&shutdown_op, NULL); 1032 shutdown_task = GNUNET_SCHEDULER_add_now (&shutdown_op, NULL);
950 GNUNET_SCHEDULER_shutdown ();
951 } 1033 }
952} 1034}
953 1035
@@ -1056,7 +1138,7 @@ rps_connect_complete_cb (void *cls,
1056 "Failed to connect to RPS service: %s\n", 1138 "Failed to connect to RPS service: %s\n",
1057 emsg); 1139 emsg);
1058 ok = 1; 1140 ok = 1;
1059 GNUNET_SCHEDULER_shutdown (); 1141 shutdown_op (NULL);
1060 return; 1142 return;
1061 } 1143 }
1062 1144
@@ -1272,38 +1354,6 @@ request_peers (void *cls)
1272 rps_peer->num_pending_reqs--; 1354 rps_peer->num_pending_reqs--;
1273} 1355}
1274 1356
1275static void
1276cancel_pending_req (struct PendingRequest *pending_req)
1277{
1278 struct RPSPeer *rps_peer;
1279
1280 rps_peer = pending_req->rps_peer;
1281 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head,
1282 rps_peer->pending_req_tail,
1283 pending_req);
1284 rps_peer->num_pending_reqs--;
1285 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1286 "Cancelling pending request\n");
1287 GNUNET_SCHEDULER_cancel (pending_req->request_task);
1288 GNUNET_free (pending_req);
1289}
1290
1291static void
1292cancel_request (struct PendingReply *pending_rep)
1293{
1294 struct RPSPeer *rps_peer;
1295
1296 rps_peer = pending_rep->rps_peer;
1297 GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head,
1298 rps_peer->pending_rep_tail,
1299 pending_rep);
1300 rps_peer->num_pending_reps--;
1301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1302 "Cancelling request\n");
1303 GNUNET_RPS_request_cancel (pending_rep->req_handle);
1304 GNUNET_free (pending_rep);
1305}
1306
1307 1357
1308/** 1358/**
1309 * Schedule requests for peer @a rps_peer that have neither been scheduled, nor 1359 * Schedule requests for peer @a rps_peer that have neither been scheduled, nor
@@ -1493,7 +1543,7 @@ churn_cb (void *cls,
1493 if (NULL != emsg) 1543 if (NULL != emsg)
1494 { 1544 {
1495 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n"); 1545 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n");
1496 GNUNET_SCHEDULER_shutdown (); 1546 shutdown_op (NULL);
1497 return; 1547 return;
1498 } 1548 }
1499 GNUNET_assert (0 != entry->delta); 1549 GNUNET_assert (0 != entry->delta);
@@ -2343,7 +2393,7 @@ post_test_shutdown_ready_cb (void *cls,
2343 GNUNET_free (stat_cls); 2393 GNUNET_free (stat_cls);
2344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2394 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2345 "Shutting down\n"); 2395 "Shutting down\n");
2346 GNUNET_SCHEDULER_shutdown (); 2396 shutdown_op (NULL);
2347 } else { 2397 } else {
2348 GNUNET_free (stat_cls); 2398 GNUNET_free (stat_cls);
2349 } 2399 }
@@ -2368,10 +2418,12 @@ stat_iterator (void *cls,
2368{ 2418{
2369 const struct STATcls *stat_cls = (const struct STATcls *) cls; 2419 const struct STATcls *stat_cls = (const struct STATcls *) cls;
2370 struct RPSPeer *rps_peer = (struct RPSPeer *) stat_cls->rps_peer; 2420 struct RPSPeer *rps_peer = (struct RPSPeer *) stat_cls->rps_peer;
2421
2371 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %s - %" PRIu64 "\n", 2422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %s - %" PRIu64 "\n",
2372 //stat_type_2_str (stat_cls->stat_type), 2423 //stat_type_2_str (stat_cls->stat_type),
2373 name, 2424 name,
2374 value); 2425 value);
2426 rps_peer->h_stat_get[stat_str_2_type (name)] = NULL;
2375 to_file (rps_peer->file_name_stats, 2427 to_file (rps_peer->file_name_stats,
2376 "%s: %" PRIu64 "\n", 2428 "%s: %" PRIu64 "\n",
2377 name, 2429 name,
@@ -2460,12 +2512,13 @@ void post_profiler (struct RPSPeer *rps_peer)
2460 stat_cls->stat_type = stat_type; 2512 stat_cls->stat_type = stat_type;
2461 rps_peer->file_name_stats = 2513 rps_peer->file_name_stats =
2462 store_prefix_file_name (rps_peer->peer_id, "stats"); 2514 store_prefix_file_name (rps_peer->peer_id, "stats");
2463 GNUNET_STATISTICS_get (rps_peer->stats_h, 2515 rps_peer->h_stat_get[stat_type] = GNUNET_STATISTICS_get (
2464 "rps", 2516 rps_peer->stats_h,
2465 stat_type_2_str (stat_type), 2517 "rps",
2466 post_test_shutdown_ready_cb, 2518 stat_type_2_str (stat_type),
2467 stat_iterator, 2519 post_test_shutdown_ready_cb,
2468 (struct STATcls *) stat_cls); 2520 stat_iterator,
2521 (struct STATcls *) stat_cls);
2469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2470 "Requested statistics for %s (peer %" PRIu32 ")\n", 2523 "Requested statistics for %s (peer %" PRIu32 ")\n",
2471 stat_type_2_str (stat_type), 2524 stat_type_2_str (stat_type),