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

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:        }
1.1.2.11! misho      37:        /*
        !            38:        mpool_getquota(mp, &curr, NULL);
        !            39:        printf("___current=%lu\n", curr);
        !            40:        */
1.1.2.1   misho      41: 
1.1.2.2   misho      42:        for (i = 0; i < 3; i++) {
1.1.2.4   misho      43:                addr = mpool_malloc(mp, 4000, "mdaaa 4000");
                     44:                if (!addr) {
                     45:                        printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
                     46:                        mpool_destroy(&mp);
                     47:                        return 2;
                     48:                }
                     49:                printf("addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr));
                     50: 
                     51:                strlcpy(addr, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\ndddddd\n", 
                     52:                                mpool_getsizebyaddr(addr));
                     53: //             mpool_free(mp, addr, 0);
                     54:        }
                     55: 
1.1.2.8   misho      56:        mpool_getquota(mp, &curr, NULL);
                     57:        printf("___current=%lu\n", curr);
                     58: 
1.1.2.9   misho      59:        printf("0) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", 
                     60:                        mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, 
                     61:                        mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
                     62:        mpool_statistics(mp, show);
                     63: 
1.1.2.10  misho      64:        addr = mpool_realloc(mp, addr, 1000, "|||||||||||||");
1.1.2.9   misho      65:        if (!addr)
                     66:                printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
                     67:        mpool_getquota(mp, &curr, NULL);
                     68:        printf("addr=%p_current=%lu\n", addr, curr);
                     69: 
1.1.2.7   misho      70:        printf("1) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", 
                     71:                        mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, 
                     72:                        mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
1.1.2.6   misho      73:        mpool_statistics(mp, show);
                     74: 
1.1.2.9   misho      75: 
                     76:        if (addr)
                     77:                mpool_free(mp, addr, 0);
1.1.2.4   misho      78: 
1.1.2.7   misho      79:        printf("2) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", 
                     80:                        mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, 
                     81:                        mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
1.1.2.6   misho      82:        mpool_statistics(mp, show);
                     83: 
1.1.2.4   misho      84:        mpool_purge(mp, 0);
                     85: 
1.1.2.8   misho      86:        mpool_getquota(mp, &curr, NULL);
                     87:        printf("___current=%lu\n", curr);
                     88: 
1.1.2.7   misho      89:        printf("3) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", 
                     90:                        mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, 
                     91:                        mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
1.1.2.6   misho      92:        mpool_statistics(mp, show);
                     93: 
1.1.2.2   misho      94:        addr = mpool_malloc(mp, 4000, "mdaaa 4000");
                     95:        if (!addr) {
                     96:                printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
                     97:                mpool_destroy(&mp);
                     98:                return 2;
                     99:        }
                    100:        printf("addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr));
1.1.2.3   misho     101:        mpool_free(mp, addr, 0);
1.1.2.2   misho     102: 
1.1.2.7   misho     103:        printf("4) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n", 
                    104:                        mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free, 
                    105:                        mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
1.1.2.6   misho     106:        mpool_statistics(mp, show);
1.1.2.1   misho     107:        mpool_destroy(&mp);
                    108:        return 0;
                    109: }

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