mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #9327 from cgundogan/pr/tlsf_total_sizes
tlsf: add custom walker to get total free / used sizes
This commit is contained in:
commit
91c65e40f8
@ -43,6 +43,28 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Struct to hold the total sizes of free and used blocks
|
||||
* Used for @ref tlsf_size_walker()
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned free; /**< total free size */
|
||||
unsigned used; /**< total used size */
|
||||
} tlsf_size_container_t;
|
||||
|
||||
/**
|
||||
* Walk the memory pool to print all block sizes and to calculate
|
||||
* the total amount of free and used block sizes.
|
||||
*
|
||||
* @note This function is passed to tlsf_walk_pool()
|
||||
*
|
||||
* @param ptr Pointer to the current block.
|
||||
* @param size Size of the current block at @p ptr.
|
||||
* @param used Shows whether the current block is used or free.
|
||||
* @param user Custom data expected to be of type ``pointer to tlsf_size_container_t``
|
||||
*/
|
||||
void tlsf_size_walker(void* ptr, size_t size, int used, void* user);
|
||||
|
||||
/**
|
||||
* Add an area of memory to the global allocator pool.
|
||||
*
|
||||
|
@ -63,6 +63,18 @@ tlsf_t *_tlsf_get_global_control(void)
|
||||
return gheap;
|
||||
}
|
||||
|
||||
void tlsf_size_walker(void* ptr, size_t size, int used, void* user)
|
||||
{
|
||||
printf("\t%p %s size: %u (%p)\n", ptr, used ? "used" : "free", (unsigned int)size, ptr);
|
||||
|
||||
if (used) {
|
||||
((tlsf_size_container_t *)user)->used += (unsigned int)size;
|
||||
}
|
||||
else {
|
||||
((tlsf_size_container_t *)user)->free += (unsigned int)size;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate a block of size "bytes"
|
||||
*/
|
||||
|
@ -147,7 +147,10 @@ void ps(void)
|
||||
overall_stacksz, overall_used);
|
||||
# ifdef MODULE_TLSF_MALLOC
|
||||
puts("\nHeap usage:");
|
||||
tlsf_walk_pool(tlsf_get_pool(_tlsf_get_global_control()), NULL, NULL);
|
||||
tlsf_size_container_t sizes = { .free = 0, .used = 0 };
|
||||
tlsf_walk_pool(tlsf_get_pool(_tlsf_get_global_control()), tlsf_size_walker, &sizes);
|
||||
printf("\tTotal free size: %u\n", sizes.free);
|
||||
printf("\tTotal used size: %u\n", sizes.used);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user