diff options
author | Julius Bünger <buenger@mytum.de> | 2019-04-11 13:02:18 +0200 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2019-04-11 13:03:13 +0200 |
commit | 6fd0634f2e378276c93e84b3d296f43307aae317 (patch) | |
tree | 8e7394c8d67e152dd55c0e79293e45e0c6528c6b /src/rps/gnunet-rps-profiler.c | |
parent | c457ee81954163e0b7295fbd4a713474b3059abf (diff) | |
download | gnunet-6fd0634f2e378276c93e84b3d296f43307aae317.tar.gz gnunet-6fd0634f2e378276c93e84b3d296f43307aae317.zip |
RPS profiler: Compute probabilities wrt history
Diffstat (limited to 'src/rps/gnunet-rps-profiler.c')
-rw-r--r-- | src/rps/gnunet-rps-profiler.c | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/src/rps/gnunet-rps-profiler.c b/src/rps/gnunet-rps-profiler.c index 474a83768..1ab81c3fb 100644 --- a/src/rps/gnunet-rps-profiler.c +++ b/src/rps/gnunet-rps-profiler.c | |||
@@ -561,6 +561,11 @@ struct RPSPeer | |||
561 | const char *file_name_probs; | 561 | const char *file_name_probs; |
562 | 562 | ||
563 | /** | 563 | /** |
564 | * @brief File name of the file the stats are finally written to | ||
565 | */ | ||
566 | const char *file_name_probs_hist; | ||
567 | |||
568 | /** | ||
564 | * @brief The current view | 569 | * @brief The current view |
565 | */ | 570 | */ |
566 | struct GNUNET_PeerIdentity *cur_view; | 571 | struct GNUNET_PeerIdentity *cur_view; |
@@ -811,6 +816,12 @@ struct SingleTestRun | |||
811 | * of the run | 816 | * of the run |
812 | */ | 817 | */ |
813 | uint32_t stat_collect_flags; | 818 | uint32_t stat_collect_flags; |
819 | |||
820 | /** | ||
821 | * @brief Keep the probabilities in cache for computing the probabilities | ||
822 | * with respect to history. | ||
823 | */ | ||
824 | double *eval_probs_cache; | ||
814 | } cur_test_run; | 825 | } cur_test_run; |
815 | 826 | ||
816 | /** | 827 | /** |
@@ -2222,6 +2233,7 @@ static void compute_probabilities (uint32_t peer_idx) | |||
2222 | { | 2233 | { |
2223 | //double probs[num_peers] = { 0 }; | 2234 | //double probs[num_peers] = { 0 }; |
2224 | double probs[num_peers]; | 2235 | double probs[num_peers]; |
2236 | double probs_hist[num_peers]; /* Probability respecting the history */ | ||
2225 | size_t probs_as_str_size = (num_peers * 10 + 2) * sizeof (char); | 2237 | size_t probs_as_str_size = (num_peers * 10 + 2) * sizeof (char); |
2226 | char *probs_as_str = GNUNET_malloc (probs_as_str_size); | 2238 | char *probs_as_str = GNUNET_malloc (probs_as_str_size); |
2227 | char *probs_as_str_cpy; | 2239 | char *probs_as_str_cpy; |
@@ -2232,7 +2244,8 @@ static void compute_probabilities (uint32_t peer_idx) | |||
2232 | uint32_t cont_views; | 2244 | uint32_t cont_views; |
2233 | uint32_t number_of_being_in_pull_events; | 2245 | uint32_t number_of_being_in_pull_events; |
2234 | int tmp; | 2246 | int tmp; |
2235 | uint32_t sum_non_zero_prob = 0; | 2247 | double sum_non_zero_prob = 0; |
2248 | double sum_non_zero_prob_hist = 0; | ||
2236 | 2249 | ||
2237 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2238 | "Computing probabilities for peer %" PRIu32 "\n", peer_idx); | 2251 | "Computing probabilities for peer %" PRIu32 "\n", peer_idx); |
@@ -2315,12 +2328,26 @@ static void compute_probabilities (uint32_t peer_idx) | |||
2315 | i, | 2328 | i, |
2316 | number_of_being_in_pull_events); | 2329 | number_of_being_in_pull_events); |
2317 | 2330 | ||
2331 | probs_hist[i] = 0.9 * cur_test_run.eval_probs_cache[i] + probs[i]; | ||
2332 | cur_test_run.eval_probs_cache[i] = probs_hist[i]; | ||
2333 | |||
2318 | sum_non_zero_prob += probs[i]; | 2334 | sum_non_zero_prob += probs[i]; |
2335 | sum_non_zero_prob_hist += probs_hist[i]; | ||
2319 | } | 2336 | } |
2320 | /* normalize */ | 2337 | /* normalize */ |
2321 | for (i = 0; i < num_peers; i++) | 2338 | if (0 != sum_non_zero_prob) |
2322 | { | 2339 | { |
2323 | probs[i] = probs[i] * (1.0 / sum_non_zero_prob); | 2340 | for (i = 0; i < num_peers; i++) |
2341 | { | ||
2342 | probs[i] = probs[i] * (1.0 / sum_non_zero_prob); | ||
2343 | } | ||
2344 | } | ||
2345 | if (0 != sum_non_zero_prob_hist) | ||
2346 | { | ||
2347 | for (i = 0; i < num_peers; i++) | ||
2348 | { | ||
2349 | probs_hist[i] = probs_hist[i] * (1.0 / sum_non_zero_prob_hist); | ||
2350 | } | ||
2324 | } | 2351 | } |
2325 | 2352 | ||
2326 | /* str repr */ | 2353 | /* str repr */ |
@@ -2337,6 +2364,20 @@ static void compute_probabilities (uint32_t peer_idx) | |||
2337 | to_file_w_len (rps_peers[peer_idx].file_name_probs, | 2364 | to_file_w_len (rps_peers[peer_idx].file_name_probs, |
2338 | probs_as_str_size, | 2365 | probs_as_str_size, |
2339 | probs_as_str); | 2366 | probs_as_str); |
2367 | |||
2368 | for (i = 0; i < num_peers; i++) | ||
2369 | { | ||
2370 | probs_as_str_cpy = GNUNET_strndup (probs_as_str, probs_as_str_size); | ||
2371 | tmp = GNUNET_snprintf (probs_as_str, | ||
2372 | probs_as_str_size, | ||
2373 | "%s %7.6f", probs_as_str_cpy, probs_hist[i]); | ||
2374 | GNUNET_free (probs_as_str_cpy); | ||
2375 | GNUNET_assert (0 <= tmp); | ||
2376 | } | ||
2377 | |||
2378 | to_file_w_len (rps_peers[peer_idx].file_name_probs_hist, | ||
2379 | probs_as_str_size, | ||
2380 | probs_as_str); | ||
2340 | GNUNET_free (probs_as_str); | 2381 | GNUNET_free (probs_as_str); |
2341 | } | 2382 | } |
2342 | 2383 | ||
@@ -2518,7 +2559,9 @@ static void | |||
2518 | pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) | 2559 | pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) |
2519 | { | 2560 | { |
2520 | rps_peer->file_name_probs = | 2561 | rps_peer->file_name_probs = |
2521 | store_prefix_file_name (rps_peer->peer_id, "probs"); | 2562 | store_prefix_file_name (rps_peer->index, "probs"); |
2563 | rps_peer->file_name_probs_hist = | ||
2564 | store_prefix_file_name (rps_peer->index, "probs_hist"); | ||
2522 | GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer); | 2565 | GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer); |
2523 | } | 2566 | } |
2524 | 2567 | ||
@@ -2767,6 +2810,7 @@ post_profiler (struct RPSPeer *rps_peer) | |||
2767 | rps_peer->index); | 2810 | rps_peer->index); |
2768 | } | 2811 | } |
2769 | } | 2812 | } |
2813 | GNUNET_free (cur_test_run.eval_probs_cache); | ||
2770 | } | 2814 | } |
2771 | 2815 | ||
2772 | 2816 | ||
@@ -2955,6 +2999,8 @@ run (void *cls, | |||
2955 | BIT(STAT_TYPE_PEERS_IN_VIEW) | | 2999 | BIT(STAT_TYPE_PEERS_IN_VIEW) | |
2956 | BIT(STAT_TYPE_VIEW_SIZE_AIM); | 3000 | BIT(STAT_TYPE_VIEW_SIZE_AIM); |
2957 | cur_test_run.have_collect_view = COLLECT_VIEW; | 3001 | cur_test_run.have_collect_view = COLLECT_VIEW; |
3002 | cur_test_run.eval_probs_cache = GNUNET_new_array (num_peers, double); | ||
3003 | memset (cur_test_run.eval_probs_cache, num_peers * sizeof (double), 0); | ||
2958 | 3004 | ||
2959 | /* 'Clean' directory */ | 3005 | /* 'Clean' directory */ |
2960 | (void) GNUNET_DISK_directory_remove ("/tmp/rps/"); | 3006 | (void) GNUNET_DISK_directory_remove ("/tmp/rps/"); |