aboutsummaryrefslogtreecommitdiff
path: root/src/set/gnunet-set-profiler.c
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2015-10-07 22:01:03 +0000
committerFlorian Dold <florian.dold@gmail.com>2015-10-07 22:01:03 +0000
commit383814672c031e49c4dffca0a69af3b0973d2248 (patch)
tree1c889a53a32ce6fd5786e23cd4f45e7de06db403 /src/set/gnunet-set-profiler.c
parentaf432574e5009cc4748e512f6b78b43f40fdc19c (diff)
downloadgnunet-383814672c031e49c4dffca0a69af3b0973d2248.tar.gz
gnunet-383814672c031e49c4dffca0a69af3b0973d2248.zip
statistics in set profiler, temp. fix for salt
Diffstat (limited to 'src/set/gnunet-set-profiler.c')
-rw-r--r--src/set/gnunet-set-profiler.c61
1 files changed, 50 insertions, 11 deletions
diff --git a/src/set/gnunet-set-profiler.c b/src/set/gnunet-set-profiler.c
index 2ee1b762d..4b6a1e202 100644
--- a/src/set/gnunet-set-profiler.c
+++ b/src/set/gnunet-set-profiler.c
@@ -25,6 +25,7 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_statistics_service.h"
28#include "gnunet_set_service.h" 29#include "gnunet_set_service.h"
29#include "gnunet_testbed_service.h" 30#include "gnunet_testbed_service.h"
30 31
@@ -35,6 +36,8 @@ static unsigned int num_a = 5;
35static unsigned int num_b = 5; 36static unsigned int num_b = 5;
36static unsigned int num_c = 20; 37static unsigned int num_c = 20;
37 38
39static unsigned int dump_statistics;
40
38static char *op_str = "union"; 41static char *op_str = "union";
39 42
40const static struct GNUNET_CONFIGURATION_Handle *config; 43const static struct GNUNET_CONFIGURATION_Handle *config;
@@ -57,6 +60,8 @@ static struct GNUNET_PeerIdentity local_peer;
57 60
58static struct GNUNET_SET_ListenHandle *set_listener; 61static struct GNUNET_SET_ListenHandle *set_listener;
59 62
63static struct GNUNET_STATISTICS_Handle *statistics;
64
60 65
61static int 66static int
62map_remove_iterator (void *cls, 67map_remove_iterator (void *cls,
@@ -76,6 +81,37 @@ map_remove_iterator (void *cls,
76} 81}
77 82
78 83
84/**
85 * Callback function to process statistic values.
86 *
87 * @param cls closure
88 * @param subsystem name of subsystem that created the statistic
89 * @param name the name of the datum
90 * @param value the current value
91 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
92 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
93 */
94static int
95statistics_result (void *cls,
96 const char *subsystem,
97 const char *name,
98 uint64_t value,
99 int is_persistent)
100{
101 printf ("stat %s/%s=%lu\n", subsystem, name, (unsigned long) value);
102 return GNUNET_OK;
103}
104
105
106static void
107statistics_done (void *cls,
108 int success)
109{
110 GNUNET_assert (GNUNET_YES == success);
111 printf("dumped statistics\n");
112 GNUNET_SCHEDULER_shutdown ();
113}
114
79static void 115static void
80check_all_done (void) 116check_all_done (void)
81{ 117{
@@ -88,7 +124,14 @@ check_all_done (void)
88 printf ("set a: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size (info1.sent)); 124 printf ("set a: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size (info1.sent));
89 printf ("set b: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size (info2.sent)); 125 printf ("set b: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size (info2.sent));
90 126
91 GNUNET_SCHEDULER_shutdown (); 127 if (0 == dump_statistics)
128 {
129 GNUNET_SCHEDULER_shutdown ();
130 return;
131 }
132
133 GNUNET_STATISTICS_get (statistics, NULL, NULL, GNUNET_TIME_UNIT_FOREVER_REL,
134 statistics_done, statistics_result, NULL);
92} 135}
93 136
94 137
@@ -215,6 +258,7 @@ handle_shutdown (void *cls,
215 GNUNET_SET_destroy (info2.set); 258 GNUNET_SET_destroy (info2.set);
216 info2.set = NULL; 259 info2.set = NULL;
217 } 260 }
261 GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
218} 262}
219 263
220 264
@@ -225,7 +269,6 @@ run (void *cls,
225{ 269{
226 unsigned int i; 270 unsigned int i;
227 struct GNUNET_HashCode hash; 271 struct GNUNET_HashCode hash;
228 struct GNUNET_HashCode hashhash;
229 272
230 config = cfg; 273 config = cfg;
231 274
@@ -236,6 +279,8 @@ run (void *cls,
236 return; 279 return;
237 } 280 }
238 281
282 statistics = GNUNET_STATISTICS_create ("set-profiler", cfg);
283
239 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, handle_shutdown, NULL); 284 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, handle_shutdown, NULL);
240 285
241 info1.id = "a"; 286 info1.id = "a";
@@ -251,9 +296,6 @@ run (void *cls,
251 for (i = 0; i < num_a; i++) 296 for (i = 0; i < num_a; i++)
252 { 297 {
253 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash); 298 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash);
254 GNUNET_CRYPTO_hash (&hash, sizeof (struct GNUNET_HashCode), &hashhash);
255 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Set a: Created element %s\n",
256 GNUNET_h2s (&hashhash));
257 GNUNET_CONTAINER_multihashmap_put (info1.sent, &hash, NULL, 299 GNUNET_CONTAINER_multihashmap_put (info1.sent, &hash, NULL,
258 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); 300 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
259 } 301 }
@@ -261,9 +303,6 @@ run (void *cls,
261 for (i = 0; i < num_b; i++) 303 for (i = 0; i < num_b; i++)
262 { 304 {
263 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash); 305 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash);
264 GNUNET_CRYPTO_hash (&hash, sizeof (struct GNUNET_HashCode), &hashhash);
265 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Set b: Created element %s\n",
266 GNUNET_h2s (&hashhash));
267 GNUNET_CONTAINER_multihashmap_put (info2.sent, &hash, NULL, 306 GNUNET_CONTAINER_multihashmap_put (info2.sent, &hash, NULL,
268 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); 307 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
269 } 308 }
@@ -271,9 +310,6 @@ run (void *cls,
271 for (i = 0; i < num_c; i++) 310 for (i = 0; i < num_c; i++)
272 { 311 {
273 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash); 312 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash);
274 GNUNET_CRYPTO_hash (&hash, sizeof (struct GNUNET_HashCode), &hashhash);
275 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Set c: Created element %s\n",
276 GNUNET_h2s (&hashhash));
277 GNUNET_CONTAINER_multihashmap_put (common_sent, &hash, NULL, 313 GNUNET_CONTAINER_multihashmap_put (common_sent, &hash, NULL,
278 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); 314 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
279 } 315 }
@@ -328,6 +364,9 @@ main (int argc, char **argv)
328 { 'x', "operation", NULL, 364 { 'x', "operation", NULL,
329 gettext_noop ("operation to execute"), 365 gettext_noop ("operation to execute"),
330 GNUNET_YES, &GNUNET_GETOPT_set_string, &op_str }, 366 GNUNET_YES, &GNUNET_GETOPT_set_string, &op_str },
367 { 's', "statistics", NULL,
368 gettext_noop ("dump statistics to stdout after completion"),
369 GNUNET_NO, &GNUNET_GETOPT_set_one, &dump_statistics },
331 GNUNET_GETOPT_OPTION_END 370 GNUNET_GETOPT_OPTION_END
332 }; 371 };
333 GNUNET_PROGRAM_run2 (argc, argv, "gnunet-set-profiler", 372 GNUNET_PROGRAM_run2 (argc, argv, "gnunet-set-profiler",