Track strdups too in the statistics
authorDale Weiler <killfieldengine@gmail.com>
Sun, 2 Jun 2013 04:38:20 +0000 (04:38 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Sun, 2 Jun 2013 04:38:20 +0000 (04:38 +0000)
util.c

diff --git a/util.c b/util.c
index 3e81a51c0bb89f6f19251b85a6614ab4e306abea..351aba6d8bb4732357a779a1765280237d82fd33 100644 (file)
--- a/util.c
+++ b/util.c
@@ -208,6 +208,7 @@ void util_st_put(size_table_t table, size_t key, size_t value) {
     table[hash]->value = value;
 }
 
+static uint64_t      strdups      = 0;
 static uint64_t      vectors      = 0;
 static uint64_t      vector_sizes = 0;
 static size_table_t  vector_usage = NULL;
@@ -249,26 +250,30 @@ void util_meminfo() {
     
     if (OPTS_OPTION_BOOL(OPTION_STATISTICS) ||
         OPTS_OPTION_BOOL(OPTION_MEMCHK)) {
-        size_t i;
+        size_t i=0;
+        size_t e=1;
         
         con_out("Additional Statistics:\n\
-            Total vectors used:         %u\n\
+            Total vectors allocated:    %u\n\
+            Total string duplicates:    %u\n\
             Total unique vector sizes:  %u\n",
             (unsigned)vectors,
+            (unsigned)strdups,
             (unsigned)vector_sizes
         );
         
-        /* TODO: */
-        for (i = 0; i < ST_SIZE; i++) {
+        for (; i < ST_SIZE; i++) {
             size_entry_t *entry;
             
             if (!(entry = vector_usage[i]))
                 continue;
             
-            con_out("               # of %3u (bytes) vectors: %u\n",
+            con_out("               %u| # of %3u (bytes) vectors: %u\n",
+                (unsigned)e,
                 (unsigned)entry->key,
                 (unsigned)entry->value
             );
+            e++;
         }
     }
     
@@ -295,6 +300,7 @@ char *_util_Estrdup(const char *s, const char *file, size_t line) {
         memcpy(ptr, s, len);
         ptr[len] = '\0';
     }
+    strdups++;
     return ptr;
 }
 
@@ -314,6 +320,7 @@ char *_util_Estrdup_empty(const char *s, const char *file, size_t line) {
         memcpy(ptr, s, len);
         ptr[len] = '\0';
     }
+    strdups++;
     return ptr;
 }