mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-01-18 04:58:51 +02:00
Add memContextSize().
Calculates the memory used by the context and all child contexts. This is primarily useful for debugging but it is not conditional on DEBUG because it is useful for profile/performance tests.
This commit is contained in:
parent
216a61d936
commit
f9d923ca3b
@ -719,6 +719,36 @@ memContextPrior(void)
|
||||
FUNCTION_TEST_RETURN(memContextStack[memContextCurrentStackIdx - priorIdx].memContext);
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
size_t
|
||||
memContextSize(const MemContext *this)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(MEM_CONTEXT, this);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
// Size of struct and child context/alloc arrays
|
||||
size_t result =
|
||||
sizeof(MemContext) + (this->contextChildListSize * sizeof(MemContext *)) +
|
||||
(this->allocListSize * sizeof(MemContextAlloc *));
|
||||
|
||||
// Add child contexts
|
||||
for (unsigned int contextIdx = 0; contextIdx < this->contextChildListSize; contextIdx++)
|
||||
{
|
||||
if (this->contextChildList[contextIdx])
|
||||
result += memContextSize(this->contextChildList[contextIdx]);
|
||||
}
|
||||
|
||||
// Add allocations
|
||||
for (unsigned int allocIdx = 0; allocIdx < this->allocListSize; allocIdx++)
|
||||
{
|
||||
if (this->allocList[allocIdx] != NULL)
|
||||
result += this->allocList[allocIdx]->size;
|
||||
}
|
||||
|
||||
FUNCTION_TEST_RETURN(result);
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
memContextClean(unsigned int tryDepth)
|
||||
|
@ -250,6 +250,9 @@ MemContext *memContextTop(void);
|
||||
// Mem context name
|
||||
const char *memContextName(MemContext *this);
|
||||
|
||||
// Get total size of mem context and all children
|
||||
size_t memContextSize(const MemContext *this);
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Macros for function logging
|
||||
***********************************************************************************************************************************/
|
||||
|
@ -145,6 +145,9 @@ testRun(void)
|
||||
memContextTop()->contextChildList[MEM_CONTEXT_INITIAL_SIZE]->contextChildListSize, MEM_CONTEXT_INITIAL_SIZE,
|
||||
"context child list initial size");
|
||||
|
||||
// This test will change if the contexts above change
|
||||
TEST_RESULT_UINT(memContextSize(memContextTop()), TEST_64BIT() ? 960 : 544, "check size");
|
||||
|
||||
TEST_ERROR(
|
||||
memContextFree(memContextTop()->contextChildList[MEM_CONTEXT_INITIAL_SIZE]),
|
||||
AssertError, "cannot free current context 'test5'");
|
||||
@ -219,6 +222,9 @@ testRun(void)
|
||||
TEST_RESULT_VOID(memNew(3), "new allocation");
|
||||
TEST_RESULT_UINT(memContextCurrent()->allocFreeIdx, MEM_CONTEXT_ALLOC_INITIAL_SIZE + 3, "check alloc free idx");
|
||||
|
||||
// This test will change if the allocations above change
|
||||
TEST_RESULT_UINT(memContextSize(memContextCurrent()), TEST_64BIT() ? 249 : 165, "check size");
|
||||
|
||||
TEST_ERROR(
|
||||
memFree(NULL), AssertError,
|
||||
"assertion '((MemContextAlloc *)buffer - 1) != NULL"
|
||||
|
Loading…
x
Reference in New Issue
Block a user