Annotation of libaitsess/contrib/test_mem.c, revision 1.1.2.10

1.1.2.1   misho       1: #include <stdio.h>
                      2: #include <aitsess.h>
                      3: 
                      4: 
1.1.2.6   misho       5: void show(u_int size, u_int act, u_int inact)
                      6: {
                      7:        if (!act && !inact)
                      8:                return;
                      9: 
                     10:        if (size < 1024)
                     11:                printf("Statistics:: BUCKET %uB size, %u active, %u inactive\n", size, act, inact);
                     12:        else if (size < 1024 * 1024)
                     13:                printf("Statistics:: BUCKET %uKB size, %u active, %u inactive\n", size / 1024, act, inact);
                     14:        else
                     15:                printf("Statistics:: BUCKET %uMB size, %u active, %u inactive\n", size / (1024 * 1024), act, inact);
                     16: }
                     17: 
1.1.2.1   misho      18: int
                     19: main(int argc, char **argv)
                     20: {
                     21:        mpool_t *mp;
1.1.2.2   misho      22:        void *addr;
                     23:        int i;
1.1.2.8   misho      24:        u_long curr;
1.1.2.2   misho      25: 
1.1.2.3   misho      26:        for (i = 0; i < 3; i++) {
                     27:                addr = malloc(4000);
                     28:                printf("addr=%p\n", addr);
                     29:                free(addr);
                     30:        }
1.1.2.1   misho      31: 
1.1.2.5   misho      32:        mp = mpool_init(0);
1.1.2.1   misho      33:        if (!mp) {
                     34:                printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
                     35:                return 1;
                     36:        }
                     37: 
1.1.2.2   misho      38:        for (i = 0; i < 3; i++) {
1.1.2.4   misho      39:                addr = mpool_malloc(mp, 4000, "mdaaa 4000");
                     40:                if (!addr) {
                     41:                        printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
                     42:                        mpool_destroy(&mp);
                     43:                        return 2;
                     44:                }
                     45:                printf("addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr));
                     46: 
                     47:                strlcpy(addr, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\ndddddd\n", 
                     48:                                mpool_getsizebyaddr(addr));
                     49: //             mpool_free(mp, addr, 0);
                     50:        }
                     51: 
1.1.2.8   misho      52:        mpool_getquota(mp, &curr, NULL);
                     53:        printf("___current=%lu\n", curr);
                     54: 
1.1.2.9   misho      55:        printf("0) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", 
                     56:                        mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, 
                     57:                        mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
                     58:        mpool_statistics(mp, show);
                     59: 
1.1.2.10! misho      60:        addr = mpool_realloc(mp, addr, 1000, "|||||||||||||");
1.1.2.9   misho      61:        if (!addr)
                     62:                printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
                     63:        mpool_getquota(mp, &curr, NULL);
                     64:        printf("addr=%p_current=%lu\n", addr, curr);
                     65: 
1.1.2.7   misho      66:        printf("1) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", 
                     67:                        mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, 
                     68:                        mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
1.1.2.6   misho      69:        mpool_statistics(mp, show);
                     70: 
1.1.2.9   misho      71: 
                     72:        if (addr)
                     73:                mpool_free(mp, addr, 0);
1.1.2.4   misho      74: 
1.1.2.7   misho      75:        printf("2) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", 
                     76:                        mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, 
                     77:                        mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
1.1.2.6   misho      78:        mpool_statistics(mp, show);
                     79: 
1.1.2.4   misho      80:        mpool_purge(mp, 0);
                     81: 
1.1.2.8   misho      82:        mpool_getquota(mp, &curr, NULL);
                     83:        printf("___current=%lu\n", curr);
                     84: 
1.1.2.7   misho      85:        printf("3) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", 
                     86:                        mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, 
                     87:                        mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
1.1.2.6   misho      88:        mpool_statistics(mp, show);
                     89: 
1.1.2.2   misho      90:        addr = mpool_malloc(mp, 4000, "mdaaa 4000");
                     91:        if (!addr) {
                     92:                printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
                     93:                mpool_destroy(&mp);
                     94:                return 2;
                     95:        }
                     96:        printf("addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr));
1.1.2.3   misho      97:        mpool_free(mp, addr, 0);
1.1.2.2   misho      98: 
1.1.2.7   misho      99:        printf("4) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", 
                    100:                        mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, 
                    101:                        mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
1.1.2.6   misho     102:        mpool_statistics(mp, show);
1.1.2.1   misho     103:        mpool_destroy(&mp);
                    104:        return 0;
                    105: }

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