]> git.puffer.fish Git - matthieu/frr.git/commitdiff
2004-11-15 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
authorajs <ajs>
Mon, 15 Nov 2004 16:12:32 +0000 (16:12 +0000)
committerajs <ajs>
Mon, 15 Nov 2004 16:12:32 +0000 (16:12 +0000)
* memory.c: (zerror) Use zlog_err instead of fprintf to stderr.
  Instead of exiting, log currenty memory usage and then abort.
  (log_memstats) New function to log memory statistics, called by
  zerror.
  (show_memory_all) Loop over new mlists array instead of calling
  show_memory_vty separately for each memory_list.

lib/ChangeLog
lib/memory.c

index 4434009974f55a211658d5ad429bb48d7a4705fb..b662aed7a93d2457940170d9e0faf2ca11f0624a 100644 (file)
@@ -1,3 +1,12 @@
+2004-11-15 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
+
+       * memory.c: (zerror) Use zlog_err instead of fprintf to stderr.
+         Instead of exiting, log currenty memory usage and then abort.
+         (log_memstats) New function to log memory statistics, called by
+         zerror.
+         (show_memory_all) Loop over new mlists array instead of calling
+         show_memory_vty separately for each memory_list.
+
 2004-11-08 Paul Jakma <paul@dishone.st>
 
        * buffer.c: Add missing include of log.h.
index bef0997f79fbfaffe5fee56a411cd91f3d5f252e..1f52bdf6792fa1b38b9c513f0c2d4ec8f47d208d 100644 (file)
@@ -27,6 +27,7 @@
 
 void alloc_inc (int);
 void alloc_dec (int);
+static void log_memstats(int log_priority);
 \f
 struct message mstr [] =
 {
@@ -42,9 +43,10 @@ struct message mstr [] =
 static void
 zerror (const char *fname, int type, size_t size)
 {
-  fprintf (stderr, "%s : can't allocate memory for `%s' size %d\n", 
-          fname, lookup (mstr, type), (int) size);
-  exit (1);
+  zlog_err ("%s : can't allocate memory for `%s' size %d: %s\n", 
+           fname, lookup (mstr, type), (int) size, strerror(errno));
+  log_memstats(LOG_WARNING);
+  abort();
 }
 
 /* Memory allocation. */
@@ -406,6 +408,36 @@ struct memory_list memory_list_isis[] =
   { -1, NULL },
 };
 
+static struct mlist {
+  struct memory_list *list;
+  const char *name;
+} mlists[] = {
+  { memory_list_lib,   "LIB"},
+  { memory_list_rip,   "RIP"},
+  { memory_list_ripng, "RIPNG"},
+  { memory_list_ospf,  "OSPF"},
+  { memory_list_ospf6, "OSPF6"},
+  { memory_list_isis,  "ISIS"},
+  { memory_list_bgp,   "BGP"},
+  { NULL, NULL},
+};
+
+static void
+log_memstats(int pri)
+{
+  struct mlist *ml;
+
+  for (ml = mlists; ml->list; ml++)
+    {
+      struct memory_list *m;
+
+      zlog (NULL, pri, "Memory utilization in module %s:", ml->name);
+      for (m = ml->list; m->index >= 0; m++)
+       if (m->index && mstat[m->index].alloc)
+         zlog (NULL, pri, "  %-22s: %5ld", m->format, mstat[m->index].alloc);
+    }
+}
+
 struct memory_list memory_list_separator[] =
 {
   { 0, NULL},
@@ -431,19 +463,14 @@ DEFUN (show_memory_all,
        "Memory statistics\n"
        "All memory statistics\n")
 {
-  show_memory_vty (vty, memory_list_lib);
-  show_memory_vty (vty, memory_list_separator);
-  show_memory_vty (vty, memory_list_rip);
-  show_memory_vty (vty, memory_list_separator);
-  show_memory_vty (vty, memory_list_ripng);
-  show_memory_vty (vty, memory_list_separator);
-  show_memory_vty (vty, memory_list_ospf);
-  show_memory_vty (vty, memory_list_separator);
-  show_memory_vty (vty, memory_list_ospf6);
-  show_memory_vty (vty, memory_list_separator);
-  show_memory_vty (vty, memory_list_isis);
-  show_memory_vty (vty, memory_list_separator);
-  show_memory_vty (vty, memory_list_bgp);
+  struct mlist *ml;
+
+  for (ml = mlists; ml->list; ml++)
+    {
+      if (ml != mlists)
+        show_memory_vty (vty, memory_list_separator);
+      show_memory_vty (vty, ml->list);
+    }
 
   return CMD_SUCCESS;
 }