/*
This file is part of GNUnet
- Copyright (C) 2013 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2013 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
*/
#include "platform.h"
#include "gnunet_util_lib.h"
+#include "gnunet_statistics_service.h"
#include "gnunet_set_service.h"
#include "gnunet_testbed_service.h"
static struct GNUNET_SET_ListenHandle *set_listener;
+/**
+ * Handle to the statistics service.
+ */
+static struct GNUNET_STATISTICS_Handle *statistics;
+
+/**
+ * The profiler will write statistics
+ * for all peers to the file with this name.
+ */
+static char *statistics_filename;
+
+/**
+ * The profiler will write statistics
+ * for all peers to this file.
+ */
+static FILE *statistics_file;
+
static int
map_remove_iterator (void *cls,
}
+/**
+ * Callback function to process statistic values.
+ *
+ * @param cls closure
+ * @param subsystem name of subsystem that created the statistic
+ * @param name the name of the datum
+ * @param value the current value
+ * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
+ * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
+ */
+static int
+statistics_result (void *cls,
+ const char *subsystem,
+ const char *name,
+ uint64_t value,
+ int is_persistent)
+{
+ if (NULL != statistics_file)
+ {
+ fprintf (statistics_file, "%s\t%s\t%lu\n", subsystem, name, (unsigned long) value);
+ }
+ return GNUNET_OK;
+}
+
+
+static void
+statistics_done (void *cls,
+ int success)
+{
+ GNUNET_assert (GNUNET_YES == success);
+ if (NULL != statistics_file)
+ fclose (statistics_file);
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
static void
check_all_done (void)
{
printf ("set a: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size (info1.sent));
printf ("set b: %d missing elements\n", GNUNET_CONTAINER_multihashmap_size (info2.sent));
- GNUNET_SCHEDULER_shutdown ();
+ if (NULL == statistics_filename)
+ {
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+
+ statistics_file = fopen (statistics_filename, "w");
+ GNUNET_STATISTICS_get (statistics, NULL, NULL, GNUNET_TIME_UNIT_FOREVER_REL,
+ statistics_done, statistics_result, NULL);
}
static void
set_result_cb (void *cls,
- const struct GNUNET_SET_Element *element,
- enum GNUNET_SET_Status status)
+ const struct GNUNET_SET_Element *element,
+ enum GNUNET_SET_Status status)
{
struct SetInfo *info = cls;
struct GNUNET_HashCode hash;
if (element->size != sizeof (struct GNUNET_HashCode))
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "wrong element size: %u, expected %u\n", element->size, sizeof (struct GNUNET_HashCode));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "wrong element size: %u, expected %u\n",
+ element->size,
+ (unsigned int) sizeof (struct GNUNET_HashCode));
GNUNET_assert (0);
}
static void
-handle_shutdown (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+handle_shutdown (void *cls)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Shutting down set profiler\n");
GNUNET_SET_destroy (info2.set);
info2.set = NULL;
}
+ GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
}
{
unsigned int i;
struct GNUNET_HashCode hash;
- struct GNUNET_HashCode hashhash;
config = cfg;
return;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, handle_shutdown, NULL);
+ statistics = GNUNET_STATISTICS_create ("set-profiler", cfg);
+
+ GNUNET_SCHEDULER_add_shutdown (&handle_shutdown, NULL);
info1.id = "a";
info2.id = "b";
for (i = 0; i < num_a; i++)
{
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash);
- GNUNET_CRYPTO_hash (&hash, sizeof (struct GNUNET_HashCode), &hashhash);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Set a: Created element %s\n",
- GNUNET_h2s (&hashhash));
GNUNET_CONTAINER_multihashmap_put (info1.sent, &hash, NULL,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
}
for (i = 0; i < num_b; i++)
{
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash);
- GNUNET_CRYPTO_hash (&hash, sizeof (struct GNUNET_HashCode), &hashhash);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Set b: Created element %s\n",
- GNUNET_h2s (&hashhash));
GNUNET_CONTAINER_multihashmap_put (info2.sent, &hash, NULL,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
}
for (i = 0; i < num_c; i++)
{
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_STRONG, &hash);
- GNUNET_CRYPTO_hash (&hash, sizeof (struct GNUNET_HashCode), &hashhash);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Set c: Created element %s\n",
- GNUNET_h2s (&hashhash));
GNUNET_CONTAINER_multihashmap_put (common_sent, &hash, NULL,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
}
{ 'x', "operation", NULL,
gettext_noop ("operation to execute"),
GNUNET_YES, &GNUNET_GETOPT_set_string, &op_str },
+ { 's', "statistics", NULL,
+ gettext_noop ("write statistics to file"),
+ GNUNET_YES, &GNUNET_GETOPT_set_filename, &statistics_filename },
GNUNET_GETOPT_OPTION_END
};
GNUNET_PROGRAM_run2 (argc, argv, "gnunet-set-profiler",
options, &pre_run, NULL, GNUNET_YES);
return ret;
}
-