Hi all,
is it somehow possible to obtain statistic information about the memory usage of a NIOS2 program at runtime? I tried to use the "struct mstats" from the GNU extensions but it seems that this is not implemented here. Thanks, Marco.链接已复制
2 回复数
I'm also searching for function which returns the amount of memory usage.
I only found function mallinfo from newlib, but it gives not the information I need. But maybe enought for your application. Regards Usage:#include <malloc.h>
struct mallinfo meminfo;
meminfo=mallinfo();
# define OUT(DATA) printf("meminfo.%s = %d\n",#DATA,meminfo.DATA);
OUT(arena); // This is the total size of memory allocated with sbrk by malloc, in bytes.
OUT(ordblks); // This is the number of chunks not in use.
OUT(hblks); // This is the total number of chunks allocated with mmap.
OUT(hblkhd); // This is the total size of memory allocated with mmap, in bytes.
OUT(uordblks); // This is the total size of memory occupied by chunks handed out by malloc.
OUT(fordblks); // This is the total size of memory occupied by free (not in use) chunks.
OUT(keepcost); // This is the size of the top-most releasable chunk that normally borders the end of the heap
Hi,
i found a WORK AROUND to optain the approximated memory allocation. This solution uses the function sbrk to optain the current top of the heap pointer and assumes, that the heap is allways placed at last in the memory device. So for non uCOS applications, it ignores the stack allocation.#include "system.h"# include <unistd.h>
# define CONCAT(A,B) A# # B# define CONCAT_MACRO(X,Y) CONCAT(X,Y) // does first Macro expandation and then concatenation# define MEM_START CONCAT_MACRO(ALT_RWDATA_DEVICE,_BASE)# define MEM_END (CONCAT_MACRO(ALT_RWDATA_DEVICE,_BASE) + CONCAT_MACRO(ALT_RWDATA_DEVICE,_SPAN))
...
printf("used memory: %d\n",(unsigned int) sbrk(0) - MEM_START);
printf("free memory: %d\n",MEM_END - (unsigned int) sbrk(0));
If you need it the amount of bytes more detailed, you can use information from mallinfo and stack allocation in non-ucos applications. Regards
