-
Notifications
You must be signed in to change notification settings - Fork 3k
Add heap stats for IAR #4965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add heap stats for IAR #4965
Conversation
c746b1f
to
e826de3
Compare
It will be nicer if we change dmalloc.c, add wrap function to malloc, free, etc... |
I believe this is not just for IAR, is it? To wrap all functions to enable trace/stats. |
Just in case, as the referenced page above is from 2015, this has no depedency on IAR 8? I would say no it does not. @c1728p9 Please review |
This is just for IAR and not dependent on IAR 8.x version. |
@YarivCol - Yes it would be good to update dlmalloc.c and provide full support. @sg- @bulislaw @0xc0170 @c1728p9 - Do we have any concerns in adding IAR code base file into mbed-os? dlmalloc.c code will be for only IAR support and we will have to re-visit this file everytime we upgrade to new IAR version, to make sure nothing breaks. I compared dlmalloc.c in IAR7.8 and IAR 8.11 versions, and only change was an additional API added |
I dont think this is a file we should check in, rather ask IAR for a hook. |
Isn't this something where one could use "$Super$$ and Example: #include <stdlib.h>
#include <stdio.h>
int main()
{
int * p = (int *)malloc(100);
int * p2 = (int *)malloc(100);
p[2] = 45;
free(p2);
return p[3];
}
extern void * $Super$$__iar_dlmalloc(size_t);
void * $Sub$$__iar_dlmalloc(size_t w)
{
printf("Called with %d\n", w);
return $Super$$__iar_dlmalloc(w);
} |
@TTornblom Github uses |
Thanks Jimmy, I noticed that the formatting was not good and tried wrapping it into the code quotes, but someone (you?) appeared to have fixed it already.
Cheers,
Thomas
15 sep. 2017 kl. 17:16 skrev Jimmy Brisson <notifications@github.com<mailto:notifications@github.com>>:
@TTornblom<https://github.com/ttornblom> Github uses ``` instead of --- for code comments, and you can get syntax highlighting if you specify the language after the first ```C.
-
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#4965 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/Ad-7pczfVqQ8Cn71F4Jvtyof3r00EBJ1ks5sipS3gaJpZM4PAfta>.
|
Oh, FYI @TTornblom, |
I work for IAR and this example was provided by IAR engineering, so works with IAR EWARM :) |
@TTornblom Ah! My bad. Glad to have you in this discussion. |
e826de3
to
8a5dec4
Compare
@sg- @c1728p9 - Please review new implementation for heap stats as per suggestion from @TTornblom |
platform/mbed_alloc_wrappers.cpp
Outdated
@@ -329,6 +329,122 @@ extern "C" void $Sub$$free(void *ptr) { | |||
#endif // #if defined(MBED_MEM_TRACING_ENABLED) || defined(MBED_HEAP_STATS_ENABLED) | |||
|
|||
/******************************************************************************/ | |||
/* IAR memory allocation wrappers */ | |||
/******************************************************************************/ | |||
#elif defined(__ICCARM__) // #if defined(TOOLCHAIN_GCC) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this lingering comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sg- Nah, just kept to have consistency.. Will remove
platform/mbed_alloc_wrappers.cpp
Outdated
/******************************************************************************/ | ||
#elif defined(__ICCARM__) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might be able to combine the ARM and IAR code and just define the function names. Something like this:
#elif defined(TOOLCHAIN_ARM)
#define SUPER_MALLOC $Super$$malloc
#define SUB_MALLOC $Sub$$malloc
...
#elif defined(__ICCARM__)
#define SUPER_MALLOC $Super$$__iar_dlmalloc
#define SUB_MALLOC $Sub$$__iar_dlmalloc
...
#endif
extern "C" {
void *SUPER_MALLOC(size_t);
void *SUPER_REALLOC(void *ptr, size_t size);
void *SUPER_CALLOC(size_t nmemb, size_t size);
void SUPER_FREE(void *ptr);
}
extern "C" void *SUB_MALLOC(size_t size) {
void *ptr = NULL;
...
}
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intentionally separated IAR as was not sure if something additional would be required or not. Since its now working can merge ARM and IAR implementation
565ac7a
to
459e7d4
Compare
/morph test |
Result: ABORTEDYour command has finished executing! Here's what you wrote!
|
/morph test |
Result: SUCCESSYour command has finished executing! Here's what you wrote!
OutputAll builds and test passed! |
Heap stats were not calculated for IAR, since we didn't have mechanism to hook IAR functions.
IAR has internal heap statistic data, which can be enabled and used. Below is the reference link
https://www.iar.com/support/tech-notes/general/iar-dlib-library-heap-usage-statistics/
Only current heap size (with 8 bytes of overhead per malloc) and max heap size is reported.
Below is the output for simple malloc program allocating and freeing 1000 bytes of memory