aboutsummaryrefslogtreecommitdiff
path: root/src/datacache
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-04-28 11:33:29 +0000
committerChristian Grothoff <christian@grothoff.org>2010-04-28 11:33:29 +0000
commit684476aafc7c225d565295fdac4a00ee8bfc207f (patch)
treee0d7790b83276467fcd8eb50e1537b8a8e8e8fc0 /src/datacache
parent43bb2e8d1def0d823a876e30f50bca941e351da0 (diff)
downloadgnunet-684476aafc7c225d565295fdac4a00ee8bfc207f.tar.gz
gnunet-684476aafc7c225d565295fdac4a00ee8bfc207f.zip
stats for datacache
Diffstat (limited to 'src/datacache')
-rw-r--r--src/datacache/Makefile.am1
-rw-r--r--src/datacache/datacache.c33
2 files changed, 32 insertions, 2 deletions
diff --git a/src/datacache/Makefile.am b/src/datacache/Makefile.am
index 5e01fe03e..564af9f28 100644
--- a/src/datacache/Makefile.am
+++ b/src/datacache/Makefile.am
@@ -18,6 +18,7 @@ lib_LTLIBRARIES = \
18libgnunetdatacache_la_SOURCES = \ 18libgnunetdatacache_la_SOURCES = \
19 datacache.c plugin_datacache.h 19 datacache.c plugin_datacache.h
20libgnunetdatacache_la_LIBADD = \ 20libgnunetdatacache_la_LIBADD = \
21 $(top_builddir)/src/statistics/libgnunetstatistics.la \
21 $(top_builddir)/src/util/libgnunetutil.la \ 22 $(top_builddir)/src/util/libgnunetutil.la \
22 $(GN_LIBINTL) 23 $(GN_LIBINTL)
23libgnunetdatacache_la_LDFLAGS = \ 24libgnunetdatacache_la_LDFLAGS = \
diff --git a/src/datacache/datacache.c b/src/datacache/datacache.c
index 4c474e9ba..0ad9b9df4 100644
--- a/src/datacache/datacache.c
+++ b/src/datacache/datacache.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 (C) 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) 3 (C) 2004, 2005, 2006, 2007, 2009, 2010 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -26,6 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_datacache_lib.h" 28#include "gnunet_datacache_lib.h"
29#include "gnunet_statistics_service.h"
29#include "plugin_datacache.h" 30#include "plugin_datacache.h"
30 31
31/** 32/**
@@ -45,6 +46,11 @@ struct GNUNET_DATACACHE_Handle
45 const struct GNUNET_CONFIGURATION_Handle *cfg; 46 const struct GNUNET_CONFIGURATION_Handle *cfg;
46 47
47 /** 48 /**
49 * Opaque handle for the statistics service.
50 */
51 struct GNUNET_STATISTICS_Handle *stats;
52
53 /**
48 * Configuration section to use. 54 * Configuration section to use.
49 */ 55 */
50 char *section; 56 char *section;
@@ -100,6 +106,10 @@ env_delete_notify (void *cls,
100 GNUNET_assert (h->utilization >= size); 106 GNUNET_assert (h->utilization >= size);
101 h->utilization -= size; 107 h->utilization -= size;
102 GNUNET_CONTAINER_bloomfilter_remove (h->filter, key); 108 GNUNET_CONTAINER_bloomfilter_remove (h->filter, key);
109 GNUNET_STATISTICS_update (h->stats,
110 gettext_noop ("# bytes stored"),
111 -size,
112 GNUNET_NO);
103} 113}
104 114
105 115
@@ -157,6 +167,9 @@ GNUNET_DATACACHE_create (struct GNUNET_SCHEDULER_Handle *sched,
157 { 167 {
158 ret->filter = GNUNET_CONTAINER_bloomfilter_load (NULL, bf_size, 5); /* approx. 3% false positives at max use */ 168 ret->filter = GNUNET_CONTAINER_bloomfilter_load (NULL, bf_size, 5); /* approx. 3% false positives at max use */
159 } 169 }
170 ret->stats = GNUNET_STATISTICS_create (sched,
171 "datacache",
172 cfg);
160 ret->section = GNUNET_strdup (section); 173 ret->section = GNUNET_strdup (section);
161 ret->env.sched = sched; 174 ret->env.sched = sched;
162 ret->env.cfg = cfg; 175 ret->env.cfg = cfg;
@@ -204,6 +217,8 @@ void GNUNET_DATACACHE_destroy (struct GNUNET_DATACACHE_Handle *h)
204 h->bloom_name); 217 h->bloom_name);
205 GNUNET_free (h->bloom_name); 218 GNUNET_free (h->bloom_name);
206 } 219 }
220 GNUNET_STATISTICS_destroy (h->stats,
221 GNUNET_NO);
207 GNUNET_free (h); 222 GNUNET_free (h);
208} 223}
209 224
@@ -237,6 +252,10 @@ GNUNET_DATACACHE_put (struct GNUNET_DATACACHE_Handle *h,
237 discard_time); 252 discard_time);
238 if (used == 0) 253 if (used == 0)
239 return GNUNET_SYSERR; 254 return GNUNET_SYSERR;
255 GNUNET_STATISTICS_update (h->stats,
256 gettext_noop ("# bytes stored"),
257 size,
258 GNUNET_NO);
240 GNUNET_CONTAINER_bloomfilter_add (h->filter, key); 259 GNUNET_CONTAINER_bloomfilter_add (h->filter, key);
241 while (h->utilization + used > h->env.quota) 260 while (h->utilization + used > h->env.quota)
242 GNUNET_assert (GNUNET_OK == h->api->del (h->api->cls)); 261 GNUNET_assert (GNUNET_OK == h->api->del (h->api->cls));
@@ -263,9 +282,19 @@ GNUNET_DATACACHE_get (struct GNUNET_DATACACHE_Handle *h,
263 GNUNET_DATACACHE_Iterator iter, 282 GNUNET_DATACACHE_Iterator iter,
264 void *iter_cls) 283 void *iter_cls)
265{ 284{
285 GNUNET_STATISTICS_update (h->stats,
286 gettext_noop ("# requests received"),
287 1,
288 GNUNET_NO);
266 if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter, 289 if (GNUNET_OK != GNUNET_CONTAINER_bloomfilter_test (h->filter,
267 key)) 290 key))
268 return 0; /* can not be present */ 291 {
292 GNUNET_STATISTICS_update (h->stats,
293 gettext_noop ("# requests filtered by bloom filter"),
294 1,
295 GNUNET_NO);
296 return 0; /* can not be present */
297 }
269 return h->api->get (h->api->cls, 298 return h->api->get (h->api->cls,
270 key, 299 key,
271 type, 300 type,