mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2026-06-20 01:17:49 +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:
@@ -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
|
||||
***********************************************************************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user