*** ./src/interfaces/libpq/fe-exec.c.orig	2005-11-24 19:06:18.000000000 +0900
--- ./src/interfaces/libpq/fe-exec.c	2005-11-24 21:12:20.000000000 +0900
***************
*** 152,157 ****
--- 152,161 ----
  	result->curOffset = 0;
  	result->spaceLeft = 0;
  
+ 	result->mallocCalls = 0;
+ 	result->spaceAllocated = 0;
+ 	result->spaceUnused = 0;
+ 
  	if (conn)
  	{
  		/* copy connection data we might need for operations on PGresult */
***************
*** 243,248 ****
--- 247,256 ----
  		block = (PGresult_data *) malloc(nBytes + PGRESULT_BLOCK_OVERHEAD);
  		if (!block)
  			return NULL;
+ 
+ 		res->mallocCalls++;
+ 		res->spaceAllocated += nBytes + PGRESULT_BLOCK_OVERHEAD;
+ 
  		space = block->space + PGRESULT_BLOCK_OVERHEAD;
  		if (res->curBlock)
  		{
***************
*** 267,272 ****
--- 275,285 ----
  	block = (PGresult_data *) malloc(PGRESULT_DATA_BLOCKSIZE);
  	if (!block)
  		return NULL;
+ 
+ 	res->mallocCalls++;
+ 	res->spaceAllocated += PGRESULT_DATA_BLOCKSIZE;
+ 	res->spaceUnused += res->spaceLeft;
+ 
  	block->next = res->curBlock;
  	res->curBlock = block;
  	if (isBinary)
***************
*** 348,353 ****
--- 361,372 ----
  	if (!res)
  		return;
  
+ 	fprintf(stderr,
+ 		"malloc calls: %d, allocated(bytes): %d, unused(bytes): %d\n",
+ 		res->mallocCalls,
+ 		res->spaceAllocated,
+ 		res->spaceUnused + res->spaceLeft);
+ 
  	/* Free all the subsidiary blocks */
  	while ((block = res->curBlock) != NULL)
  	{
*** ./src/interfaces/libpq/libpq-int.h.orig	2005-11-24 19:06:13.000000000 +0900
--- ./src/interfaces/libpq/libpq-int.h	2005-11-24 19:07:27.000000000 +0900
***************
*** 176,181 ****
--- 176,185 ----
  	PGresult_data *curBlock;	/* most recently allocated block */
  	int			curOffset;		/* start offset of free space in block */
  	int			spaceLeft;		/* number of free bytes remaining in block */
+ 
+ 	int			mallocCalls;
+ 	int			spaceAllocated;
+ 	int			spaceUnused;
  };
  
  /* PGAsyncStatusType defines the state of the query-execution state machine */
