Annotation of libaitsess/contrib/test_mem.c, revision 1.1.2.8
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.7 misho 55: printf("1) 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);
1.1.2.6 misho 58: mpool_statistics(mp, show);
59:
1.1.2.4 misho 60: mpool_free(mp, addr, 0);
61:
1.1.2.7 misho 62: printf("2) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n",
63: mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free,
64: mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
1.1.2.6 misho 65: mpool_statistics(mp, show);
66:
1.1.2.4 misho 67: mpool_purge(mp, 0);
68:
1.1.2.8 ! misho 69: mpool_getquota(mp, &curr, NULL);
! 70: printf("___current=%lu\n", curr);
! 71:
1.1.2.7 misho 72: printf("3) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n",
73: mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free,
74: mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
1.1.2.6 misho 75: mpool_statistics(mp, show);
76:
1.1.2.2 misho 77: addr = mpool_malloc(mp, 4000, "mdaaa 4000");
78: if (!addr) {
79: printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
80: mpool_destroy(&mp);
81: return 2;
82: }
83: printf("addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr));
1.1.2.3 misho 84: mpool_free(mp, addr, 0);
1.1.2.2 misho 85:
1.1.2.7 misho 86: printf("4) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n",
87: mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free,
88: mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
1.1.2.6 misho 89: mpool_statistics(mp, show);
1.1.2.1 misho 90: mpool_destroy(&mp);
91: return 0;
92: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>