Annotation of libaitsess/contrib/test_mem.c, revision 1.1.2.7
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;
24:
1.1.2.3 misho 25: for (i = 0; i < 3; i++) {
26: addr = malloc(4000);
27: printf("addr=%p\n", addr);
28: free(addr);
29: }
1.1.2.1 misho 30:
1.1.2.5 misho 31: mp = mpool_init(0);
1.1.2.1 misho 32: if (!mp) {
33: printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
34: return 1;
35: }
36:
1.1.2.2 misho 37: for (i = 0; i < 3; i++) {
1.1.2.4 misho 38: addr = mpool_malloc(mp, 4000, "mdaaa 4000");
39: if (!addr) {
40: printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
41: mpool_destroy(&mp);
42: return 2;
43: }
44: printf("addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr));
45:
46: strlcpy(addr, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\ndddddd\n",
47: mpool_getsizebyaddr(addr));
48: // mpool_free(mp, addr, 0);
49: }
50:
1.1.2.7 ! misho 51: printf("1) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n",
! 52: mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free,
! 53: mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
1.1.2.6 misho 54: mpool_statistics(mp, show);
55:
1.1.2.4 misho 56: mpool_free(mp, addr, 0);
57:
1.1.2.7 ! misho 58: printf("2) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n",
! 59: mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free,
! 60: mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
1.1.2.6 misho 61: mpool_statistics(mp, show);
62:
1.1.2.4 misho 63: mpool_purge(mp, 0);
64:
1.1.2.7 ! misho 65: printf("3) calls.act=%lu calls.inact=%lu calls.free=%lu; bytes.act=%lu bytes.inact=%lu bytes.free=%lu;\n",
! 66: mp->pool_calls.alloc, mp->pool_calls.cache, mp->pool_calls.free,
! 67: mp->pool_bytes.alloc, mp->pool_bytes.cache, mp->pool_bytes.free);
1.1.2.6 misho 68: mpool_statistics(mp, show);
69:
1.1.2.2 misho 70: addr = mpool_malloc(mp, 4000, "mdaaa 4000");
71: if (!addr) {
72: printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
73: mpool_destroy(&mp);
74: return 2;
75: }
76: printf("addr=%p chkaddr=%d addr_size=%d\n", addr, mpool_chkaddr(addr), mpool_getsizebyaddr(addr));
1.1.2.3 misho 77: mpool_free(mp, addr, 0);
1.1.2.2 misho 78:
1.1.2.7 ! misho 79: printf("4) 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);
1.1.2.1 misho 83: mpool_destroy(&mp);
84: return 0;
85: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>