Diff for /libaitsess/contrib/Attic/test_mem.c between versions 1.1.2.2 and 1.1.2.12

version 1.1.2.2, 2012/02/27 23:57:12 version 1.1.2.12, 2012/02/28 12:45:51
Line 2 Line 2
 #include <aitsess.h>  #include <aitsess.h>
   
   
   void show(u_int size, u_int act, u_int inact)
   {
           if (!act && !inact)
                   return;
   
           if (size < 1024)
                   printf("Statistics:: BUCKET %uB size, %u active, %u inactive\n", size, act, inact);
           else if (size < 1024 * 1024)
                   printf("Statistics:: BUCKET %uKB size, %u active, %u inactive\n", size / 1024, act, inact);
           else
                   printf("Statistics:: BUCKET %uMB size, %u active, %u inactive\n", size / (1024 * 1024), act, inact);
   }
   
 int  int
 main(int argc, char **argv)  main(int argc, char **argv)
 {  {
         mpool_t *mp;          mpool_t *mp;
         void *addr;          void *addr;
         uintptr_t blah = 4000;  
         int i;          int i;
           u_long curr;
   
        printf("blah=%x\n", sizeof(uintptr_t) == sizeof(u_int) ? 0 : blah >> 32);        for (i = 0; i < 3; i++) {
                 addr = malloc(4000);
                 printf("addr=%p\n", addr);
                 free(addr);
         }
   
        mp = mpool_init();        mp = mpool_init(0);
         if (!mp) {          if (!mp) {
                 printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());                  printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
                 return 1;                  return 1;
         }          }
           /*
           mpool_getquota(mp, &curr, NULL);
           printf("___current=%lu\n", curr);
           */
   
         for (i = 0; i < 3; i++) {          for (i = 0; i < 3; i++) {
                   addr = mpool_malloc(mp, 4000, "mdaaa 4000");
                   if (!addr) {
                           printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
                           mpool_destroy(&mp);
                           return 2;
                   }
                   printf("addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr));
   
                   strlcpy(addr, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\ndddddd\n", 
                                   mpool_getsizebyaddr(addr));
   //              mpool_free(mp, addr, 0);
           }
   
           mpool_getquota(mp, &curr, NULL);
           printf("___current=%lu\n", curr);
   
           printf("0) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", 
                           mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, 
                           mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
           mpool_statistics(mp, show);
   
           addr = mpool_realloc(mp, addr, 4010, "|||||||||||||");
           if (!addr)
                   printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
           mpool_getquota(mp, &curr, NULL);
           printf("addr=%p_current=%lu\n", addr, curr);
   
           printf("1) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", 
                           mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, 
                           mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
           mpool_statistics(mp, show);
   
   
           if (addr)
                   mpool_free(mp, addr, 0);
   
           printf("2) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", 
                           mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, 
                           mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
           mpool_statistics(mp, show);
   
           mpool_purge(mp, 0);
   
           mpool_getquota(mp, &curr, NULL);
           printf("___current=%lu\n", curr);
   
           printf("3) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", 
                           mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, 
                           mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
           mpool_statistics(mp, show);
   
         addr = mpool_malloc(mp, 4000, "mdaaa 4000");          addr = mpool_malloc(mp, 4000, "mdaaa 4000");
         if (!addr) {          if (!addr) {
                 printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());                  printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
Line 26  main(int argc, char **argv) Line 98  main(int argc, char **argv)
                 return 2;                  return 2;
         }          }
         printf("addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr));          printf("addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr));
           mpool_free(mp, addr, 0);
   
        strlcpy(addr, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\ndddddd\n",         printf("4) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", 
                        mpool_getsizebyaddr(addr));                        mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, 
//      mpool_free(mp, addr, 0);                        mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
        }        mpool_statistics(mp, show);
 
        mpool_purge(mp, 1); 
 
         mpool_destroy(&mp);          mpool_destroy(&mp);
         return 0;          return 0;
 }  }

Removed from v.1.1.2.2  
changed lines
  Added in v.1.1.2.12


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