summaryrefslogtreecommitdiff
path: root/src/rps/test_rps.c
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2018-04-12 12:06:46 +0200
committerJulius Bünger <buenger@mytum.de>2018-04-12 22:25:42 +0200
commit78b04addaf643f8084df2f649f26dde01a1b5ddd (patch)
treea86819060941478ee5d20f4c430934d891911de2 /src/rps/test_rps.c
parentf1d5be8c05ae4207596b9b8b6ef552b3df8dffc7 (diff)
downloadgnunet-78b04addaf643f8084df2f649f26dde01a1b5ddd.tar.gz
gnunet-78b04addaf643f8084df2f649f26dde01a1b5ddd.zip
rps service/profiler: count observed (unique) peers
Diffstat (limited to 'src/rps/test_rps.c')
-rw-r--r--src/rps/test_rps.c56
1 files changed, 4 insertions, 52 deletions
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c
index 9ccf3e61c..8d31bf50d 100644
--- a/src/rps/test_rps.c
+++ b/src/rps/test_rps.c
@@ -1809,56 +1809,6 @@ profiler_eval (void)
1809 return evaluate (); 1809 return evaluate ();
1810} 1810}
1811 1811
1812/**
1813 * @brief Try to ensure that `/tmp/rps` exists.
1814 *
1815 * @return #GNUNET_YES on success
1816 * #GNUNET_SYSERR on failure
1817 */
1818static int ensure_folder_exist (void)
1819{
1820 if (GNUNET_NO == GNUNET_DISK_directory_test ("/tmp/rps/", GNUNET_NO))
1821 {
1822 GNUNET_DISK_directory_create ("/tmp/rps");
1823 }
1824 if (GNUNET_YES != GNUNET_DISK_directory_test ("/tmp/rps/", GNUNET_NO))
1825 {
1826 return GNUNET_SYSERR;
1827 }
1828 return GNUNET_YES;
1829}
1830
1831static const char *
1832store_prefix_file_name (struct RPSPeer *rps_peer, const char *prefix)
1833{
1834 unsigned int len_file_name;
1835 unsigned int out_size;
1836 char *file_name;
1837 const char *pid_long;
1838
1839 if (GNUNET_SYSERR == ensure_folder_exist()) return NULL;
1840 pid_long = GNUNET_i2s_full (rps_peer->peer_id);
1841 len_file_name = (strlen (prefix) +
1842 strlen (pid_long) +
1843 11)
1844 * sizeof (char);
1845 file_name = GNUNET_malloc (len_file_name);
1846 out_size = GNUNET_snprintf (file_name,
1847 len_file_name,
1848 "/tmp/rps/%s-%s",
1849 prefix,
1850 pid_long);
1851 if (len_file_name < out_size ||
1852 0 > out_size)
1853 {
1854 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1855 "Failed to write string to buffer (size: %i, out_size: %i)\n",
1856 len_file_name,
1857 out_size);
1858 }
1859 return file_name;
1860}
1861
1862static uint32_t fac (uint32_t x) 1812static uint32_t fac (uint32_t x)
1863{ 1813{
1864 if (1 >= x) 1814 if (1 >= x)
@@ -2253,7 +2203,8 @@ void view_update_cb (void *cls,
2253static void 2203static void
2254pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) 2204pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h)
2255{ 2205{
2256 rps_peer->file_name_probs = store_prefix_file_name (rps_peer, "probs"); 2206 rps_peer->file_name_probs =
2207 store_prefix_file_name (rps_peer->peer_id, "probs");
2257 GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer); 2208 GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer);
2258} 2209}
2259 2210
@@ -2576,7 +2527,8 @@ void post_profiler (struct RPSPeer *rps_peer)
2576 stat_cls = GNUNET_malloc (sizeof (struct STATcls)); 2527 stat_cls = GNUNET_malloc (sizeof (struct STATcls));
2577 stat_cls->rps_peer = rps_peer; 2528 stat_cls->rps_peer = rps_peer;
2578 stat_cls->stat_type = stat_type; 2529 stat_cls->stat_type = stat_type;
2579 rps_peer->file_name_stats = store_prefix_file_name (rps_peer, "stats"); 2530 rps_peer->file_name_stats =
2531 store_prefix_file_name (rps_peer->peer_id, "stats");
2580 GNUNET_STATISTICS_get (rps_peer->stats_h, 2532 GNUNET_STATISTICS_get (rps_peer->stats_h,
2581 "rps", 2533 "rps",
2582 stat_type_2_str (stat_type), 2534 stat_type_2_str (stat_type),