aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rps/gnunet-rps-profiler.c54
-rw-r--r--src/rps/rps-test_util.c21
-rw-r--r--src/rps/rps-test_util.h2
3 files changed, 67 insertions, 10 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
2518pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) 2559pre_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/");
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c
index fcb4f59a0..ab023a7a6 100644
--- a/src/rps/rps-test_util.c
+++ b/src/rps/rps-test_util.c
@@ -456,18 +456,29 @@ ensure_folder_exist (void)
456 456
457 457
458char * 458char *
459store_prefix_file_name (const struct GNUNET_PeerIdentity *peer, 459store_prefix_file_name (const unsigned int index,
460 const char *prefix) 460 const char *prefix)
461{ 461{
462 int len_file_name; 462 int len_file_name;
463 int out_size; 463 int out_size;
464 char *file_name; 464 char *file_name;
465 const char *pid_long; 465 char index_str[64];
466 466
467 if (GNUNET_SYSERR == ensure_folder_exist()) return NULL; 467 if (GNUNET_SYSERR == ensure_folder_exist()) return NULL;
468 pid_long = GNUNET_i2s_full (peer); 468 out_size = GNUNET_snprintf (index_str,
469 64,
470 "%u",
471 index);
472 if (64 < out_size ||
473 0 > out_size)
474 {
475 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
476 "Failed to write string to buffer (size: %i, out_size: %i)\n",
477 64,
478 out_size);
479 }
469 len_file_name = (strlen (prefix) + 480 len_file_name = (strlen (prefix) +
470 strlen (pid_long) + 481 strlen (index_str) +
471 11) 482 11)
472 * sizeof (char); 483 * sizeof (char);
473 file_name = GNUNET_malloc (len_file_name); 484 file_name = GNUNET_malloc (len_file_name);
@@ -475,7 +486,7 @@ store_prefix_file_name (const struct GNUNET_PeerIdentity *peer,
475 len_file_name, 486 len_file_name,
476 "/tmp/rps/%s-%s", 487 "/tmp/rps/%s-%s",
477 prefix, 488 prefix,
478 pid_long); 489 index_str);
479 if (len_file_name < out_size || 490 if (len_file_name < out_size ||
480 0 > out_size) 491 0 > out_size)
481 { 492 {
diff --git a/src/rps/rps-test_util.h b/src/rps/rps-test_util.h
index d5a2db9de..5aa0688d5 100644
--- a/src/rps/rps-test_util.h
+++ b/src/rps/rps-test_util.h
@@ -101,7 +101,7 @@ close_all_files ();
101#endif /* TO_FILE */ 101#endif /* TO_FILE */
102 102
103char * 103char *
104store_prefix_file_name (const struct GNUNET_PeerIdentity *peer, 104store_prefix_file_name (const unsigned int index,
105 const char *prefix); 105 const char *prefix);
106 106
107void 107void