From 244acf03bb6313c3e8a900c940f1eed5536c7aa9 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 21 Oct 2009 12:44:37 +0000 Subject: extra debug for datastore, stats api fix --- src/datastore/Makefile.am | 1 + src/datastore/gnunet-service-datastore.c | 13 +++++------ src/datastore/plugin_datastore_sqlite.c | 39 ++++++++++++++++++++++++++++++-- src/hostlist/hostlist-client.c | 4 ++-- src/include/gnunet_statistics_service.h | 6 ++--- src/statistics/gnunet-statistics.c | 8 ++++--- src/statistics/statistics_api.c | 8 +++---- 7 files changed, 58 insertions(+), 21 deletions(-) diff --git a/src/datastore/Makefile.am b/src/datastore/Makefile.am index 1ca588926..608fb7770 100644 --- a/src/datastore/Makefile.am +++ b/src/datastore/Makefile.am @@ -44,6 +44,7 @@ libgnunet_plugin_datastore_sqlite_la_SOURCES = \ plugin_datastore_sqlite.c libgnunet_plugin_datastore_sqlite_la_LIBADD = \ $(top_builddir)/src/statistics/libgnunetstatistics.la \ + $(top_builddir)/src/arm/libgnunetarm.la \ $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) -lsqlite3 libgnunet_plugin_datastore_sqlite_la_LDFLAGS = \ $(GN_PLUGIN_LDFLAGS) diff --git a/src/datastore/gnunet-service-datastore.c b/src/datastore/gnunet-service-datastore.c index 0fe1263ce..c895bb1c8 100644 --- a/src/datastore/gnunet-service-datastore.c +++ b/src/datastore/gnunet-service-datastore.c @@ -134,11 +134,10 @@ static int reservation_gen; static unsigned long long quota; /** - * How much space are we using for the cache? - * (space available for insertions that will be - * instantly reclaimed by discarding less - * important content --- or possibly whatever - * we just inserted into the "cache"). + * How much space are we using for the cache? (space available for + * insertions that will be instantly reclaimed by discarding less + * important content --- or possibly whatever we just inserted into + * the "cache"). */ static unsigned long long cache_size; @@ -354,7 +353,7 @@ manage (void *cls, (0 == *need) ? GNUNET_YES : GNUNET_NO); #if DEBUG_DATASTORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Deleting %llu bytes of low-priority content (still trying to recover %llu bytes)\n", + "Deleting %llu bytes of low-priority content (still trying to free another %llu bytes)\n", size + GNUNET_DATASTORE_ENTRY_OVERHEAD, *need); #endif @@ -383,7 +382,7 @@ manage_space (unsigned long long need) #if DEBUG_DATASTORE GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Asked to recover %llu bytes of cache space\n", + "Asked to free up %llu bytes of cache space\n", need); #endif n = GNUNET_malloc (sizeof(unsigned long long)); diff --git a/src/datastore/plugin_datastore_sqlite.c b/src/datastore/plugin_datastore_sqlite.c index 2223dd6eb..b5d5990c6 100644 --- a/src/datastore/plugin_datastore_sqlite.c +++ b/src/datastore/plugin_datastore_sqlite.c @@ -25,11 +25,12 @@ */ #include "platform.h" +#include "gnunet_arm_service.h" #include "gnunet_statistics_service.h" #include "plugin_datastore.h" #include -#define DEBUG_SQLITE GNUNET_NO +#define DEBUG_SQLITE GNUNET_YES /** * After how many payload-changing operations @@ -614,11 +615,28 @@ sqlite_next_request_cont (void *cls, nc->end_it = GNUNET_YES; return; } +#if DEBUG_SQLITE + if (ret == GNUNET_NO) + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + "sqlite", + "Asked to remove entry %llu (%u bytes)\n", + (unsigned long long) rowid, + size + GNUNET_DATASTORE_ENTRY_OVERHEAD); +#endif if ( (ret == GNUNET_NO) && (GNUNET_OK == delete_by_rowid (plugin, rowid)) ) { plugin->payload -= (size + GNUNET_DATASTORE_ENTRY_OVERHEAD); plugin->lastSync++; +#if DEBUG_SQLITE + if (ret == GNUNET_NO) + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + "sqlite", + "Removed entry %llu (%u bytes), new payload is %llu\n", + (unsigned long long) rowid, + size + GNUNET_DATASTORE_ENTRY_OVERHEAD, + (unsigned long long) plugin->payload); +#endif if (plugin->lastSync >= MAX_STAT_SYNC_LAG) sync_stats (plugin); } @@ -741,6 +759,13 @@ sqlite_plugin_put (void *cls, GNUNET_ERROR_TYPE_BULK, "sqlite3_reset"); plugin->lastSync++; plugin->payload += size + GNUNET_DATASTORE_ENTRY_OVERHEAD; +#if DEBUG_SQLITE + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + "sqlite", + "Stored new entry (%u bytes), new payload is %llu\n", + size + GNUNET_DATASTORE_ENTRY_OVERHEAD, + (unsigned long long) plugin->payload); +#endif if (plugin->lastSync >= MAX_STAT_SYNC_LAG) sync_stats (plugin); return GNUNET_OK; @@ -1522,11 +1547,18 @@ static int process_stat_in (void *cls, const char *subsystem, const char *name, - unsigned long long value, + uint64_t value, int is_persistent) { struct Plugin *plugin = cls; plugin->payload += value; +#if DEBUG_SQLITE + GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, + "sqlite", + "Notification from statistics about existing payload (%llu), new payload is %llu\n", + value, + (unsigned long long) plugin->payload); +#endif return GNUNET_OK; } @@ -1548,6 +1580,7 @@ libgnunet_plugin_datastore_sqlite_init (void *cls) return NULL; /* can only initialize once! */ memset (&plugin, 0, sizeof(struct Plugin)); plugin.env = env; + GNUNET_ARM_start_services (env->cfg, env->sched, "statistics"); plugin.statistics = GNUNET_STATISTICS_create (env->sched, "sqlite", env->cfg); @@ -1562,6 +1595,7 @@ libgnunet_plugin_datastore_sqlite_init (void *cls) database_setup (env->cfg, &plugin)) { database_shutdown (&plugin); + GNUNET_ARM_stop_services (env->cfg, env->sched, "statistics"); return NULL; } api = GNUNET_malloc (sizeof (struct GNUNET_DATASTORE_PluginFunctions)); @@ -1603,6 +1637,7 @@ libgnunet_plugin_datastore_sqlite_done (void *cls) plugin->env = NULL; plugin->payload = 0; GNUNET_STATISTICS_destroy (plugin->statistics); + GNUNET_ARM_stop_services (plugin->env->cfg, plugin->env->sched, "statistics"); GNUNET_free (api); if (fn != NULL) { diff --git a/src/hostlist/hostlist-client.c b/src/hostlist/hostlist-client.c index db7d1c586..e0ff1f5a2 100644 --- a/src/hostlist/hostlist-client.c +++ b/src/hostlist/hostlist-client.c @@ -607,10 +607,10 @@ static int process_stat (void *cls, const char *subsystem, const char *name, - unsigned long long value, + uint64_t value, int is_persistent) { - hostlist_delay.value = (uint64_t) value; + hostlist_delay.value = value; return GNUNET_OK; } diff --git a/src/include/gnunet_statistics_service.h b/src/include/gnunet_statistics_service.h index 2496f4091..d8f17b8a1 100644 --- a/src/include/gnunet_statistics_service.h +++ b/src/include/gnunet_statistics_service.h @@ -64,7 +64,7 @@ struct GNUNET_STATISTICS_Handle; typedef int (*GNUNET_STATISTICS_Iterator) (void *cls, const char *subsystem, const char *name, - unsigned long long value, + uint64_t value, int is_persistent); /** @@ -129,7 +129,7 @@ GNUNET_STATISTICS_get (struct GNUNET_STATISTICS_Handle *handle, void GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle, const char *name, - unsigned long long value, int make_persistent); + uint64_t value, int make_persistent); /** * Set statistic value for the peer. Will always use our @@ -143,7 +143,7 @@ GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle, void GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle, const char *name, - long long delta, int make_persistent); + int64_t delta, int make_persistent); diff --git a/src/statistics/gnunet-statistics.c b/src/statistics/gnunet-statistics.c index bea9ca0ca..dd9850418 100644 --- a/src/statistics/gnunet-statistics.c +++ b/src/statistics/gnunet-statistics.c @@ -65,11 +65,13 @@ static int persistent; static int printer (void *cls, const char *subsystem, - const char *name, unsigned long long value, int is_persistent) + const char *name, + uint64_t value, int is_persistent) { FPRINTF (stdout, "%s%-20s %-40s: %16llu\n", - is_persistent ? "!" : " ", subsystem, _(name), value); + is_persistent ? "!" : " ", subsystem, _(name), + (unsigned long long) value); return GNUNET_OK; } @@ -127,7 +129,7 @@ run (void *cls, ret = 1; return; } - GNUNET_STATISTICS_set (h, name, val, persistent); + GNUNET_STATISTICS_set (h, name, (uint64_t) val, persistent); GNUNET_STATISTICS_destroy (h); return; } diff --git a/src/statistics/statistics_api.c b/src/statistics/statistics_api.c index 335cd4165..21b8ecd8a 100644 --- a/src/statistics/statistics_api.c +++ b/src/statistics/statistics_api.c @@ -88,7 +88,7 @@ struct ActionItem /** * Associated value. */ - unsigned long long value; + uint64_t value; /** * Flag for SET/UPDATE actions. @@ -630,7 +630,7 @@ static void add_setter_action (struct GNUNET_STATISTICS_Handle *h, const char *name, int make_persistent, - unsigned long long value, enum ActionType type) + uint64_t value, enum ActionType type) { struct ActionItem *ai; size_t slen; @@ -674,7 +674,7 @@ add_setter_action (struct GNUNET_STATISTICS_Handle *h, void GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle, const char *name, - unsigned long long value, int make_persistent) + uint64_t value, int make_persistent) { add_setter_action (handle, name, make_persistent, value, ACTION_SET); } @@ -692,7 +692,7 @@ GNUNET_STATISTICS_set (struct GNUNET_STATISTICS_Handle *handle, void GNUNET_STATISTICS_update (struct GNUNET_STATISTICS_Handle *handle, const char *name, - long long delta, int make_persistent) + int64_t delta, int make_persistent) { add_setter_action (handle, name, make_persistent, (unsigned long long) delta, ACTION_UPDATE); -- cgit v1.2.3