summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Conway2007-08-07 06:25:14 +0000
committerNeil Conway2007-08-07 06:25:14 +0000
commit5eb22a1567d42899a86b6582fcb3d519349fc26d (patch)
treeec5134213f520029f2a5fb5817fcaa95b5d2f5b1
parentd40a8d19faf3b1d37f9992f358162f5db7c464d1 (diff)
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().
-rw-r--r--src/backend/utils/mmgr/aset.c9
-rw-r--r--src/backend/utils/mmgr/mcxt.c13
-rw-r--r--src/include/nodes/memnodes.h2
3 files changed, 18 insertions, 6 deletions
diff --git a/src/backend/utils/mmgr/aset.c b/src/backend/utils/mmgr/aset.c
index 6c4f84a810..81dbe75f3f 100644
--- a/src/backend/utils/mmgr/aset.c
+++ b/src/backend/utils/mmgr/aset.c
@@ -214,7 +214,7 @@ static void AllocSetReset(MemoryContext context);
static void AllocSetDelete(MemoryContext context);
static Size AllocSetGetChunkSpace(MemoryContext context, void *pointer);
static bool AllocSetIsEmpty(MemoryContext context);
-static void AllocSetStats(MemoryContext context);
+static void AllocSetStats(MemoryContext context, int level);
#ifdef MEMORY_CONTEXT_CHECKING
static void AllocSetCheck(MemoryContext context);
@@ -1034,7 +1034,7 @@ AllocSetIsEmpty(MemoryContext context)
* Displays stats about memory consumption of an allocset.
*/
static void
-AllocSetStats(MemoryContext context)
+AllocSetStats(MemoryContext context, int level)
{
AllocSet set = (AllocSet) context;
long nblocks = 0;
@@ -1044,6 +1044,7 @@ AllocSetStats(MemoryContext context)
AllocBlock block;
AllocChunk chunk;
int fidx;
+ int i;
for (block = set->blocks; block != NULL; block = block->next)
{
@@ -1060,6 +1061,10 @@ AllocSetStats(MemoryContext context)
freespace += chunk->size + ALLOC_CHUNKHDRSZ;
}
}
+
+ for (i = 0; i < level; i++)
+ fprintf(stderr, " ");
+
fprintf(stderr,
"%s: %lu total in %ld blocks; %lu free (%ld chunks); %lu used\n",
set->header.name, totalspace, nblocks, freespace, nchunks,
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c
index d392376970..8c49df15ab 100644
--- a/src/backend/utils/mmgr/mcxt.c
+++ b/src/backend/utils/mmgr/mcxt.c
@@ -49,6 +49,8 @@ MemoryContext CurTransactionContext = NULL;
/* This is a transient link to the active portal's memory context: */
MemoryContext PortalContext = NULL;
+static void MemoryContextStatsInternal(MemoryContext context, int level);
+
/*****************************************************************************
* EXPORTED ROUTINES *
@@ -321,16 +323,21 @@ MemoryContextIsEmpty(MemoryContext context)
void
MemoryContextStats(MemoryContext context)
{
+ MemoryContextStatsInternal(context, 0);
+}
+
+static void
+MemoryContextStatsInternal(MemoryContext context, int level)
+{
MemoryContext child;
AssertArg(MemoryContextIsValid(context));
- (*context->methods->stats) (context);
+ (*context->methods->stats) (context, level);
for (child = context->firstchild; child != NULL; child = child->nextchild)
- MemoryContextStats(child);
+ MemoryContextStatsInternal(child, level + 1);
}
-
/*
* MemoryContextCheck
* Check all chunks in the named context.
diff --git a/src/include/nodes/memnodes.h b/src/include/nodes/memnodes.h
index 7db193f8b5..13fac47edb 100644
--- a/src/include/nodes/memnodes.h
+++ b/src/include/nodes/memnodes.h
@@ -44,7 +44,7 @@ typedef struct MemoryContextMethods
void (*delete) (MemoryContext context);
Size (*get_chunk_space) (MemoryContext context, void *pointer);
bool (*is_empty) (MemoryContext context);
- void (*stats) (MemoryContext context);
+ void (*stats) (MemoryContext context, int level);
#ifdef MEMORY_CONTEXT_CHECKING
void (*check) (MemoryContext context);
#endif