components/bt: Add more functions for memory debug.

pull/7874/head
baohongde 2019-04-24 15:04:24 +08:00
rodzic 2ad65bb434
commit 8024fcb296
2 zmienionych plików z 76 dodań i 12 usunięć

Wyświetl plik

@ -36,11 +36,17 @@ typedef struct {
} osi_mem_dbg_info_t;
static uint32_t mem_dbg_count = 0;
static uint32_t mem_dbg_count2 = 0;
static osi_mem_dbg_info_t mem_dbg_info[OSI_MEM_DBG_INFO_MAX];
static uint32_t mem_dbg_total_size = 0;
static uint32_t mem_dbg_current_size = 0;
static uint32_t mem_dbg_max_size = 0;
#define OSI_MEM_DBG_MAX_SECTION_NUM 5
typedef struct {
bool used;
uint32_t max_size;
} osi_mem_dbg_max_size_section_t;
static osi_mem_dbg_max_size_section_t mem_dbg_max_size_section[OSI_MEM_DBG_MAX_SECTION_NUM];
void osi_mem_dbg_init(void)
{
int i;
@ -52,9 +58,13 @@ void osi_mem_dbg_init(void)
mem_dbg_info[i].line = 0;
}
mem_dbg_count = 0;
mem_dbg_count2 = 0;
mem_dbg_total_size = 0;
mem_dbg_current_size = 0;
mem_dbg_max_size = 0;
for (i = 0; i < OSI_MEM_DBG_MAX_SECTION_NUM; i++){
mem_dbg_max_size_section[i].used = false;
mem_dbg_max_size_section[i].max_size = 0;
}
}
void osi_mem_dbg_record(void *p, int size, const char *func, int line)
@ -81,9 +91,17 @@ void osi_mem_dbg_record(void *p, int size, const char *func, int line)
OSI_TRACE_ERROR("%s full %s %d !!\n", __func__, func, line);
}
mem_dbg_total_size += size;
if(mem_dbg_max_size < mem_dbg_total_size) {
mem_dbg_max_size = mem_dbg_total_size;
mem_dbg_current_size += size;
if(mem_dbg_max_size < mem_dbg_current_size) {
mem_dbg_max_size = mem_dbg_current_size;
}
for (i = 0; i < OSI_MEM_DBG_MAX_SECTION_NUM; i++){
if (mem_dbg_max_size_section[i].used) {
if(mem_dbg_max_size_section[i].max_size < mem_dbg_current_size) {
mem_dbg_max_size_section[i].max_size = mem_dbg_current_size;
}
}
}
}
@ -98,7 +116,7 @@ void osi_mem_dbg_clean(void *p, const char *func, int line)
for (i = 0; i < OSI_MEM_DBG_INFO_MAX; i++) {
if (mem_dbg_info[i].p == p) {
mem_dbg_total_size -= mem_dbg_info[i].size;
mem_dbg_current_size -= mem_dbg_info[i].size;
mem_dbg_info[i].p = NULL;
mem_dbg_info[i].size = 0;
mem_dbg_info[i].func = NULL;
@ -123,7 +141,7 @@ void osi_mem_dbg_show(void)
}
}
OSI_TRACE_ERROR("--> count %d\n", mem_dbg_count);
OSI_TRACE_ERROR("--> size %dB\n--> max size %dB\n", mem_dbg_total_size, mem_dbg_max_size);
OSI_TRACE_ERROR("--> size %dB\n--> max size %dB\n", mem_dbg_current_size, mem_dbg_max_size);
}
uint32_t osi_mem_dbg_get_max_size(void)
@ -131,9 +149,52 @@ uint32_t osi_mem_dbg_get_max_size(void)
return mem_dbg_max_size;
}
uint32_t osi_mem_dbg_get_total_size(void)
uint32_t osi_mem_dbg_get_current_size(void)
{
return mem_dbg_total_size;
return mem_dbg_current_size;
}
void osi_men_dbg_set_section_start(uint8_t index)
{
if (index >= OSI_MEM_DBG_MAX_SECTION_NUM) {
OSI_TRACE_ERROR("Then range of index should be between 0 and %d, current index is %d.\n",
OSI_MEM_DBG_MAX_SECTION_NUM - 1, index);
return;
}
if (mem_dbg_max_size_section[index].used) {
OSI_TRACE_WARNING("This index(%d) has been started, restart it.\n", index);
}
mem_dbg_max_size_section[index].used = true;
mem_dbg_max_size_section[index].max_size = mem_dbg_current_size;
}
void osi_men_dbg_set_section_end(uint8_t index)
{
if (index >= OSI_MEM_DBG_MAX_SECTION_NUM) {
OSI_TRACE_ERROR("Then range of index should be between 0 and %d, current index is %d.\n",
OSI_MEM_DBG_MAX_SECTION_NUM - 1, index);
return;
}
if (!mem_dbg_max_size_section[index].used) {
OSI_TRACE_ERROR("This index(%d) has not been started.\n", index);
return;
}
mem_dbg_max_size_section[index].used = false;
}
uint32_t osi_mem_dbg_get_max_size_section(uint8_t index)
{
if (index >= OSI_MEM_DBG_MAX_SECTION_NUM){
OSI_TRACE_ERROR("Then range of index should be between 0 and %d, current index is %d.\n",
OSI_MEM_DBG_MAX_SECTION_NUM - 1, index);
return 0;
}
return mem_dbg_max_size_section[index].max_size;
}
#endif

Wyświetl plik

@ -36,7 +36,10 @@ void osi_mem_dbg_record(void *p, int size, const char *func, int line);
void osi_mem_dbg_clean(void *p, const char *func, int line);
void osi_mem_dbg_show(void);
uint32_t osi_mem_dbg_get_max_size(void);
uint32_t osi_mem_dbg_get_total_size(void);
uint32_t osi_mem_dbg_get_current_size(void);
void osi_men_dbg_set_section_start(uint8_t index);
void osi_men_dbg_set_section_end(uint8_t index);
uint32_t osi_mem_dbg_get_max_size_section(uint8_t index);
#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST
#define osi_malloc(size) \