]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
update
authorkostas <>
Sat, 28 Feb 1998 10:10:35 +0000 (10:10 +0000)
committerkostas <>
Sat, 28 Feb 1998 10:10:35 +0000 (10:10 +0000)
test-suite/Makefile
test-suite/hash.c
test-suite/hash.h
test-suite/membanger.c

index 9e8856b8c89a159b4b80f566e758a459b9af12f9..ba7ea030a171c86070b83a3edd21a6881b75f9d3 100644 (file)
@@ -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)
index 0a61749ddd239b48b36f6e18a4d018a8c846524e..35edc2e42670297e6084068e3e17f69269cc3977 100644 (file)
@@ -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
 #include <ctype.h>
 #include <sys/time.h>
 #include <strings.h>
+#include <assert.h>
 #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) {
-
-}
 
index 4519945b92f3f6a6cb0176b8ba169a257d936a75..4e2d1a2219e685f8bab885e7f73a3daad383a945 100644 (file)
@@ -38,4 +38,3 @@ void hashFreeMemory(hash_table *);
 HASHHASH hash_string;
 HASHHASH hash_url;
 HASHHASH hash4;
-void assert(int);
index 4db2154b12b55a96328296736b1d3b207fb300f7..81532690ddc4e90b2e981a4d5d0b38c3c94a2c16 100644 (file)
@@ -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 <assert.h>
+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;j<size2id_len;j++)
-               if (size2id_array[0][j]==sz) {
-                       size2id_array[1][j]++;
-                       mi->id=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
+}