*** Help with Runtime Heap and Stack Tracking ***
I am trying to learn my way around Rowley Crossworks for ARM, Cortex M0-4 specifically, we are still evaluating if we want to use this tool rather than the other ones out there. But, the first thing I have found is the "search" and "help" literally can't find anything in the tool itself. So, we use google, and then google usually finds a post here or somewhere else that is semi-helpful.
That said, I need to track real time use of the stack and the heap. I have found the tracking variables for the stack and implemented a sentinel scan to determine how large the stack is, but for the heap, I am having trouble.
Normally, under windows, linux, GCC support a couple functions malloc_stats() and malloc_info() to determine real time heap usage, but within Rowley's C-lib and headers, I can't seem to find anything, but malloc, realloc, calloc, and free?
So, how does one track real time memory use in the heap with Rowley ARM Cortex projects? Is there something I am missing in the debugger perhaps?
My final approach will be to instrument malloc and free and override them with mine, but I would prefer not to do this, there has to be something in Rowley C-lib or debugger to help with this.
I am reading thru the crossworks reference manual, but only a handful of references to the heap. Same on line search here on these forums.
Finally, I would like more technical data on the heap implementation, algorithm, etc. just to decide if I want to implement my own.
Hopefully, someone out there has had the need to interrogate the heap in real time and has a solution to this other than manually instrumenting and overriding malloc and free!
Thanks,
Andre'
-
Look for malloc.c in the "C:\Program Files (x86)\Rowley Associates Limited\CrossWorks for ARM 3.3\source" or wherever yours is located.
Here are a couple of functions I added for usefulness
typedef struct heap_tag
{
struct heap_tag *next;
unsigned size;
} heap_t;
extern heap_t __heap_start__;#define HEAP_CHUNK_SIZE 16 /* Must be a power of two. */
uint32_t freemem(void) {
heap_t *p;
uint32_t mem;__heap_lock();
p = &__heap_start__;
mem = 0;
/* Search for best-fit block. */
while (p) {
mem += p->size;
p = p->next;
}
__heap_unlock();
return mem;
}
uint32_t largestblockmem(void) {
heap_t *p;
uint32_t best_size;__heap_lock();
p = &__heap_start__;
best_size = ~0U;
while (p) {
if (p->size > best_size) {
best_size = p->size;
}
p = p->next;
}
__heap_unlock();
return best_size;
}
Please sign in to leave a comment.
Comments
2 comments