Implement memory profiler, optimize memory usage, modify code indent (#35)
This commit is contained in:
@ -52,6 +52,8 @@ int bh_memory_init_with_allocator(void *malloc_func, void *free_func);
|
||||
*/
|
||||
void bh_memory_destroy();
|
||||
|
||||
#if BEIHAI_ENABLE_MEMORY_PROFILING == 0
|
||||
|
||||
/**
|
||||
* This function allocates a memory chunk from system
|
||||
*
|
||||
@ -68,6 +70,32 @@ void* bh_malloc(unsigned int size);
|
||||
*/
|
||||
void bh_free(void *ptr);
|
||||
|
||||
#else
|
||||
|
||||
void* bh_malloc_profile(const char *file, int line, const char *func, unsigned int size);
|
||||
void bh_free_profile(const char *file, int line, const char *func, void *ptr);
|
||||
|
||||
#define bh_malloc(size) bh_malloc_profile(__FILE__, __LINE__, __func__, size)
|
||||
#define bh_free(ptr) bh_free_profile(__FILE__, __LINE__, __func__, ptr)
|
||||
|
||||
/**
|
||||
* Print current memory profiling data
|
||||
*
|
||||
* @param file file name of the caller
|
||||
* @param line line of the file of the caller
|
||||
* @param func function name of the caller
|
||||
*/
|
||||
void memory_profile_print(const char *file, int line, const char *func, int alloc);
|
||||
|
||||
/**
|
||||
* Summarize memory usage and print it out
|
||||
* Can use awk to analyze the output like below:
|
||||
* awk -F: '{print $2,$4,$6,$8,$9}' OFS="\t" ./out.txt | sort -n -r -k 1
|
||||
*/
|
||||
void memory_usage_summarize();
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user