Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 849ec99

Browse files
author
Neil Conway
committed
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().
1 parent 3605c8c commit 849ec99

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

src/backend/utils/mmgr/aset.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/utils/mmgr/aset.c,v 1.72 2007/04/30 00:12:08 tgl Exp $
14+
* $PostgreSQL: pgsql/src/backend/utils/mmgr/aset.c,v 1.73 2007/08/07 06:25:14 neilc Exp $
1515
*
1616
* NOTE:
1717
* This is a new (Feb. 05, 1999) implementation of the allocation set
@@ -214,7 +214,7 @@ static void AllocSetReset(MemoryContext context);
214214
static void AllocSetDelete(MemoryContext context);
215215
static Size AllocSetGetChunkSpace(MemoryContext context, void *pointer);
216216
static bool AllocSetIsEmpty(MemoryContext context);
217-
static void AllocSetStats(MemoryContext context);
217+
static void AllocSetStats(MemoryContext context, int level);
218218

219219
#ifdef MEMORY_CONTEXT_CHECKING
220220
static void AllocSetCheck(MemoryContext context);
@@ -1034,7 +1034,7 @@ AllocSetIsEmpty(MemoryContext context)
10341034
* Displays stats about memory consumption of an allocset.
10351035
*/
10361036
static void
1037-
AllocSetStats(MemoryContext context)
1037+
AllocSetStats(MemoryContext context, int level)
10381038
{
10391039
AllocSet set = (AllocSet) context;
10401040
long nblocks = 0;
@@ -1044,6 +1044,7 @@ AllocSetStats(MemoryContext context)
10441044
AllocBlock block;
10451045
AllocChunk chunk;
10461046
int fidx;
1047+
int i;
10471048

10481049
for (block = set->blocks; block != NULL; block = block->next)
10491050
{
@@ -1060,6 +1061,10 @@ AllocSetStats(MemoryContext context)
10601061
freespace += chunk->size + ALLOC_CHUNKHDRSZ;
10611062
}
10621063
}
1064+
1065+
for (i = 0; i < level; i++)
1066+
fprintf(stderr, " ");
1067+
10631068
fprintf(stderr,
10641069
"%s: %lu total in %ld blocks; %lu free (%ld chunks); %lu used\n",
10651070
set->header.name, totalspace, nblocks, freespace, nchunks,

src/backend/utils/mmgr/mcxt.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.61 2007/07/25 12:22:52 mha Exp $
17+
* $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.62 2007/08/07 06:25:14 neilc Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -49,6 +49,8 @@ MemoryContext CurTransactionContext = NULL;
4949
/* This is a transient link to the active portal's memory context: */
5050
MemoryContext PortalContext = NULL;
5151

52+
static void MemoryContextStatsInternal(MemoryContext context, int level);
53+
5254

5355
/*****************************************************************************
5456
* EXPORTED ROUTINES *
@@ -320,17 +322,22 @@ MemoryContextIsEmpty(MemoryContext context)
320322
*/
321323
void
322324
MemoryContextStats(MemoryContext context)
325+
{
326+
MemoryContextStatsInternal(context, 0);
327+
}
328+
329+
static void
330+
MemoryContextStatsInternal(MemoryContext context, int level)
323331
{
324332
MemoryContext child;
325333

326334
AssertArg(MemoryContextIsValid(context));
327335

328-
(*context->methods->stats) (context);
336+
(*context->methods->stats) (context, level);
329337
for (child = context->firstchild; child != NULL; child = child->nextchild)
330-
MemoryContextStats(child);
338+
MemoryContextStatsInternal(child, level + 1);
331339
}
332340

333-
334341
/*
335342
* MemoryContextCheck
336343
* Check all chunks in the named context.

src/include/nodes/memnodes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/nodes/memnodes.h,v 1.32 2007/01/05 22:19:55 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/nodes/memnodes.h,v 1.33 2007/08/07 06:25:14 neilc Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -44,7 +44,7 @@ typedef struct MemoryContextMethods
4444
void (*delete) (MemoryContext context);
4545
Size (*get_chunk_space) (MemoryContext context, void *pointer);
4646
bool (*is_empty) (MemoryContext context);
47-
void (*stats) (MemoryContext context);
47+
void (*stats) (MemoryContext context, int level);
4848
#ifdef MEMORY_CONTEXT_CHECKING
4949
void (*check) (MemoryContext context);
5050
#endif

0 commit comments

Comments
 (0)