src/backend/utils/mmgr/mcxt.c
static void
MemoryContextStatsInternal(MemoryContext context, int level,
						   bool print, int max_children,
						   MemoryContextCounters *totals,
						   bool print_to_stderr)
{
	MemoryContextCounters local_totals;
	MemoryContext child;
	int			ichild;

	AssertArg(MemoryContextIsValid(context));

	/* Examine the context itself */
	context->methods->stats(context,
							print ? MemoryContextStatsPrint : NULL,
							(void *) &level,
							totals, print_to_stderr);

	/*
	 * Examine children.  If there are more than max_children of them, we do
	 * not print the rest explicitly, but just summarize them.
	 */
	memset(&local_totals, 0, sizeof(local_totals));

	for (child = context->firstchild, ichild = 0;
		 child != NULL;
		 child = child->nextchild, ichild++)
	{
		if (ichild < max_children)
			MemoryContextStatsInternal(child, level + 1,
									   print, max_children,
									   totals,
									   print_to_stderr);
		else
			MemoryContextStatsInternal(child, level + 1,
									   false, max_children,
									   &local_totals,
									   print_to_stderr);
	}

	/* Deal with excess children */
	if (ichild > max_children)
	{
		if (print)
		{
			if (print_to_stderr)
			{
				int			i;

				for (i = 0; i <= level; i++)
					fprintf(stderr, "  ");
				fprintf(stderr,
						"%d more child contexts containing %zu total in %zu blocks; %zu free (%zu chunks); %zu used\n",
						ichild - max_children,
						local_totals.totalspace,
						local_totals.nblocks,
						local_totals.freespace,
						local_totals.freechunks,
						local_totals.totalspace - local_totals.freespace);
			}
			else
				ereport(LOG_SERVER_ONLY,
						(errhidestmt(true),
						 errhidecontext(true),
						 errmsg_internal("level: %d; %d more child contexts containing %zu total in %zu blocks; %zu free (%zu chunks); %zu used",
										 level,
										 ichild - max_children,
										 local_totals.totalspace,
										 local_totals.nblocks,
										 local_totals.freespace,
										 local_totals.freechunks,
										 local_totals.totalspace - local_totals.freespace)));
		}

		if (totals)
		{
			totals->nblocks += local_totals.nblocks;
			totals->freechunks += local_totals.freechunks;
			totals->totalspace += local_totals.totalspace;
			totals->freespace += local_totals.freespace;
		}
	}
}
/*
 * MemoryContextStatsInternal
 *		One recursion level for MemoryContextStats
 *
 * Print this context if print is true, but in any case accumulate counts into
 * *totals (if given).
 */


Print this context if print is true, but in any case accumulate counts into
*totals (if given).
Print this context if print is true but in any case accumulate counts into * totals ( if given ) .
static void
MemoryContextStatsInternal(MemoryContext context, int level,
						   bool print, int max_children,
						   MemoryContextCounters *totals,
						   bool print_to_stderr)
{
	MemoryContextCounters local_totals;
	MemoryContext child;
	int			ichild;
	AssertArg(MemoryContextIsValid(context));
	context->methods->stats(context,
							print ? MemoryContextStatsPrint : NULL,
							(void *) &level,
							totals, print_to_stderr);
	memset(&local_totals, 0, sizeof(local_totals));
	for (child = context->firstchild, ichild = 0;
		 child != NULL;
		 child = child->nextchild, ichild++)
	{
		if (ichild < max_children)
			MemoryContextStatsInternal(child, level + 1,
									   print, max_children,
									   totals,
									   print_to_stderr);
		else
			MemoryContextStatsInternal(child, level + 1,
									   false, max_children,
									   &local_totals,
									   print_to_stderr);
	}
	if (ichild > max_children)
	{
		if (print)
		{
			if (print_to_stderr)
			{
				int			i;
				for (i = 0; i <= level; i++)
					fprintf(stderr, "  ");
				fprintf(stderr,
						"%d more child contexts containing %zu total in %zu blocks; %zu free (%zu chunks); %zu used\n",
						ichild - max_children,
						local_totals.totalspace,
						local_totals.nblocks,
						local_totals.freespace,
						local_totals.freechunks,
						local_totals.totalspace - local_totals.freespace);
			}
			else
				ereport(LOG_SERVER_ONLY,
						(errhidestmt(true),
						 errhidecontext(true),
						 errmsg_internal("level: %d; %d more child contexts containing %zu total in %zu blocks; %zu free (%zu chunks); %zu used",
										 level,
										 ichild - max_children,
										 local_totals.totalspace,
										 local_totals.nblocks,
										 local_totals.freespace,
										 local_totals.freechunks,
										 local_totals.totalspace - local_totals.freespace)));
		}
		if (totals)
		{
			totals->nblocks += local_totals.nblocks;
			totals->freechunks += local_totals.freechunks;
			totals->totalspace += local_totals.totalspace;
			totals->freespace += local_totals.freespace;
		}
	}
}
static void MemoryContextStatsInternal ( MemoryContext context , int level , bool print , int max_children , MemoryContextCounters * totals , bool print_to_stderr ) { MemoryContextCounters local_totals ; MemoryContext child ; int ichild ; AssertArg ( MemoryContextIsValid ( context ) ) ; context -> methods -> stats ( context , print ? MemoryContextStatsPrint : NULL , ( void * ) & level , totals , print_to_stderr ) ; memset ( & local_totals , 0 , sizeof ( local_totals ) ) ; for ( child = context -> firstchild , ichild = 0 ; child != NULL ; child = child -> nextchild , ichild ++ ) { if ( ichild < max_children ) MemoryContextStatsInternal ( child , level + 1 , print , max_children , totals , print_to_stderr ) ; else MemoryContextStatsInternal ( child , level + 1 , false , max_children , & local_totals , print_to_stderr ) ; } if ( ichild > max_children ) { if ( print ) { if ( print_to_stderr ) { int i ; for ( i = 0 ; i <= level ; i ++ ) fprintf ( stderr , " " ) ; fprintf ( stderr , " \n " , ichild - max_children , local_totals . totalspace , local_totals . nblocks , local_totals . freespace , local_totals . freechunks , local_totals . totalspace - local_totals . freespace ) ; } else ereport ( LOG_SERVER_ONLY , ( errhidestmt ( true ) , errhidecontext ( true ) , errmsg_internal ( " " , level , ichild - max_children , local_totals . totalspace , local_totals . nblocks , local_totals . freespace , local_totals . freechunks , local_totals . totalspace - local_totals . freespace ) ) ) ; } if ( totals ) { totals -> nblocks += local_totals . nblocks ; totals -> freechunks += local_totals . freechunks ; totals -> totalspace += local_totals . totalspace ; totals -> freespace += local_totals . freespace ; } } }
MemoryContextStatsInternal
              One recursion level for MemoryContextStats
MemoryContextStatsInternal One recursion level for MemoryContextStats
/* Examine the context itself */ /*
	 * Examine children.  If there are more than max_children of them, we do
	 * not print the rest explicitly, but just summarize them.
	 */ /* Deal with excess children */