httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgau...@hyperreal.org
Subject cvs commit: apache-1.3/src/main alloc.c
Date Tue, 20 Apr 1999 16:28:48 GMT
dgaudet     99/04/20 09:28:47

  Modified:    src/main alloc.c
  Log:
  ALLOC_STATS support... I don't think this hurts anything... but feel
  free to remove it if someone objects.
  
  Revision  Changes    Path
  1.108     +51 -0     apache-1.3/src/main/alloc.c
  
  Index: alloc.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/main/alloc.c,v
  retrieving revision 1.107
  retrieving revision 1.108
  diff -u -r1.107 -r1.108
  --- alloc.c	1999/04/08 11:36:33	1.107
  +++ alloc.c	1999/04/20 16:28:46	1.108
  @@ -111,6 +111,11 @@
    */
   /* #define MAKE_TABLE_PROFILE */
   
  +/* Provide some statistics on the cost of allocations.  It requires a
  + * bit of an understanding of how alloc.c works.
  + */
  +/* #define ALLOC_STATS */
  +
   #ifdef POOL_DEBUG
   #ifdef ALLOC_USE_MALLOC
   # error "sorry, no support for ALLOC_USE_MALLOC and POOL_DEBUG at the same time"
  @@ -171,6 +176,13 @@
   static union block_hdr *global_block_list;
   #define FREE_POOL	((struct pool *)(-1))
   #endif
  +#ifdef ALLOC_STATS
  +static unsigned long long num_free_blocks_calls;
  +static unsigned long long num_blocks_freed;
  +static unsigned max_blocks_in_one_free;
  +static unsigned num_malloc_calls;
  +static unsigned num_malloc_bytes;
  +#endif
   
   #ifdef ALLOC_DEBUG
   #define FILL_BYTE	((char)(0xa5))
  @@ -208,6 +220,10 @@
        */
       size += CLICK_SZ;
   #endif
  +#ifdef ALLOC_STATS
  +    ++num_malloc_calls;
  +    num_malloc_bytes += size + sizeof(union block_hdr);
  +#endif
       blok = (union block_hdr *) malloc(size + sizeof(union block_hdr));
       if (blok == NULL) {
   	fprintf(stderr, "Ouch!  malloc failed in malloc_block()\n");
  @@ -261,6 +277,9 @@
   	free(blok);
       }
   #else
  +#ifdef ALLOC_STATS
  +    unsigned num_blocks;
  +#endif
       /* First, put new blocks at the head of the free list ---
        * we'll eventually bash the 'next' pointer of the last block
        * in the chain to point to the free blocks we already had.
  @@ -281,7 +300,13 @@
        * now.
        */
   
  +#ifdef ALLOC_STATS
  +    num_blocks = 1;
  +#endif
       while (blok->h.next != NULL) {
  +#ifdef ALLOC_STATS
  +	++num_blocks;
  +#endif
   	chk_on_blk_list(blok, old_free_list);
   	blok->h.first_avail = (char *) (blok + 1);
   	debug_fill(blok->h.first_avail, blok->h.endp - blok->h.first_avail);
  @@ -301,6 +326,15 @@
       /* Finally, reset next pointer to get the old free blocks back */
   
       blok->h.next = old_free_list;
  +
  +#ifdef ALLOC_STATS
  +    if (num_blocks > max_blocks_in_one_free) {
  +	max_blocks_in_one_free = num_blocks;
  +    }
  +    ++num_free_blocks_calls;
  +    num_blocks_freed += num_blocks;
  +#endif
  +
       (void) ap_release_mutex(alloc_mutex);
   #endif
   }
  @@ -448,6 +482,20 @@
   }
   #endif
   
  +#ifdef ALLOC_STATS
  +static void dump_stats(void)
  +{
  +    fprintf(stderr,
  +	"alloc_stats: [%d] #free_blocks %llu #blocks %llu max %u #malloc %u #bytes %u\n",
  +	(int)getpid(),
  +	num_free_blocks_calls,
  +	num_blocks_freed,
  +	max_blocks_in_one_free,
  +	num_malloc_calls,
  +	num_malloc_bytes);
  +}
  +#endif
  +
   pool *ap_init_alloc(void)
   {
   #ifdef POOL_DEBUG
  @@ -459,6 +507,9 @@
       alloc_mutex = ap_create_mutex(NULL);
       spawn_mutex = ap_create_mutex(NULL);
       permanent_pool = ap_make_sub_pool(NULL);
  +#ifdef ALLOC_STATS
  +    atexit(dump_stats);
  +#endif
   
       return permanent_pool;
   }
  
  
  

Mime
View raw message