gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r7740 - in GNUnet/src: applications/stats util/string


From: gnunet
Subject: [GNUnet-SVN] r7740 - in GNUnet/src: applications/stats util/string
Date: Wed, 8 Oct 2008 14:34:08 -0600 (MDT)

Author: durner
Date: 2008-10-08 14:34:07 -0600 (Wed, 08 Oct 2008)
New Revision: 7740

Modified:
   GNUnet/src/applications/stats/statistics.c
   GNUnet/src/util/string/xmalloc.c
Log:
heap usage

Modified: GNUnet/src/applications/stats/statistics.c
===================================================================
--- GNUnet/src/applications/stats/statistics.c  2008-10-08 07:00:09 UTC (rev 
7739)
+++ GNUnet/src/applications/stats/statistics.c  2008-10-08 20:34:07 UTC (rev 
7740)
@@ -48,6 +48,8 @@
  */
 #define HAVE_SQSTATS GNUNET_NO
 
+#define HAVE_MEMSTATS GNUNET_NO
+
 /* *************** service *************** */
 
 /**
@@ -79,6 +81,10 @@
  */
 static GNUNET_CoreAPIForPlugins *coreAPI;
 
+#if HAVE_MEMSTATS
+extern volatile int GNUNET_memory_usage;
+#endif
+
 /**
  * Get a handle to a statistical entity.
  *
@@ -213,6 +219,9 @@
 #ifdef MINGW
 static int stat_handles;
 #endif
+#if HAVE_MEMSTATS
+static int stat_mem;
+#endif
 static GNUNET_Stats_ServiceAPI *stats;
 static GNUNET_CoreAPIForPlugins *myCoreAPI;
 
@@ -241,6 +250,9 @@
 #ifdef MINGW
   stat_handles = statHandle (gettext_noop ("# plibc handles"));
 #endif
+#if HAVE_MEMSTATS
+  stat_mem = statHandle ("# bytes dynamically allocated");
+#endif
 }
 
 static void
@@ -274,6 +286,9 @@
 #ifdef MINGW
   statSet (stat_handles, plibc_get_handle_count ());
 #endif
+#if HAVE_MEMSTATS
+  statSet (stat_mem, GNUNET_memory_usage);
+#endif
 }
 
 

Modified: GNUnet/src/util/string/xmalloc.c
===================================================================
--- GNUnet/src/util/string/xmalloc.c    2008-10-08 07:00:09 UTC (rev 7739)
+++ GNUnet/src/util/string/xmalloc.c    2008-10-08 20:34:07 UTC (rev 7740)
@@ -32,6 +32,12 @@
 #define INT_MAX 0x7FFFFFFF
 #endif
 
+#define RECORD_USAGE 0
+
+#if RECORD_USAGE
+volatile int GNUNET_memory_usage = 0;
+#endif
+
 /**
  * Allocate memory. Checks the return value, aborts if no more
  * memory is available.
@@ -61,12 +67,25 @@
   void *result;
 
   GNUNET_GE_ASSERT_FL (NULL, size < INT_MAX, filename, linenumber);
+
+#if RECORD_USAGE
+  size += sizeof (size_t);
+#endif
+
   result = malloc (size);
   if (result == NULL)
     GNUNET_GE_DIE_STRERROR_FL (NULL,
                                GNUNET_GE_IMMEDIATE | GNUNET_GE_USER |
                                GNUNET_GE_DEVELOPER | GNUNET_GE_FATAL,
                                "malloc", filename, linenumber);
+
+#if RECORD_USAGE
+  size -= sizeof (size_t);
+  *((size_t *) result) = size;
+  result += sizeof (size_t);
+  GNUNET_memory_usage += size;
+#endif
+
   memset (result, 0, size);     /* client code should not rely on this, 
though... */
   return result;
 }
@@ -87,6 +106,13 @@
 GNUNET_xrealloc_ (void *ptr,
                   const size_t n, const char *filename, int linenumber)
 {
+#if RECORD_USAGE
+  ptr -= sizeof (size_t);
+  GNUNET_memory_usage = GNUNET_memory_usage - (*((size_t *) ptr)) + n;
+  *((size_t *) ptr) = n;
+  (*((size_t *) & n)) += sizeof (size_t);
+#endif
+
   ptr = realloc (ptr, n);
 
   if (!ptr)
@@ -94,6 +120,11 @@
                                GNUNET_GE_IMMEDIATE | GNUNET_GE_USER |
                                GNUNET_GE_DEVELOPER | GNUNET_GE_FATAL,
                                "realloc", filename, linenumber);
+
+#if RECORD_USAGE
+  ptr += sizeof (size_t);
+#endif
+
   return ptr;
 }
 
@@ -109,6 +140,12 @@
 GNUNET_xfree_ (void *ptr, const char *filename, int linenumber)
 {
   GNUNET_GE_ASSERT_FL (NULL, ptr != NULL, filename, linenumber);
+
+#if RECORD_USAGE
+  ptr -= sizeof (size_t);
+  GNUNET_memory_usage -= *((size_t *) ptr);
+#endif
+
   free (ptr);
 }
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]