File:  [ELWIX - Embedded LightWeight unIX -] / libaitsess / contrib / Attic / test_mem.c
Revision 1.1.2.8: download - view: text, annotated - select for diffs - revision graph
Tue Feb 28 10:34:43 2012 UTC (12 years, 4 months ago) by misho
Branches: sess3_1
added new getquota api
added mpool_realloc()

    1: #include <stdio.h>
    2: #include <aitsess.h>
    3: 
    4: 
    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: 
   18: int
   19: main(int argc, char **argv)
   20: {
   21: 	mpool_t *mp;
   22: 	void *addr;
   23: 	int i;
   24: 	u_long curr;
   25: 
   26: 	for (i = 0; i < 3; i++) {
   27: 		addr = malloc(4000);
   28: 		printf("addr=%p\n", addr);
   29: 		free(addr);
   30: 	}
   31: 
   32: 	mp = mpool_init(0);
   33: 	if (!mp) {
   34: 		printf("Error:: #%d - %s\n", sess_GetErrno(), sess_GetError());
   35: 		return 1;
   36: 	}
   37: 
   38: 	for (i = 0; i < 3; i++) {
   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: 
   52: 	mpool_getquota(mp, &curr, NULL);
   53: 	printf("___current=%lu\n", curr);
   54: 
   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);
   58: 	mpool_statistics(mp, show);
   59: 
   60: 	mpool_free(mp, addr, 0);
   61: 
   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);
   65: 	mpool_statistics(mp, show);
   66: 
   67: 	mpool_purge(mp, 0);
   68: 
   69: 	mpool_getquota(mp, &curr, NULL);
   70: 	printf("___current=%lu\n", curr);
   71: 
   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);
   75: 	mpool_statistics(mp, show);
   76: 
   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));
   84: 	mpool_free(mp, addr, 0);
   85: 
   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);
   89: 	mpool_statistics(mp, show);
   90: 	mpool_destroy(&mp);
   91: 	return 0;
   92: }

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