Commit 849ec997 authored by Neil Conway's avatar Neil Conway

Adjust the output of MemoryContextStats() so that the stats for a

child memory contexts is indented two spaces to the right of its
parent context.  This should make it easier to deduce the memory
context hierarchy from the output of MemoryContextStats().
parent 3605c8c8
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/mmgr/aset.c,v 1.72 2007/04/30 00:12:08 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/mmgr/aset.c,v 1.73 2007/08/07 06:25:14 neilc Exp $
* *
* NOTE: * NOTE:
* This is a new (Feb. 05, 1999) implementation of the allocation set * This is a new (Feb. 05, 1999) implementation of the allocation set
...@@ -214,7 +214,7 @@ static void AllocSetReset(MemoryContext context); ...@@ -214,7 +214,7 @@ static void AllocSetReset(MemoryContext context);
static void AllocSetDelete(MemoryContext context); static void AllocSetDelete(MemoryContext context);
static Size AllocSetGetChunkSpace(MemoryContext context, void *pointer); static Size AllocSetGetChunkSpace(MemoryContext context, void *pointer);
static bool AllocSetIsEmpty(MemoryContext context); static bool AllocSetIsEmpty(MemoryContext context);
static void AllocSetStats(MemoryContext context); static void AllocSetStats(MemoryContext context, int level);
#ifdef MEMORY_CONTEXT_CHECKING #ifdef MEMORY_CONTEXT_CHECKING
static void AllocSetCheck(MemoryContext context); static void AllocSetCheck(MemoryContext context);
...@@ -1034,7 +1034,7 @@ AllocSetIsEmpty(MemoryContext context) ...@@ -1034,7 +1034,7 @@ AllocSetIsEmpty(MemoryContext context)
* Displays stats about memory consumption of an allocset. * Displays stats about memory consumption of an allocset.
*/ */
static void static void
AllocSetStats(MemoryContext context) AllocSetStats(MemoryContext context, int level)
{ {
AllocSet set = (AllocSet) context; AllocSet set = (AllocSet) context;
long nblocks = 0; long nblocks = 0;
...@@ -1044,6 +1044,7 @@ AllocSetStats(MemoryContext context) ...@@ -1044,6 +1044,7 @@ AllocSetStats(MemoryContext context)
AllocBlock block; AllocBlock block;
AllocChunk chunk; AllocChunk chunk;
int fidx; int fidx;
int i;
for (block = set->blocks; block != NULL; block = block->next) for (block = set->blocks; block != NULL; block = block->next)
{ {
...@@ -1060,6 +1061,10 @@ AllocSetStats(MemoryContext context) ...@@ -1060,6 +1061,10 @@ AllocSetStats(MemoryContext context)
freespace += chunk->size + ALLOC_CHUNKHDRSZ; freespace += chunk->size + ALLOC_CHUNKHDRSZ;
} }
} }
for (i = 0; i < level; i++)
fprintf(stderr, " ");
fprintf(stderr, fprintf(stderr,
"%s: %lu total in %ld blocks; %lu free (%ld chunks); %lu used\n", "%s: %lu total in %ld blocks; %lu free (%ld chunks); %lu used\n",
set->header.name, totalspace, nblocks, freespace, nchunks, set->header.name, totalspace, nblocks, freespace, nchunks,
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.61 2007/07/25 12:22:52 mha Exp $ * $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.62 2007/08/07 06:25:14 neilc Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -49,6 +49,8 @@ MemoryContext CurTransactionContext = NULL; ...@@ -49,6 +49,8 @@ MemoryContext CurTransactionContext = NULL;
/* This is a transient link to the active portal's memory context: */ /* This is a transient link to the active portal's memory context: */
MemoryContext PortalContext = NULL; MemoryContext PortalContext = NULL;
static void MemoryContextStatsInternal(MemoryContext context, int level);
/***************************************************************************** /*****************************************************************************
* EXPORTED ROUTINES * * EXPORTED ROUTINES *
...@@ -320,17 +322,22 @@ MemoryContextIsEmpty(MemoryContext context) ...@@ -320,17 +322,22 @@ MemoryContextIsEmpty(MemoryContext context)
*/ */
void void
MemoryContextStats(MemoryContext context) MemoryContextStats(MemoryContext context)
{
MemoryContextStatsInternal(context, 0);
}
static void
MemoryContextStatsInternal(MemoryContext context, int level)
{ {
MemoryContext child; MemoryContext child;
AssertArg(MemoryContextIsValid(context)); AssertArg(MemoryContextIsValid(context));
(*context->methods->stats) (context); (*context->methods->stats) (context, level);
for (child = context->firstchild; child != NULL; child = child->nextchild) for (child = context->firstchild; child != NULL; child = child->nextchild)
MemoryContextStats(child); MemoryContextStatsInternal(child, level + 1);
} }
/* /*
* MemoryContextCheck * MemoryContextCheck
* Check all chunks in the named context. * Check all chunks in the named context.
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/nodes/memnodes.h,v 1.32 2007/01/05 22:19:55 momjian Exp $ * $PostgreSQL: pgsql/src/include/nodes/memnodes.h,v 1.33 2007/08/07 06:25:14 neilc Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -44,7 +44,7 @@ typedef struct MemoryContextMethods ...@@ -44,7 +44,7 @@ typedef struct MemoryContextMethods
void (*delete) (MemoryContext context); void (*delete) (MemoryContext context);
Size (*get_chunk_space) (MemoryContext context, void *pointer); Size (*get_chunk_space) (MemoryContext context, void *pointer);
bool (*is_empty) (MemoryContext context); bool (*is_empty) (MemoryContext context);
void (*stats) (MemoryContext context); void (*stats) (MemoryContext context, int level);
#ifdef MEMORY_CONTEXT_CHECKING #ifdef MEMORY_CONTEXT_CHECKING
void (*check) (MemoryContext context); void (*check) (MemoryContext context);
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment