summaryrefslogtreecommitdiff
path: root/src/backend/utils/mmgr
diff options
context:
space:
mode:
authorTom Lane2000-05-21 02:23:30 +0000
committerTom Lane2000-05-21 02:23:30 +0000
commitaa1617911836bd8f500320a365d59920fca2613b (patch)
treeaad6018f3a1cf8b07ff4b06ca00fef3a35c4e1f6 /src/backend/utils/mmgr
parent25a7a7f4469f3c861fbbe72733560dba71ae8ea7 (diff)
Add debug code to aid in memory-leak tracking: if SHOW_MEMORY_STATS is
defined then statistics about memory usage of all the global memory contexts are printed after each commit.
Diffstat (limited to 'src/backend/utils/mmgr')
-rw-r--r--src/backend/utils/mmgr/aset.c40
-rw-r--r--src/backend/utils/mmgr/mcxt.c25
2 files changed, 60 insertions, 5 deletions
diff --git a/src/backend/utils/mmgr/aset.c b/src/backend/utils/mmgr/aset.c
index 4bc96c5a2aa..574b98697d2 100644
--- a/src/backend/utils/mmgr/aset.c
+++ b/src/backend/utils/mmgr/aset.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/aset.c,v 1.26 2000/04/12 17:16:09 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/aset.c,v 1.27 2000/05/21 02:23:29 tgl Exp $
*
* NOTE:
* This is a new (Feb. 05, 1999) implementation of the allocation set
@@ -541,3 +541,41 @@ AllocSetDump(AllocSet set)
{
elog(DEBUG, "Currently unable to dump AllocSet");
}
+
+/*
+ * AllocSetStats
+ * Displays stats about memory consumption of an allocset.
+ */
+void
+AllocSetStats(AllocSet set, const char *ident)
+{
+ long nblocks = 0;
+ long nchunks = 0;
+ long totalspace = 0;
+ long freespace = 0;
+ AllocBlock block;
+ AllocChunk chunk;
+ int fidx;
+
+ AssertArg(AllocSetIsValid(set));
+
+ 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++)
+ {
+ for (chunk = set->freelist[fidx]; chunk != NULL;
+ chunk = (AllocChunk) chunk->aset)
+ {
+ nchunks++;
+ freespace += chunk->size + ALLOC_CHUNKHDRSZ;
+ }
+ }
+ fprintf(stderr,
+ "%s: %ld total in %ld blocks; %ld free (%ld chunks); %ld used\n",
+ ident, totalspace, nblocks, freespace, nchunks,
+ totalspace - freespace);
+}
diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c
index 29af5ce8e2a..5a3be6700e6 100644
--- a/src/backend/utils/mmgr/mcxt.c
+++ b/src/backend/utils/mmgr/mcxt.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/mcxt.c,v 1.20 2000/01/26 05:57:30 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/mcxt.c,v 1.21 2000/05/21 02:23:29 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -489,7 +489,7 @@ GlobalMemoryDump(GlobalMemory this)
if (PointerIsValid(context))
printf("\tsucessor=%s\n", GlobalMemoryGetName(context));
- AllocSetDump(&this->setData); /* XXX is this right interface */
+ AllocSetDump(&this->setData);
}
/*
@@ -511,9 +511,26 @@ DumpGlobalMemories()
{
GlobalMemoryDump(context);
- context = (GlobalMemory) OrderedElemGetSuccessor(
- &context->elemData);
+ context = (GlobalMemory) OrderedElemGetSuccessor(&context->elemData);
}
}
#endif
+
+/*
+ * GlobalMemoryStats
+ * Displays stats about memory consumption of all global contexts.
+ */
+void
+GlobalMemoryStats(void)
+{
+ GlobalMemory context;
+
+ context = (GlobalMemory) OrderedSetGetHead(&ActiveGlobalMemorySetData);
+
+ while (PointerIsValid(context))
+ {
+ AllocSetStats(&context->setData, GlobalMemoryGetName(context));
+ context = (GlobalMemory) OrderedElemGetSuccessor(&context->elemData);
+ }
+}