src/backend/utils/mmgr/aset.c
static void
AllocSetStats(MemoryContext context,
			  MemoryStatsPrintFunc printfunc, void *passthru,
			  MemoryContextCounters *totals, bool print_to_stderr)
{
	AllocSet	set = (AllocSet) context;
	Size		nblocks = 0;
	Size		freechunks = 0;
	Size		totalspace;
	Size		freespace = 0;
	AllocBlock	block;
	int			fidx;

	/* Include context header in totalspace */
	totalspace = MAXALIGN(sizeof(AllocSetContext));

	for (block = set->blocks; block != NULL; block = block->next)
	{
		nblocks++;
		totalspace += block->endptr - ((char *) block);
		freespace += block->endptr - block->freeptr;
	}
	for (fidx = 0; fidx < ALLOCSET_NUM_FREELISTS; fidx++)
	{
		AllocChunk	chunk;

		for (chunk = set->freelist[fidx]; chunk != NULL;
			 chunk = (AllocChunk) chunk->aset)
		{
			freechunks++;
			freespace += chunk->size + ALLOC_CHUNKHDRSZ;
		}
	}

	if (printfunc)
	{
		char		stats_string[200];

		snprintf(stats_string, sizeof(stats_string),
				 "%zu total in %zu blocks; %zu free (%zu chunks); %zu used",
				 totalspace, nblocks, freespace, freechunks,
				 totalspace - freespace);
		printfunc(context, passthru, stats_string, print_to_stderr);
	}

	if (totals)
	{
		totals->nblocks += nblocks;
		totals->freechunks += freechunks;
		totals->totalspace += totalspace;
		totals->freespace += freespace;
	}
}
/*
 * AllocSetStats
 *		Compute stats about memory consumption of an allocset.
 *
 * printfunc: if not NULL, pass a human-readable stats string to this.
 * passthru: pass this pointer through to printfunc.
 * totals: if not NULL, add stats about this context into *totals.
 * print_to_stderr: print stats to stderr if true, elog otherwise.
 */
AllocSetStats
Compute stats about memory consumption of an allocset.

if not NULL, pass a human-readable stats string to this.
passthru: pass this pointer through to printfunc.
totals: if not NULL, add stats about this context into *totals.
print_to_stderr: print stats to stderr if true, elog otherwise.
AllocSetStats Compute stats about memory consumption of an allocset . if not NULL pass a human - readable stats string to this . passthru : pass this pointer through to printfunc . totals : if not NULL add stats about this context into * totals . print_to_stderr : print stats to stderr if true elog otherwise .
static void
AllocSetStats(MemoryContext context,
			  MemoryStatsPrintFunc printfunc, void *passthru,
			  MemoryContextCounters *totals, bool print_to_stderr)
{
	AllocSet	set = (AllocSet) context;
	Size		nblocks = 0;
	Size		freechunks = 0;
	Size		totalspace;
	Size		freespace = 0;
	AllocBlock	block;
	int			fidx;
	totalspace = MAXALIGN(sizeof(AllocSetContext));
	for (block = set->blocks; block != NULL; block = block->next)
	{
		nblocks++;
		totalspace += block->endptr - ((char *) block);
		freespace += block->endptr - block->freeptr;
	}
	for (fidx = 0; fidx < ALLOCSET_NUM_FREELISTS; fidx++)
	{
		AllocChunk	chunk;
		for (chunk = set->freelist[fidx]; chunk != NULL;
			 chunk = (AllocChunk) chunk->aset)
		{
			freechunks++;
			freespace += chunk->size + ALLOC_CHUNKHDRSZ;
		}
	}
	if (printfunc)
	{
		char		stats_string[200];
		snprintf(stats_string, sizeof(stats_string),
				 "%zu total in %zu blocks; %zu free (%zu chunks); %zu used",
				 totalspace, nblocks, freespace, freechunks,
				 totalspace - freespace);
		printfunc(context, passthru, stats_string, print_to_stderr);
	}
	if (totals)
	{
		totals->nblocks += nblocks;
		totals->freechunks += freechunks;
		totals->totalspace += totalspace;
		totals->freespace += freespace;
	}
}
static void AllocSetStats ( MemoryContext context , MemoryStatsPrintFunc printfunc , void * passthru , MemoryContextCounters * totals , bool print_to_stderr ) { AllocSet set = ( AllocSet ) context ; Size nblocks = 0 ; Size freechunks = 0 ; Size totalspace ; Size freespace = 0 ; AllocBlock block ; int fidx ; totalspace = MAXALIGN ( sizeof ( AllocSetContext ) ) ; for ( block = set -> blocks ; block != NULL ; block = block -> next ) { nblocks ++ ; totalspace += block -> endptr - ( ( char * ) block ) ; freespace += block -> endptr - block -> freeptr ; } for ( fidx = 0 ; fidx < ALLOCSET_NUM_FREELISTS ; fidx ++ ) { AllocChunk chunk ; for ( chunk = set -> freelist [ fidx ] ; chunk != NULL ; chunk = ( AllocChunk ) chunk -> aset ) { freechunks ++ ; freespace += chunk -> size + ALLOC_CHUNKHDRSZ ; } } if ( printfunc ) { char stats_string [ 200 ] ; snprintf ( stats_string , sizeof ( stats_string ) , " " , totalspace , nblocks , freespace , freechunks , totalspace - freespace ) ; printfunc ( context , passthru , stats_string , print_to_stderr ) ; } if ( totals ) { totals -> nblocks += nblocks ; totals -> freechunks += freechunks ; totals -> totalspace += totalspace ; totals -> freespace += freespace ; } }
AllocSetStats
              Compute stats about memory consumption of an allocset.
AllocSetStats Compute stats about memory consumption of an allocset .
/* Include context header in totalspace */