From: Julius Bünger Date: Thu, 25 Jan 2018 14:56:57 +0000 (+0100) Subject: rps profiler: write statistics to file X-Git-Tag: v0.11.0pre66~231 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=aac096bb15f2f0d7ed2450428a2e5d7fcf91c737;p=oweals%2Fgnunet.git rps profiler: write statistics to file --- diff --git a/src/rps/rps-test_util.h b/src/rps/rps-test_util.h index 209152151..225db4b1d 100644 --- a/src/rps/rps-test_util.h +++ b/src/rps/rps-test_util.h @@ -53,7 +53,7 @@ create_file (const char *name); int size;\ size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ if (0 > size)\ - LOG (GNUNET_ERROR_TYPE_WARNING,\ + GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ "Failed to create tmp_buf\n");\ else\ to_file_(file_name,tmp_buf);\ 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 * Used to check whether we are able to shutdown. */ uint32_t stat_collected_flags; + + /** + * @brief File name of the file the stats are finally written to + */ + char *file_name_stats; }; enum STAT_TYPE @@ -1737,6 +1742,50 @@ profiler_eval (void) return evaluate (); } +/** + * @brief Try to ensure that `/tmp/rps` exists. + * + * @return #GNUNET_YES on success + * #GNUNET_SYSERR on failure + */ +static int ensure_folder_exist (void) +{ + if (GNUNET_NO == GNUNET_DISK_directory_test ("/tmp/rps/", GNUNET_NO)) + { + GNUNET_DISK_directory_create ("/tmp/rps"); + } + if (GNUNET_YES != GNUNET_DISK_directory_test ("/tmp/rps/", GNUNET_NO)) + { + return GNUNET_SYSERR; + } + return GNUNET_YES; +} + +static void +store_stats_file_name (struct RPSPeer *rps_peer) +{ + unsigned int len_file_name; + unsigned int out_size; + char *file_name; + + if (GNUNET_SYSERR == ensure_folder_exist()) return; + len_file_name = (14 + strlen (GNUNET_i2s_full (rps_peer->peer_id)) + 1) * sizeof (char); + file_name = GNUNET_malloc (len_file_name); + out_size = GNUNET_snprintf (file_name, + len_file_name, + "/tmp/rps/stat-%s", + GNUNET_i2s_full (rps_peer->peer_id)); + if (len_file_name < out_size || + 0 > out_size) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Failed to write string to buffer (size: %i, out_size: %i)\n", + len_file_name, + out_size); + } + rps_peer->file_name_stats = file_name; +} + /** * Continuation called by #GNUNET_STATISTICS_get() functions. * @@ -1848,9 +1897,15 @@ stat_iterator (void *cls, int is_persistent) { const struct STATcls *stat_cls = (const struct STATcls *) cls; + const struct RPSPeer *rps_peer = (const struct RPSPeer *) stat_cls->rps_peer; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %s - %" PRIu64 "\n", - stat_type_2_str (stat_cls->stat_type), + //stat_type_2_str (stat_cls->stat_type), + name, value); + to_file (rps_peer->file_name_stats, + "%s: %" PRIu64 "\n", + name, + value); return GNUNET_OK; } @@ -1876,6 +1931,7 @@ void post_profiler (struct RPSPeer *rps_peer) stat_cls = GNUNET_malloc (sizeof (struct STATcls)); stat_cls->rps_peer = rps_peer; stat_cls->stat_type = stat_type; + store_stats_file_name (rps_peer); GNUNET_STATISTICS_get (rps_peer->stats_h, "rps", stat_type_2_str (stat_type),