diff options
author | Julius Bünger <buenger@mytum.de> | 2018-01-25 15:56:57 +0100 |
---|---|---|
committer | Julius Bünger <buenger@mytum.de> | 2018-01-25 16:04:35 +0100 |
commit | aac096bb15f2f0d7ed2450428a2e5d7fcf91c737 (patch) | |
tree | e662500f4d10a550394d812d5c70216eaea199d4 /src/rps/test_rps.c | |
parent | e7ba3b64baa9aef8f1ca83c6da443cb4a1ec362a (diff) | |
download | gnunet-aac096bb15f2f0d7ed2450428a2e5d7fcf91c737.tar.gz gnunet-aac096bb15f2f0d7ed2450428a2e5d7fcf91c737.zip |
rps profiler: write statistics to file
Diffstat (limited to 'src/rps/test_rps.c')
-rw-r--r-- | src/rps/test_rps.c | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c index c5a2c0458..cba992740 100644 --- a/src/rps/test_rps.c +++ b/src/rps/test_rps.c | |||
@@ -253,6 +253,11 @@ struct RPSPeer | |||
253 | * Used to check whether we are able to shutdown. | 253 | * Used to check whether we are able to shutdown. |
254 | */ | 254 | */ |
255 | uint32_t stat_collected_flags; | 255 | uint32_t stat_collected_flags; |
256 | |||
257 | /** | ||
258 | * @brief File name of the file the stats are finally written to | ||
259 | */ | ||
260 | char *file_name_stats; | ||
256 | }; | 261 | }; |
257 | 262 | ||
258 | enum STAT_TYPE | 263 | enum STAT_TYPE |
@@ -1738,6 +1743,50 @@ profiler_eval (void) | |||
1738 | } | 1743 | } |
1739 | 1744 | ||
1740 | /** | 1745 | /** |
1746 | * @brief Try to ensure that `/tmp/rps` exists. | ||
1747 | * | ||
1748 | * @return #GNUNET_YES on success | ||
1749 | * #GNUNET_SYSERR on failure | ||
1750 | */ | ||
1751 | static int ensure_folder_exist (void) | ||
1752 | { | ||
1753 | if (GNUNET_NO == GNUNET_DISK_directory_test ("/tmp/rps/", GNUNET_NO)) | ||
1754 | { | ||
1755 | GNUNET_DISK_directory_create ("/tmp/rps"); | ||
1756 | } | ||
1757 | if (GNUNET_YES != GNUNET_DISK_directory_test ("/tmp/rps/", GNUNET_NO)) | ||
1758 | { | ||
1759 | return GNUNET_SYSERR; | ||
1760 | } | ||
1761 | return GNUNET_YES; | ||
1762 | } | ||
1763 | |||
1764 | static void | ||
1765 | store_stats_file_name (struct RPSPeer *rps_peer) | ||
1766 | { | ||
1767 | unsigned int len_file_name; | ||
1768 | unsigned int out_size; | ||
1769 | char *file_name; | ||
1770 | |||
1771 | if (GNUNET_SYSERR == ensure_folder_exist()) return; | ||
1772 | len_file_name = (14 + strlen (GNUNET_i2s_full (rps_peer->peer_id)) + 1) * sizeof (char); | ||
1773 | file_name = GNUNET_malloc (len_file_name); | ||
1774 | out_size = GNUNET_snprintf (file_name, | ||
1775 | len_file_name, | ||
1776 | "/tmp/rps/stat-%s", | ||
1777 | GNUNET_i2s_full (rps_peer->peer_id)); | ||
1778 | if (len_file_name < out_size || | ||
1779 | 0 > out_size) | ||
1780 | { | ||
1781 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1782 | "Failed to write string to buffer (size: %i, out_size: %i)\n", | ||
1783 | len_file_name, | ||
1784 | out_size); | ||
1785 | } | ||
1786 | rps_peer->file_name_stats = file_name; | ||
1787 | } | ||
1788 | |||
1789 | /** | ||
1741 | * Continuation called by #GNUNET_STATISTICS_get() functions. | 1790 | * Continuation called by #GNUNET_STATISTICS_get() functions. |
1742 | * | 1791 | * |
1743 | * Remembers that this specific statistics value was received for this peer. | 1792 | * Remembers that this specific statistics value was received for this peer. |
@@ -1848,9 +1897,15 @@ stat_iterator (void *cls, | |||
1848 | int is_persistent) | 1897 | int is_persistent) |
1849 | { | 1898 | { |
1850 | const struct STATcls *stat_cls = (const struct STATcls *) cls; | 1899 | const struct STATcls *stat_cls = (const struct STATcls *) cls; |
1900 | const struct RPSPeer *rps_peer = (const struct RPSPeer *) stat_cls->rps_peer; | ||
1851 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %s - %" PRIu64 "\n", | 1901 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %s - %" PRIu64 "\n", |
1852 | stat_type_2_str (stat_cls->stat_type), | 1902 | //stat_type_2_str (stat_cls->stat_type), |
1903 | name, | ||
1853 | value); | 1904 | value); |
1905 | to_file (rps_peer->file_name_stats, | ||
1906 | "%s: %" PRIu64 "\n", | ||
1907 | name, | ||
1908 | value); | ||
1854 | return GNUNET_OK; | 1909 | return GNUNET_OK; |
1855 | } | 1910 | } |
1856 | 1911 | ||
@@ -1876,6 +1931,7 @@ void post_profiler (struct RPSPeer *rps_peer) | |||
1876 | stat_cls = GNUNET_malloc (sizeof (struct STATcls)); | 1931 | stat_cls = GNUNET_malloc (sizeof (struct STATcls)); |
1877 | stat_cls->rps_peer = rps_peer; | 1932 | stat_cls->rps_peer = rps_peer; |
1878 | stat_cls->stat_type = stat_type; | 1933 | stat_cls->stat_type = stat_type; |
1934 | store_stats_file_name (rps_peer); | ||
1879 | GNUNET_STATISTICS_get (rps_peer->stats_h, | 1935 | GNUNET_STATISTICS_get (rps_peer->stats_h, |
1880 | "rps", | 1936 | "rps", |
1881 | stat_type_2_str (stat_type), | 1937 | stat_type_2_str (stat_type), |