util/ralloc: add total_size helper
It's useful to determine how much memory a nir_shader consumes for debugging memory bloat, particularly for persistent NIR library. Add a helper that lets us compute this. Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31892>
This commit is contained in:
committed by
Marge Bot
parent
33299354e0
commit
af2a796b13
@@ -264,6 +264,31 @@ ralloc_free(void *ptr)
|
||||
unsafe_free(info);
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
static size_t
|
||||
ralloc_total_size_internal(const ralloc_header *info)
|
||||
{
|
||||
/* Count the block itself. This requires NDEBUG for the statistic. */
|
||||
unsigned sum = align64(info->size + sizeof(ralloc_header),
|
||||
alignof(ralloc_header));
|
||||
|
||||
/* Recursively count children */
|
||||
ralloc_header *it = info->child;
|
||||
while (it != NULL) {
|
||||
sum += ralloc_total_size_internal(it);
|
||||
it = it->next;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
size_t
|
||||
ralloc_total_size(const void *ptr)
|
||||
{
|
||||
return ralloc_total_size_internal(get_header(ptr));
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
unlink_block(ralloc_header *info)
|
||||
{
|
||||
|
||||
@@ -483,6 +483,16 @@ bool ralloc_asprintf_append (char **str, const char *fmt, ...)
|
||||
bool ralloc_vasprintf_append(char **str, const char *fmt, va_list args);
|
||||
/// @}
|
||||
|
||||
/**
|
||||
* Estimate the memory usage in bytes of a ralloc context, recursively including
|
||||
* all of its child counts. This is only available in debug builds as release
|
||||
* builds do not track size information. It is providing as a aid for debugging
|
||||
* memory bloat.
|
||||
*/
|
||||
#ifndef NDEBUG
|
||||
size_t ralloc_total_size(const void *ptr);
|
||||
#endif
|
||||
|
||||
typedef struct gc_ctx gc_ctx;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user