[prev in list] [next in list] [prev in thread] [next in thread] 

List:       quagga-dev
Subject:    [quagga-dev 14779] [PATCH 08/10] lib: clean/restore memory debugging functions
From:       David Lamparter <equinox () opensourcerouting ! org>
Date:       2016-02-26 7:00:34
Message-ID: 1456470036-72063-9-git-send-email-equinox () opensourcerouting ! org
[Download RAW message or body]

This adapts the dump-at-exit handler and removes the old leftover code.

(Note the text in log_memtype_stderr was actually incorrect as the only
caller in bgpd cleans up configuration before calling it, i.e. any
remaining allocations are missing-cleanup bugs.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Acked-by: Vincent JARDIN <vincent.jardin@6wind.com>
Acked-by: Donald Sharp <sharpd@cumulusnetworks.com>
---
 lib/memory.c     | 35 ++++++++++++++++++++++
 lib/memory.h     |  1 +
 lib/memory_vty.c | 89 +-------------------------------------------------------
 lib/memory_vty.h |  1 -
 4 files changed, 37 insertions(+), 89 deletions(-)

diff --git a/lib/memory.c b/lib/memory.c
index 562b0f5..38e424d 100644
--- a/lib/memory.c
+++ b/lib/memory.c
@@ -112,3 +112,38 @@ qmem_walk (qmem_walk_fn *func, void *arg)
     }
   return 0;
 }
+
+struct exit_dump_args
+{
+  const char *prefix;
+  int error;
+};
+
+static int
+qmem_exit_walker (void *arg, struct memgroup *mg, struct memtype *mt)
+{
+  struct exit_dump_args *eda = arg;
+
+  if (!mt)
+    {
+      fprintf (stderr, "%s: showing active allocations in memory group %s\n",
+               eda->prefix, mg->name);
+    }
+  else if (mt->n_alloc)
+    {
+      char size[32];
+      eda->error++;
+      snprintf (size, sizeof (size), "%10zu", mt->size);
+      fprintf (stderr, "%s:  %-30s: %6zu * %s\n",
+               eda->prefix, mt->name, mt->n_alloc,
+               mt->size == SIZE_VAR ? "(variably sized)" : size);
+    }
+  return 0;
+}
+
+void
+log_memstats_stderr (const char *prefix)
+{
+  struct exit_dump_args eda = { .prefix = prefix, .error = 0 };
+  qmem_walk (qmem_exit_walker, &eda);
+}
diff --git a/lib/memory.h b/lib/memory.h
index 6edbe2f..e0c420a 100644
--- a/lib/memory.h
+++ b/lib/memory.h
@@ -171,6 +171,7 @@ static inline size_t mtype_stats_alloc(struct memtype *mt)
  * last value from qmem_walk_fn. */
 typedef int qmem_walk_fn (void *arg, struct memgroup *mg, struct memtype *mt);
 extern int qmem_walk (qmem_walk_fn *func, void *arg);
+extern void log_memstats_stderr (const char *);
 
 extern void memory_oom (size_t size, const char *name);
 
diff --git a/lib/memory_vty.c b/lib/memory_vty.c
index e1c08ce..0b702ed 100644
--- a/lib/memory_vty.c
+++ b/lib/memory_vty.c
@@ -35,80 +35,6 @@
 #include "vty.h"
 #include "command.h"
 
-void
-log_memstats_stderr (const char *prefix)
-{
-#if 0
-  struct mlist *ml;
-  struct memory_list *m;
-  int i;
-  int j = 0;
-
-  for (ml = mlists; ml->list; ml++)
-    {
-      i = 0;
-
-      for (m = ml->list; m->index >= 0; m++)
-        if (m->index && mstat[m->index].alloc)
-          {
-            if (!i)
-              fprintf (stderr,
-                       "%s: memstats: Current memory utilization in module %s:\n",
-                       prefix,
-                       ml->name);
-            fprintf (stderr,
-                     "%s: memstats:  %-30s: %10ld%s\n",
-                     prefix,
-                     m->format,
-                     mstat[m->index].alloc,
-                     mstat[m->index].alloc < 0 ? " (REPORT THIS BUG!)" : "");
-            i = j = 1;
-          }
-    }
-
-  if (j)
-    fprintf (stderr,
-             "%s: memstats: NOTE: If configuration exists, utilization may be "
-             "expected.\n",
-             prefix);
-  else
-    fprintf (stderr,
-             "%s: memstats: No remaining tracked memory utilization.\n",
-             prefix);
-#endif
-}
-
-#if 0
-static void
-show_separator(struct vty *vty)
-{
-  vty_out (vty, "-----------------------------\r\n");
-}
-
-static int
-show_memory_vty (struct vty *vty, struct memory_list *list)
-{
-  struct memory_list *m;
-  int needsep = 0;
-
-  for (m = list; m->index >= 0; m++)
-    if (m->index == 0)
-      {
-	if (needsep)
-	  {
-	    show_separator (vty);
-	    needsep = 0;
-	  }
-      }
-    else if (mstat[m->index].alloc)
-      {
-	vty_out (vty, "%-30s: %10ld\r\n", m->format, mstat[m->index].alloc);
-	needsep = 1;
-      }
-  return needsep;
-}
-#endif
-
 #ifdef HAVE_MALLINFO
 static int
 show_memory_mallinfo (struct vty *vty)
@@ -174,23 +100,10 @@ DEFUN (show_memory,
        "Show running system information\n"
        "Memory statistics\n")
 {
-  int needsep = 0;
-  
 #ifdef HAVE_MALLINFO
-  needsep = show_memory_mallinfo (vty);
+  show_memory_mallinfo (vty);
 #endif /* HAVE_MALLINFO */
 
-  (void) needsep;
-#if 0
-  struct mlist *ml;
-  for (ml = mlists; ml->list; ml++)
-    {
-      if (needsep)
-	show_separator (vty);
-      needsep = show_memory_vty (vty, ml->list);
-    }
-#endif
-
   qmem_walk(qmem_walker, vty);
   return CMD_SUCCESS;
 }
diff --git a/lib/memory_vty.h b/lib/memory_vty.h
index 7aab01e..565a75a 100644
--- a/lib/memory_vty.h
+++ b/lib/memory_vty.h
@@ -24,7 +24,6 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 #include "memory.h"
 
 extern void memory_init (void);
-extern void log_memstats_stderr (const char *);
 
 /* Human friendly string for given byte count */
 #define MTYPE_MEMSTR_LEN 20
-- 
2.3.6


_______________________________________________
Quagga-dev mailing list
Quagga-dev@lists.quagga.net
https://lists.quagga.net/mailman/listinfo/quagga-dev
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic