From: kostas <> Date: Sat, 28 Feb 1998 10:10:35 +0000 (+0000) Subject: update X-Git-Tag: SQUID_3_0_PRE1~3952 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e7740002c82e1f87536e06947598ff530b3b17ce;p=thirdparty%2Fsquid.git update --- diff --git a/test-suite/Makefile b/test-suite/Makefile index 9e8856b8c8..ba7ea030a1 100644 --- a/test-suite/Makefile +++ b/test-suite/Makefile @@ -1,15 +1,23 @@ CC = gcc -CFLAGS = -O2 -OBJS = membanger.o hash.o -LIB = -lmylib +CFLAGS = -g -DWITH_LIB +OBJS = membanger.o hash.o SizeToPool.o +LIB = -L. -lMem +TARGLIB = libMem.a +LIBOBJS = Mem.o \ + Stack.o +AR_R = /usr/bin/ar r +RM = rm +XTRA_LIBS = -lm -lmalloc -all: membanger +all: membanger - -membanger: $(OBJS) - gcc -o membanger $(OBJS) +membanger: $(OBJS) $(TARGLIB) + gcc -o membanger $(OBJS) $(LIB) $(OBJS): Makefile -clean: membanger - rm $(OBJS) +$(TARGLIB): $(LIBOBJS) + $(AR_R) $(TARGLIB) $(LIBOBJS) + +clean: + rm $(OBJS) $(TARGLIB) $(LIBOBJS) diff --git a/test-suite/hash.c b/test-suite/hash.c index 0a61749ddd..35edc2e426 100644 --- a/test-suite/hash.c +++ b/test-suite/hash.c @@ -1,6 +1,6 @@ /* - * $Id: hash.c,v 1.2 1998/02/27 19:04:15 kostas Exp $ + * $Id: hash.c,v 1.3 1998/02/28 03:10:35 kostas Exp $ * * DEBUG: section 0 Hash Tables * AUTHOR: Harvest Derived @@ -111,7 +111,12 @@ #include #include #include +#include #include "hash.h" +#undef free +extern void my_free(char *, int , void *); + +#define free(a) my_free(__FILE__, __LINE__, a) extern void print_stats(); /* @@ -367,8 +372,9 @@ hash_unlink(hash_table * hid, hash_link * hl, int FreeLink) if (walker == hid->current_ptr) hid->current_ptr = walker->next; if (FreeLink) { - if (walker) + if (walker) { free(walker); + } } return 0; } @@ -471,7 +477,4 @@ main(void) exit(0); } #endif -void assert(int a) { - -} diff --git a/test-suite/hash.h b/test-suite/hash.h index 4519945b92..4e2d1a2219 100644 --- a/test-suite/hash.h +++ b/test-suite/hash.h @@ -38,4 +38,3 @@ void hashFreeMemory(hash_table *); HASHHASH hash_string; HASHHASH hash_url; HASHHASH hash4; -void assert(int); diff --git a/test-suite/membanger.c b/test-suite/membanger.c index 4db2154b12..81532690dd 100644 --- a/test-suite/membanger.c +++ b/test-suite/membanger.c @@ -14,6 +14,15 @@ static hash_table *mem_table = NULL; static hash_link *mem_entry; struct rusage myusage; +#ifdef WITH_LIB +#include "Mem.h" +#include +extern void sizeToPoolInit(); +extern MemPool *sizeToPool(size_t size); +#endif +extern char *malloc_options; +void my_free(char *, int, void *); + FILE *fp; char *fn; int initsiz; @@ -30,6 +39,7 @@ int amt; int i; int a; +int run_stats=0; void *my_xmalloc(size_t); void *my_xcalloc(int, size_t); int my_xfree(void *); @@ -48,7 +58,6 @@ typedef struct { #ifdef WITH_LIB MemPool *pool; #endif - int id; int size; } memitem; @@ -60,21 +69,30 @@ memitem *mi; void size2id(size_t, memitem *); void badformat(); void init_stats(), print_stats(); - +void my_hash_insert(hash_table *h, const char *k, memitem *item); +static void *xmemAlloc(memitem *item); +static void xmemFree(memitem *item); int ptrcmp(const void *a,const void *b) { - return (a==b); + return (strcmp(a,b)); } main(int argc,char **argv) { char c; extern char *optarg; + malloc_options = "A"; a=0; - while ((c = getopt(argc, argv, "f:i:M:m:")) != -1) { + while ((c = getopt(argc, argv, "f:i:M:l:m:r:N")) != -1) { switch (c) { + case 'N': + mem_pools_on=0; + break; + case 'r': + run_stats=atoi(optarg); + break; case 'f': fn=strdup(optarg); fp=fopen(fn,"r"); @@ -82,6 +100,9 @@ main(int argc,char **argv) case 'i': initsiz=atoi(optarg); break; + case 'l': + mem_max_size = atoi(optarg)*1024*1024; + break; case 'M': maxsiz=atoi(optarg); break; @@ -101,14 +122,13 @@ main(int argc,char **argv) argv[0], getenv("USER"), argv[0]); exit(1); } +#ifdef WITH_LIB + sizeToPoolInit(); +#endif mem_table = hash_create(ptrcmp, 229, hash4); /* small hash table */ init_stats(); - while (fgets(mbuf, 256, fp)!=NULL) { -#if RUNTIME_STATSA - a++; - if (a%20000==0) print_stats(); -#endif + if (run_stats>0 && (++a)%run_stats==0) print_stats(); p=NULL; switch(mbuf[0]) { case 'm': /* malloc */ @@ -121,8 +141,9 @@ main(int argc,char **argv) strcpy(mi->orig_ptr,p); mi->size=size; size2id(size,mi); - mi->my_ptr=(void *)xmalloc(size); - hash_insert(mem_table, mi->orig_ptr, mi); + mi->my_ptr = xmemAlloc(mi); /* (void *)xmalloc(size); */ + assert(mi->my_ptr); + my_hash_insert(mem_table, mi->orig_ptr, mi); mstat.mallocs++; break; case 'c': /* calloc */ @@ -138,8 +159,9 @@ main(int argc,char **argv) strcpy(mi->orig_ptr,p); size2id(size,mi); mi->size=amt*size; - mi->my_ptr=(void *)xmalloc(amt*size); - hash_insert(mem_table, mi->orig_ptr, mi); + mi->my_ptr= xmemAlloc(mi); /*(void *)xmalloc(amt*size);*/ + assert(mi->my_ptr); + my_hash_insert(mem_table, mi->orig_ptr, mi); mstat.callocs++; break; case 'r': @@ -153,23 +175,30 @@ main(int argc,char **argv) fprintf(stderr,"invalid realloc (%s)!\n",p); break; } - mi=(memitem *)mem_entry; - xfree(mi->my_ptr); + mi=(memitem *)(mem_entry->item); + assert(mi->pool); + assert(mi->my_ptr); + xmemFree(mi); /* xfree(mi->my_ptr); */ + size2id(atoi(p),mi); /* we don't need it here I guess? */ strcpy(mi->orig_ptr,abuf); p=strtok(NULL,"\n"); if (!p) badformat(); - mi->my_ptr=(char *)xmalloc(atoi(p)); + mi->my_ptr= xmemAlloc(mi); /* (char *)xmalloc(atoi(p)); */ + assert(mi->my_ptr); mstat.reallocs++; break; case 'f': p=strtok(&mbuf[2],"\n"); mem_entry=hash_lookup(mem_table, p); if (mem_entry==NULL) { - fprintf(stderr,"invalid free (%s)!\n",p); + if (p[0]!='0') + fprintf(stderr,"invalid free (%s) at line %d!\n",p,a); break; } - mi=(memitem *)mem_entry; - xfree(mi->my_ptr); + mi=(memitem *)(mem_entry->item); + assert(mi->pool); + assert(mi->my_ptr); + xmemFree(mi); /* xfree(mi->my_ptr); */ hash_unlink(mem_table, mem_entry, 1); mstat.frees++; break; @@ -209,10 +238,15 @@ init_stats() void print_stats() { +#ifdef WITH_LIB + memReport(stdout); +#endif getrusage(RUSAGE_SELF, &myusage); printf("m/c/f/r=%d/%d/%d/%d\n",mstat.mallocs,mstat.callocs, mstat.frees, mstat.reallocs); +#if 0 printf("types : %d\n",size2id_len); +#endif printf("user time used : %d.%d\n", (int)myusage.ru_utime.tv_sec, (int)myusage.ru_utime.tv_usec); printf("system time used : %d.%d\n", (int)myusage.ru_stime.tv_sec, @@ -224,34 +258,11 @@ print_stats() void size2id(size_t sz,memitem *mi) { - int j; - for(j=0;jid=j; - return; - } - - /* we have a different size, so we need a new pool */ - - mi->id=size2id_len; #ifdef WITH_LIB - mi->pool = memPoolCreate(size2id_len, sz); + mi->pool = sizeToPool(sz); + assert(mi->pool); #endif - size2id_len++; - if (size2id_len==1) { - size2id_alloc=100; - size2id_array[0]=malloc(size2id_alloc*sizeof(int)); - size2id_array[1]=malloc(size2id_alloc*sizeof(int)); - } else { - if (size2id_len > size2id_alloc ) - size2id_alloc+=100; - size2id_array[0]=realloc(size2id_array[0],size2id_alloc*sizeof(int)); - size2id_array[1]=realloc(size2id_array[1],size2id_alloc*sizeof(int)); - } - - size2id_array[0][size2id_len-1]=sz; - size2id_array[1][size2id_len-1]++; + return; } void @@ -269,3 +280,45 @@ make_nam(int id, int size) sprintf((char *)buf, "pl:%d/%d", id, size); return buf; } + +void +my_hash_insert(hash_table *h, const char *k, memitem *item) +{ + memitem *l; + assert( item->pool); + assert( item->my_ptr); + hash_insert(h,k,item); +} + +static void * +xmemAlloc(memitem *item) +{ + extern MemPool *StringPool; + assert(item && item->pool); + if (StringPool == item->pool) + return memStringAlloc(item->pool, item->size); + else + return memAlloc(item->pool); +} + +static void +xmemFree(memitem *item) +{ + extern MemPool *StringPool; + assert(item && item->pool); + if (StringPool == item->pool) + return memStringFree(item->pool, item->my_ptr, item->size); + else + return memFree(item->pool, item->my_ptr); +} + +void my_free(char *file, int line, void *ptr) +{ +#if 0 +fprintf(stderr,"{%s:%d:%p",file,line,ptr); +#endif +free(ptr); +#if 0 +fprintf(stderr,"}\n"); +#endif +}