Diff for /embedaddon/quagga/lib/memory.c between versions 1.1.1.2 and 1.1.1.3

version 1.1.1.2, 2012/10/09 09:22:28 version 1.1.1.3, 2016/11/02 10:09:11
Line 32 Line 32
 static void alloc_inc (int);  static void alloc_inc (int);
 static void alloc_dec (int);  static void alloc_dec (int);
 static void log_memstats(int log_priority);  static void log_memstats(int log_priority);
 static const struct message mstr [] =  static const struct message mstr [] =
 {  {
   { MTYPE_THREAD, "thread" },    { MTYPE_THREAD, "thread" },
Line 42  static const struct message mstr [] = Line 42  static const struct message mstr [] =
   { MTYPE_IF, "interface" },    { MTYPE_IF, "interface" },
   { 0, NULL },    { 0, NULL },
 };  };
 /* Fatal memory allocation error occured. */  /* Fatal memory allocation error occured. */
 static void __attribute__ ((noreturn))  static void __attribute__ ((noreturn))
 zerror (const char *fname, int type, size_t size)  zerror (const char *fname, int type, size_t size)
Line 108  zrealloc (int type, void *ptr, size_t size) Line 108  zrealloc (int type, void *ptr, size_t size)
 {  {
   void *memory;    void *memory;
   
     if (ptr == NULL)              /* is really alloc */
         return zcalloc(type, size);
   
   memory = realloc (ptr, size);    memory = realloc (ptr, size);
   if (memory == NULL)    if (memory == NULL)
     zerror ("realloc", type, size);      zerror ("realloc", type, size);
Line 150  zstrdup (int type, const char *str) Line 153  zstrdup (int type, const char *str)
   alloc_inc (type);    alloc_inc (type);
   return dup;    return dup;
 }  }
 #ifdef MEMORY_LOG  #ifdef MEMORY_LOG
 static struct   static struct 
 {  {
Line 259  alloc_dec (int type) Line 262  alloc_dec (int type)
 {  {
   mstat[type].alloc--;    mstat[type].alloc--;
 }  }
 /* Looking up memory status from vty interface. */  /* Looking up memory status from vty interface. */
 #include "vector.h"  #include "vector.h"
 #include "vty.h"  #include "vty.h"
Line 392  show_memory_mallinfo (struct vty *vty) Line 395  show_memory_mallinfo (struct vty *vty)
 }  }
 #endif /* HAVE_MALLINFO */  #endif /* HAVE_MALLINFO */
   
DEFUN (show_memory_all,DEFUN (show_memory,
       show_memory_all_cmd,       show_memory_cmd,
       "show memory all",       "show memory",
        "Show running system information\n"         "Show running system information\n"
       "Memory statistics\n"       "Memory statistics\n")
       "All memory statistics\n") 
 {  {
   struct mlist *ml;    struct mlist *ml;
   int needsep = 0;    int needsep = 0;
Line 416  DEFUN (show_memory_all, Line 418  DEFUN (show_memory_all,
   return CMD_SUCCESS;    return CMD_SUCCESS;
 }  }
   
 ALIAS (show_memory_all,  
        show_memory_cmd,  
        "show memory",  
        "Show running system information\n"  
        "Memory statistics\n")  
   
 DEFUN (show_memory_lib,  
        show_memory_lib_cmd,  
        "show memory lib",  
        SHOW_STR  
        "Memory statistics\n"  
        "Library memory\n")  
 {  
   show_memory_vty (vty, memory_list_lib);  
   return CMD_SUCCESS;  
 }  
   
 DEFUN (show_memory_zebra,  
        show_memory_zebra_cmd,  
        "show memory zebra",  
        SHOW_STR  
        "Memory statistics\n"  
        "Zebra memory\n")  
 {  
   show_memory_vty (vty, memory_list_zebra);  
   return CMD_SUCCESS;  
 }  
   
 DEFUN (show_memory_rip,  
        show_memory_rip_cmd,  
        "show memory rip",  
        SHOW_STR  
        "Memory statistics\n"  
        "RIP memory\n")  
 {  
   show_memory_vty (vty, memory_list_rip);  
   return CMD_SUCCESS;  
 }  
   
 DEFUN (show_memory_ripng,  
        show_memory_ripng_cmd,  
        "show memory ripng",  
        SHOW_STR  
        "Memory statistics\n"  
        "RIPng memory\n")  
 {  
   show_memory_vty (vty, memory_list_ripng);  
   return CMD_SUCCESS;  
 }  
   
 DEFUN (show_memory_babel,  
        show_memory_babel_cmd,  
        "show memory babel",  
        SHOW_STR  
        "Memory statistics\n"  
        "Babel memory\n")  
 {  
   show_memory_vty (vty, memory_list_babel);  
   return CMD_SUCCESS;  
 }  
   
 DEFUN (show_memory_bgp,  
        show_memory_bgp_cmd,  
        "show memory bgp",  
        SHOW_STR  
        "Memory statistics\n"  
        "BGP memory\n")  
 {  
   show_memory_vty (vty, memory_list_bgp);  
   return CMD_SUCCESS;  
 }  
   
 DEFUN (show_memory_ospf,  
        show_memory_ospf_cmd,  
        "show memory ospf",  
        SHOW_STR  
        "Memory statistics\n"  
        "OSPF memory\n")  
 {  
   show_memory_vty (vty, memory_list_ospf);  
   return CMD_SUCCESS;  
 }  
   
 DEFUN (show_memory_ospf6,  
        show_memory_ospf6_cmd,  
        "show memory ospf6",  
        SHOW_STR  
        "Memory statistics\n"  
        "OSPF6 memory\n")  
 {  
   show_memory_vty (vty, memory_list_ospf6);  
   return CMD_SUCCESS;  
 }  
   
 DEFUN (show_memory_isis,  
        show_memory_isis_cmd,  
        "show memory isis",  
        SHOW_STR  
        "Memory statistics\n"  
        "ISIS memory\n")  
 {  
   show_memory_vty (vty, memory_list_isis);  
   return CMD_SUCCESS;  
 }  
   
 void  void
 memory_init (void)  memory_init (void)
 {  {
   install_element (RESTRICTED_NODE, &show_memory_cmd);    install_element (RESTRICTED_NODE, &show_memory_cmd);
   install_element (RESTRICTED_NODE, &show_memory_all_cmd);  
   install_element (RESTRICTED_NODE, &show_memory_lib_cmd);  
   install_element (RESTRICTED_NODE, &show_memory_rip_cmd);  
   install_element (RESTRICTED_NODE, &show_memory_ripng_cmd);  
   install_element (RESTRICTED_NODE, &show_memory_babel_cmd);  
   install_element (RESTRICTED_NODE, &show_memory_bgp_cmd);  
   install_element (RESTRICTED_NODE, &show_memory_ospf_cmd);  
   install_element (RESTRICTED_NODE, &show_memory_ospf6_cmd);  
   install_element (RESTRICTED_NODE, &show_memory_isis_cmd);  
   
   install_element (VIEW_NODE, &show_memory_cmd);    install_element (VIEW_NODE, &show_memory_cmd);
   install_element (VIEW_NODE, &show_memory_all_cmd);  
   install_element (VIEW_NODE, &show_memory_lib_cmd);  
   install_element (VIEW_NODE, &show_memory_rip_cmd);  
   install_element (VIEW_NODE, &show_memory_ripng_cmd);  
   install_element (VIEW_NODE, &show_memory_babel_cmd);  
   install_element (VIEW_NODE, &show_memory_bgp_cmd);  
   install_element (VIEW_NODE, &show_memory_ospf_cmd);  
   install_element (VIEW_NODE, &show_memory_ospf6_cmd);  
   install_element (VIEW_NODE, &show_memory_isis_cmd);  
   
   install_element (ENABLE_NODE, &show_memory_cmd);    install_element (ENABLE_NODE, &show_memory_cmd);
   install_element (ENABLE_NODE, &show_memory_all_cmd);  
   install_element (ENABLE_NODE, &show_memory_lib_cmd);  
   install_element (ENABLE_NODE, &show_memory_zebra_cmd);  
   install_element (ENABLE_NODE, &show_memory_rip_cmd);  
   install_element (ENABLE_NODE, &show_memory_ripng_cmd);  
   install_element (ENABLE_NODE, &show_memory_babel_cmd);  
   install_element (ENABLE_NODE, &show_memory_bgp_cmd);  
   install_element (ENABLE_NODE, &show_memory_ospf_cmd);  
   install_element (ENABLE_NODE, &show_memory_ospf6_cmd);  
   install_element (ENABLE_NODE, &show_memory_isis_cmd);  
 }  }
 /* Stats querying from users */  /* Stats querying from users */
 /* Return a pointer to a human friendly string describing  /* Return a pointer to a human friendly string describing
  * the byte count passed in. E.g:   * the byte count passed in. E.g:
Line 570  memory_init (void) Line 440  memory_init (void)
 const char *  const char *
 mtype_memstr (char *buf, size_t len, unsigned long bytes)  mtype_memstr (char *buf, size_t len, unsigned long bytes)
 {  {
  unsigned int t, g, m, k;  unsigned int m, k;
  
   /* easy cases */    /* easy cases */
   if (!bytes)    if (!bytes)
     return "0 bytes";      return "0 bytes";
   if (bytes == 1)    if (bytes == 1)
     return "1 byte";      return "1 byte";
    
  if (sizeof (unsigned long) >= 8)  /*
    /* Hacked to make it not warn on ILP32 machines   * When we pass the 2gb barrier mallinfo() can no longer report
     * Shift will always be 40 at runtime. See below too */   * correct data so it just does something odd...
    t = bytes >> (sizeof (unsigned long) >= 8 ? 40 : 0);   * Reporting like Terrabytes of data.  Which makes users...
  else   * edgy.. yes edgy that's the term for it.
    t = 0;   * So let's just give up gracefully
  g = bytes >> 30;   */
   if (bytes > 0x7fffffff)
     return "> 2GB";
 
   m = bytes >> 20;    m = bytes >> 20;
   k = bytes >> 10;    k = bytes >> 10;
  
  if (t > 10) if (m > 10)
    { 
      /* The shift will always be 39 at runtime. 
       * Just hacked to make it not warn on 'smaller' machines.  
       * Static compiler analysis should mean no extra code 
       */ 
      if (bytes & (1UL << (sizeof (unsigned long) >= 8 ? 39 : 0))) 
        t++; 
      snprintf (buf, len, "%4d TiB", t); 
    } 
  else if (g > 10) 
    { 
      if (bytes & (1 << 29)) 
        g++; 
      snprintf (buf, len, "%d GiB", g); 
    } 
  else if (m > 10) 
     {      {
       if (bytes & (1 << 19))        if (bytes & (1 << 19))
         m++;          m++;

Removed from v.1.1.1.2  
changed lines
  Added in v.1.1.1.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>